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.
Zonal Computing Olympiad 2012, 26 Nov 2011
A sequence of opening and closing brackets is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the usual sense. For instance, the sequences (), (()) and ()(()) are well-... | {"inputs": ["20\n1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2"], "outputs": ["2 4 6 9"]} | 666 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Chef has decided to go to a gold mine along with N of his friends (thus, total N+1 people including Chef go to the gold mine).
The gold mine contains a total of X kg of gold. Every person has the capacity of carrying up \textbf{atmost} Y kg of gold.
Wi... | {"inputs": ["3\n2 10 3\n2 10 4\n1 5 10\n"], "outputs": ["NO\nYES\nYES\n"]} | 373 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and offered an a... | {"inputs": ["2\n-1 100\n2 -1\n", "2\n-1 000\n2 -1\n", "2\n-1 101\n2 -1\n", "2\n-1 001\n2 -1\n", "2\n-2 101\n2 -1\n", "2\n-2 100\n2 -1\n", "2\n-2 000\n2 -1\n", "2\n-4 100\n2 -1\n"], "outputs": ["99\n2 1 \n", "-1\n2 1 ", "100\n2 1 ", "0\n2 1 ", "99\n2 1 ", "98\n2 1 ", "-2\n2 1 ", "96\n2 1 "]} | 641 | 191 |
coding | Solve the programming task below in a Python markdown code block.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each datas... | {"inputs": ["2\n0\n8", "2\n0\n1", "2\n1\n8", "2\n2\n8", "2\n1\n1", "2\n4\n8", "2\n1\n2", "2\n4\n1"], "outputs": ["10\n1\n165\n", "10\n1\n4\n", "10\n4\n165\n", "10\n10\n165\n", "10\n4\n4\n", "10\n35\n165\n", "10\n4\n10\n", "10\n35\n4\n"]} | 158 | 146 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that
- i ≠ j
- |ai + aj - K| is minimal possible
Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of ... | {"inputs": ["1\n4 9\n4 4 2 6", "1 \n4 7\n4 0 2 6", "1 \n4 7\n0 0 0 0", "1 \n4 0\n9 1 1 1", "1 \n4 8\n0 1 1 1", "1 \n4 9\n4 4 2 6", "1 \n4 14\n4 4 2 6", "1 \n4 14\n4 1 2 6"], "outputs": ["1 4", "1 3\n", "7 6\n", "2 3\n", "6 3\n", "1 4\n", "4 2\n", "4 1\n"]} | 343 | 189 |
coding | Solve the programming task below in a Python markdown code block.
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ... | {"inputs": ["1\n0\n", "1\n5\n", "1\n9\n", "1\n1\n", "1\n-1\n", "1\n-2\n", "1\n-4\n", "1\n-7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 505 | 90 |
coding | Solve the programming task below in a Python markdown code block.
The chef is having one string of English lower case alphabets only. The chef wants to remove all "abc" special pairs where a,b,c are occurring consecutively. After removing the pair, create a new string and again remove "abc" special pair from a newly fo... | {"inputs": ["2\naabcc\nbababccc"], "outputs": ["ac\nbc"]} | 262 | 21 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer num. You will apply the following steps exactly two times:
Pick a digit x (0 <= x <= 9).
Pick another digit y (0 <= y <= 9). The digit y can be equal to x.
Replace all the occurrences of x in... | {"functional": "def check(candidate):\n assert candidate(num = 555) == 888\n assert candidate(num = 9) == 8\n assert candidate(num = 123456) == 820000\n assert candidate(num = 10000) == 80000\n assert candidate(num = 9288) == 8700\n\n\ncheck(Solution().maxDiff)"} | 160 | 107 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:
If t... | {"functional": "def check(candidate):\n assert candidate(title = \"capiTalIze tHe titLe\") == \"Capitalize The Title\"\n assert candidate(title = \"First leTTeR of EACH Word\") == \"First Letter of Each Word\"\n assert candidate(title = \"i lOve leetcode\") == \"i Love Leetcode\"\n\n\ncheck(Solution().capitali... | 128 | 89 |
coding | Solve the programming task below in a Python markdown code block.
You are asked to watch your nephew who likes to play with toy blocks in a strange way.
He has $n$ boxes and the $i$-th box has $a_i$ blocks. His game consists of two steps:
he chooses an arbitrary box $i$;
he tries to move all blocks from the $i$-th b... | {"inputs": ["1\n3\n1000 1000 1001\n", "1\n3\n1000 1000 1001\n", "1\n3\n0000 1000 1001\n", "1\n3\n1000 1001 1001\n", "1\n3\n0000 1000 1000\n", "1\n3\n1000 1001 0001\n", "1\n3\n0001 1000 1000\n", "1\n2\n1000000000 1000000000\n"], "outputs": ["1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "0\n"]} | 610 | 213 |
coding | Solve the programming task below in a Python markdown code block.
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: if the last digit of the number is non-zero, she decreases... | {"inputs": ["5 2\n", "2 1\n", "2 1\n", "5 2\n", "2 0\n", "9 2\n", "3 2\n", "3 0\n"], "outputs": ["3\n", "1\n", "1\n", "3\n", "2\n", "7\n", "1\n", "3\n"]} | 326 | 86 |
coding | Solve the programming task below in a Python markdown code block.
The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!
There are $n$ snacks flavors, numbered with integer... | {"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "4 2\n1 2\n2 3\n", "4 2\n1 3\n2 4\n", "4 2\n1 3\n2 4\n", "4 2\n1 2\n2 3\n", "4 2\n2 3\n2 4\n", "4 2\n1 2\n2 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 525 | 142 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums containing n integers, find the beauty of each subarray of size k.
The beauty of a subarray is the xth smallest integer in the subarray if it is negative, or 0 if there are fewer than x neg... | {"functional": "def check(candidate):\n assert candidate(nums = [1,-1,-3,-2,3], k = 3, x = 2) == [-1,-2,-2]\n assert candidate(nums = [-1,-2,-3,-4,-5], k = 2, x = 2) == [-1,-2,-3,-4]\n assert candidate(nums = [-3,1,2,-3,0,-3], k = 2, x = 1) == [-3,0,-3,-3,-3]\n\n\ncheck(Solution().getSubarrayBeauty)"} | 158 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.
~~~if-not:racket
```
invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []
```
~... | {"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, -2, 3, -4, 5]], [[]], [[0]]]\n_outputs = [[[-1, -2, -3, -4, -5]], [[-1, 2, -3, 4, -5]], [[]], [[0]]]\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 i... | 262 | 220 |
coding | Solve the programming task below in a Python markdown code block.
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string s ... | {"inputs": ["1 2\na\n", "1 2\nb\n", "1 1\na\n", "1 2\nb\n", "1 2\na\n", "1 2\nb\n", "1 1\na\n", "1 4\na\n"], "outputs": ["b\n", "NO\n", "NO\n", "NO\n", "b\n", "NO\n", "NO\n", "b\n"]} | 336 | 102 |
coding | Solve the programming task below in a Python markdown code block.
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and a_{i} is the length of i-th segment. No two seg... | {"inputs": ["1 1\n1\n", "1 2\n1\n", "1 6\n5\n", "1 5\n2\n", "1 3\n1\n", "1 7\n5\n", "1 1\n3\n", "1 3\n2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 422 | 102 |
coding | Solve the programming task below in a Python markdown code block.
We have N integers. The i-th number is A_i.
\{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.
\{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots... | {"inputs": ["3\n4 4 2", "3\n4 3 1", "3\n4 4 5", "3\n4 8 2", "3\n8 8 2", "3\n4 4 1", "3\n4 4 4", "3\n6 8 2"], "outputs": ["not coprime\n", "pairwise coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n"]} | 318 | 137 |
coding | Solve the programming task below in a Python markdown code block.
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two int... | {"inputs": ["1 5\n1 7\n", "1 2\n0 8\n", "1 7\n1 7\n", "1 5\n1 7\n", "1 5\n1 13\n", "1 4\n1 13\n", "1 4\n0 13\n", "1 2\n0 13\n"], "outputs": ["-1\n", "-6\n", "1\n", "-1\n", "-7\n", "-8\n", "-9\n", "-11\n"]} | 413 | 124 |
coding | Solve the programming task below in a Python markdown code block.
The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.
There is a permutation $p_i$ of number... | {"inputs": ["2\n3 4 2 1\n", "2\n1 4 4 2\n", "2\n1 2 4 2\n", "2\n3 4 2 1\n", "3\n6 3 2 5 4 1\n", "3\n5 4 1 6 3 2\n", "3\n5 4 1 6 3 2\n", "3\n6 1 2 5 4 2\n"], "outputs": ["-1\n", "-1\n", "-1\n", "\n-1\n", "3\n", "2\n", "2\n", "-1\n"]} | 453 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
You are given a grid with $N$ rows and $M$ columns; each cell of this grid is either empty or contains an obstacle. Initially, all cells are colorless.
You ... | {"inputs": ["2\n3 3\n..#\n...\n...\n3 3\n...\n.#.\n..."], "outputs": ["YES\nNO"]} | 429 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions:
* The largest among the values in th... | {"inputs": ["0 2\n4 3\n3 4", "2 2\n6 4\n4 4", "2 2\n6 4\n5 4", "0 2\n8 3\n3 4", "2 2\n6 1\n5 4", "0 2\n8 3\n3 0", "2 2\n6 2\n5 4", "0 2\n7 3\n3 0"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]} | 464 | 142 |
coding | Solve the programming task below in a Python markdown code block.
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher... | {"inputs": ["1\n(\n", "1\n(\n", "1\n)\n", "2\n((\n", "2\n((\n", "2\n()\n", "3\n(()\n", "3\n((*\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n", "-1\n", "-1\n"]} | 539 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have... | {"inputs": ["2\n2\n", "1\n1\n", "9\n9\n", "5\n5\n", "5\n5\n", "1\n1\n", "9\n9\n", "2\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 229 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums.
The low score of nums is the minimum absolute difference between any two integers.
The high score of nums is the maximum absolute difference between any two integers.
The score of... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,3]) == 0\n assert candidate(nums = [1,4,7,8,5]) == 3\n\n\ncheck(Solution().minimizeSum)"} | 111 | 56 |
coding | Solve the programming task below in a Python markdown code block.
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a ≤ b). You want to fi... | {"inputs": ["2 4 2\n", "1 4 3\n", "5 8 2\n", "1 5 2\n", "6 8 3\n", "1 1 1\n", "1 2 1\n", "1 3 1\n"], "outputs": ["3\n", "-1\n", "4\n", "3\n", "-1\n", "-1\n", "2\n", "2\n"]} | 255 | 102 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array of `n+1` integers `1` through `n`. In addition there is a single duplicate integer.
The array is unsorted.
An example valid array would be `[3, 2, 5, 1, 3, 4]`. It has the integers `1` through `5` and `3` is duplicated. `[1, 2, 4... | {"functional": "_inputs = [[[1, 1, 2, 3]], [[1, 2, 2, 3]], [[5, 4, 3, 2, 1, 1]], [[1, 3, 2, 5, 4, 5, 7, 6]], [[8, 2, 6, 3, 7, 2, 5, 1, 4]]]\n_outputs = [[1], [2], [1], [5], [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=t... | 149 | 256 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
On a campus represented as a 2D grid, there are n workers and m bikes, with n <= m. Each worker and bike is a 2D coordinate on this grid.
We assign one unique bike to each worker so that the sum of the Manhattan dista... | {"functional": "def check(candidate):\n assert candidate(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]) == 6\n assert candidate(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]) == 4\n assert candidate(workers = [[0,0],[1,0],[2,0],[3,0],[4,0]], bikes = [[0,999],[1,999],[2,999],[3,999],[4,999]]) == 4... | 175 | 155 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings words and a character separator, split each string in words by separator.
Return an array of strings containing the new strings formed after the splits, excluding empty strings.
Notes
separa... | {"functional": "def check(candidate):\n assert candidate(words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\") == [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\n assert candidate(words = [\"$easy$\",\"$problem$\"], separator = \"$\") == [\"easy\",\"problem\"]\n assert candidate(words = ... | 141 | 112 |
coding | Solve the programming task below in a Python markdown code block.
Rupsa really loves triangles. One day she came across an equilateral triangle having length of each side as an integer N. She started wondering if it was possible to transform the triangle keeping two sides fixed and alter the third side such that it sti... | {"inputs": ["2\n5\n3"], "outputs": ["YES\nNO"]} | 342 | 18 |
coding | Solve the programming task below in a Python markdown code block.
Alex is attending a Halloween party with his girlfriend, Silvia. At the party, Silvia spots the corner of an infinite chocolate bar (two dimensional, infinitely long in width and length).
If the chocolate can be served only as 1 x 1 sized pieces and A... | {"inputs": ["4\n5\n6\n7\n8\n"], "outputs": ["6\n9\n12\n16\n"]} | 329 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
Return all lonely numbers in nums. You may return the answer in ... | {"functional": "def check(candidate):\n assert candidate(nums = [10,6,5,8]) == [10,8]\n assert candidate(nums = [1,3,5,3]) == [1,5]\n\n\ncheck(Solution().findLonely)"} | 108 | 64 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to h... | {"inputs": ["1 1\n-27\n61769\n", "1 1\n1\n-164538\n", "1 1\n1\n-4000000\n", "1 1\n1\n-4000000\n", "1 1\n1\n-1911669\n", "1 1\n1\n-1398610\n", "1 1\n1\n-1396982\n", "1 1\n-659\n61769\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 542 | 172 |
coding | Solve the programming task below in a Python markdown code block.
Chef and Chefina are competing against each other in a programming contest. They were both able to solve all the problems in the contest, so the winner between them must be decided by time penalty. Chef solved all the problems in X minutes and made P wro... | {"inputs": ["3\n10 8 2 3\n10 10 10 10\n40 21 2 0\n"], "outputs": ["Chef\nDraw\nChefina"]} | 721 | 49 |
coding | Solve the programming task below in a Python markdown code block.
The medians of a triangle are the segments that unit the vertices with the midpoint of their opposite sides.
The three medians of a triangle intersect at the same point, called the barycenter or the centroid.
Given a triangle, defined by the cartesian co... | {"functional": "_inputs = [[[4, 6], [12, 4], [10, 10]], [[4, 2], [12, 2], [6, 10]], [[4, 8], [8, 2], [16, 6]]]\n_outputs = [[[8.6667, 6.6667]], [[7.3333, 4.6667]], [[9.3333, 5.3333]]]\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... | 355 | 257 |
coding | Solve the programming task below in a Python markdown code block.
You are given a keyboard that consists of $26$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.
You have to type the word $s$ on this keyboard. It also consists only of lowe... | {"inputs": ["1\nabcdefghilkjmnopqrstuvwxyz\nabdes\n", "1\nabcdefghilkjmnopqrstuvwxyz\nabdes\n", "1\nabcdefyhilkjmnopqrstuvwxgz\nabdes\n", "1\nzhxwvutsrqponmjklihyfedcba\nasdeb\n", "1\nzhxwvutsrqponmjklihyfedcba\naseeb\n", "1\nzhxwvutsrqponmjklihyfedcba\nbbdes\n", "1\nzhxwvutsrqponmjklihyfedcba\nsaeeb\n", "1\nabcdefjhil... | 562 | 189 |
coding | Solve the programming task below in a Python markdown code block.
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \... | {"inputs": ["2\n17 23\n11 15\n", "3\n12 15\n2 3\n8 13\n"], "outputs": ["16\n8\n", "12\n2\n8\n"]} | 611 | 57 |
coding | Solve the programming task below in a Python markdown code block.
There are N towns in the State of Atcoder, connected by M bidirectional roads.
The i-th road connects Town A_i and B_i and has a length of C_i.
Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).
She will fly to the ... | {"inputs": ["5 3 2\n1 3\n2 3 2\n1 3 6\n1 2 2", "5 3 2\n1 3\n2 3 2\n1 3 6\n1 1 2", "3 3 2\n1 3\n2 3 0\n0 3 6\n1 2 2", "6 3 2\n1 3\n2 3 2\n1 3 9\n0 1 2", "6 3 2\n1 4\n4 3 2\n1 3 9\n0 1 2", "5 3 2\n2 2\n2 3 0\n1 5 8\n1 2 2", "6 3 2\n1 3\n2 3 2\n1 3 6\n1 1 2", "6 3 2\n1 3\n2 3 2\n1 3 7\n1 1 2"], "outputs": ["4\n", "6\n", "... | 425 | 271 |
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. Each digit of n has a sign according to the following rules:
The most significant digit is assigned a positive sign.
Each other digit has an opposite sign to its adjacent digits.
... | {"functional": "def check(candidate):\n assert candidate(n = 521) == 4\n assert candidate(n = 111) == 1\n assert candidate(n = 886996) == 0\n\n\ncheck(Solution().alternateDigitSum)"} | 102 | 65 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition o... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,4]) == [2,3]\n assert candidate(nums = [1,1]) == [1,2]\n\n\ncheck(Solution().findErrorNums)"} | 146 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Story:
In the realm of numbers, the apocalypse has arrived. Hordes of zombie numbers have infiltrated and are ready to turn everything into undead. The properties of zombies are truly apocalyptic: they reproduce themselves unlimitedly and freely interact... | {"functional": "_inputs = [[[7, 11]], [[1, 7, 15]], [[2, 10]], [[687, 829, 998]], [[]], [[1]]]\n_outputs = [[59], [0], [-1], [45664], [-1], [0]]\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 isinstan... | 420 | 216 |
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 that you must perform k replacement operations on. The replacement operations are given as three 0-indexed parallel arrays, indices, sources, and targets, all of length k.
To complet... | {"functional": "def check(candidate):\n assert candidate(s = \"abcd\", indices = [0,2], sources = [\"a\",\"cd\"], targets = [\"eee\",\"ffff\"]) == \"eeebffff\"\n assert candidate(s = \"abcd\", indices = [0,2], sources = [\"ab\",\"ec\"], targets = [\"eee\",\"ffff\"]) == \"eeecd\"\n\n\ncheck(Solution().findReplaceS... | 300 | 99 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary tree, determine if it is height-balanced.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=Non... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == True\n assert candidate(root = tree_node([1,2,2,3,3,None,None,4,4])) == False\n assert candidate(root = tree_node([])) == True\n\n\ncheck(Solution().isBalanced)"} | 114 | 84 |
coding | Solve the programming task below in a Python markdown code block.
An English text needs to be encrypted using the following encryption scheme.
First, the spaces are removed from the text. Let $L$ be the length of this text.
Then, characters are written into a grid, whose rows and columns have the following constrai... | {"inputs": ["chillout\n", "haveaniceday\n", "feedthedog \n"], "outputs": ["clu hlt io\n", "hae and via ecy\n", "fto ehg ee dd\n"]} | 662 | 53 |
coding | Solve the programming task below in a Python markdown code block.
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.
Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ... | {"inputs": ["2\n0\n1 0\n", "3\n0 0\n0 1 1\n", "5\n0 1 1 3\n0 0 0 1 1\n", "6\n0 2 1 0 4\n1 1 0 0 1 0\n", "6\n0 2 1 0 4\n1 1 0 1 1 0\n", "6\n0 1 1 0 4\n1 1 0 1 1 0\n", "6\n0 1 1 0 4\n1 1 0 1 1 1\n", "6\n0 1 2 0 4\n1 1 0 0 1 0\n"], "outputs": ["1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 436 | 214 |
coding | Solve the programming task below in a Python markdown code block.
You talked to Polycarp and asked him a question. You know that when he wants to answer "yes", he repeats Yes many times in a row.
Because of the noise, you only heard part of the answer — some substring of it. That is, if he answered YesYes, then you co... | {"inputs": ["1\nesY\n", "1\nali\n", "1\nccf\n", "1\nYesYesYesYesYesYesa\n", "1\nsYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesY\n", "12\nYES\nesYes\ncodeforces\nes\nse\nYesY\nesYesYesYesYesYesYe\nseY\nYess\nsY\no\nYes\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nNO\... | 397 | 149 |
coding | Solve the programming task below in a Python markdown code block.
Omkar's most recent follower, Ajit, has entered the Holy Forest. Ajit realizes that Omkar's forest is an n by m grid (1 ≤ n, m ≤ 2000) of some non-negative integers. Since the forest is blessed by Omkar, it satisfies some special conditions:
1. For an... | {"inputs": ["3\n5 3\n###\n###\n###\n###\n0##\n3 3\n###\n###\n#0#\n2 4\n####\n####\n", "5\n5 4\n0000\n0000\n00#0\n0000\n0000\n4 4\n#000\n00#0\n#000\n0000\n4 3\n000\n0#0\n#00\n000\n5 1\n0\n0\n0\n0\n0\n2 8\n00#00000\n000#000#\n", "1\n6 10\n0####0###0\n00#000##00\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\... | 630 | 840 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this ... | {"inputs": ["5\n1 1 3 1 1\n", "5\n1 1 5 1 1\n", "5\n1 1 3 1 1\n", "5\n1 1 30 34 11\n", "7\n3 4 1 2 2 1 1\n", "7\n1 4 1 2 2 1 1\n", "7\n1 4 1 2 1 1 1\n", "7\n1 4 1 3 1 1 1\n"], "outputs": ["2\n3 4 \n", "2\n5 4 ", "2\n3 4 ", "4\n2 30 34 11 ", "4\n3 8 2 1 \n", "2\n8 4 ", "3\n8 2 1 ", "3\n3 8 1 "]} | 592 | 213 |
coding | Solve the programming task below in a Python markdown code block.
This kata is inspired on the problem #50 of the Project Euler.
The prime ``` 41``` is the result of the sum of many consecutive primes.
In fact, ``` 2 + 3 + 5 + 7 + 11 + 13 = 41 , (6 addens) ```
Furthermore, the prime ``` 41``` is the prime belo... | {"functional": "_inputs = [[100], [200], [500], [1000]]\n_outputs = [[[41]], [[197]], [[499]], [[953]]]\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) ... | 405 | 191 |
coding | Solve the programming task below in a Python markdown code block.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of s... | {"inputs": ["1\n4\n5\n", "1\n5\n4\n", "1\n5\n5\n", "1\n6\n5\n", "1\n5\n0\n", "1\n6\n6\n", "1\n2\n6\n", "1\n2\n1\n"], "outputs": ["4 ", "4 ", "5 ", "5\n", "0\n", "6\n", "2\n", "1\n"]} | 540 | 99 |
coding | Solve the programming task below in a Python markdown code block.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.... | {"inputs": ["2 35 7\n0\n26", "2 9 4\n20\n91", "2 10 4\n20\n37", "2 17 4\n20\n37", "2 11 7\n20\n37", "2 10 4\n39\n37", "2 10 4\n39\n64", "2 10 4\n20\n20"], "outputs": ["1\n", "11\n", "5\n", "3\n", "4\n", "6\n", "8\n", "4"]} | 399 | 148 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings.
Return the maximum number of copies of target that can be formed by taking letters from s and ... | {"functional": "def check(candidate):\n assert candidate(s = \"ilovecodingonleetcode\", target = \"code\") == 2\n assert candidate(s = \"abcba\", target = \"abc\") == 1\n assert candidate(s = \"abbaccaddaeea\", target = \"aaaaa\") == 1\n\n\ncheck(Solution().rearrangeCharacters)"} | 103 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts share... | {"inputs": ["1 1\n+ 1\n", "2 1\n- 2\n", "2 1\n+ 1\n", "2 1\n+ 2\n", "20 1\n- 16\n", "2 2\n- 1\n+ 1\n", "6 2\n+ 1\n- 2\n", "6 2\n+ 1\n- 4\n"], "outputs": ["1\n1 \n", "2\n1 2 \n", "2\n1 2 \n", "2\n1 2 \n", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \n", "2\n1 2 \n", "4\n3 4 5 6 \n", "4\n2 3 5 6 \n"]} | 613 | 226 |
coding | Solve the programming task below in a Python markdown code block.
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.
Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his s... | {"inputs": ["1 2\nab\n", "1 3\nab\n", "1 3\nab\n", "1 0\nab\n", "0 2\nab\n", "1 1\nab\n", "1 1\naa\n", "1 2\nab\n"], "outputs": ["Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n"]} | 341 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has $n$ rooms. In the $i$-th room you can install at mos... | {"inputs": ["4\n1 10000\n10000 1\n2 6\n4 6\n", "4\n1 10000\n10000 1\n2 9\n4 6\n", "4\n1 10000\n10000 1\n2 9\n4 9\n", "4\n1 10000\n10000 1\n2 9\n4 4\n", "4\n1 10000\n10000 1\n2 9\n4 3\n", "4\n1 10000\n10000 1\n2 7\n4 6\n", "4\n1 11000\n10000 1\n2 9\n4 6\n", "4\n1 10000\n10000 1\n2 7\n4 8\n"], "outputs": ["100000000\n1\n... | 561 | 388 |
coding | Solve the programming task below in a Python markdown code block.
Chef has two distinct positive integers A and B.
Chef wonders how many distinct values are possible for the expression \mathrm{gcd}(A+X,B+X), where X can take any non-negative integer value.
Help Chef find this value.
Here, \mathrm{gcd} stands for [G... | {"inputs": ["2\n1 2\n12 8\n"], "outputs": ["1\n3\n"]} | 374 | 25 |
coding | Solve the programming task below in a Python markdown code block.
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.
You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
--... | {"inputs": ["0 0\n5", "0 2\n31", "0 0\n31", "0 0\n48", "0 0\n32", "1 0\n32", "1 0\n48", "0 2\n55"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 203 | 101 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.
Please complete the following python code precisely:
```python
class Solution:
def ... | {"functional": "def check(candidate):\n assert candidate(nums1 = [4,1,3], nums2 = [5,7]) == 15\n assert candidate(nums1 = [3,5,2,6], nums2 = [3,1,7]) == 3\n\n\ncheck(Solution().minNumber)"} | 81 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Given an array of size n, you have to answer queries of the form : L R k . For each query, you have to find an element which occurs consecutively in the subarray [L,R] more t... | {"inputs": ["5 1\n1 2 2 2 2\n1 5 3"], "outputs": ["2"]} | 390 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She h... | {"inputs": ["VYYYVV\n", "OBRRYY\n", "RRYOGB\n", "RROOYY\n", "GOGGVG\n", "GVGBVO\n", "BOBGBB\n", "OOYYBY\n"], "outputs": ["2\n", "8\n", "15\n", "6\n", "2\n", "8\n", "2\n", "3\n"]} | 368 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers v... | {"inputs": ["3 3 2 2\n", "4 4 2 2\n", "8 3 2 1\n", "4 3 2 1\n", "4 4 1 1\n", "2 1 3 1\n", "6 6 1 3\n", "1 4 1 1\n"], "outputs": ["474774", "44747774", "44444447477", "4447477", "44477774", "-1", "-1", "74777"]} | 382 | 149 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [directioni, amounti]:
directioni can be 0 (for left shift) or 1 (for right shift).
amounti is the amount by which s... | {"functional": "def check(candidate):\n assert candidate(s = \"abc\", shift = [[0,1],[1,2]]) == \"cab\"\n assert candidate(s = \"abcdefg\", shift = [[1,1],[1,1],[0,2],[1,3]]) == \"efgabcd\"\n\n\ncheck(Solution().stringShift)"} | 164 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
This problem's statement is really a short one.
You are given an integer S. Consider an infinite sequence S, 2S, 3S, ... . Find the first number in this sequence that can be represented as Q^{... | {"inputs": ["2\n2\n2 2\n2\n2 3"], "outputs": ["8\n216"]} | 524 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Karl is developing a key storage service. Each user has a positive integer key.
Karl knows that storing keys in plain text is bad practice. So, instead of storing a key, he decided to store a fingerprint of a key. However, using some existing fingerprin... | {"inputs": ["3\n3\n1\n222880\n", "3\n3\n1\n339159\n", "3\n4\n1\n337517\n", "3\n3\n19\n45773\n", "3\n4\n1\n528334\n", "3\n2\n3\n223713\n", "3\n3\n3\n125981\n", "3\n1\n38\n45773\n"], "outputs": ["0\n0\n1070\n", "0\n0\n199\n", "0\n0\n107\n", "0\n1\n699\n", "0\n0\n2411\n", "0\n0\n95\n", "0\n0\n664\n", "0\n6\n699\n"]} | 571 | 207 |
coding | Solve the programming task below in a Python markdown code block.
Indian National Olympiad in Informatics 2015
A string is any nonempty sequence of 0s and 1s. Examples of strings are 00, 101, 111000, 1, 0, 01. The length of a string is the number of symbols in it. For example, the length of 111000 is 6. If u and v are ... | {"inputs": ["3 176"], "outputs": ["6"]} | 556 | 16 |
coding | Solve the programming task below in a Python markdown code block.
There are two groups, one of $N$ boys and the other of $N$ girls numbered from $1$ to $N$.
You are given two arrays $A$ and $B$ containing $N$ numbers each, denoting the height of boys and girls in the group.
You have to form $N$ couples, where each cou... | {"inputs": ["1\n3\n4 5 1\n2 2 2"], "outputs": ["7"]} | 482 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
* a1 = p, where p is some... | {"inputs": ["1\n63\n", "1\n68\n", "1\n170\n", "1\n331\n", "2\n3 0\n", "2\n2 0\n", "1\n120\n", "1\n116\n"], "outputs": ["1\n", "1\n", "1", "1\n", "2\n", "2\n", "1\n", "1\n"]} | 354 | 99 |
coding | Solve the programming task below in a Python markdown code block.
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region wi... | {"inputs": ["3\n4\n3", "3\n3\n3", "3\n3\n1", "3\n2\n1", "3\n0\n1", "3\n0\n2", "3\n1\n1", "3\n2\n2"], "outputs": ["0\n", "1\n", "3\n", "6\n", "12\n", "8\n", "9\n", "4\n"]} | 192 | 95 |
coding | Solve the programming task below in a Python markdown code block.
There is data that records the customer number of the business partner and the trading date on a monthly basis. Please create a program that reads this month's data and last month's data and outputs the customer number of the company with which you have ... | {"inputs": ["123,10\n56,12\n35,14\n\n123,3\n56,4\n123,5", "123,10\n56,12\n45,13\n\n113,4\n56,4\n123,5", "132,10\n56,12\n45,13\n\n113,4\n56,4\n123,5", "123,10\n51,62\n34,14\n\n124,3\n56,4\n123,5", "123,10\n65,12\n34,14\n\n123,3\n56,4\n123,5", "123,10\n57,12\n35,14\n\n123,3\n57,4\n123,5", "0032,1\n56,12\n21,45\n\n12,34\n... | 261 | 391 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
There is a positive integer sequence $ a_1, a_2, \ ldots, a_N $ of length $ N $.
Consider the following game, which uses this sequence and is played by $ 2 $ players on the play and the play.
* Alternately select one of the following... | {"inputs": ["2\n0 2", "2\n0 4", "2\n0 1", "2\n1 0", "2\n0 7", "2\n2 0", "2\n4 0", "2\n5 0"], "outputs": ["Second\n", "Second\n", "First\n", "First\n", "First\n", "Second\n", "Second\n", "First\n"]} | 517 | 94 |
coding | Solve the programming task below in a Python markdown code block.
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.
A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) ex... | {"inputs": ["2 1\n1 2\n3\n1 2\n1 2\n2 1\n", "5 4\n1 3\n2 3\n4 3\n1 5\n3\n1 3\n2 4\n5 2\n", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n4\n1 2\n1 6\n6 5\n4 3\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n5 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n3 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n1 5\n5\n1 5\n3 1\... | 674 | 438 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ pairs of hard disk drives (HDDs) in a cluster. Each HDD is located at an integer coordinate on an infinite straight line, and each pair consists of one primary HDD and one backup HDD.
Next, you want to place $\boldsymbol{\mbox{k}}$ compute... | {"inputs": ["5 2\n6 7\n-1 1\n0 1\n5 2\n7 3\n"], "outputs": ["13\n"]} | 721 | 38 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.
For exampl... | {"functional": "def check(candidate):\n assert candidate(turnedOn = 1) == [\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]\n assert candidate(turnedOn = 9) == []\n\n\ncheck(Solution().readBinaryWatch)"} | 230 | 99 |
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.
Chef is taking a cooking exam. The exam consists of $N$ multiple-choice questions numbered $1$ through $N$. In each question, Chef may choose one ou... | {"inputs": ["3\n6\nABCDAB\nABCDAB\n8\nDDCABCCA\nDNCBBBBA\n3\nCDD\nNDC"], "outputs": ["6\n3\n1"]} | 701 | 47 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.
The final result should be an irreducible fraction. If your final result is an... | {"functional": "def check(candidate):\n assert candidate(expression = \"-1/2+1/2\") == \"0/1\"\n assert candidate(expression = \"-1/2+1/2+1/3\") == \"1/3\"\n assert candidate(expression = \"1/3-1/2\") == \"-1/6\"\n\n\ncheck(Solution().fractionAddition)"} | 118 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has ... | {"inputs": ["1 1 2\n3 1\n", "1 1 2\n3 1\n", "1 1 3\n3 1\n", "4 1 2\n2 1\n", "4 1 4\n2 1\n", "4 1 2\n10 1\n", "20 1 5\n8 4\n", "20 1 5\n8 4\n"], "outputs": ["5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "4\nHEAL\nSTRIKE\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE... | 737 | 383 |
coding | Solve the programming task below in a Python markdown code block.
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortu... | {"inputs": ["A.a\nB.b\nC.c\nD.d\n", "A.a\nB.b\nC.c\nD.d\n", "a.A\nB.b\nC.c\nD.d\n", "A.c\nB.cc\nC.c\nD.c\n", "A.c\nB.cc\nC.c\nD.c\n", "A.aa\nB.bb\nC.cc\nD.ddd\n", "A.aa\nB.bb\nC.cc\nD.ddd\n", "A.ab\nB.abcde\nC.ab\nD.abc\n"], "outputs": ["C\n", "C\n", "C\n", "B\n", "B", "C\n", "C\n", "C\n"]} | 536 | 156 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor.
The doctor advised Alice to only eat n / 2 of the candies she has (n is always ... | {"functional": "def check(candidate):\n assert candidate(candyType = [1,1,2,2,3,3]) == 3\n assert candidate(candyType = [1,1,2,3]) == 2\n assert candidate(candyType = [6,6,6,6]) == 1\n\n\ncheck(Solution().distributeCandies)"} | 165 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Let f(A, B) be the exclusive OR of A, A+1, ..., B. Find f(A, B).
What is exclusive OR?
The bitwise exclusive OR of integers c_1, c_2, ..., c_n (let us call it y) is defined as follows:
- When y is written in base two, the digit in the 2^k's place (k \ge... | {"inputs": ["2 4\n", "0 0\n", "0 1\n", "123 456\n", "7 549755813887\n", "0 1000000000000\n", "16469429916 70896110856\n", "4917728545 146793804400\n"], "outputs": ["5\n", "0\n", "1\n", "435\n", "7\n", "1000000000000\n", "70896110856\n", "150467061584\n"]} | 313 | 188 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$.
Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to... | {"inputs": ["3\n1 3 2\n", "3\n2 3 1\n", "3\n1 3 2\n", "4\n5 5 5 5\n", "4\n5 5 5 5\n", "4\n3 1 5 5\n", "4\n5 1 5 8\n", "4\n1 3 8 64\n"], "outputs": ["1\n", "1\n", "1\n", "11\n", "11\n", "5\n", "4\n", "9\n"]} | 468 | 131 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ variables and $m$ requirements. Requirements are represented as $\left(x\leq y\right)$, meaning that the $x^{th}$ variable must be less than or equal to the $y^{th}$ variable.
Your task is to assign non-negative numbers smaller than $10$ ... | {"inputs": ["6 7\n1 3\n0 1\n2 4\n0 4\n2 5\n3 4\n0 2\n"], "outputs": ["1000\n"]} | 444 | 47 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of integers, find the sum of its elements.
For example, if the array $ar=[1,2,3]$, $1+2+3=6$, so return $6$.
Function Description
Complete the simpleArraySum function in the editor below. It must return the sum of the array elements ... | {"inputs": ["6\n1 2 3 4 10 11\n"], "outputs": ["31\n"]} | 231 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.
He came up with the following game. The player has a positive integer $n$. Initially the value ... | {"inputs": ["8\n", "1\n", "4\n", "3\n", "2\n", "5\n", "7\n", "9\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n"]} | 350 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Given the string S and m queries. The i-th query is given by the two strings xi and yi.
For each query, answer the longest substring of the string S, starting with xi and ending with yi.
For the string S, | S | represents the length of S. Also, the fac... | {"inputs": ["abracadabsa\n5\nab a\na a\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na b\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na c\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na c\na c\nac ca\nz z", "abracadabsa\n5\nba a\na c\na c\nac ca\nz y", "abracadabsa\n5\nba a\na c\nb c\nac ca\nz y", "abracadabsa\n2\nba a\na c\nb c\... | 491 | 288 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well.
Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls.
Then, Chef painted the boxes using $M$ distinct col... | {"inputs": ["1 \n4 2 \n10 20 15 28"], "outputs": ["5"]} | 576 | 32 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple... | {"functional": "def check(candidate):\n assert candidate(answerKey = \"TTFF\", k = 2) == 4\n assert candidate(answerKey = \"TFFT\", k = 1) == 3\n assert candidate(answerKey = \"TTFTTFTT\", k = 1) == 5\n\n\ncheck(Solution().maxConsecutiveAnswers)"} | 213 | 81 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a square board of characters. You can move on the board starting at the bottom right square marked with the character 'S'.
You need to reach the top left square marked with the character 'E'. The rest of... | {"functional": "def check(candidate):\n assert candidate(board = [\"E23\",\"2X2\",\"12S\"]) == [7,1]\n assert candidate(board = [\"E12\",\"1X1\",\"21S\"]) == [4,2]\n assert candidate(board = [\"E11\",\"XXX\",\"11S\"]) == [0,0]\n\n\ncheck(Solution().pathsWithMaxScore)"} | 215 | 100 |
coding | Solve the programming task below in a Python markdown code block.
A total of $n$ depots are located on a number line. Depot $i$ lies at the point $x_i$ for $1 \le i \le n$.
You are a salesman with $n$ bags of goods, attempting to deliver one bag to each of the $n$ depots. You and the $n$ bags are initially at the orig... | {"inputs": ["4\n5 1\n1 2 3 4 5\n9 3\n-5 -10 -15 6 5 8 3 7 4\n5 3\n2 2 3 3 3\n4 2\n1000000000 1000000000 1000000000 1000000000\n"], "outputs": ["25\n41\n7\n3000000000\n"]} | 739 | 132 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Cascading Style Sheets, or CSS is a style sheet language, most popularly known for styling web pages. Each object on a web page (like a picture, a paragraph, a table) can have various propertie... | {"inputs": ["3 1\n22 1 200 2\n22 1 300 2\n22 1 100 1\n22 1"], "outputs": ["300"]} | 540 | 54 |
coding | Solve the programming task below in a Python markdown code block.
You have N cards. On the i-th card, an integer A_i is written.
For each j = 1, 2, ..., M in this order, you will perform the following operation once:
Operation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card wi... | {"inputs": ["3 2\n5 1 1\n2 3\n1 5", "3 2\n5 1 1\n2 3\n1 7", "3 2\n5 1 1\n2 3\n1 6", "3 2\n5 1 1\n2 3\n2 6", "3 2\n5 1 1\n2 3\n1 0", "3 2\n5 1 1\n1 2\n1 5", "3 2\n5 0 0\n1 6\n1 5", "3 2\n5 1 1\n0 3\n2 7"], "outputs": ["13\n", "15\n", "14\n", "17\n", "11\n", "12\n", "16\n", "19\n"]} | 315 | 198 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The red-green-blue color "#AABBCC" can be written as "#ABC" in shorthand.
For example, "#15c" is shorthand for the color "#1155cc".
The similarity between the two colors "#ABCDEF" and "#UVWXYZ" is -(AB - UV)2 - (CD ... | {"functional": "def check(candidate):\n assert candidate(color = \"#09f166\") == \"#11ee66\"\n assert candidate(color = \"#4e3fe1\") == \"#5544dd\"\n\n\ncheck(Solution().similarRGB)"} | 184 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from ... | {"inputs": ["5 5 3", "1 7 7", "4 4 8", "5 4 6", "7 1 2", "5 4 8", "3 0 2", "7 1 4"], "outputs": ["0\n", "1\n", "9\n", "7\n", "6\n", "13\n", "3\n", "16\n"]} | 154 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game with $n$ piles of stones. It is guaranteed that $n$ is an even number. The $i$-th pile has $a_i$ stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exac... | {"inputs": ["2\n8 8\n", "2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n2 0\n", "2\n8 8\n", "2\n15 8\n", "4\n3 1 4 1\n"], "outputs": ["Bob\n", "Bob\n", "Bob\n", "Alice\n", "Alice\n", "Bob\n", "Alice\n", "Alice\n"]} | 391 | 107 |
coding | Solve the programming task below in a Python markdown code block.
In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is co... | {"inputs": ["6", "82", "60", "85", "51", "96", "65", "57"], "outputs": ["-12\n", "26\n", "15\n", "27\n", "10\n", "33\n", "17\n", "13\n"]} | 285 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return true if nums has a good subarray or false otherwise.
A good subarray is a subarray where:
its length is at least two, and
the sum of the elements of the subarray i... | {"functional": "def check(candidate):\n assert candidate(nums = [23,2,4,6,7], k = 6) == True\n assert candidate(nums = [23,2,6,4,7], k = 6) == True\n assert candidate(nums = [23,2,6,4,7], k = 13) == False\n\n\ncheck(Solution().checkSubarraySum)"} | 156 | 97 |
coding | Solve the programming task below in a Python markdown code block.
We have N balance beams numbered 1 to N. The length of each beam is 1 meters. Snuke walks on Beam i at a speed of 1/A_i meters per second, and Ringo walks on Beam i at a speed of 1/B_i meters per second.
Snuke and Ringo will play the following game:
* ... | {"inputs": ["2\n0 2\n1 2", "2\n2 1\n2 6", "2\n3 2\n1 2", "3\n1 1\n5 2\n6 3", "3\n1 1\n6 0\n1 3", "3\n4 1\n5 2\n6 3", "3\n1 2\n5 0\n14 3", "3\n1 4\n5 0\n14 3"], "outputs": ["3 4", "2 3", "1 4", "0 1", "4 9", "0 1", "1 6", "1 4"]} | 681 | 156 |
coding | Solve the programming task below in a Python markdown code block.
Fans of The Wire will appreciate this one.
For those that haven't seen the show, the Barksdale Organization has a simple method for encoding telephone numbers exchanged via pagers: "Jump to the other side of the 5 on the keypad, and swap 5's and 0's."
... | {"functional": "_inputs = [['4103432323'], ['4103438970'], ['4104305768'], ['4102204351'], ['4107056043']]\n_outputs = [['6957678787'], ['6957672135'], ['6956750342'], ['6958856709'], ['6953504567']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | 279 | 268 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Princess Rupsa saw one of her friends playing a special game. The game goes as follows:
N+1 numbers occur sequentially (one at a time) from A_{0} to A_{N}.
You must write th... | {"inputs": ["2\n1\n1 2\n2\n1 2 1", "2\n1\n1 2\n2\n2 2 1", "2\n1\n1 2\n2\n2 2 0", "2\n1\n1 0\n2\n2 2 0", "2\n1\n1 0\n2\n3 2 0", "2\n1\n1 2\n2\n1 2 2", "2\n1\n1 2\n2\n2 3 1", "2\n1\n1 2\n2\n2 1 0"], "outputs": ["4\n14", "4\n24\n", "4\n16\n", "0\n16\n", "0\n24\n", "4\n20\n", "4\n34\n", "4\n8\n"]} | 667 | 196 |
coding | Solve the programming task below in a Python markdown code block.
The numbers 1 to n x n are contained in the n x n square squares one by one, and the sum of the squares in any vertical column and the sum of the squares in any horizontal column are diagonal squares. Those with the same sum of eyes are called magic squa... | {"inputs": ["3\n0\n0", "3\n7\n0", "3\n3\n0", "3\n9\n0", "3\n0\n1", "3\n0\n2", "3\n0\n3", "3\n0\n4"], "outputs": [" 4 9 2\n 3 5 7\n 8 1 6\n", " 4 9 2\n 3 5 7\n 8 1 6\n 22 47 16 41 10 35 4\n 5 23 48 17 42 11 29\n 30 6 24 49 18 36 12\n 13 31 7 25 43 19 37... | 500 | 866 |
coding | Solve the programming task below in a Python markdown code block.
Monocarp has got an array $a$ consisting of $n$ integers. Let's denote $k$ as the mathematic mean of these elements (note that it's possible that $k$ is not an integer).
The mathematic mean of an array of $n$ elements is the sum of elements divided by t... | {"inputs": ["1\n1\n228 1337 3\n", "1\n1\n228 1512 3\n", "1\n1\n228 2063 3\n", "1\n1\n228 2063 2\n", "1\n1\n342 1512 3\n", "1\n1\n228 2063 0\n", "1\n1\n228 4021 2\n", "1\n3\n40 270 228\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 577 | 174 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Solve a given equation and return the value of 'x' in the form of a string "x=#value". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return "No solution" if there is n... | {"functional": "def check(candidate):\n assert candidate(equation = \"x+5-3+x=6+x-2\") == \"x=2\"\n assert candidate(equation = \"x=x\") == \"Infinite solutions\"\n assert candidate(equation = \"2x=x\") == \"x=0\"\n\n\ncheck(Solution().solveEquation)"} | 144 | 84 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.