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.
Read problems statements in Mandarin Chinese and Russian as well.
Mike takes part in programming contests. His favourite topic is dynamic programming(DP). As he said, that he likes problems on DP, because "you spend a lot of time on thinking and a litt... | {"inputs": ["5\n1 1\n2 2\n2 3\n2 4\n2 5"], "outputs": ["1 5 6 9 10 12 13 14 15 "]} | 599 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Chef likes inequalities. Please help him to solve next one.
Given four integers a, b, c, d. Find number of solutions x < y, where a ≤ x ≤ b and c ≤ y ≤ d and x, y integers.
-----Input-----
The first line contains an integer T denoting number of tests.
F... | {"inputs": ["1\n2 3 3 4", "1\n2 999999 1 1000000"], "outputs": ["3", "499998500001"]} | 258 | 56 |
coding | Solve the programming task below in a Python markdown code block.
An acrostic is a text in which the first letter of each line spells out a word. It is also a quick and cheap way of writing a poem for somebody, as exemplified below :
Write a program that reads an acrostic to identify the "hidden" word. Specifically,... | {"functional": "_inputs = [[['Jolly', 'Amazing', 'Courteous', 'Keen']], [['Marvelous', 'Excellent', 'Gifted']]]\n_outputs = [['JACK'], ['MEG']]\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 isinstanc... | 142 | 185 |
coding | Solve the programming task below in a Python markdown code block.
We have an integer sequence of length N: A_0,A_1,\cdots,A_{N-1}.
Find the following sum (\mathrm{lcm}(a, b) denotes the least common multiple of a and b):
* \sum_{i=0}^{N-2} \sum_{j=i+1}^{N-1} \mathrm{lcm}(A_i,A_j)
Since the answer may be enormous, ... | {"inputs": ["3\n1 4 6", "3\n2 3 6", "3\n2 1 6", "3\n2 4 6", "3\n0 1 10", "8\n1 4 3 4 6 8 12 12", "8\n1 8 3 4 6 8 12 12", "8\n1 8 3 4 6 7 12 12"], "outputs": ["22\n", "18\n", "14\n", "22", "10\n", "327\n", "383\n", "585\n"]} | 347 | 157 |
coding | Solve the programming task below in a Python markdown code block.
You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.
#Examples:
~~~if-not:bf
```
Kata.getMiddle(... | {"functional": "_inputs = [['test'], ['testing'], ['middle'], ['A'], ['of']]\n_outputs = [['es'], ['t'], ['dd'], ['A'], ['of']]\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, tupl... | 300 | 178 |
coding | Solve the programming task below in a Python markdown code block.
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclus... | {"inputs": ["1\n0 1\n", "1\n0 2\n", "1\n1 2\n", "1\n0 4\n", "1\n1 1\n", "1\n2 1\n", "1\n2 2\n", "1\n4 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 454 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
-----Input-----
The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and... | {"inputs": ["9 5\n", "3 3\n", "5 2\n", "6 0\n", "2 0\n", "2 2\n", "3 1\n", "6 2\n"], "outputs": ["4\n", "2\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n"]} | 219 | 86 |
coding | Solve the programming task below in a Python markdown code block.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ... | {"inputs": ["2 0", "1 2", "0 3", "1 0", "1 3", "3 0", "4 0", "7 0"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 256 | 78 |
coding | Solve the programming task below in a Python markdown code block.
There is a task in Among Us in which $N$ temperature scale with unique readings are given and you have to make all of them equal. In one second you can choose an odd number and add or subtract that number in any one temperature value. Find minimum time (... | {"inputs": ["3\n5\n1 2 3 4 5\n4\n5 2 3 8\n2\n50 53"], "outputs": ["5\n4\n1"]} | 346 | 46 |
coding | Solve the programming task below in a Python markdown code block.
A sum of p rubles is charged from Arkady's mobile phone account every day in the morning. Among the following m days, there are n days when Arkady will top up the account: in the day d_{i} he will deposit t_{i} rubles on his mobile phone account. Arkady ... | {"inputs": ["1 1 1\n1 1\n", "1 2 1\n1 1\n", "1 2 1\n1 3\n", "1 1 1\n1 1\n", "1 2 1\n1 1\n", "1 2 1\n1 3\n", "1 2 1\n1 0\n", "1 4 1\n1 3\n"], "outputs": ["0\n", "1\n", "0\n", " 0", " 1", " ... | 723 | 137 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordi... | {"functional": "def check(candidate):\n assert candidate(radius = 1, xCenter = 0, yCenter = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1) == True\n assert candidate(radius = 1, xCenter = 1, yCenter = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1) == False\n assert candidate(radius = 1, xCenter = 0, yCenter = 0, x1 = -1, y1 = 0, x... | 192 | 160 |
coding | Solve the programming task below in a Python markdown code block.
Let's consider a permutation P = {$p_{1}$,$ p_{2}$, ..., $p_{N}$} of the set of N = {1, 2, 3, ..., N} elements .
P is called a magic set if it satisfies both of the following constraints:
Given a set of K integers, the elements in positions $a_{1}$... | {"inputs": ["4 1 1\n2\n3\n", "10 2 2\n2 4\n3 9\n"], "outputs": ["5\n", "161280\n"]} | 520 | 48 |
coding | Solve the programming task below in a Python markdown code block.
Anmol gained a lot of weight last semester. So this semester, he decided to run everyday. There is a very long straight road starting at his hostel. There are N poles on the road - P1, P2, P3,..., PN on the road. All the poles lie on the same side of his... | {"inputs": ["3\n5 1\n1 5 10 12 14\n5\n5 2\n5 8 13 16 21\n3 5\n5 3\n2 6 8 11 16\n2 3 5"], "outputs": ["1\n2\n1"]} | 529 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an exam which will start exactly M minutes from now. However, instead of preparing for his exam, Chef started watching Season-1 of Superchef. Season-1 has N episodes, and the duration of each episode is K minutes.
Will Chef be able to finish w... | {"inputs": ["3\n10 1 10\n25 2 10\n15 2 10"], "outputs": ["NO\nYES\nNO"]} | 520 | 40 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as '#'.
For example, the abo... | {"functional": "def check(candidate):\n assert candidate(preorder = \"9,3,4,#,#,1,#,#,2,#,6,#,#\") == True\n assert candidate(preorder = \"1,#\") == False\n assert candidate(preorder = \"9,#,#,1\") == False\n\n\ncheck(Solution().isValidSerialization)"} | 221 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:
- For any integer j (1 \leq j \leq i), P_i \leq P_j.
-----Constraints-----
- 1 \leq N \leq 2 \times 10^5
... | {"inputs": ["1\n0", "1\n1", "1\n1\n", "1\n-1", "1\n-2", "1\n-4", "4\n4 3 2 1", "4\n4 3 2 1\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "4", "4\n"]} | 260 | 93 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected graph with n nodes, numbered from 0 to n - 1.
You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges ... | {"functional": "def check(candidate):\n assert candidate(scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]) == 24\n assert candidate(scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]) == -1\n\n\ncheck(Solution().maximumScore)"} | 217 | 111 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integer sequences, each of length N: a_1, ..., a_N and b_1, ..., b_N.
There are N^2 ways to choose two integers i and j such that 1 \leq i, j \leq N. For each of these N^2 pairs, we will compute a_i + b_j and write it on a sheet of pape... | {"inputs": ["1\n0\n0\n", "2\n1 2\n3 4\n", "5\n1 2 3 4 5\n1 2 3 4 5\n", "6\n4 6 0 0 3 3\n0 5 6 5 0 3\n"], "outputs": ["0\n", "2\n", "2\n", "8\n"]} | 440 | 94 |
coding | Solve the programming task below in a Python markdown code block.
With your birthday coming up soon, your eccentric friend sent you a message to say "happy birthday":
hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu
hhapppyyyy biirtttthdaaay too youuu
happy birrrthdayy to youuu
happpyyyy birrtthdaaay toooo... | {"functional": "_inputs = [['happy birthday', 'appyh appy birth day'], ['happy birthday', 'hhaappyy bbiirrtthhddaayy'], ['happy birthday', 'happy holidays'], ['happy birthday', 'happy birthday'], ['happy', 'hhhappy'], ['happy birthday', 'hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu']]\n_outputs = [[1], [2048], [0], [1]... | 407 | 250 |
coding | Solve the programming task below in a Python markdown code block.
# Do names have colors?
*Now they do.*
Make a function that takes in a name (Any string two chars or longer really, but the name is the idea) and use the ascii values of it's substrings to produce the hex value of its color! Here is how it's going to w... | {"functional": "_inputs = [['A'], [''], ['John Doe'], ['CodeWars']]\n_outputs = [[None], [None], ['C70033'], ['182892']]\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 ... | 415 | 183 |
coding | Solve the programming task below in a Python markdown code block.
Modify the `kebabize` function so that it converts a camel case string into a kebab case.
Notes:
- the returned string should only contain lowercase letters
Also feel free to reuse/extend the following starter code:
```python
def kebabize(string):
``` | {"functional": "_inputs = [['myCamelCasedString'], ['myCamelHas3Humps'], ['SOS'], ['42'], ['CodeWars']]\n_outputs = [['my-camel-cased-string'], ['my-camel-has-humps'], ['s-o-s'], [''], ['code-wars']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | 70 | 207 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
-----Constraints-----
- 2≤K≤2500
- 0≤S≤3K
- K and... | {"inputs": ["2 2\n", "5 15\n", "1050 0\n", "148 35\n", "602 293\n", "446 491\n", "2500 3750\n", "2500 7500\n"], "outputs": ["6\n", "1\n", "1\n", "666\n", "43365\n", "118173\n", "4691251\n", "1\n"]} | 260 | 130 |
coding | Solve the programming task below in a Python markdown code block.
Chefland is a grid with N$N$ rows and M$M$ columns. Each cell of this grid is either empty or contains a house. The distance between a pair of houses is the Manhattan distance between the cells containing them.
For each d$d$ between 1$1$ and N+M−2$N+M-2$... | {"inputs": ["1\n3 4\n0011\n0000\n0100"], "outputs": ["1 0 1 1 0"]} | 461 | 39 |
coding | Solve the programming task below in a Python markdown code block.
This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a se... | {"inputs": ["1\n7\n2\n7 9\n", "1\n6\n2\n7 9\n", "1\n6\n2\n7 16\n", "2\n6 10\n3\n6 3 3\n", "2\n1 10\n3\n6 3 3\n", "2\n2 10\n3\n6 3 3\n", "2\n5 2\n4\n8 8 0 4\n", "2\n5 2\n4\n8 8 0 8\n"], "outputs": ["1\n7 \n", "0\n\n", "0\n\n", "1\n6 \n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]} | 382 | 174 |
coding | Solve the programming task below in a Python markdown code block.
Alice buys a toy with a selling price of 100 rupees. There is a discount of x percent on the toy. Find the amount Alice needs to pay for it.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of t... | {"inputs": ["4\n5\n9\n11\n21\n"], "outputs": ["95\n91\n89\n79\n"]} | 233 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Elon Musk has succesfully built an automated staircase from Earth to Mars. Many people want to go to Mars, but that's not possible due to limited capacity of the staircase and logistics involved. Hence, Elon asks interested candidates to solve a tough ch... | {"inputs": ["2\n10 2 \n12 1\n"], "outputs": ["63\n10\n"]} | 383 | 29 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:
Remove the first character of a string s and give it to the robot. The ... | {"functional": "def check(candidate):\n assert candidate(s = \"zza\") == \"azz\"\n assert candidate(s = \"bac\") == \"abc\"\n assert candidate(s = \"bdda\") == \"addb\"\n\n\ncheck(Solution().robotWithString)"} | 143 | 60 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums.
Return the minimum number of deletions such that the smallest element in nums divides all the elements of... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15]) == 2\n assert candidate(nums = [4,3,6], numsDivide = [8,2,6,10]) == -1\n\n\ncheck(Solution().minOperations)"} | 126 | 85 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).
You are given a binary string s. You can flip s[i] changing it from 0 t... | {"functional": "def check(candidate):\n assert candidate(s = \"00110\") == 1\n assert candidate(s = \"010110\") == 2\n assert candidate(s = \"00011000\") == 2\n\n\ncheck(Solution().minFlipsMonoIncr)"} | 128 | 75 |
coding | Solve the programming task below in a Python markdown code block.
You are given a weighted undirected graph consisting of n$n$ nodes and m$m$ edges. The nodes are numbered from 1$1$ to n$n$. The graph does not contain any multiple edges or self loops.
A walk W$W$ on the graph is a sequence of vertices (with repetitions... | {"inputs": ["3 3\n1 2 1\n2 3 2\n3 1 3\n3\n1\n2\n3"], "outputs": ["2\n10\n36"]} | 712 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Compare given two sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}$ lexicographically.
Constraints
* $1 \leq n, m \leq 1,000$
* $0 \leq a_i, b_i \leq 1,000$
Input
The input is given in the following format.
$n$
$a_0 \;... | {"inputs": ["3\n1 4 3\n2\n2 4", "3\n1 4 3\n2\n2 2", "3\n1 4 3\n3\n2 2", "3\n1 4 3\n3\n2 1", "3\n1 4 3\n6\n2 1", "3\n1 4 5\n6\n2 1", "3\n1 4 8\n6\n2 1", "3\n1 4 8\n6\n4 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 306 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Chef has N candies. He has to distribute them to exactly M of his friends such that each friend gets equal number of candies and each friend gets even number of candies. Determine whether it is possible to do so.
NOTE: Chef will not take any candies him... | {"inputs": ["4\n9 3\n4 1\n4 2\n8 3"], "outputs": ["No\nYes\nYes\nNo"]} | 449 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Ada has two matrices $A$ and $B$, each with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$).
Ada may perform the foll... | {"inputs": ["1\n3\n1 2 3\n4 5 6\n7 8 9\n1 2 7\n4 5 8\n3 6 9"], "outputs": ["Yes"]} | 571 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Ashish has an array $a$ of size $n$.
A subsequence of $a$ is defined as a sequence that can be obtained from $a$ by deleting some elements (possibly none), without changing the order of the remaining elements.
Consider a subsequence $s$ of $a$. He defi... | {"inputs": ["2 2\n5 10\n", "2 2\n5 10\n", "4 2\n1 2 3 4\n", "4 3\n1 2 3 4\n", "4 2\n1 3 3 4\n", "4 2\n1 2 3 4\n", "4 3\n1 2 3 4\n", "5 3\n5 3 4 2 6\n"], "outputs": ["5", "5\n", "1", "2", "1\n", "1\n", "2\n", "2"]} | 624 | 142 |
coding | Solve the programming task below in a Python markdown code block.
The final match of the Berland Football Cup has been held recently. The referee has shown $n$ yellow cards throughout the match. At the beginning of the match there were $a_1$ players in the first team and $a_2$ players in the second team.
The rules of ... | {"inputs": ["2\n3\n5\n1\n8\n", "8\n4\n1\n2\n9\n", "1\n7\n2\n3\n5\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n2\n", "1\n1\n7\n1\n2\n", "1\n1\n1\n3\n4\n", "8\n4\n1\n2\n9\n"], "outputs": ["0 4\n", "5 8\n", "0 2\n", "1 1\n", "2 2\n", "0 1\n", "2 2\n", "5 8\n"]} | 661 | 150 |
coding | Solve the programming task below in a Python markdown code block.
There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer a_i. They will form N teams, each consisting of three participants. No participant may belong to multiple teams.
The strength of a team... | {"inputs": ["2\n2 2 8 5 1 5", "2\n0 4 8 5 1 5", "2\n0 7 8 5 1 5", "2\n0 7 8 9 1 5", "2\n1 4 8 9 1 2", "2\n1 4 8 4 1 2", "2\n5 2 8 5 1 5", "2\n0 4 10 4 1 0"], "outputs": ["7\n", "9\n", "12\n", "13\n", "10\n", "6\n", "10", "5\n"]} | 570 | 162 |
coding | Solve the programming task below in a Python markdown code block.
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current ... | {"inputs": ["2 6 0 1 4\n5 1\n", "1 100 1 2 30\n1\n", "1 100 1 2 30\n0\n", "1 100 1 2 59\n0\n", "1 100 2 2 59\n1\n", "1 100 0 2 30\n1\n", "1 100 1 2 42\n0\n", "1 100 0 4 30\n1\n"], "outputs": ["5\n5 5 \n", "62\n31 \n", "60\n30\n", "118\n59\n", "120\n60\n", "62\n31\n", "84\n42\n", "124\n31\n"]} | 488 | 210 |
coding | Solve the programming task below in a Python markdown code block.
A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that f... | {"inputs": ["5 5 3\n*.***\n.****\n..***\n*.***\n.**.*\n", "5 5 1\n.....\n.....\n.*..*\n*.*..\n....*\n", "5 5 4\n*.***\n.****\n..***\n*.***\n.**.*\n", "5 5 7\n*.***\n.****\n..***\n*.***\n.**.*\n", "5 5 3\n*.***\n.****\n..***\n***.*\n.**.*\n", "5 6 1\n....*.\n...***\n....*.\n..*...\n.*.*.*\n", "5 6 1\n....*.\n...***\n...... | 589 | 319 |
coding | Solve the programming task below in a Python markdown code block.
We say that a string contains the word hackerrank if a subsequence of its characters spell the word hackerrank. Remeber that a subsequence maintains the order of characters selected from a sequence.
More formally, let $p[0],p[1],\cdots,p[9]$ be the ... | {"inputs": ["2\nhereiamstackerrank\nhackerworld\n", "2\nhhaacckkekraraannk\nrhbaasdndfsdskgbfefdbrsdfhuyatrjtcrtyytktjjt\n"], "outputs": ["YES\nNO\n", "YES\nNO\n"]} | 640 | 70 |
coding | Solve the programming task below in a Python markdown code block.
ABC Gene
There is a gene sequence represented by the string `ABC`. You can rewrite this gene sequence by performing the following operations several times.
* Choose one of the letters `A`,` B`, `C`. Let this be x. Replace all x in the gene sequence wit... | {"inputs": ["BAC", "ACB", "CAB", "CBA", "ACA", "BCA", "BAB", "ABA"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 331 | 67 |
coding | Solve the programming task below in a Python markdown code block.
In mathematics, a [Diophantine equation](https://en.wikipedia.org/wiki/Diophantine_equation) is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied.
In this kata we want to find all intege... | {"functional": "_inputs = [[5], [12], [13], [16], [17], [20], [9001], [9004], [9005], [9008], [90001], [90002], [90004], [90005], [90009], [900001], [900004], [900005], [9000001], [9000004], [90000001], [90000004], [900000012], [9000000041]]\n_outputs = [[[[3, 1]]], [[[4, 1]]], [[[7, 3]]], [[[4, 0]]], [[[9, 4]]], [[[6,... | 312 | 1,003 |
coding | Solve the programming task below in a Python markdown code block.
A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character '+' and one cha... | {"inputs": ["099\n", "112\n", "101\n", "011\n", "178\n", "000\n", "178\n", "101\n"], "outputs": ["0+9=9\n", "1+1=2\n", "1+0=1\n", "0+1=1\n", "1+7=8\n", "0+0=0\n", "1+7=8", "1+0=1"]} | 421 | 116 |
coding | Solve the programming task below in a Python markdown code block.
At the annual family gathering, the family likes to find the oldest living family member’s age and the youngest family member’s age and calculate the difference between them.
You will be given an array of all the family members' ages, in any order. The... | {"functional": "_inputs = [[[16, 22, 31, 44, 3, 38, 27, 41, 88]], [[5, 8, 72, 98, 41, 16, 55]], [[57, 99, 14, 32]], [[62, 0, 3, 77, 88, 102, 26, 44, 55]], [[2, 44, 34, 67, 88, 76, 31, 67]], [[46, 86, 33, 29, 87, 47, 28, 12, 1, 4, 78, 92]], [[66, 73, 88, 24, 36, 65, 5]], [[12, 76, 49, 37, 29, 17, 3, 65, 84, 38]], [[0, 1... | 145 | 541 |
coding | Solve the programming task below in a Python markdown code block.
A sequence of non-negative integers a_1, a_2, ..., a_{n} of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that $a_{l} \oplus a_{l + 1} \oplus \cdots \oplus a_{r} = 0$. In other words each wool se... | {"inputs": ["3 2\n", "4 2\n", "1 2\n", "1 1\n", "2 1\n", "2 2\n", "3 1\n", "3 2\n"], "outputs": ["6\n", "0\n", "3\n", "1\n", "0\n", "6\n", "0\n", "6\n"]} | 394 | 86 |
coding | Solve the programming task below in a Python markdown code block.
A 1-indexed array is called *positive* if every element of the array is greater than or equal to the index on which it lies. Formally, an array B of size M is called positive if B_{i} ≥ i for each 1≤ i ≤ M.
For example, the arrays [1], [2, 2], [3, 2, 4... | {"inputs": ["5\n3\n2 3 3\n4\n3 1 1 2\n3\n1 1 1\n5\n1 2 2 4 5\n6\n3 2 1 2 2 1\n"], "outputs": ["1\n2\n3\n2\n3\n"]} | 590 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.
Two people can directly communicate when the distance between them ... | {"inputs": ["4 7 2 3", "4 5 2 3", "4 7 9 3", "4 7 9 3\n", "0 011 5 8", "0 011 5 3", "0 111 5 3", "0 111 1 3"], "outputs": ["Yes\n", "Yes\n", "Yes", "Yes\n", "Yes\n", "No\n", "No\n", "Yes\n"]} | 228 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He c... | {"inputs": ["3 6\n3 1\n4 4\n2 5", "3 1\n3 3\n4 4\n2 5", "3 6\n4 1\n4 4\n2 5", "3 6\n2 3\n4 4\n2 5", "3 6\n0 0\n4 2\n3 5", "3 1\n3 3\n4 4\n4 5", "3 6\n0 1\n4 4\n2 5", "3 6\n0 1\n3 4\n2 5"], "outputs": ["9\n", "0\n", "10\n", "12\n", "5\n", "0\n", "10\n", "10\n"]} | 333 | 178 |
coding | Solve the programming task below in a Python markdown code block.
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more t... | {"inputs": ["1 1 1 0 0\n", "4 1 2 2 0\n", "1 5 5 1 1\n", "1 2 3 0 0\n", "1 1 1 1 0\n", "9 1 4 2 0\n", "4 2 2 0 1\n", "8 3 4 2 0\n"], "outputs": ["1\n", "3\n", "1\n", "1\n", "1\n", "4\n", "3\n", "3\n"]} | 482 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upw... | {"inputs": ["3\n2 1\n1 0\n0 1\n", "3\n2 1\n1 0\n0 1\n", "5\n0 0\n0 1\n0 2\n0 3\n0 4\n", "5\n0 0\n0 1\n0 2\n0 3\n0 4\n", "2\n72098079 0\n72098078 1\n", "2\n73639551 1\n73639551 0\n", "2\n72098079 0\n72098078 1\n", "2\n73639551 1\n73639551 0\n"], "outputs": ["19\n", "19\n", "2930\n", "2930\n", "2\n", "1\n", "2\n", "1\n"]... | 568 | 230 |
coding | Solve the programming task below in a Python markdown code block.
In the mysterious country of Byteland, everything is quite different from what you'd
normally expect. In most places, if you were approached by two mobsters in a dark alley, they would
probably tell you to give them all the money that you have. If yo... | {"inputs": ["5\n3 3\n1\n1\n1\n5 11\n1\n2\n4\n8\n16\n5 23\n1\n2\n4\n8\n16\n5 13\n1\n5\n5\n10\n10\n20 132\n17\n6\n4\n998\n254\n137\n259\n153\n154\n3\n28\n19\n123\n542\n857\n23\n687\n35\n99\n999"], "outputs": ["Yes\nYes\nYes\nNo\nYes"]} | 619 | 154 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will sort elements in an array by decreasing frequency of elements. If two elements have the same frequency, sort them by increasing value.
More examples in test cases.
Good luck!
Please also try [Simple time difference](https://w... | {"functional": "_inputs = [[[2, 3, 5, 3, 7, 9, 5, 3, 7]], [[1, 2, 3, 0, 5, 0, 1, 6, 8, 8, 6, 9, 1]], [[5, 9, 6, 9, 6, 5, 9, 9, 4, 4]], [[4, 4, 2, 5, 1, 1, 3, 3, 2, 8]], [[4, 9, 5, 0, 7, 3, 8, 4, 9, 0]]]\n_outputs = [[[3, 3, 3, 5, 5, 7, 7, 2, 9]], [[1, 1, 1, 0, 0, 6, 6, 8, 8, 2, 3, 5, 9]], [[9, 9, 9, 9, 4, 4, 5, 5, 6, 6... | 115 | 460 |
coding | Solve the programming task below in a Python markdown code block.
Just like in the ["father" kata](http://www.codewars.com/kata/find-fibonacci-last-digit/), you will have to return the last digit of the nth element in the Fibonacci sequence (starting with 1,1, to be extra clear, not with 0,1 or other numbers).
You wil... | {"functional": "_inputs = [[1], [21], [302], [4003], [50004], [600005], [7000006], [80000007], [900000008], [1000000009]]\n_outputs = [[1], [6], [1], [7], [8], [5], [3], [8], [1], [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, re... | 261 | 255 |
coding | Solve the programming task below in a Python markdown code block.
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The buildin... | {"inputs": ["2 2\n0010\n0100\n", "2 2\n0010\n0100\n", "3 2\n0000\n0100\n0100\n", "3 2\n0000\n0100\n0100\n", "3 2\n0010\n0100\n0100\n", "3 3\n00010\n00000\n00010\n", "3 3\n00010\n00000\n00010\n", "3 3\n00010\n00000\n00110\n"], "outputs": ["5\n", "5\n", "4\n", "4\n", "8\n", "7\n", "7\n", "7\n"]} | 685 | 205 |
coding | Solve the programming task below in a Python markdown code block.
Chef likes cooking. But more than that, he likes to give gifts. And now he wants to give his girlfriend an unforgettable gift. But unfortunately he forgot the password to the safe where the money he saved for the gift is kept.
But he knows how to hack t... | {"inputs": ["2\n3\n1 2 3\n1\n9", "2\n3\n2 2 3\n1\n9", "2\n3\n2 1 3\n1\n9", "2\n3\n3 1 3\n1\n9", "2\n3\n3 4 3\n1\n9", "2\n3\n1 2 6\n1\n9", "2\n3\n3 1 3\n1\n6", "2\n3\n3 4 3\n1\n4"], "outputs": ["-4\n9", "-3\n9\n", "-2\n9\n", "-1\n9\n", "-4\n9\n", "-7\n9\n", "-1\n6\n", "-4\n4\n"]} | 527 | 174 |
coding | Solve the programming task below in a Python markdown code block.
Mr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path.
To cut the distance short, one day he decides to construct a skywalk from his place to his friend’s place. Help him to f... | {"inputs": ["1\n2 L 2 R 2 L 1"], "outputs": ["5.0NW"]} | 308 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until... | {"inputs": ["1\n2 00\n", "2\n1 23\n", "3\n11 23\n", "5\n01 07\n", "2\n14 37\n", "3\n12 15\n", "9\n16 53\n", "5\n13 10\n"], "outputs": ["3\n", "3\n", "2\n", "0\n", "0\n", "6\n", "4\n", "63\n"]} | 449 | 117 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer arrays of the same length present and future where present[i] is the current price of the ith stock and future[i] is the price of the ith stock a year in the future. You may buy eac... | {"functional": "def check(candidate):\n assert candidate(present = [5,4,6,2,3], future = [8,5,4,3,5], budget = 10) == 6\n assert candidate(present = [2,2,5], future = [3,4,10], budget = 6) == 5\n assert candidate(present = [3,3,12], future = [0,3,15], budget = 10) == 0\n\n\ncheck(Solution().maximumProfit)"} | 138 | 125 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$.
Your problem is to find such pair of indices $i, j$ ($1 \le i < j \le n$) that $lcm(a_i, a_j)$ is minimum possible.
$lcm(x, y)$ is the least common multiple of $x$ and $y$ (m... | {"inputs": ["2\n1 1\n", "2\n7 2\n", "2\n6 7\n", "2\n4 4\n", "2\n8 8\n", "2\n6 5\n", "2\n8 8\n", "2\n6 5\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n"]} | 349 | 118 |
coding | Solve the programming task below in a Python markdown code block.
In a long narrow forest stretching east-west, there are N beasts. Below, we will call the point that is p meters from the west end Point p. The i-th beast from the west (1 ≤ i ≤ N) is at Point x_i, and can be sold for s_i yen (the currency of Japan) if c... | {"inputs": ["5\n10 2\n40 5\n60 3\n70 5\n90 1", "5\n10 2\n40 8\n60 3\n70 5\n90 1", "5\n10 2\n40 5\n60 3\n70 4\n90 1", "5\n28 17\n40 50\n60 35\n70 40\n90 3", "5\n2 20\n40 50\n60 13\n70 40\n89 10", "5\n2 20\n40 50\n60 13\n70 40\n71 10", "5\n18 17\n40 44\n60 35\n70 40\n90 3", "5\n10 20\n40 50\n60 35\n70 40\n90 10"], "outpu... | 428 | 288 |
coding | Solve the programming task below in a Python markdown code block.
Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of n steps. On... | {"inputs": ["1\n0\n1\n", "1\n0\n1\n", "2\n0 5\n4 0\n1 2\n", "2\n0 5\n7 0\n1 2\n", "2\n0 4\n7 0\n1 2\n", "2\n0 9\n7 0\n1 2\n", "2\n0 1\n7 0\n1 2\n", "2\n0 5\n4 0\n1 2\n"], "outputs": ["0 ", "0 \n", "9 0 ", "12 0", "11 0", "16 0", "8 0", "9 0 \n"]} | 510 | 161 |
coding | Solve the programming task below in a Python markdown code block.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know th... | {"inputs": ["1 1 1 0\n0\n", "1 1 1 0\n0\n", "2 2 1 0\n00\n", "2 2 1 0\n00\n", "5 1 2 1\n00100\n", "5 4 1 0\n00000\n", "5 1 2 1\n00100\n", "5 4 1 0\n00000\n"], "outputs": ["1\n1 \n", "1\n1 ", "1\n1 \n", "1\n1 \n", "2\n2 5 \n", "2\n1 2 \n", "2\n2 5\n", "2\n1 2 \n"]} | 530 | 181 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Under the grammar given below, strings can represent a set of lowercase words. Let R(expr) denote the set of words the expression represents.
The grammar can best be understood through simple examples:
Single letters... | {"functional": "def check(candidate):\n assert candidate(expression = \"{a,b}{c,{d,e}}\") == [\"ac\",\"ad\",\"ae\",\"bc\",\"bd\",\"be\"]\n assert candidate(expression = \"{{a,z},a{b,c},{ab,z}}\") == [\"a\",\"ab\",\"ac\",\"z\"]\n\n\ncheck(Solution().braceExpansionII)"} | 438 | 84 |
coding | Solve the programming task below in a Python markdown code block.
In McD's Burger, n hungry burger fans are ordering burgers. The ith order is placed by the ith fan at ti time and it takes di time to procees. What is the order in which the fans will get their burgers?
Input Format
On the first line you will get n, th... | {"inputs": ["2\n1 1\n1 1", "3\n1 3\n2 3\n3 3", "5\n8 1\n4 2\n5 6\n3 1\n4 3", "25\n122470 725261\n193218 693005\n355776 603340\n830347 284246\n974815 823134\n251206 572501\n55509 927152\n299590 651593\n222305 641645\n984018 463771\n494787 286091\n217190 833029\n820867 380896\n744986 630663\n875880 667\n449199 520904\n92... | 356 | 495 |
coding | Solve the programming task below in a Python markdown code block.
In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.
He decides to choose K trees from these trees and decorate them with electric lights. To make the ... | {"inputs": ["3 3\n5\n7\n0\n1\n7", "3 3\n5\n7\n5\n7\n7", "3 3\n5\n7\n5\n1\n7", "3 3\n5\n7\n5\n1\n5", "5 3\n5\n7\n5\n9\n7", "3 3\n5\n7\n5\n7\n6", "5 3\n5\n7\n2\n0\n6", "5 3\n5\n7\n5\n1\n5"], "outputs": ["7\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "0\n"]} | 334 | 158 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer x, return true if x is a palindrome, and false otherwise.
Please complete the following python code precisely:
```python
class Solution:
def isPalindrome(self, x: int) -> bool:
``` | {"functional": "def check(candidate):\n assert candidate(x = 121) == True\n assert candidate(x = -121) == False\n assert candidate(x = 10) == False\n\n\ncheck(Solution().isPalindrome)"} | 64 | 57 |
coding | Solve the programming task below in a Python markdown code block.
The member states of the UN are planning to send $2$ people to the moon. They want them to be from different countries. You will be given a list of pairs of astronaut ID's. Each pair is made of astronauts from the same country. Determine how many pair... | {"inputs": ["4 1\n0 2\n", "5 3\n0 1\n2 3\n0 4\n"], "outputs": ["5\n", "6\n"]} | 559 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Tenten runs a weapon shop for ninjas. Today she is willing to sell $n$ shurikens which cost $1$, $2$, ..., $n$ ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is f... | {"inputs": ["1\n- 1\n+\n", "1\n+\n- 1\n", "1\n+\n- 1\n", "1\n- 1\n+\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "3\n+\n+\n+\n- 2\n- 1\n- 2\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "4\n+\n+\n- 2\n+\n- 3\n+\n- 1\n- 4\n"], "outputs": ["NO\n", "YES\n1 \n", "YES\n1\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n4 2 3 1 \n"]} | 723 | 186 |
coding | Solve the programming task below in a Python markdown code block.
You are given an unrooted tree of $n$ nodes numbered from $\mbox{1}$ to $n$. Each node $\boldsymbol{i}$ has a color, $c_i$.
Let $d(i,j)$ be the number of different colors in the path between node $\boldsymbol{i}$ and node $j$. For each node $\boldsymbo... | {"inputs": ["5\n1 2 3 2 3\n1 2\n2 3\n2 4\n1 5\n"], "outputs": ["10\n9\n11\n9\n12\n"]} | 646 | 51 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s representing a list of words. Each letter in the word has one or more options.
If there is one option, the letter is represented as is.
If there is more than one option, then curly braces del... | {"functional": "def check(candidate):\n assert candidate(s = \"{a,b}c{d,e}f\") == [\"acdf\",\"acef\",\"bcdf\",\"bcef\"]\n assert candidate(s = \"abcd\") == [\"abcd\"]\n\n\ncheck(Solution().expand)"} | 181 | 66 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a singly linked list, reverse the list, and return the reversed list.
Please complete the following python code precisely:
```python
# Definition for singly-linked list.
# class ListNode:
# def... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5])), list_node([5,4,3,2,1]))\n assert is_same_list(candidate(head = list_node([1,2])), list_node([2,1]))\n assert is_same_list(candidate(head = list_node([])), list_node([]))\n\n\ncheck(Solution().reverseList)"} | 110 | 97 |
coding | Solve the programming task below in a Python markdown code block.
Rashmi loves the festival of Diwali as she gets to spend time with family and enjoy the festival. Before she can fully enjoy the festival she needs to complete the homework assigned by her teacher. Since Rashmi is smart , she has solved all the problems ... | {"inputs": ["1\n4", "2\n3 5"], "outputs": ["1 4 10 22\n2 5 11 23\n4 10 22 46\n3 6 12 24", "1 4 10\n2 5 11\n4 10 22\n3 6 12\n1 4 10 22 46\n2 5 11 23 47\n4 10 22 46 94\n3 6 12 24 48"]} | 398 | 143 |
coding | Solve the programming task below in a Python markdown code block.
This kata is from check py.checkio.org
You are given an array with positive numbers and a number N. You should find the N-th power of the element in the array with the index N. If N is outside of the array, then return -1. Don't forget that the first el... | {"functional": "_inputs = [[[1, 2, 3, 4], 2], [[1, 3, 10, 100], 3], [[0, 1], 0], [[0, 1], 1], [[1, 2], 2], [[1, 2], 3], [[0], 0], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 9], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 100], 9], [[29, 82, 45, 10], 3], [[6, 31], 3], [[75, 68, 35, 61, 9, 36, 89, 0, 30], 10]]\n_outputs = [[9], [1000000], [1], [... | 176 | 420 |
coding | Solve the programming task below in a Python markdown code block.
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are n cities in Berland. People can travel between cities using two-directional train route... | {"inputs": ["4 2\n1 2 4\n2 3 7\n6 20 1 25\n", "4 2\n1 2 7\n2 3 7\n6 20 1 25\n", "4 2\n1 2 4\n2 3 7\n6 20 1 37\n", "4 2\n1 2 4\n2 3 7\n6 20 1 25\n", "3 1\n1 2 2\n8 3 1\n1 0 2\n9 10 20\n", "3 1\n1 2 2\n3 3 1\n1 3 0\n30 9 20\n", "3 1\n1 2 2\n3 3 1\n1 5 0\n30 9 20\n", "3 1\n1 2 2\n4 3 1\n1 3 2\n9 10 20\n"], "outputs": ["6 ... | 669 | 326 |
coding | Solve the programming task below in a Python markdown code block.
In the previous challenge, you wrote code to perform an Insertion Sort on an unsorted array. But how would you prove that the code is correct? I.e. how do you show that for any input your code will provide the right output?
Loop Invariant
In computer ... | {"inputs": ["6\n7 4 3 5 6 2\n"], "outputs": ["2 3 4 5 6 7\n"]} | 653 | 36 |
coding | Solve the programming task below in a Python markdown code block.
In this challenge, you will be given an array $\mbox{B}$ and must determine an array $\mbox{A}$. There is a special rule: For all $\boldsymbol{i}$, $A[i]\leq B[i]$. That is, $A[i]$ can be any number you choose such that $1\leq A[i]\leq B[i]$. Your ta... | {"inputs": ["1\n5\n10 1 10 1 10\n"], "outputs": ["36\n"]} | 681 | 30 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers k, p_{a} and p_{b}.
You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability p_{a} / (p_{a} + p_{b}), add 'a' to the end of the... | {"inputs": ["1 1 1\n", "3 1 4\n", "1 1 2\n", "3 1 2\n", "3 1 1\n", "1 1 1\n", "3 1 4\n", "4 78149 46740\n"], "outputs": ["2\n", "370000006\n", "500000005", "722222231", "250000006", "2\n", "370000006\n", "604608981"]} | 471 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Give me Biscuit
Sunny wants to make slices of biscuit of size c * d into identical pieces.
but each piece is a square having maximum possible side length with no left over piece of biscuit.
Input Format
The first line contains an integer N.
N lines ... | {"inputs": ["2\n2 2\n6 9"], "outputs": ["1\n6"]} | 279 | 22 |
coding | Solve the programming task below in a Python markdown code block.
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single sto... | {"inputs": ["1\n2\n1 6\n", "1\n2\n1 3\n", "1\n2\n1 4\n", "1\n2\n1 1\n", "1\n2\n1 8\n", "1\n2\n2 1\n", "1\n2\n2 2\n", "1\n2\n1 9\n"], "outputs": ["T\n", "T\n", "T\n", "HL\n", "T\n", "T\n", "HL\n", "T\n"]} | 393 | 118 |
coding | Solve the programming task below in a Python markdown code block.
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct pos... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n2\n", "1 1\n3\n", "1 2\n3\n", "1 4\n3\n", "1 2\n5\n", "1 4\n5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 276 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has 3 bags that she wants to take on a flight. They weigh A, B, and C kgs respectively. She wants to check-in exactly two of these bags and carry the rem... | {"inputs": ["3\n1 1 1 15 5\n8 7 6 15 5\n8 5 7 15 6"], "outputs": ["YES\nNO\nYES"]} | 505 | 49 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones.
Call a stone an endpoint stone if it has the smallest or largest position. In one move, y... | {"functional": "def check(candidate):\n assert candidate([7,4,9]) == [1,2]\n assert candidate([6,5,4,3,10]) == [2,3]\n assert candidate([100,101,104,102,103]) == [0,0]\n\n\ncheck(Solution().numMovesStonesII)"} | 240 | 92 |
coding | Solve the programming task below in a Python markdown code block.
In an infinite array with two rows, the numbers in the top row are denoted
`. . . , A[−2], A[−1], A[0], A[1], A[2], . . .`
and the numbers in the bottom row are denoted
`. . . , B[−2], B[−1], B[0], B[1], B[2], . . .`
For each integer `k`, the entry `... | {"functional": "_inputs = [[[1, 2, 3, 4], 2], [[38, 200, -18, 45], 1], [[1, 0, 0, 1], 5], [[0, 2, 0, 3], -2], [[-20, 1, -3, 14], -5], [[1, 2, 3, 5], 100], [[0, 4, 6, 13], 100]]\n_outputs = [[3], [200], [20], [-126], [-44402], [60560100487003612846322657690093088848428068520476594299], [335254562473098582210532865941148... | 362 | 407 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not.
He has a positive integer X represented as a product of... | {"inputs": ["1\n3\n21 11 6"], "outputs": ["3"]} | 513 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Gru has a string $S$ of length $N$, consisting of only characters $a$ and $b$ for banana and $P$ points to spend.
Now Gru wants to replace and/or re-arrange characters of this given string to get the lexicographically smallest string possible. For this, ... | {"inputs": ["1\n3 3\nbba"], "outputs": ["aab"]} | 389 | 19 |
coding | Solve the programming task below in a Python markdown code block.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioni... | {"inputs": ["4\n1 2 3 4\n2\n2 3\n2 2\n", "4\n1 2 3 4\n2\n2 3\n2 1\n", "4\n1 2 3 8\n2\n2 3\n2 1\n", "4\n2 4 3 8\n2\n2 3\n2 1\n", "4\n1 2 3 4\n2\n2 3\n2 4\n", "4\n1 2 3 0\n2\n2 3\n2 1\n", "4\n0 2 5 4\n2\n2 3\n2 1\n", "4\n1 2 4 0\n2\n2 3\n2 1\n"], "outputs": ["3 3 3 4\n", "3 3 3 4\n", "3 3 3 8\n", "3 4 3 8\n", "4 4 4 4\n"... | 553 | 262 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length N, a_1,a_2,...,a_N.
For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.
After these operations, you select an integer X and count the number of i such that a_i=X.
Maximiz... | {"inputs": ["1\n68972", "1\n99999", "7\n3 1 7 1 5 9 2", "7\n3 1 7 1 5 9 0", "7\n3 1 2 1 5 9 1", "7\n1 2 2 0 1 2 1", "7\n3 1 2 1 5 9 0", "7\n3 1 2 0 5 9 1"], "outputs": ["1\n", "1", "4\n", "3\n", "5\n", "7\n", "4\n", "4\n"]} | 240 | 157 |
coding | Solve the programming task below in a Python markdown code block.
Four-digit palindromes start with `[1001,1111,1221,1331,1441,1551,1551,...]` and the number at position `2` is `1111`.
You will be given two numbers `a` and `b`. Your task is to return the `a-digit` palindrome at position `b` if the palindromes were a... | {"functional": "_inputs = [[2, 2], [3, 10], [4, 5], [5, 19], [6, 3], [6, 20], [7, 3]]\n_outputs = [[22], [191], [1441], [11811], [102201], [119911], [1002001]]\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... | 267 | 240 |
coding | Solve the programming task below in a Python markdown code block.
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts ... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "2 1 2\n1 2\n", "2 1 2\n2 1\n", "2 2 2\n1 2\n", "2 2 2\n2 1\n", "2 1 1\n2 1\n", "2 1 2\n2 1\n"], "outputs": ["0\n", "0\n", "-1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]} | 494 | 130 |
coding | Solve the programming task below in a Python markdown code block.
Hardy wants to test Ramanujam of his Mathematical skills. So he gives him a puzzle which is described below.
Puzzle:
There are 100 doors, numbered 1,2,....100 .Initially all doors are closed.
Now a person comes(lets call him the 1st person)he opens the ... | {"inputs": ["400012 31\n10194\n59030\n6930\n39402\n24765\n38154\n147756\n25399\n221328\n30059\n71528\n128184\n18710\n79764\n47450\n176355\n8061\n7335\n82824\n61380\n286810\n634\n7410\n153984\n2277\n46980\n12568\n18390\n173054\n20181\n184416"], "outputs": ["1252\n5968\n890\n4148\n2739\n4027\n13656\n2800\n19724\n3250\n70... | 594 | 363 |
coding | Solve the programming task below in a Python markdown code block.
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.
An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connec... | {"inputs": ["3\n1 2\n2 3\n3\n", "3\n1 2\n1 3\n2 3\n", "3\n1 2\n1 3\n3 2\n", "4\n1 2\n1 3\n1 4\n4 3 2\n", "5\n1 2\n4 3\n1 4\n4 5\n5 2 3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6\n", "8\n4 3\n1 4\n8 5\n7 6\n3 5\n7 3\n4 2\n2 6 8\n"], "outputs": ["1 2 3 2 1 ", "1 2 1 3 1 ", "1 3 1 2 1 ",... | 434 | 307 |
coding | Solve the programming task below in a Python markdown code block.
Adam and Martha are planning to leave the city after their retirement and build a house in a huge land belonging to their family. To keep everyone happy, they want to build the house at a location having distance _a*d1_ from aunt Kimberly's house, where ... | {"inputs": ["3 4\n4 0\n0 0\n-2 -4\n-2 -1\n"], "outputs": ["-2.00 0.00\n"]} | 408 | 43 |
coding | Solve the programming task below in a Python markdown code block.
You are the best freelancer in the city. Everybody knows you, but what they don't know, is that you are actually offloading your work to other freelancers and and you rarely need to do any work. You're living the life!
To make this process easier you ne... | {"functional": "_inputs = [[60, [[1, 0]]], [60, [[0, 0]]]]\n_outputs = [['Easy Money!'], ['I need to work 1 hour(s) and 0 minute(s)']]\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, (lis... | 244 | 192 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that takes two arguments, and returns a new array populated with the elements **that only appear once, in either one array or the other, taken only once**; display order should follow what appears in arr1 first, then arr2:
```python
ho... | {"functional": "_inputs = [[['tartar', 'blanket', 'domino'], ['blanket']], [[77, 'basketweave'], [78, 42, 'basketweave']], [[100, 45, 'ciao'], [100, 2, 3, 45, 5]], [[10, 200, 30], [10, 20, 3, 4, 5, 5, 5, 200]], [[1, 2, 3, 3], [3, 2, 1, 4, 5, 4]]]\n_outputs = [[['tartar', 'domino']], [[77, 78, 42]], [['ciao', 2, 3, 5]],... | 258 | 350 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a m x n matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix.
Among all possible paths starting from the top-left corner ... | {"functional": "def check(candidate):\n assert candidate(grid = [[-1,-2,-3],[-2,-3,-3],[-3,-3,-2]]) == -1\n assert candidate(grid = [[1,-2,1],[1,-2,1],[3,-4,1]]) == 8\n assert candidate(grid = [[1,3],[0,-4]]) == 0\n\n\ncheck(Solution().maxProductPath)"} | 194 | 95 |
coding | Solve the programming task below in a Python markdown code block.
My grandfather always predicted how old people would get, and right before he passed away he revealed his secret!
In honor of my grandfather's memory we will write a function using his formula!
* Take a list of ages when each of your great-grandparent ... | {"functional": "_inputs = [[65, 60, 75, 55, 60, 63, 64, 45], [32, 54, 76, 65, 34, 63, 64, 45]]\n_outputs = [[86], [79]]\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 ... | 275 | 220 |
coding | Solve the programming task below in a Python markdown code block.
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
- Decrease the height of the square by 1.
- Do nothing.
Determine i... | {"inputs": ["1\n1\n", "4\n1 5 2 1", "4\n1 5 2 2", "4\n0 5 2 2", "4\n0 8 2 2", "4\n0 8 4 2", "4\n0 1 4 2", "4\n0 1 4 1"], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 244 | 121 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a list of songs where the ith song has a duration of time[i] seconds.
Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of ind... | {"functional": "def check(candidate):\n assert candidate(time = [30,20,150,100,40]) == 3\n assert candidate(time = [60,60,60]) == 3\n\n\ncheck(Solution().numPairsDivisibleBy60)"} | 128 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Chef has two piles of stones with him, one has n1 stones and the other has n2 stones. Fired up by boredom, he invented a game with the two piles.
Before the start of the game Chef chooses an integer m.
In the j-th move:
- He chooses a number xj such... | {"inputs": ["3\n1 1 1\n1 2 1\n4 5 2"], "outputs": ["0\n1\n3"]} | 622 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chefland has $7$ days in a week. Chef is very conscious about his work done during the week.
There are two ways he can spend his energy during the week. The ... | {"inputs": ["3\n1 2 3 1\n6 2 3 1\n1 2 8 1"], "outputs": ["14\n19\n14"]} | 535 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Look for the Winner!
The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting is going ... | {"inputs": ["1\nA\n4\nA A B C\n5\nL M N L O\n1\nJ K K K J K\n0\nX Y Y Y Z X\n8\nB B A B A C A D C B\n1\nV V U U U W V W V V\n0", "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n1\nV U U U U V V W V W\n0", "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A ... | 699 | 702 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.