task_type
stringclasses
4 values
problem
stringlengths
21
5.23k
answer
stringlengths
1
8.29k
problem_tokens
int64
11
1.16k
answer_tokens
int64
1
2.04k
coding
Solve the programming task below in a Python markdown code block. Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc. A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i. He would like to make ...
{"inputs": ["7\n1 2\n2 3\n2 4\n2 5\n4 6\n6 7", "7\n1 4\n2 3\n2 4\n4 5\n4 6\n6 7", "7\n1 4\n2 3\n2 4\n4 5\n7 6\n6 7", "7\n1 4\n2 3\n2 4\n1 5\n7 6\n6 7", "7\n1 4\n2 3\n2 4\n1 5\n7 6\n6 5", "7\n1 4\n2 3\n2 4\n4 5\n7 3\n6 3", "7\n1 2\n2 3\n4 4\n1 5\n7 6\n6 7", "7\n1 4\n2 3\n2 4\n1 5\n5 6\n7 7"], "outputs": ["2 4\n", "2 3\n...
522
270
coding
Solve the programming task below in a Python markdown code block. Given a sequence of integers $a$, a triplet $(a[i],a[j],a[k])$ is beautiful if: $i\lt j\lt k$ $a[j]-a[i]=a[k]-a[j]=d$ Given an increasing sequenc of integers and the value of $\boldsymbol{d}$, count the number of beautiful triplets in the sequence. Ex...
{"inputs": ["7 3 \n1 2 4 5 7 8 10\n"], "outputs": ["3\n"]}
572
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti]. You have to divide the intervals into one or more groups such that each interval is in...
{"functional": "def check(candidate):\n assert candidate(intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]) == 3\n assert candidate(intervals = [[1,3],[5,6],[8,10],[11,13]]) == 1\n\n\ncheck(Solution().minGroups)"}
162
82
coding
Solve the programming task below in a Python markdown code block. Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic ...
{"inputs": ["1\n#h\n", "1\n#h\n", "2\n#y\n#q\n", "2\n#y\n#q\n", "2\n#y\n#p\n", "2\n#y\n#o\n", "2\n#x\n#o\n", "2\n#x\n#p\n"], "outputs": ["#h\n", "#h\n", "#\n#q\n", "#\n#q\n", "#\n#p\n", "#\n#o\n", "#\n#o\n", "#\n#p\n"]}
698
131
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.   Please complete the following python code precisely: ```python # Definition for a b...
{"functional": "def check(candidate):\n assert candidate(root1 = tree_node([2,1,4]), root2 = tree_node([1,0,3])) == [0,1,1,2,3,4]\n assert candidate(root1 = tree_node([1,None,8]), root2 = tree_node([8,1])) == [1,1,8,8]\n\n\ncheck(Solution().getAllElements)"}
132
96
coding
Solve the programming task below in a Python markdown code block. A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that th...
{"inputs": ["4\n7\n44\n7\n4747477", "4\n7\n7\n477\n4747477", "4\n7\n7\n447\n4747477", "4\n7\n47\n477\n4747477", "4\n4\n47\n477\n4747477", "4\n7\n44\n477\n4747477", "4\n47\n4\n477\n4747477", "4\n47\n7\n477\n4747477"], "outputs": ["0\n3\n0\n23\n", "0\n0\n3\n23\n", "0\n0\n5\n23\n", "0\n2\n3\n23\n", "1\n2\n3\n23\n", "0\n3\...
618
250
coding
Solve the programming task below in a Python markdown code block. Today is rose day, batch mates of Kabir and Tara decided to celebrate this day by exchanging roses with each other. Note:$Note:$ exchanging means both the boy and the girl will give rose to each other. In the class there are B$B$ boys and G$G$ girls. ...
{"inputs": ["1\n2 3"], "outputs": ["8"]}
321
16
coding
Solve the programming task below in a Python markdown code block. Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG". Maxim was very boring to sit in class, so the teacher came up with a task for him: o...
{"inputs": ["4\nZCTH\n", "4\nNPGT\n", "4\nAZTG\n", "4\nYCTG\n", "4\nANTG\n", "4\nOCTG\n", "4\nACHG\n", "4\nANTG\n"], "outputs": ["2", "52", "3", "2", "11", "12", "12", "11\n"]}
536
96
coding
Solve the programming task below in a Python markdown code block. You have two strings A = A_1 A_2 ... A_n and B = B_1 B_2 ... B_n of the same length consisting of 0 and 1. You can transform A using the following operations in any order and as many times as you want: * Shift A by one character to the left (i.e., if A...
{"inputs": ["1\n1", "1\n0", "1010\n1110", "1010\n1111", "1010\n0000", "1010\n1010", "1010\n1011", "1010\n1001"], "outputs": ["0\n", "-1", "1\n", "2\n", "-1\n", "0\n", "1\n", "3\n"]}
366
113
coding
Solve the programming task below in a Python markdown code block. # Sort an array by value and index Your task is to sort an array of integer numbers by the product of the value and the index of the positions. For sorting the index starts at 1, NOT at 0! The sorting has to be ascending. The array will never be null a...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[23, 2, 3, 4, 5]], [[26, 2, 3, 4, 5]], [[9, 5, 1, 4, 3]]]\n_outputs = [[[1, 2, 3, 4, 5]], [[2, 3, 4, 23, 5]], [[2, 3, 4, 5, 26]], [[1, 9, 5, 3, 4]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo...
288
275
coding
Solve the programming task below in a Python markdown code block. Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing. A subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$. A subarray $A[i, j]$ is non-decreasing if $A_i ≤ A_i+...
{"inputs": ["2\n4\n1 4 2 3\n1\n5", "2\n4\n1 2 2 3\n1\n5", "2\n4\n1 4 2 2\n1\n5", "2\n4\n2 1 2 2\n1\n5", "2\n4\n2 1 3 2\n1\n5", "2\n4\n6 5 3 2\n1\n2", "2\n4\n1 4 2 2\n1\n3", "2\n4\n2 4 2 2\n1\n5"], "outputs": ["6\n1", "10\n1\n", "6\n1\n", "7\n1\n", "5\n1\n", "4\n1\n", "6\n1\n", "6\n1\n"]}
459
190
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Bear Limak has a string S. Each character of S is a digit '0' or '1'. Help Limak and check if all the '1' digits form a single non-empty segment (consecutive subsequence) in...
{"inputs": ["6\n001111110\n00110011\n000\n1111\n101010101\n101111111111"], "outputs": ["YES\nNO\nNO\nYES\nNO\nNO"]}
456
73
coding
Solve the programming task below in a Python markdown code block. Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises...
{"inputs": ["6\n9 english\n6 mathematics\n8 geography\n-1\n3 graphics\n-1", "6\n9 english\n6 mathematics\n6 geography\n-1\n3 grcphias\n-1", "6\n9 english\n6 mathematics\n0 geography\n-1\n3 grcphias\n-1", "6\n9 english\n6 mathematics\n0 geography\n-1\n3 gscphias\n-1", "6\n9 english\n6 mathematics\n8 geography\n-1\n3 hra...
608
283
coding
Solve the programming task below in a Python markdown code block. A population of bears consists of black bears, brown bears, and white bears. The input is an array of two elements. Determine whether the offspring of the two bears will return `'black'`, `'brown'`, `'white'`, `'dark brown'`, `'grey'`, `'light brown'`...
{"functional": "_inputs = [[['black', 'black']], [['white', 'white']], [['brown', 'brown']], [['black', 'brown']], [['black', 'white']], [['white', 'brown']], [['pink', 'black']]]\n_outputs = [['black'], ['white'], ['brown'], ['dark brown'], ['grey'], ['light brown'], ['unknown']]\nimport math\ndef _deep_eq(a, b, tol=1...
226
217
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence $A_1, A_2, \ldots, A_N$ and an integer $X$. Consider a $N \times N$ matrix $B$, where $B_{i,j} = A_i + A_j$ for each valid $i$ and $j$. You need to find the number of square submatrices of $B$ such that the sum of their ...
{"inputs": ["2\n5 36\n1 2 3 1 12\n4 54\n3 3 3 3"], "outputs": ["6\n4"]}
499
43
coding
Solve the programming task below in a Python markdown code block. One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as p...
{"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "3 2\n1 2\n2 3\n", "3 2\n1 2\n2 3\n", "3 3\n2 1\n1 3\n3 2\n", "3 3\n2 1\n1 3\n3 2\n", "4 4\n1 2\n2 3\n3 1\n4 1\n", "7 4\n1 2\n2 3\n3 1\n4 1\n"], "outputs": ["yes\n", "yes\n", "yes\n", "yes\n", "no\n", "no\n", "no\n", "no\n"]}
423
166
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized. Return the maximum product of the sums of the two subtrees....
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,6])) == 110\n assert candidate(root = tree_node([1,None,2,3,4,None,None,5,6])) == 90\n assert candidate(root = tree_node([2,3,9,10,7,8,6,5,4,11,1])) == 1025\n assert candidate(root = tree_node([1,1])) == 1\n\n\ncheck(Soluti...
185
128
coding
Solve the programming task below in a Python markdown code block. We have a string S of length N consisting of R, G, and B. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: - S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. - j - i \neq k - j. -----Constraint...
{"inputs": ["3\nRGB\n", "4\nBGRR", "4\nGRRB", "4\nRGBR", "4\nRRBG", "4\nGBRR", "4\nRGRB", "4\nBRGR"], "outputs": ["0\n", "1\n", "2\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
228
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score: Select an element m from nums. Remove the selected eleme...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5], k = 3) == 18\n assert candidate(nums = [5,5,5], k = 2) == 11\n\n\ncheck(Solution().maximizeSum)"}
139
68
coding
Solve the programming task below in a Python markdown code block. Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider t...
{"inputs": ["1\n1\n0\n", "1\n1\n0\n", "2\n1 1\n0 0\n", "2\n1 1\n0 0\n", "2\n0 1\n0 0\n", "4\n1 0 0 0\n2 3 4 2\n", "4\n1 0 0 0\n2 3 4 2\n", "5\n0 0 0 0 1\n0 1 2 3 4\n"], "outputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n1\n", "1\n1\n", "5\n1 2 3 4 5\n"]}
674
178
coding
Solve the programming task below in a Python markdown code block. Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of `0` or `1` for each term: `25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1` The choice of `0` and `1` is... not very binary. We shall perform the *true* binary...
{"functional": "_inputs = [[25], [47], [1], [3], [1234567]]\n_outputs = [[[1, 1, 1, -1, -1]], [[1, 1, -1, 1, 1, 1]], [[1]], [[1, 1]], [[1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n re...
329
276
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. Timothy (age: 16) really likes to smoke. Unfortunately, he is too young to buy his own cigarettes and that's why he has to be extremely efficient in smoking. It's now your task to create a function that calculates how many cigarettes Timothy can smoke o...
{"functional": "_inputs = [[0, 1], [1, 0], [1, 1]]\n_outputs = [[22], [224], [247]]\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) != len(b): return Fa...
196
181
coding
Solve the programming task below in a Python markdown code block. Imagine that you have an array of 3 integers each representing a different person. Each number can be 0, 1, or 2 which represents the number of hands that person holds up. Now imagine there is a sequence which follows these rules: * None of the people h...
{"functional": "_inputs = [[54], [98], [3]]\n_outputs = [[[0, 0, 0]], [[2, 2, 1]], [[0, 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 isinstance(a, (list, tuple)):\n if len(a) != len(b...
340
186
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the a...
{"functional": "def check(candidate):\n assert candidate(nums = [12,5,7,23]) == True\n assert candidate(nums = [29,6,10]) == True\n assert candidate(nums = [3,6]) == False\n\n\ncheck(Solution().isGoodArray)"}
127
69
coding
Solve the programming task below in a Python markdown code block. Write a function to split a string and convert it into an array of words. For example: ```python "Robin Singh" ==> ["Robin", "Singh"] "I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"] ``` Also feel free t...
{"functional": "_inputs = [['Robin Singh'], ['CodeWars'], ['I love arrays they are my favorite'], ['1 2 3'], ['']]\n_outputs = [[['Robin', 'Singh']], [['CodeWars']], [['I', 'love', 'arrays', 'they', 'are', 'my', 'favorite']], [['1', '2', '3']], [['']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, f...
101
220
coding
Solve the programming task below in a Python markdown code block. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the di...
{"inputs": ["2\n1 2\nba\nac\n", "2\n1 1\naa\naa\n", "2\n1 1\naa\naa\n", "2\n1 1\naa\na`\n", "2\n1 2\nab\nac\n", "2\n2 1\naa\na`\n", "2\n1 2\n`b\nac\n", "2\n2 1\naa\n`a\n"], "outputs": ["1\n", "0\n", "0", "-1\n", "0\n", "-1\n", "0\n", "-1\n"]}
585
137
coding
Solve the programming task below in a Python markdown code block. You are given a sequence $A_1, A_2, \ldots, A_N$. For each $k$ ($1 \le k \le N$), let's define a function $f(k)$ in the following way: - Consider a sequence $B_1, B_2, \ldots, B_N$, which is created by setting $A_k = 0$. Formally, $B_k = 0$ and $B_i = A_...
{"inputs": ["2\n6\n1 2 1 1 3 1\n3\n4 1 4"], "outputs": ["6\n2"]}
368
36
coding
Solve the programming task below in a Python markdown code block. Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a ...
{"inputs": ["0 0 0 1\n0 1 0 1\n0 1 0 0\n0 1 0 1\n", "0 0 2 2\n0 0 2 0\n2 2 2 2\n0 2 0 2\n", "0 0 1 0\n1 0 1 1\n0 1 1 1\n0 0 0 1\n", "0 0 2 0\n0 1 0 3\n0 4 3 4\n3 0 3 3\n", "0 0 0 0\n1 1 1 1\n0 1 0 1\n1 0 1 0\n", "0 0 0 0\n0 0 0 1\n0 0 1 0\n1 1 1 1\n", "0 0 4 0\n4 0 3 0\n3 0 2 0\n2 0 0 0\n", "0 0 0 1\n0 1 1 1\n1 1 1 0\n...
293
310
coding
Solve the programming task below in a Python markdown code block. Johnny has a pool in his garden. There are several islands in the pool. Some islands are connected by bridges. Any bridge can be removed. Every day Johnny removes some bridges so that there is only one way from any island to any other. In the evening he ...
{"inputs": ["1\n4\n0111\n1011\n1101\n1110\n2\n1 2\n3 4"], "outputs": ["4"]}
376
44
coding
Solve the programming task below in a Python markdown code block. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 1...
{"inputs": ["ETAUDARGTSOP", "AACDEFGHIJKL", "COCEFESTIVAL", "POSTGRADUATF", "ALCDEFGHIJKA", "COCEFESTIV@L", "POSTGRAUDATF", "AKJIHGFEDCLA"], "outputs": ["ETAU DARGTSOP\n", "AACD EFGHIJKL\n", "COCE FESTIVAL\n", "POST GRADUATF\n", "ALCD EFGHIJKA\n", "COCE FESTIV@L\n", "POST GRAUDATF\n", "AKJI HGFEDCLA\n"]}
221
140
coding
Solve the programming task below in a Python markdown code block. Snakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house at coord...
{"inputs": ["3\n2\n**\n**\n3\n***\n*..\n3\n*..\n.*."], "outputs": ["2\n3\n1"]}
523
40
coding
Solve the programming task below in a Python markdown code block. Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'. There is a single robot in the maze. Its start position is denoted with the character '...
{"inputs": ["2 2\n..\nSE\n0\n", "2 2\nSE\n##\n0\n", "2 2\nSE\n##\n0\n", "2 2\n..\nSE\n0\n", "2 2\n#E\nS.\n2\n", "2 2\n./\nSE\n0\n", "2 2\nS.\n/E\n1\n", "2 2\nS.\nE/\n1\n"], "outputs": ["6\n", "6\n", "6\n", "6\n", "0\n", "6\n", "0\n", "6\n"]}
611
142
coding
Solve the programming task below in a Python markdown code block. You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a squa...
{"inputs": ["1 1\n1\n", "2 1\n2\n", "2 1\n1\n", "2 1\n2\n", "1 1\n1\n", "2 1\n1\n", "2 2\n2 2\n", "4 2\n1 2\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n"]}
412
106
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A perfectly straight street is represented by a number line. The street has building(s) on it and is represented by a 2D integer array buildings, where buildings[i] = [starti, endi, heighti]. This means that there is ...
{"functional": "def check(candidate):\n assert candidate(buildings = [[1,4,2],[3,9,4]]) == [[1,3,2],[3,4,3],[4,9,4]]\n assert candidate(buildings = [[1,3,2],[2,5,3],[2,8,3]]) == [[1,3,2],[3,8,3]]\n assert candidate(buildings = [[1,2,1],[5,6,1]]) == [[1,2,1],[5,6,1]]\n\n\ncheck(Solution().averageHeightOfBuildin...
430
139
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone. A number is valid if ea...
{"functional": "def check(candidate):\n assert candidate(n = 10) == 4\n assert candidate(n = 1) == 0\n assert candidate(n = 2) == 1\n\n\ncheck(Solution().rotatedDigits)"}
197
57
coding
Solve the programming task below in a Python markdown code block. Polycarp loves ciphers. He has invented his own cipher called Right-Left. Right-Left cipher is used for strings. To encrypt the string $s=s_{1}s_{2} \dots s_{n}$ Polycarp uses the following algorithm: he writes down $s_1$, he appends the current word ...
{"inputs": ["z\n", "y\n", "x\n", "{\n", "|\n", "}\n", "~\n", "z\n"], "outputs": ["z\n", "y\n", "x\n", "{\n", "|\n", "}\n", "~\n", "z\n"]}
425
68
coding
Solve the programming task below in a Python markdown code block. A format for expressing an ordered list of integers is to use a comma separated list of either * individual integers * or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. The range includes ...
{"functional": "_inputs = [[[-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]], [[-3, -2, -1, 2, 10, 15, 16, 18, 19, 20]], [[1, 2, 3, 4, 5]]]\n_outputs = [['-6,-3-1,3-5,7-11,14,15,17-20'], ['-3--1,2,10,15,16,18-20'], ['1-5']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float...
379
324
coding
Solve the programming task below in a Python markdown code block. # Task The year of `2013` is the first year after the old `1987` with only distinct digits. Now your task is to solve the following problem: given a `year` number, find the minimum year number which is strictly larger than the given one and has only d...
{"functional": "_inputs = [[1987], [2013]]\n_outputs = [[2013], [2014]]\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) != len(b): return False\n ...
161
174
coding
Solve the programming task below in a Python markdown code block. Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercas...
{"inputs": ["zzy", "yzz", "zz{", "{zz", "{zy", "yz{", "xz{", "{zx"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
225
67
coding
Solve the programming task below in a Python markdown code block. Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and r...
{"inputs": ["1\n5\n4\n", "1\n5\n4\n", "1\n8\n4\n", "1\n8\n1\n", "1\n7\n1\n", "1\n5\n1\n", "1\n5\n2\n", "1\n8\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
446
102
coding
Solve the programming task below in a Python markdown code block. Given an array of numbers, return an array, with each member of input array rounded to a nearest number, divisible by 5. For example: ``` roundToFive([34.5, 56.2, 11, 13]); ``` should return ``` [35, 55, 10, 15] ``` ```if:python Roundings have to be do...
{"functional": "_inputs = [[[1, 5, 87, 45, 8, 8]], [[3, 56.2, 11, 13]], [[22.5, 544.9, 77.5]]]\n_outputs = [[[0, 5, 85, 45, 10, 10]], [[5, 55, 10, 15]], [[25, 545, 80]]]\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_...
144
255
coding
Solve the programming task below in a Python markdown code block. You're given a list of n strings a_1, a_2, ..., a_{n}. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest. Given the list of strings, output the lexicographically smallest concatenati...
{"inputs": ["3\nc\ncb\ncba\n", "3\nb\ncb\ncba\n", "3\nb\nbb\ncba\n", "3\nb\nbb\ncab\n", "3\nb\nbb\ncaa\n", "3\nb\nbb\ndaa\n", "3\nb\nbb\naad\n", "3\nc\nbb\ndaa\n"], "outputs": ["cbacbc\n", "bcbacb\n", "bbbcba\n", "bbbcab\n", "bbbcaa\n", "bbbdaa\n", "aadbbb\n", "bbcdaa\n"]}
235
140
coding
Solve the programming task below in a Python markdown code block. You'll be given a list of two strings, and each will contain exactly one colon (`":"`) in the middle (but not at beginning or end). The length of the strings, before and after the colon, are random. Your job is to return a list of two strings (in the sa...
{"functional": "_inputs = [[['abc:123', 'cde:456']], [['a:12345', '777:xyz']]]\n_outputs = [[['abc:456', 'cde:123']], [['a:xyz', '777:12345']]]\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...
184
215
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given two strings `a` and `b` and your task will be to return the characters that are not common in the two strings. For example: ```Haskell solve("xyab","xzca") = "ybzc" --The first string has 'yb' which is not in the second...
{"functional": "_inputs = [['xyab', 'xzca'], ['xyabb', 'xzca'], ['abcd', 'xyz'], ['xxx', 'xzca']]\n_outputs = [['ybzc'], ['ybbzc'], ['abcdxyz'], ['zca']]\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...
198
194
coding
Solve the programming task below in a Python markdown code block. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many mar...
{"inputs": ["2\n0 1", "2\n0 0", "2\n0 0\n", "5\n0 1 1 0 3", "5\n0 1 1 1 4", "5\n0 1 0 0 4", "5\n0 1 4 0 4", "5\n0 1 1 0 4"], "outputs": ["12\n", "8", "8\n", "128\n", "120\n", "88\n", "96\n", "96"]}
412
131
coding
Solve the programming task below in a Python markdown code block. Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more tim...
{"inputs": ["7 6", "7 9", "5 9", "7 7", "7 2", "8 4", "8 7", "8 9"], "outputs": ["1\n", "2\n", "4\n", "0\n", "1\n", "0\n", "1\n", "1\n"]}
204
78
coding
Solve the programming task below in a Python markdown code block. You like the way the Python `+` operator easily handles adding different numeric types, but you need a tool to do that kind of addition without killing your program with a `TypeError` exception whenever you accidentally try adding incompatible types like...
{"functional": "_inputs = [[1, 3.414], [42, ' is the answer.'], [10, '2']]\n_outputs = [[4.414], [None], [None]]\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 i...
194
188
coding
Solve the programming task below in a Python markdown code block. Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m ho...
{"inputs": ["2", "8", "16", "1000010000000", "1000011000000", "1100011000000", "1110011000000", "1110011100000"], "outputs": ["0\n", "10", "22\n", "2716922731275\n", "3307289212967\n", "2999416055122\n", "3146654438234\n", "4080876601631\n"]}
180
184
coding
Solve the programming task below in a Python markdown code block. You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and e...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n1 2\n", "2\n1 4\n", "2\n0 4\n", "3\n4 1 2\n", "3\n3 1 2\n", "3\n3 1 1\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "3\n", "0\n"]}
658
108
coding
Solve the programming task below in a Python markdown code block. There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i). We will repeat the following operation as long as possible: - Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of ...
{"inputs": ["2\n1 4\n5 5", "2\n1 14\n5 5", "2\n3 2\n17 6", "2\n5 10\n17 4", "2\n9 10\n17 4", "2\n9 11\n17 4", "2\n7 11\n17 6", "2\n3 11\n17 6"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
333
138
coding
Solve the programming task below in a Python markdown code block. A [Power Law](https://en.wikipedia.org/wiki/Power_law) distribution occurs whenever "a relative change in one quantity results in a proportional relative change in the other quantity." For example, if *y* = 120 when *x* = 1 and *y* = 60 when *x* = 2 (i.e...
{"functional": "_inputs = [[[1, 120], [2, 60], 4], [[1, 120], [2, 60], 8], [[1, 120], [4, 30], 8], [[1, 120], [3, 60], 9], [[1, 120], [3, 60], 27], [[1, 120], [9, 30], 27], [[1, 81], [2, 27], 4], [[1, 81], [2, 27], 8], [[1, 81], [4, 9], 8], [[1, 81], [5, 27], 25], [[1, 81], [5, 27], 125], [[1, 81], [25, 9], 125], [[4, ...
415
532
coding
Solve the programming task below in a Python markdown code block. Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of...
{"inputs": ["1 1 1\n.\n", "1 1 1\n*\n", "1 1 1\n.\n", "1 1 1\n*\n", "1 2 2\n..\n", "1 2 1\n..\n", "1 2 3\n..\n", "1 2 2\n..\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "2\n", "0\n", "1\n"]}
421
118
coding
Solve the programming task below in a Python markdown code block. Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore...
{"inputs": ["1 3\n2\n", "1 6\n4\n", "1 2\n1\n", "1 7\n6\n", "1 5\n2\n", "1 9\n6\n", "1 8\n5\n", "1 7\n4\n"], "outputs": ["3\n0 1 2 ", "3\n0 2 4 ", "2\n0 1 ", "7\n0 1 2 3 4 5 6 ", "5\n0 1 2 3 4 ", "3\n0 3 6 ", "8\n0 1 2 3 4 5 6 7 ", "7\n0 1 2 3 4 5 6 "]}
647
171
coding
Solve the programming task below in a Python markdown code block. Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong...
{"inputs": ["X\n", "RXLR\n", "RLXR\n", "XLRR\n", "RRLX\n", "LXRR\n", "RXLLRLRR\n", "RXRLRLLR\n"], "outputs": ["0.000000\n", "50.000000\n", "50.000000\n", "50.000000\n", "50.000000\n", "50.000000\n", "58.333333\n", "70.000000\n"]}
575
147
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s. Specifically: Each letter in p...
{"functional": "def check(candidate):\n assert candidate(pattern = \"abba\", s = \"dog cat cat dog\") == True\n assert candidate(pattern = \"abba\", s = \"dog cat cat fish\") == False\n assert candidate(pattern = \"aaaa\", s = \"dog cat cat dog\") == False\n\n\ncheck(Solution().wordPattern)"}
143
78
coding
Solve the programming task below in a Python markdown code block. "Ring Ring!!" Sherlock's phone suddenly started ringing. And it was none other than Jim Moriarty.. "Long time no see ! You miss me right ? Anyway we'll talk about it later . Let me first tell you something. Dr.Watson is with me . And you've got only on...
{"inputs": ["2\n4 4\n6 5"], "outputs": ["EVEN\nODD"]}
332
24
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Russian]. Chef has an array A of size N. Chef wants to choose any subsequence of size exactly \lceil \frac{N}{2} \rceil from the array such that GCD of all the elements in that sequence must be 2. Chef names such a kind of ...
{"inputs": ["3\n5\n1 2 3 4 5\n4\n1 2 3 4\n3\n30 42 70"], "outputs": ["NO\nYES\nNO"]}
624
49
coding
Solve the programming task below in a Python markdown code block. A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are no...
{"inputs": ["(\n", ")\n", ")(()(\n", "()(()\n", "((())\n", "())((\n", "))(((\n", "(())(\n"], "outputs": ["0\n", "0\n", "2\n", "4\n", "4\n", "2\n", "0\n", "4\n"]}
183
79
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order. A word matches the pattern if there exists a permutation of letters p so that a...
{"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"deq\",\"mee\",\"aqq\",\"dkd\",\"ccc\"], pattern = \"abb\") == [\"mee\",\"aqq\"]\n\n\ncheck(Solution().findAndReplacePattern)"}
152
61
coding
Solve the programming task below in a Python markdown code block. In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\{h_1,h_2,h_3,......\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by ...
{"inputs": ["1\n7\n", "4\n1 4 2 1", "4\n1 8 2 1", "4\n1 2 2 2", "4\n1 2 2 1", "4\n1 2 2 1\n", "4\n1 12 2 1", "4\n1 12 0 2"], "outputs": ["7\n", "4\n", "8\n", "2\n", "2", "2\n", "12\n", "14\n"]}
302
125
coding
Solve the programming task below in a Python markdown code block. Following from the previous kata and taking into account how cool psionic powers are compare to the Vance spell system (really, the idea of slots to dumb down the game sucks, not to mention that D&D became a smash hit among geeks, so...), your task in th...
{"functional": "_inputs = [[1, 0], [1, 10], [1, 11], [0, 11], [1, 20], [21, 30]]\n_outputs = [[0], [0], [2], [0], [4], [448]]\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)...
594
212
coding
Solve the programming task below in a Python markdown code block. # Task You got a `scratch lottery`, you want to know how much money you win. There are `6` sets of characters on the lottery. Each set of characters represents a chance to win. The text has a coating on it. When you buy the lottery ticket and then blow...
{"functional": "_inputs = [[['tiger tiger tiger 100', 'rabbit dragon snake 100', 'rat ox pig 1000', 'dog cock sheep 10', 'horse monkey rat 5', 'dog dog dog 1000']]]\n_outputs = [[1100]]\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, r...
346
210
coding
Solve the programming task below in a Python markdown code block. Given an array $A$ of length $N$, we can define rotation as follows. If we rotate $A$ to the right, all elements move to the right one unit, and the last element moves to the beginning. That is, it becomes $[A_{N}, A_{1},A_{2},\ldots,A_{N-1}]$. Similarly...
{"inputs": ["2\n1 2\n2\n1 1"], "outputs": ["6\n12"]}
753
25
coding
Solve the programming task below in a Python markdown code block. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time,...
{"inputs": ["2 5 4", "2 5 5", "2 5 9", "1 0 8", "1 0 1", "1 2 3", "0 2 2", "2 5 0"], "outputs": ["64\n", "65\n", "9\n", "8\n", "1\n", "3\n", "2\n", "0\n"]}
380
96
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
Solve the programming task below in a Python markdown code block. Phoenix has $n$ coins with weights $2^1, 2^2, \dots, 2^n$. He knows that $n$ is even. He wants to split the coins into two piles such that each pile has exactly $\frac{n}{2}$ coins and the difference of weights between the two piles is minimized. Formal...
{"inputs": ["1\n2\n", "1\n2\n", "1\n4\n", "1\n6\n", "2\n2\n4\n", "2\n4\n4\n", "2\n4\n6\n", "2\n6\n4\n"], "outputs": ["2\n", "2\n", "6\n", "14\n", "2\n6\n", "6\n6\n", "6\n14\n", "14\n6\n"]}
374
105
coding
Solve the programming task below in a Python markdown code block. Given a sorted array of numbers, return the summary of its ranges. ## Examples ```python summary_ranges([1, 2, 3, 4]) == ["1->4"] summary_ranges([1, 1, 1, 1, 1]) == ["1"] summary_ranges([0, 1, 2, 5, 6, 9]) == ["0->2", "5->6", "9"] summary_ranges([0, 1, ...
{"functional": "_inputs = [[[]], [[1, 1, 1, 1]], [[1, 2, 3, 4]], [[0, 1, 2, 5, 6, 9]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7, 9, 10]], [[-2, 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 12]], [[-3, -2, -1, 0, 2, 3]], [[-2]]]\n_outputs = [[[]], [['1']], [['1->4']], [['0->2', '5->6', '9']], [['0...
304
416
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There is a large tree house in an unknown world. It is ruled by the great emperor KZS. It consists of $N$ nodes numbered from $1$ to $N$ in which the people o...
{"inputs": ["2\n4 1\n1 2\n1 3\n1 4\n8 1\n1 2\n1 3\n2 4\n2 5\n5 6\n5 7\n7 8"], "outputs": ["7\n11"]}
609
63
coding
Solve the programming task below in a Python markdown code block. In this kata, you should calculate type of triangle with three given sides ``a``, ``b`` and ``c`` (given in any order). If all angles are less than ``90°``, this triangle is ``acute`` and function should return ``1``. If one angle is strictly ``90°``, ...
{"functional": "_inputs = [[1, 2, 3], [5.5, 4.5, 10], [7, 3, 2], [5, 10, 5], [3, 3, 0], [3, 3, 1], [5, 5, 5], [122.14, 222.11, 250], [8, 5, 7], [100000, 100005, 111111], [3, 4, 5], [21, 220, 221], [8.625, 33.625, 32.5], [65, 56, 33], [68000, 285000, 293000], [2, 4, 5], [105, 100, 6], [102, 200, 250], [65, 55, 33], [7, ...
412
488
coding
Solve the programming task below in a Python markdown code block. In genetics, a sequence’s motif is a nucleotides (or amino-acid) sequence pattern. Sequence motifs have a biological significance. For more information you can take a look [here](https://en.wikipedia.org/wiki/Sequence_motif). For this kata you need to ...
{"functional": "_inputs = [['TTCCGGAACC', 'CC'], ['ACGTTACAACGTTAG', 'ACGT'], ['ACGTACGTACGT', 'AAA'], ['ACGT', 'ACGTGAC']]\n_outputs = [[[3, 9]], [[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, rel_tol=tol, abs_t...
297
211
coding
Solve the programming task below in a Python markdown code block. Your are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array. Print $1$ if the string contains characters from the given array only els...
{"inputs": ["3\nabcd\n4\na b c d\naabbbcccdddd\n4\na b c d\nacd\n3\na b d"], "outputs": ["1\n1\n0"]}
250
45
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. In the magical land of Byteland, there are three kinds of citizens: a Bit - $2\;\mathrm{ms}$ after a Bit appears, it grows up and becomes a Nibble (i....
{"inputs": ["2\n2\n3"], "outputs": ["1 0 0\n0 1 0"]}
460
26
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree. Note: The average of n elements is the sum of the n elements divided by n ...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([4,8,5,0,1,None,6])) == 5\n assert candidate(root = tree_node([1])) == 1\n\n\ncheck(Solution().averageOfSubtree)"}
175
60
coding
Solve the programming task below in a Python markdown code block. You're familiar with [list slicing](https://docs.python.org/3/library/functions.html#slice) in Python and know, for example, that: ```python >>> ages = [12, 14, 63, 72, 55, 24] >>> ages[2:4] [63, 72] >>> ages[2:] [63, 72, 55, 24] >>> ages[:3] [12, 14, 6...
{"functional": "_inputs = [[[12, 14, 63, 72, 55, 24], 2, 4], [[12, 14, 63, 72, 55, 24], 0, 3], [['Intuition', 'is', 'a', 'poor', 'guide', 'when', 'facing', 'probabilistic', 'evidence'], 5, 13]]\n_outputs = [[[12, 14, 55, 24]], [[72, 55, 24]], [['Intuition', 'is', 'a', 'poor', 'guide']]]\nimport math\ndef _deep_eq(a, b,...
306
295
coding
Solve the programming task below in a Python markdown code block. Given two strings, determine if they share a common substring. A substring may be as small as one character. Example $s1=\text{'and'}$ $s2=\text{'art'}$ These share the common substring $\class{ML__boldsymbol}{\boldsymbol{a}}$. $\textbf{s1}...
{"inputs": ["2\nhello\nworld\nhi\nworld\n"], "outputs": ["YES\nNO\n"]}
401
24
coding
Solve the programming task below in a Python markdown code block. In all schools in Buryatia, in the $1$ class, everyone is told the theory of Fibonacci strings. "A block is a subsegment of a string where all the letters are the same and are bounded on the left and right by the ends of the string or by letters other t...
{"inputs": ["6\n1\n1\n2\n1 1\n2\n1 2\n3\n3 1 3\n2\n7 5\n6\n26 8 3 4 13 34\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\nYES\n"]}
725
71
coding
Solve the programming task below in a Python markdown code block. A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters + and 1 into this sequence. For example, sequences (())(), () and (()(())) are regular, while )(, (() and (()))( are not. Let's call a ...
{"inputs": ["5\n()\n(?)\n(??)\n??()\n)?(?\n", "5\n()\n(?)\n)??(\n??()\n)?(?\n", "5\n()\n(?)\n(??)\n??()\n?(?)\n", "5\n()\n?()\n(??)\n??()\n)?(?\n", "5\n()\n(?)\n(??)\n)(??\n?(?)\n", "5\n)(\n?()\n(??)\n??()\n)?(?\n", "5\n)(\n(?)\n(??)\n)(??\n?(?)\n", "5\n()\n(?)\n)??(\n??()\n?(?)\n"], "outputs": ["YES\nNO\nYES\nYES\nNO\...
392
272
coding
Solve the programming task below in a Python markdown code block. Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bul...
{"inputs": ["0 0 0 0 0\n0 0 0 0 0\n0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0\n", "0 1 0 0 0\n0 0 0 0 0\n0 0\n", "0 0 0 0 0\n0 0 0 0 0\n20 0\n", "0 0 0 0 0\n0 0 0 0 0\n20 0\n", "0 0 0 0 0\n0 0 0 0 0\n20 1\n", "119 0 0 0 0\n2 0 0 0 0\n5 5\n", "0 119 0 0 0\n0 2 0 0 0\n5 5\n"], "outputs": ["7500\n", "7500\n", "7496\n", "9500\n", ...
738
277
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 and $N-1$ more of his friends go to the night canteen. The canteen serves only three items (well, they serve more, but only these three are edible!), whi...
{"inputs": ["3\n5 4 4 2 2 2\n4 5 5 1 2 3\n4 5 5 3 2 1"], "outputs": ["-1\n7\n4"]}
667
53
coding
Solve the programming task below in a Python markdown code block. Flash has invited his nemesis The Turtle (He actually was a real villain! ) to play his favourite card game, SNAP. In this game a 52 card deck is dealt out so both Flash and the Turtle get 26 random cards. Each players cards will be represented by an a...
{"functional": "_inputs = [[['3', 'K', '5', 'A', '5', '6', '7', 'J', '7', '9', '10', 'Q', 'Q', '6', '8', '7', '4', 'J', '8', '9', 'K', 'J', '10', '4', 'K', '4'], ['2', '8', '9', 'Q', 'A', 'K', '6', '3', 'J', '2', '4', '3', '3', '8', 'A', '2', '6', '7', '9', '10', 'A', '5', 'Q', '10', '2', '5']], [['9', '5', '4', '4', '...
594
1,128
coding
Solve the programming task below in a Python markdown code block. There are $n$ boxers, the weight of the $i$-th boxer is $a_i$. Each of them can change the weight by no more than $1$ before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "2\n1 1\n", "2\n2 2\n", "2\n2 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n"]}
440
92
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Arya has a chessboard with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$); a square in row $r$ and column $c$ is denoted by $...
{"inputs": ["2\n4 2\n1 4\n2 2\n4 0"], "outputs": ["2 3 1 4 3\n4 1 1 2 2 3 3 4 4"]}
679
54
coding
Solve the programming task below in a Python markdown code block. Note : This question carries $150$ $points$ There is an outcry in Middle Earth, as the greatest war between Orgs of Dark Lord Sauron and Frodo Baggins is about to begin. To end the war, Frodo decides to destroy the ring in the volcano of Mordor. There ar...
{"inputs": ["1\n1 9"], "outputs": ["1 1"]}
383
18
coding
Solve the programming task below in a Python markdown code block. ## Task Find the sum of the first `n` elements in the Recamán Sequence. Input range: ```python 1000 tests 0 <= n <= 2,500,000 ``` ___ ## Sequence The sequence is formed using the next formula: * We start with `0` * At each step `i`, we subtract `i`...
{"functional": "_inputs = [[0], [1], [2], [5], [100], [200], [1000], [10000]]\n_outputs = [[0], [0], [1], [12], [7496], [36190], [837722], [82590002]]\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 is...
382
226
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string: Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L. For example, if S=39590, then c...
{"inputs": ["6\n3 5\n380\n3 9\n380\n4 2\n0123\n5 13\n78712\n6 10\n051827\n8 25\n37159725\n\n"], "outputs": ["0\n3\n1\n3\n2\n5\n"]}
701
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.   Please complete the following python code precisely: ```python class Solution...
{"functional": "def check(candidate):\n assert candidate(left = 5, right = 7) == 4\n assert candidate(left = 0, right = 0) == 0\n assert candidate(left = 1, right = 2147483647) == 0\n\n\ncheck(Solution().rangeBitwiseAnd)"}
81
81
coding
Solve the programming task below in a Python markdown code block. Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: the Euclidean distance between A and B is one u...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "0\n", "5\n", "6\n", "7\n"], "outputs": ["4\n", "8\n", "16\n", "20\n", "1\n", "28\n", "32\n", "36\n"]}
268
75
coding
Solve the programming task below in a Python markdown code block. *This is the second Kata in the Ciphers series. This series is meant to test our coding knowledge.* ## Ciphers #2 - The reversed Cipher This is a lame method I use to write things such that my friends don't understand. It's still fairly readable if you ...
{"functional": "_inputs = [['Hello World!']]\n_outputs = [['lleHo dlroW!']]\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) != len(b): return False\n ...
206
161
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive. A subarray of an array is a consecutive sequence of zero or more values taken out of that array...
{"functional": "def check(candidate):\n assert candidate(nums = [1,-2,-3,4]) == 4\n assert candidate(nums = [0,1,-2,-3,-4]) == 3\n assert candidate(nums = [-1,-2,-3,0,1]) == 2\n\n\ncheck(Solution().getMaxLen)"}
106
78
coding
Solve the programming task below in a Python markdown code block. There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the c...
{"inputs": ["3\n0 5\n3 9\n7 8", "3\n0 8\n3 9\n7 8", "3\n0 8\n3 9\n9 8", "3\n1 5\n3 9\n7 8", "3\n0 8\n3 9\n16 8", "3\n0 4\n3 9\n16 8", "3\n0 4\n3 9\n3 10", "3\n0 0\n22 26\n6 0"], "outputs": ["4\n", "1\n", "1\n", "3", "1\n", "4\n", "3\n", "16\n"]}
295
163
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums. Note that: A number greater than 1 is called prime if it is divisible by only 1 and itself...
{"functional": "def check(candidate):\n assert candidate(nums = [2,4,3,7,10,6]) == 4\n assert candidate(nums = [2,4,8,16]) == 1\n\n\ncheck(Solution().distinctPrimeFactors)"}
118
62
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a lower case string and your task will be to remove `k` characters from that string using the following rule: ```Python - first remove all letter 'a', followed by letter 'b', then 'c', etc... - remove the leftmost characte...
{"functional": "_inputs = [['abracadabra', 0], ['abracadabra', 1], ['abracadabra', 2], ['abracadabra', 6], ['abracadabra', 8], ['abracadabra', 50], ['hxehmvkybeklnj', 5], ['cccaabababaccbc', 3], ['cccaabababaccbc', 9], ['u', 1], ['back', 3]]\n_outputs = [['abracadabra'], ['bracadabra'], ['brcadabra'], ['rcdbr'], ['rdr'...
308
303
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous sequence of characters within the string.   Please ...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\") == 3\n assert candidate(s = \"aaa\") == 6\n\n\ncheck(Solution().countSubstrings)"}
92
44
coding
Solve the programming task below in a Python markdown code block. For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following progr...
{"inputs": ["3\n6 1 2", "3\n6 1 0", "3\n6 2 0", "3\n6 2 1", "3\n6 2 2", "3\n6 0 1", "3\n1 0 0", "3\n1 0 1"], "outputs": ["2\n", "3\n", "3\n", "3\n", "2\n", "2\n", "2\n", "1\n"]}
326
110
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] Chef has a sequence $A_{1}, A_{2}, \ldots, A_{N}$. In one operation, Chef can choose one index $i$ ($1 ≤ i ≤ N$) and change $A_{i}$ to $A_{i}^{p}$, where $p = \max(0, {\lceil \frac{A_{i}}{2} \rceil} - 1)$. Help Chef...
{"inputs": ["4\n4\n7 3 5 1\n5\n4 2 7 8 10\n2\n9 9\n3\n1 1 1"], "outputs": ["0\n1\n0\n-1"]}
534
56
coding
Solve the programming task below in a Python markdown code block. A Professor of Physics gave projects to the students of his class. The students have to form a team of two for doing the project. The professor left the students to decide the teams. The number of students in a class will be even. Each student has a kno...
{"inputs": ["8\n4 2 6 4 3\n6 1 1 1 1 1 1\n8 4 2 4 2 1 3 3 7\n14 5 1 8 8 13 7 6 2 1 9 5 11 3 4\n50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976\n50 7 9 1 3 7 9 5 6 4 9 3 4 2 1 3 6 5 3 6 5 7 1 7 7 4 9...
264
746
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros. In one operation you can choose any subarray from initial and increment each value...
{"functional": "def check(candidate):\n assert candidate(target = [1,2,3,2,1]) == 3\n assert candidate(target = [3,1,1,2]) == 4\n assert candidate(target = [3,1,5,4,2]) == 7\n assert candidate(target = [1,1,1,1]) == 1\n\n\ncheck(Solution().minNumberOperations)"}
125
96
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N. You can perform the following operation on S: Select an index i \ (1 ≤ i < |S|) such that S_{i}=S_{i+1}. Set S_{i} to 0 and remove S_{i+1} from the string. Note that after each operation, the length of S de...
{"inputs": ["4\n2\n11\n2\n10\n4\n1100\n3\n101\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
526
43
coding
Solve the programming task below in a Python markdown code block. A prime number is number x which has only divisors as 1 and x itself. Harsh is playing a game with his friends, where his friends give him a few numbers claiming that they are divisors of some number x but divisor 1 and the number x itself are not being ...
{"inputs": ["3\n2\n2 3\n2\n4 2\n3\n12 3 2"], "outputs": ["6\n8\n-1"]}
440
38