task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
MoEngage has a bundle of N sticks. The i^{th} stick has a length L_{i} meters.
Find the minimum number of sticks (of any length) you need to add to the bundle such that you can construct some [rectangles] where each stick of the bundle belongs to exact... | {"inputs": ["4\n1\n1\n2\n2 5\n4\n2 2 3 3\n7\n1 3 5 7 1 7 5\n"], "outputs": ["3\n2\n0\n1\n"]} | 473 | 56 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings s and t, transform string s into string t using the following operation any number of times:
Choose a non-empty substring in s and sort it in place so the characters are in ascending order.
For e... | {"functional": "def check(candidate):\n assert candidate(s = \"84532\", t = \"34852\") == True\n assert candidate(s = \"34521\", t = \"23415\") == True\n assert candidate(s = \"12345\", t = \"12435\") == False\n assert candidate(s = \"1\", t = \"2\") == False\n\n\ncheck(Solution().isTransformable)"} | 152 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n differen... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 2 3\n", "3\n2 1 3\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]} | 540 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of equal-length strings words. Assume that the length of each string is n.
Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i]... | {"functional": "def check(candidate):\n assert candidate(words = [\"adc\",\"wzy\",\"abc\"]) == \"abc\"\n assert candidate(words = [\"aaa\",\"bob\",\"ccc\",\"ddd\"]) == \"bob\"\n\n\ncheck(Solution().oddString)"} | 234 | 60 |
coding | Solve the programming task below in a Python markdown code block.
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region.
The front and back sides of these cards can be distinguished, an... | {"inputs": ["2 2\n", "1 7\n", "1 1\n", "2 8\n", "314 1592\n", "237891668 1\n", "1 1000000000\n", "17890722 23878637\n"], "outputs": ["0\n", "5\n", "1\n", "0\n", "496080\n", "237891666\n", "999999998\n", "427205972767200\n"]} | 263 | 157 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string S of length N. Your task is to check if there exists a [substring] of S which is the binary representation of a [prime number].
Formally, check if there exist integers L and R such that 1 ≤ L ≤ R ≤ N, and the substring S_{L... | {"inputs": ["3\n1\n111\n101101"], "outputs": ["No\nYes\nYes"]} | 521 | 29 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'.
A string is called balanced if and only if:
It is the empty string, or
It... | {"functional": "def check(candidate):\n assert candidate(s = \"][][\") == 1\n assert candidate(s = \"]]][[[\") == 2\n assert candidate(s = \"[]\") == 0\n\n\ncheck(Solution().minSwaps)"} | 160 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Not considering number 1, the integer 153 is the first integer having this property:
the sum of the third-power of each of its digits is equal to 153. Take a look:
153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
The next number that experiments this particu... | {"functional": "_inputs = [[100, 2], [1000, 2], [2000, 2], [200, 3], [370, 3], [400, 3], [500, 3], [1000, 3], [1500, 3]]\n_outputs = [[[]], [[]], [[]], [[153]], [[153, 370]], [[153, 370, 371]], [[153, 370, 371, 407]], [[153, 370, 371, 407]], [[153, 370, 371, 407]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if is... | 291 | 323 |
coding | Solve the programming task below in a Python markdown code block.
Given are N positive integers A_1,...,A_N.
Consider positive integers B_1, ..., B_N that satisfy the following condition.
Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.
Find the minimum possible value of B_1 + ... + B_N f... | {"inputs": ["1\n1\n", "1\n12\n", "3\n2 3 2", "3\n2 6 2", "3\n1 6 2", "3\n3 3 4", "3\n2 5 2", "3\n3 6 2"], "outputs": ["1\n", "1\n", "8\n", "7\n", "10\n", "11\n", "12\n", "6\n"]} | 270 | 108 |
coding | Solve the programming task below in a Python markdown code block.
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the n... | {"inputs": ["4\n4\n1 2 4 100\n4\n100 000 100 1\n5\n5 1 1 1 8\n6\n1 2 3 4 5 6\n", "4\n4\n1 2 5 100\n4\n100 100 100 1\n5\n5 2 1 1 8\n6\n1 2 3 6 5 6\n", "4\n4\n1 0 6 100\n4\n000 101 100 2\n5\n5 1 1 1 8\n6\n1 1 2 3 0 7\n", "4\n4\n2 2 2 100\n4\n100 101 100 1\n5\n5 1 1 1 2\n6\n1 2 4 1 5 6\n", "4\n4\n1 2 6 100\n4\n100 111 100... | 667 | 550 |
coding | Solve the programming task below in a Python markdown code block.
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordina... | {"inputs": ["1 1\n0\n0\n", "1 1\n1\n1\n", "1 1\n0\n1\n", "1 1\n5\n5\n", "1 1\n0\n0\n", "1 1\n5\n5\n", "1 1\n0\n1\n", "1 1\n1\n1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 639 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5], requests = [[1,3],[0,1]]) == 19\n assert candidate(nums = [1,2,3,4,5,6], requests = [[0,1]]) == 11\n assert candidate(nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]) == 47\n\n\ncheck(Solution().maxSumRangeQuery)"} | 162 | 122 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Two integer numbers are added using the column addition method. When using this method, some additions of digits produce non-zero carries to the next positions. Your task is to calculate the number of non-zero carries that will occur while adding... | {"functional": "_inputs = [[543, 3456], [1927, 6426], [9999, 1], [1234, 5678]]\n_outputs = [[0], [2], [4], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if... | 249 | 206 |
coding | Solve the programming task below in a Python markdown code block.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, nu... | {"inputs": ["1\n0\n0\n", "1\n1\n0\n", "1\n1\n1\n", "1\n0\n1\n", "1\n0\n2\n", "1\n0\n4\n", "1\n0\n3\n", "1\n0\n-1\n"], "outputs": ["0\n", "1\n1\n", "0\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n"]} | 477 | 115 |
coding | Solve the programming task below in a Python markdown code block.
You will be given a string S of length 3 representing the weather forecast for three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.
You w... | {"inputs": ["CSS\nBSR", "SRR\nSSR", "SSR\nRTS", "STR\nSTR", "RSR\nSSS", "SSC\nBSR", "RSR\nSSR", "SSR\nRSS"], "outputs": ["1\n", "2\n", "0\n", "3\n", "1\n", "1\n", "2\n", "1\n"]} | 301 | 90 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.
You are also given two 0-indexed integer arrays... | {"functional": "def check(candidate):\n assert candidate(initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]) == 8\n assert candidate(initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]) == 0\n\n\ncheck(Solution().minNumberOfHours)"} | 242 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.
Note t... | {"inputs": ["4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n", "3 1000000000\n-5 -1 1\n", "1 14751211\n847188590\n", "2 1000000000\n-14348867 1760823\n", "10 5\n31 36 43 47 48 50 56 69 71 86\n", "10 50\n1 4 20 27 65 79 82 83 99 100\n"], "outputs": ["4\n", "2\n", "1\n", "1\n", "0\n", "0\n", "2\n", "25\n"]} | 375 | 241 |
coding | Solve the programming task below in a Python markdown code block.
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
-----Input--... | {"inputs": ["1 1\n9\n1\n", "1 1\n8\n9\n", "1 1\n9\n8\n", "1 1\n1\n2\n", "1 1\n2\n1\n", "1 1\n9\n9\n", "1 1\n1\n1\n", "1 1\n1\n2\n"], "outputs": ["19\n", "89\n", "89\n", "12\n", "12\n", "9\n", "1\n", "12\n"]} | 353 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Create a program to determine the positional relationship between a triangle and a circle on a plane. All target figures shall include boundaries. The triangle is given the position of three vertices, and the circle is given the position of the center an... | {"inputs": ["4 0\n3 1\n3 3\n3 3\n1\n4 3\n8 2\n4 12\n8 9\n5\n0 0\n52 2\n8 5\n2 2\n5\n3 7\n23 2\n4 9\n37 1\n0\n0 0", "2 0\n3 1\n3 3\n3 3\n1\n4 3\n16 2\n4 12\n8 9\n5\n5 0\n10 2\n8 5\n7 2\n5\n3 7\n23 2\n16 9\n37 1\n0\n0 0", "2 0\n3 1\n3 3\n3 3\n1\n4 3\n16 2\n4 12\n8 9\n5\n5 0\n10 2\n8 5\n7 2\n0\n3 7\n23 2\n16 9\n37 1\n0\n0... | 393 | 754 |
coding | Solve the programming task below in a Python markdown code block.
Who's interested in football?
Rayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since.
He's got proper treatment and ... | {"inputs": ["3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 2 2 3"], "outputs": ["4\nUNFIT\n1"]} | 640 | 55 |
coding | Solve the programming task below in a Python markdown code block.
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* 0 ≤ wi ≤ 10,000
* G has arborescence(s) with the root r
Input
|V| |... | {"inputs": ["4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "4 6 0\n0 1 1\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "4 6 0\n0 1 1\n0 2 2\n3 1 1\n2 3 3\n3 0 0\n0 1 7", "4 6 0\n0 1 1\n0 2 2\n2 0 1\n2 3 0\n3 1 1\n3 1 5", "4 5 0\n0 1 4\n0 2 2\n3 1 1\n1 3 3\n3 0 0\n0 1 9", "4 5 0\n0 1 2\n0 2 3\n3 1 1\n1 3 3\n3 0 0\n0 1 9", "4... | 371 | 383 |
coding | Solve the programming task below in a Python markdown code block.
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the... | {"inputs": ["1\no\n", "1\no\n", "1\nn\n", "1\np\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\nq\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | 215 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Arkady coordinates rounds on some not really famous competitive programming platform. Each round features $n$ problems of distinct difficulty, the difficulties are numbered from $1$ to $n$.
To hold a round Arkady needs $n$ new (not used previously) prob... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "9 1\n1\n", "2 1\n1\n", "3 1\n1\n", "10 1\n1\n", "10 1\n1\n", "10 1\n2\n"], "outputs": ["1\n", "1", "0\n", "0\n", "0\n", "0\n", "0", "0\n"]} | 492 | 103 |
coding | Solve the programming task below in a Python markdown code block.
In this kata the function returns an array/list of numbers without its last element. The function is already written for you and the basic tests pass, but random tests fail. Your task is to figure out why and fix it.
Good luck!
Hint: watch out for side... | {"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[9, 7, 6, 9]]]\n_outputs = [[[1, 2, 3, 4]], [[9, 7, 6]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) ... | 164 | 197 |
coding | Solve the programming task below in a Python markdown code block.
Make a function **"add"** that will be able to sum elements of **list** continuously and return a new list of sums.
For example:
```
add [1,2,3,4,5] == [1, 3, 6, 10, 15], because it's calculated like
this : [1, 1 + 2, 1 + 2 + 3, 1 + 2 + 3 + 4, 1 + 2 ... | {"functional": "_inputs = [[[5, 10, 15, 20, 25, 30, 35, 40]], [[6, 12, 18, 24, 30, 36, 42]], [[7, 14, 21, 28, 35, 42, 49, 56]], [[8, 16, 24, 32, 40, 48, 56, 64]], [[9, 18, 27, 36, 45, 54]]]\n_outputs = [[[5, 15, 30, 50, 75, 105, 140, 180]], [[6, 18, 36, 60, 90, 126, 168]], [[7, 21, 42, 70, 105, 147, 196, 252]], [[8, 24... | 169 | 448 |
coding | Solve the programming task below in a Python markdown code block.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them contain... | {"inputs": ["5 3 2 3\n", "1 1 1 1\n", "1 2 1 2\n", "1 1 2 2\n", "1 2 1 2\n", "1 1 1 1\n", "1 1 2 2\n", "5 3 2 1\n"], "outputs": ["4\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "10\n"]} | 302 | 119 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.
For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.... | {"functional": "def check(candidate):\n assert candidate(grid = [[1],[22],[333]]) == [3]\n assert candidate(grid = [[-15,1,3],[15,7,12],[5,6,-2]]) == [3,1,2]\n\n\ncheck(Solution().findColumnWidth)"} | 162 | 77 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n matrix grid consisting of positive integers.
You can start at any cell in the first column of the matrix, and traverse the grid in the following way:
From a cell (row, col), you can mo... | {"functional": "def check(candidate):\n assert candidate(grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]) == 3\n assert candidate(grid = [[3,2,4],[2,1,9],[1,1,7]]) == 0\n\n\ncheck(Solution().maxMoves)"} | 172 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Given are integers N and K.
How many quadruples of integers (a,b,c,d) satisfy both of the following conditions?
- 1 \leq a,b,c,d \leq N
- a+b-c-d=K
-----Constraints-----
- 1 \leq N \leq 10^5
- -2(N-1) \leq K \leq 2(N-1)
- All numbers in input are i... | {"inputs": ["2 1\n", "1 0\n", "2525 -425\n", "23294 13184\n", "97692 12674\n", "24115 24178\n", "66977 75123\n", "13582 27162\n"], "outputs": ["4\n", "1\n", "10314607400\n", "5523272501050\n", "606889464360839\n", "2319008467426\n", "33936530568560\n", "1\n"]} | 215 | 192 |
coding | Solve the programming task below in a Python markdown code block.
Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k × k consis... | {"inputs": ["1 1 1 0\n", "1 1 1 0\n", "1 2 1 0\n", "1 2 2 0\n", "1 4 1 0\n", "1 4 2 0\n", "500 24 2 0\n", "500 24 4 0\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 432 | 125 |
coding | Solve the programming task below in a Python markdown code block.
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. Here, h_1 < h_2 < \cdots < h_N holds.
There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reac... | {"inputs": ["5 6\n1 2 3 4 5", "8 5\n1 3 4 6 10 11 12 13", "8 5\n1 3 4 6 10 11 12 14", "8 3\n1 3 4 6 10 11 12 13", "8 3\n2 3 4 8 10 11 12 13", "8 5\n1 3 4 5 10 11 12 13", "2 1100100000001\n91876 1100011", "2 0100010000100\n13404 1101001"], "outputs": ["20", "58\n", "62\n", "48\n", "44\n", "62", "2116436178226\n", "12828... | 390 | 268 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a string $S$ consisting of lowercase English characters. Chef defined functions left shift $L(X)$ and right shift $R(X)$ as follows.
$L(X)$ is defined as shifting all characters of string $X$ one step towards left and moving the first character... | {"inputs": ["4\na\nab\nabcd\naaaaa"], "outputs": ["YES\nYES\nNO\nYES"]} | 408 | 27 |
coding | Solve the programming task below in a Python markdown code block.
A Train started its journey at x=-infinity is travelling on the x-Coordinate Axis. Given n passengers and the coordinates $b_i$ and $d_i$ for each of the $ith$ passenger at which they board and leave from the train respectively. Due to current COVID-19 c... | {"inputs": ["3\n0 2\n1 3\n-1 4"], "outputs": ["12"]} | 446 | 26 |
coding | Solve the programming task below in a Python markdown code block.
The electrical resistance is the opposition to the passage of electric current. If two resistors with resistance R1 and R2 are connected to each other, the resultant resistance R depends on how their ends are connected. If they are connected in Series, t... | {"inputs": ["3\n1 8\n1 7\n101 00010", "3\n1 8\n1 7\n001 10010", "3\n1 8\n1 6\n100 10010", "3\n1 10\n2 3\n100 10010", "3\n1 14\n2 3\n100 10011", "3\n1 14\n4 3\n100 10011", "3\n1 14\n4 3\n100 11011", "3\n1 10\n2 3\n100 11010"], "outputs": ["1/1\n1/1\n6/1\n", "1/1\n1/1\n1/1\n", "1/1\n1/1\n5501/5775\n", "1/1\n2/0\n5501/577... | 439 | 326 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
While vacationing in Egypt, Chef found a recipe of an ancient dish. The receipt is a sequence of hieroglyphs written on a magic paper - it survived for thousands of years! Th... | {"inputs": ["3\n3 3\n1 2\n2 3\n1 3\n3 2\n1 2\n1 3\n5 4\n1 3\n2 3\n3 4\n2 5"], "outputs": ["1\n2\n2"]} | 660 | 64 |
coding | Solve the programming task below in a Python markdown code block.
Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinates he can'... | {"inputs": ["3\n2 1\n3 3\n10 5"], "outputs": ["2\n1\n252"]} | 221 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$.
Chef wants to rearrange the caps in such a way that no m... | {"inputs": ["2\n9\n1 1 1 2 2 2 3 3 3\n2\n1 1"], "outputs": ["Yes\n2 2 2 3 3 3 1 1 1\nNo"]} | 430 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy... | {"inputs": ["1\n4 1\n3 4 5 1"], "outputs": ["4"]} | 626 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
All bandits are afraid of Sheriff. Sheriff constantly fights crime, but when bandits lay low, he gets bored and starts to entertain himself.
This time Sheriff gathered all the bandits in his ga... | {"inputs": ["2\n3\n1 2 3\n5\n2 3 1 5 4", "2\n2\n1 2 3\n5\n2 3 1 5 4", "2\n3\n1 2 3\n5\n4 3 1 5 2", "2\n3\n2 1 3\n5\n4 3 1 5 2", "2\n2\n1 2 3\n5\n4 3 1 5 2", "2\n1\n1 2 3\n5\n2 3 1 5 4", "2\n1\n1 2 3\n5\n4 3 1 5 2", "2\n2\n2 1 3\n5\n4 3 1 5 2"], "outputs": ["1\n6", "1\n6\n", "1\n5\n", "2\n5\n", "1\n5\n", "1\n6\n", "1\n5... | 516 | 237 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([10,5,15,3,7,None,18]), low = 7, high = 15) == 32\n assert candidate(root = tree_node([10,5,15,3,7,13,18,1,None,6]), low = 6, high = 10) == 23\n\n\ncheck(Solution().rangeSumBST)"} | 145 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substr... | {"inputs": ["3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi", "3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nipp", "3\ncodechef\n2\ncode\ndhef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nipp", "3\ncodechef\n2\ncode\ndhef\nfoo\n1\nbar\nmississippi\n4\ns... | 380 | 391 |
coding | Solve the programming task below in a Python markdown code block.
Chef usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Chef's friend Dustin gave him binary strings $S$ and $R$, each with length $N$, and told him to make them identical. However, unlike ... | {"inputs": ["2\n5\n11000\n01001\n3\n110\n001"], "outputs": ["YES\nNO"]} | 478 | 38 |
coding | Solve the programming task below in a Python markdown code block.
The goal is to write a pair of functions the first of which will take a string of binary along with a specification of bits, which will return a numeric, signed complement in two's complement format. The second will do the reverse. It will take in an int... | {"functional": "_inputs = [['00000001', 8], ['00000010', 8], ['01111110', 8], ['01111111', 8], ['11111111', 8], ['11111110', 8], ['10000010', 8], ['1000 0000', 8], ['1010 1010 0010 0010 1110 1010 0010 1110', 32], ['1000 0000 1110 1111 0011 0100 1100 1010', 32], ['10110001000100000101100011111000', 32]]\n_outputs = [[1]... | 238 | 452 |
coding | Solve the programming task below in a Python markdown code block.
Write a program to take two numbers as input and print their difference if the first number is greater than the second number otherwise$otherwise$ print their sum.
-----Input:-----
- First line will contain the first number (N1$N1$)
- Second line will c... | {"inputs": ["82\n28"], "outputs": ["54"]} | 226 | 17 |
coding | Solve the programming task below in a Python markdown code block.
Word $s$ of length $n$ is called $k$-complete if $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$; $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \le i \le n-k$.
For example, "abaaba" is a $3$-complete word, while "abccba" i... | {"inputs": ["4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n", "4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotononstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n", "4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 3\nwudixiaoxingxing... | 551 | 509 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a binary string S of length N. Chef wants to find two substrings of equal length, such that their [bitwise XOR] is maximised.
Formally, Chef wants to find L_{1}, R_{1}, L_{2}, and R_{2} such that:
1 ≤ L_{1} ≤ R_{1} ≤ N and 1 ≤ L_{2} ≤ R_{2} ≤ N... | {"inputs": ["3\n4\n1010\n5\n11111\n3\n011\n"], "outputs": ["7\n0\n2\n"]} | 715 | 39 |
coding | Solve the programming task below in a Python markdown code block.
There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!
### input
```if-not:c
* customers: an array of positive integers representing the que... | {"functional": "_inputs = [[[], 1], [[5], 1], [[2], 5], [[1, 2, 3, 4, 5], 1], [[1, 2, 3, 4, 5], 100], [[2, 2, 3, 3, 4, 4], 2]]\n_outputs = [[0], [5], [2], [15], [5], [9]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs... | 487 | 243 |
coding | Solve the programming task below in a Python markdown code block.
We need a function ```count_sel()``` that receives an array or list of integers (positive and negative) and may give us the following information in the order and structure presented bellow:
```[(1), (2), (3), [[(4)], 5]]```
(1) - Total amount of rece... | {"functional": "_inputs = [[[-3, -2, -1, 3, 4, -5, -5, 5, -1, -5]], [[5, -1, 1, -1, -2, 5, 0, -2, -5, 3]], [[-2, 4, 4, -2, -2, -1, 3, 5, -5, 5]], [[4, -5, 1, -5, 2, 4, -1, 4, -1, 1]], [[4, 4, 2, -3, 1, 4, 3, 2, 0, -5, 2, -2, -2, -5]]]\n_outputs = [[[10, 7, 5, [[-5], 3]]], [[10, 7, 4, [[-2, -1, 5], 2]]], [[10, 6, 3, [[-... | 425 | 409 |
coding | Solve the programming task below in a Python markdown code block.
Rachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$.
Find out if the children are ... | {"inputs": ["2\n5 6\n3 5 6 8 1\n3 10\n5 2 9"], "outputs": ["NO\nYES"]} | 295 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Jack really likes his number five: the trick here is that you have to multiply each number by 5 raised to the number of digits of each numbers, so, for example:
```python
multiply(3)==15
multiply(10)==250
multiply(200)==25000
multiply(0)==0
multiply(-3)=... | {"functional": "_inputs = [[10], [5], [200], [0], [-2]]\n_outputs = [[250], [25], [25000], [0], [-10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) !... | 116 | 189 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costi, cashbacki].
The array describes transactions, where each transaction must be completed exactly once in some order. At any given ... | {"functional": "def check(candidate):\n assert candidate(transactions = [[2,1],[5,0],[4,2]]) == 10\n assert candidate(transactions = [[3,0],[0,3]]) == 3\n\n\ncheck(Solution().minimumMoney)"} | 165 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Today is the final round of La Liga, the most popular professional football league in the world. Real Madrid is playing against Malaga and Barcelona is playing against Eibar.... | {"inputs": ["2\nBarcelona 2\nMalaga 1\nRealMadrid 1\nEibar 0\nMalaga 3\nRealMadrid 2\nBarcelona 8\nEibar 6"], "outputs": ["RealMadrid\nBarcelona"]} | 436 | 61 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.
A string is called valid if ... | {"functional": "def check(candidate):\n assert candidate(word = \"b\") == 2\n assert candidate(word = \"aaa\") == 6\n assert candidate(word = \"abc\") == 0\n\n\ncheck(Solution().addMinimum)"} | 111 | 55 |
coding | Solve the programming task below in a Python markdown code block.
You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4).
Return:
* `0` if the elements can form such a sequence, and no ... | {"functional": "_inputs = [['1 2 3 5'], ['1 5'], [''], ['1 2 3 4 5'], ['2 3 4 5'], ['2 6 4 5 3'], ['_______'], ['2 1 4 3 a'], ['1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 ... | 336 | 536 |
coding | Solve the programming task below in a Python markdown code block.
Manasa is a student in the department of Mathematics. She is pretty good at doing calculations involving small numbers, but large numbers scare her. So she wants you to help her in the following calculations.
Given two numbers in the following manner:
... | {"inputs": ["2\n2 1 2 \n3 1 2\n"], "outputs": ["72\n"]} | 618 | 28 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.
k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is n... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 2), list_node([2,1,4,3,5]))\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 3), list_node([3,2,1,4,5]))\n\n\ncheck(Solution().reverseKGroup)"} | 185 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a s... | {"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n0\n", "2\n1 2\n", "2\n1 2\n", "2\n3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | 676 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Little Elephant likes lemonade.
When Little Elephant visits any room, he finds the bottle of the lemonade in that room that contains the greatest number of litres of lemonade and drinks it all.
There are n rooms (numbered from 0 to n-1), each contains ... | {"inputs": ["2\n3 3\n0 2 1\n3 1 2 3\n1 7\n2 4 7\n4 7\n0 1 3 0 1 0 0\n1 7\n3 9 4 5\n7 1 2 3 4 5 6 7\n1 1", "2\n3 3\n0 2 1\n3 1 2 3\n1 7\n2 4 7\n4 7\n0 1 2 0 1 0 0\n1 7\n3 9 4 5\n7 1 2 3 4 5 6 7\n1 1", "2\n3 3\n0 2 1\n3 1 2 3\n1 7\n2 4 7\n4 7\n0 1 2 0 2 0 0\n1 7\n3 9 4 5\n7 2 2 3 4 5 6 7\n1 1", "2\n3 3\n0 2 1\n3 1 2 3\n1... | 426 | 717 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots a_n$. Count the number of pairs of indices $1 \leq i, j \leq n$ such that $a_i < i < a_j < j$.
-----Input-----
The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.
The first... | {"inputs": ["5\n8\n1 1 2 3 8 2 1 4\n2\n1 2\n10\n0 2 1 6 3 4 1 2 8 3\n2\n1 1000000000\n3\n0 1000000000 2\n"], "outputs": ["3\n0\n10\n0\n1\n"]} | 550 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car re... | {"inputs": ["1 1 2 1\n1 10\n1\n", "1 1 2 1\n1 10\n0\n", "1 1 2 1\n2 10\n1\n", "1 1 10 18\n5 6\n5\n", "1 1 10 18\n3 6\n5\n", "1 1 10 24\n5 6\n5\n", "2 2 10 18\n10 4\n20 6\n5 3\n", "3 1 8 10\n10 8\n5 7\n11 9\n3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "5\n", "3\n", "5\n", "20\n", "10\n"]} | 750 | 199 |
coding | Solve the programming task below in a Python markdown code block.
Jem is famous for his laziness at school. He always leaves things to last minute. Now Jem has N problems in the assignment of "Advanced topics in algorithm" class to solved. The assignment is due tomorrow and as you may guess he hasn't touch any of the p... | {"inputs": ["2\n9 1 2\n123456 123456 123456"], "outputs": ["45\n131351258112"]} | 610 | 53 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A car travels from a starting position to a destination which is target miles east of the starting position.
There are gas stations along the way. The gas stations are represented as an array stations where stations[i... | {"functional": "def check(candidate):\n assert candidate(target = 1, startFuel = 1, stations = []) == 0\n assert candidate(target = 100, startFuel = 1, stations = [[10,100]]) == -1\n assert candidate(target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]) == 2\n\n\ncheck(Solution().minRefue... | 266 | 121 |
coding | Solve the programming task below in a Python markdown code block.
Ayu loves distinct letter sequences ,a distinct letter sequence is defined by a sequence of small case english alphabets such that no character appears more then once.
But however there are two phrases that she doesn't like these phrases are "kar" and "s... | {"inputs": ["2\nkarp\nabcd"], "outputs": ["22\n24"]} | 280 | 21 |
coding | Solve the programming task below in a Python markdown code block.
Given an amount and the denominations of coins available, determine how many ways change can be made for amount. There is a limitless supply of each coin type.
Example
$n=3$
$c=[8,3,1,2]$
There are $3$ ways to make change for $n=3$: $\{1,1,1\}... | {"inputs": ["4 3\n1 2 3\n", "10 4\n2 5 3 6\n"], "outputs": ["4\n", "5\n"]} | 628 | 41 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.
For example, the beauty of "abaacc" is 3 - 1 = 2.
Given a string s, return the sum of beauty of all of... | {"functional": "def check(candidate):\n assert candidate(s = \"aabcb\") == 5\n assert candidate(s = \"aabcbaa\") == 17\n\n\ncheck(Solution().beautySum)"} | 103 | 49 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob received $n$ candies from their parents. Each candy weighs either 1 gram or 2 grams. Now they want to divide all candies among themselves fairly so that the total weight of Alice's candies is equal to the total weight of Bob's candies.
Che... | {"inputs": ["5\n2\n1 1\n2\n1 2\n4\n1 2 1 2\n3\n2 2 2\n3\n2 1 2\n"], "outputs": ["YES\nNO\nYES\nNO\nNO\n"]} | 462 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Chef got in the trouble! He is the king of Chefland and Chessland. There is one queen in Chefland and one queen in Chessland and they both want a relationship with him. Chef is standing before a difficult choice…
Chessland may be considered a chessboard ... | {"inputs": ["2\n3 3 2 2\n4 4 2 3"], "outputs": ["24\n94"]} | 689 | 32 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to... | {"functional": "def check(candidate):\n assert candidate(total = 20, cost1 = 10, cost2 = 5) == 9\n assert candidate(total = 5, cost1 = 10, cost2 = 10) == 1\n\n\ncheck(Solution().waysToBuyPensPencils)"} | 139 | 77 |
coding | Solve the programming task below in a Python markdown code block.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
- Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the large... | {"inputs": ["3 3 4\n4", "3 3 4\n0", "4 3 4\n0", "4 3 1\n0", "4 1 1\n0", "3 1 1\n0", "4 2 1\n0", "3 2 4\n2"], "outputs": ["70\n", "10\n", "11\n", "8\n", "6\n", "5\n", "7\n", "21\n"]} | 352 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each ot... | {"inputs": ["1 5 4 3 2\n", "6 0 0 2 8\n", "5 8 2 1 3\n", "2 0 0 1 3\n", "1 5 6 2 1\n", "5 0 0 6 7\n", "6 0 1 6 7\n", "3 5 1 1 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | 591 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Chef and his competitor Kefa own two restaurants located at a straight road. The position of Chef's restaurant is $X_1$, the position of Kefa's restaurant is $X_2$.
Chef and Kefa found out at the same time that a bottle with a secret recipe is located on... | {"inputs": ["3\n1 3 2 1 2\n1 5 2 1 2\n1 5 3 2 2"], "outputs": ["Kefa\nChef\nDraw"]} | 462 | 47 |
coding | Solve the programming task below in a Python markdown code block.
E869120 has A 1-yen coins and infinitely many 500-yen coins.
Determine if he can pay exactly N yen using only these coins.
-----Constraints-----
- N is an integer between 1 and 10000 (inclusive).
- A is an integer between 0 and 1000 (inclusive).
---... | {"inputs": ["2763\n1", "37\n308", "2763\n2", "37\n135", "37\n244", "37\n290", "37\n381", "37\n605"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | 201 | 102 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.
All strings that ca... | {"inputs": ["0", "1", "2", "4", "3", "5", "9", "8"], "outputs": ["0\n", "1\n", "2\n", "4\n", "3\n", "5\n", "9\n", "8\n"]} | 274 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You're given an array $b$ of length $n$. Let's define another array $a$, also of length $n$, for which $a_i = 2^{b_i}$ ($1 \leq i \leq n$).
Valerii says that every two non-intersecting subarrays of $a$ have different sums of elements. You want to deter... | {"inputs": ["1\n3\n1 1 2\n", "1\n3\n1 1 1\n", "1\n3\n1 2 3\n", "1\n3\n1 2 3\n", "1\n3\n1 1 1\n", "1\n3\n1 1 2\n", "1\n3\n1 2 2\n", "1\n3\n0 2 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n"]} | 605 | 134 |
coding | Solve the programming task below in a Python markdown code block.
There is an array $a$ of length $n$. You may perform the following operation any number of times:
Choose two indices $l$ and $r$ where $1 \le l < r \le n$ and $a_l = a_r$. Then, set $a[l \ldots r] = [a_{l+1}, a_{l+2}, \ldots, a_r, a_l]$.
You are also g... | {"inputs": ["5\n5\n1 2 3 3 2\n1 3 3 2 2\n5\n1 2 4 2 1\n4 2 2 1 1\n5\n2 4 5 5 2\n2 2 4 5 5\n3\n1 2 3\n1 2 3\n3\n1 1 2\n2 1 1\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\n"]} | 725 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Chef is the judge of a competition. There are two players participating in this competition — Alice and Bob.
The competition consists of N races. For each i (1 ≤ i ≤ N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi minutes. The... | {"inputs": ["3\n5\n3 1 3 3 4\n1 6 2 5 3\n5\n1 6 2 5 3\n3 1 3 3 4\n3\n4 1 3\n2 2 7"], "outputs": ["Alice\nBob\nDraw"]} | 710 | 74 |
coding | Solve the programming task below in a Python markdown code block.
You are given a secret message you need to decipher. Here are the things you need to know to decipher it:
For each word:
- the second and the last letter is switched (e.g. `Hello` becomes `Holle`)
- the first letter is replaced by its character code (e.... | {"functional": "_inputs = [['65 119esi 111dl 111lw 108dvei 105n 97n 111ka'], ['84eh 109ero 104e 115wa 116eh 108sse 104e 115eokp'], ['84eh 108sse 104e 115eokp 116eh 109ero 104e 104dare'], ['87yh 99na 119e 110to 97ll 98e 108eki 116tah 119esi 111dl 98dri'], ['84kanh 121uo 80roti 102ro 97ll 121ruo 104ple']]\n_outputs = [['... | 175 | 417 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ positive integers $a_1, a_2, \dots, a_n$. For the one move you can choose any even value $c$ and divide by two all elements that equal $c$.
For example, if $a=[6,8,12,6,3,12]$ and you choose $c=6$, and $a$ is transformed into $a=[3,8,12,3,... | {"inputs": ["4\n6\n40 6 40 3 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 7\n"], "outputs": ["4\n10\n4\n0\n"]} | 633 | 64 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.
Return the smallest level x such that the sum of all the values of nodes at level x is maximal.
Please complete... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,7,0,7,-8,None,None])) == 2\n assert candidate(root = tree_node([989,None,10250,98693,-89388,None,None,None,-32127])) == 2\n\n\ncheck(Solution().maxLevelSum)"} | 152 | 88 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.
Please complete the following python code precisely:
```python
class So... | {"functional": "def check(candidate):\n assert candidate(grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]) == 8\n assert candidate(grid = [[3,2],[1,0]]) == 0\n\n\ncheck(Solution().countNegatives)"} | 81 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones are not. ... | {"inputs": ["4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone", "4\nacb\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone", "4\nacb\nabcdef\nAa\nabZA\naaa\n`\nwhat\nnone", "4\naca\nebcdaf\naA\nAbZa\n`aa\n`\nswha\nnomf", "4\nac`\nebcdae\naA\nAbZa\n`aa\n_\nsvha\nnome", "4\nac`\nebcdae\naA\nAbZ`\n`aa\n_\nsvha\nemon", "4\n`ca\neacdae\naA\... | 318 | 279 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time.
You a... | {"functional": "def check(candidate):\n assert candidate(n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]) == [1,2]\n assert candidate(n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]) == [0,1]\n\n\ncheck(Solution().countServers)"} | 183 | 109 |
coding | Solve the programming task below in a Python markdown code block.
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise d... | {"inputs": ["3\n1 9 3\n8 6 7\n4 2 5\n", "3\n1 5 8\n9 2 4\n3 6 7\n", "3\n1 4 7\n6 9 2\n3 8 5\n", "3\n1 6 3\n7 2 9\n4 8 5\n", "3\n1 6 3\n4 9 8\n7 2 5\n", "3\n8 6 3\n9 1 5\n2 4 7\n", "3\n1 5 2\n7 6 3\n4 8 9\n", "3\n1 4 8\n7 2 6\n5 9 3\n"], "outputs": ["12 1\n", "12 1\n", "9 1\n", "11 2\n", "9 1\n", "13 2\n", "11 0\n", "11... | 632 | 236 |
coding | Solve the programming task below in a Python markdown code block.
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much.
One can get to the shore only by hills that are situated along a straight line that connects the little island wit... | {"inputs": ["1 1 1\n1\n1\n", "2 1 1\n1\n1\n", "2 1 1\n1\n0\n", "2 1 1\n2\n0\n", "2 2 1\n2 1\n1\n", "3 2 2\n2 4\n3 2\n", "3 2 2\n2 4\n3 3\n", "5 3 5\n2 3 4\n1 1 3 4 5\n"], "outputs": ["1\n1 ", "1\n1 ", "1\n1 ", "1\n1 ", "1\n1 ", "1\n2 ", "2\n1 2 ", "3\n1 2 3 "]} | 591 | 171 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
You can perform the following operation on the array any number of times:
Choose any two adjacent elements and replace them with their sum.
For example,... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,1,2,3,1]) == 2\n assert candidate(nums = [1,2,3,4]) == 3\n\n\ncheck(Solution().minimumOperations)"} | 132 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Chef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if he has at... | {"inputs": ["1\n9\nPAAPPAPPP"], "outputs": ["1"]} | 681 | 19 |
coding | Solve the programming task below in a Python markdown code block.
Given an array a_1, a_2, ..., a_{n} of n integers, find the largest number in the array that is not a perfect square.
A number x is said to be a perfect square if there exists an integer y such that x = y^2.
-----Input-----
The first line contains a ... | {"inputs": ["1\n2\n", "1\n2\n", "1\n-1\n", "1\n-1\n", "1\n-2\n", "1\n-4\n", "1\n-6\n", "1\n-8\n"], "outputs": ["2\n", "2\n", "-1\n", "-1\n", "-2\n", "-4\n", "-6\n", "-8\n"]} | 270 | 92 |
coding | Solve the programming task below in a Python markdown code block.
You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,” just released today. As you definitely want to buy it, you are planning to borrow some money from Alice in case the amount you hav... | {"inputs": ["1 1110 3", "0 1100 3", "1 1100 2", "350 7 354", "0 1110 13", "0 1110 20", "0 1110 10", "1 1110 10"], "outputs": ["2\n", "3\n", "1\n", "4\n", "13\n", "20\n", "10\n", "9\n"]} | 330 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Space Coconut Crab
Space coconut crab
English text is not available in this practice contest.
Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crustacean in... | {"inputs": ["1\n3\n2\n3\n76\n116\n0", "1\n2\n4\n3\n76\n324\n0", "1\n1\n2\n0\n76\n116\n0", "1\n1\n1\n3\n333\n54\n0", "1\n2\n6\n1\n347\n31\n0", "1\n2\n4\n3\n76\n1250\n0", "1\n2\n3\n3\n76\n1250\n0", "1\n3\n3\n3\n76\n1250\n0"], "outputs": ["1\n3\n2\n3\n10\n14\n", "1\n2\n2\n3\n10\n18\n", "1\n1\n2\n", "1\n1\n1\n3\n21\n10\n",... | 707 | 271 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence $A_1, A_2, \ldots, A_N$. You may perform the following operation an arbitrary number of times (including zero): choose two adjacent elements of this sequence, i.e. $A_i$, $A_{i+1}$ for some valid $i$, and swap them. However, for ... | {"inputs": ["2\n4\n2 1 4 3\n4\n7 6 3 2"], "outputs": ["30\n39"]} | 498 | 36 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers. Initially all elements of $a$ are either $0$ or $1$. You need to process $q$ queries of two kinds:
1 x : Assign to $a_x$ the value $1 - a_x$.
2 k : Print the $k$-th largest value of the array.
As ... | {"inputs": ["1 1\n0\n2 1\n", "1 1\n0\n2 1\n", "5 5\n1 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n", "5 5\n0 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n", "5 5\n1 1 1 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n", "5 5\n1 1 1 1 0\n2 3\n1 2\n2 3\n2 1\n2 2\n", "5 5\n0 1 0 0 0\n2 3\n1 2\n2 3\n2 1\n2 3\n", "5 5\n1 1 1 1 0\n2 5\n1 2\n2 3\n2 1\n2 5\n"], "ou... | 633 | 314 |
coding | Solve the programming task below in a Python markdown code block.
We have N+1 integers: 10^{100}, 10^{100}+1, ..., 10^{100}+N.
We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7).
-----Constraints-----
- 1 \leq N \leq 2\times 10^5
- 1 \leq ... | {"inputs": ["3 1", "1 1", "3 4", "6 1", "2 1", "6 2", "4 3", "4 1"], "outputs": ["14\n", "3\n", "1\n", "63\n", "7\n", "56\n", "13\n", "25\n"]} | 620 | 83 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
Chef has X coins worth 1 rupee each and Y coins worth 2 rupees each. He wants to distribute all of these X+Y coins to his two sons so that the total value of coins rec... | {"inputs": ["4\n2 2\n1 3\n4 0\n1 10\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 376 | 37 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
Constraints
* $2 \leq n \leq 100,000$
* $0 \leq m \leq 100,000$
* $1 \leq q \leq 10,000$
Input
... | {"inputs": ["10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n0 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n0 8\n7 8\n8 5\n3\n0 1\n5 9\n1 3", "16 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n5 4\n5 ... | 358 | 518 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array of integers $a_1,a_2,\ldots,a_n$. Find the maximum possible value of $a_ia_ja_ka_la_t$ among all five indices $(i, j, k, l, t)$ ($i<j<k<l<t$).
-----Input-----
The input consists of multiple test cases. The first line contains an... | {"inputs": ["1\n5\n-3000 -777 -3000 810 831\n", "1\n5\n-3000 -777 -3123 810 831\n", "1\n5\n-3000 -777 -1726 810 831\n", "1\n5\n-3000 -777 -3123 810 176\n", "1\n5\n-3000 -777 -3000 810 3000\n", "1\n5\n-3000 -777 -3000 2024 3000\n", "1\n5\n-3000 -1535 -3000 3000 349\n", "1\n5\n-3000 -216 -3000 2024 3000\n"], "outputs": [... | 563 | 402 |
coding | Solve the programming task below in a Python markdown code block.
Chef made two laddus with sweetness X and Y respectively. Cheffina comes and sees the chef created two laddus with different sweetness (might be same). Cheffina has the magical power to make the sweetness of laddus equal. Cheffina requires 1 unit of powe... | {"inputs": ["2\n2 2\n4 6"], "outputs": ["0\n3"]} | 328 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n which is the number of nodes of a 0-indexed directed weighted graph and a 0-indexed 2D array edges where edges[i] = [ui, vi, wi] indicates that there is an edge from node ui to node ... | {"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[0,1,1],[1,2,3],[2,3,2],[0,3,4]], s = 0, marked = [2,3]) == 4\n assert candidate(n = 5, edges = [[0,1,2],[0,2,4],[1,3,1],[2,3,3],[3,4,2]], s = 1, marked = [0,4]) == 3\n assert candidate(n = 4, edges = [[0,1,1],[1,2,3],[2,3,2]], s = 3, mar... | 186 | 172 |
coding | Solve the programming task below in a Python markdown code block.
You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, while mov... | {"inputs": ["1 1\n.\n", "1 1\n.\n", "1 3\n.R.\n", "1 3\n.R.\n", "2 2\n.R\nR.\n", "2 2\n.R\nR.\n", "2 2\n.R\n.R\n", "2 2\nR.\n.R\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 521 | 115 |
coding | Solve the programming task below in a Python markdown code block.
A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.
The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that the... | {"inputs": ["4\n47\n74\n477\n4747477\n\n"], "outputs": ["2\n2\n3\n23"]} | 606 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Chef Al Gorithm was reading a book about climate and oceans when he encountered the word “glaciological”. He thought it was quite curious, because it has the following interesting property: For every two letters in the word, if the first appears x times ... | {"inputs": ["4\nglaciological 1\nteammate 0\npossessions 3\ndefenselessness 3", "4\nglaciological 1\nteammate 0\npossessions 3\ndefenselessness 0", "4\nglaciological 1\nteammate 0\npossessions 4\ndefenselessness 0", "4\nglaciological 1\nteammate 1\npossessions 4\ndefensdlessness 0", "4\nlacigoloicalg 2\nteammate 0\npos... | 491 | 327 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.