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
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, return true if they are both one edit distance apart, otherwise return false. A string s is said to be one distance apart from a string t if you can: Insert exactly one character into s to ...
{"functional": "def check(candidate):\n assert candidate(s = \"ab\", t = \"acb\") == True\n assert candidate(s = \"cab\", t = \"ad\") == False\n\n\ncheck(Solution().isOneEditDistance)"}
127
53
coding
Solve the programming task below in a Python markdown code block. There are $n$ red balls kept on the positive $X$ axis, and $m$ blue balls kept on the positive $Y$ axis. You are given the positions of the balls. For each $i$ from $1$ to $n$, the $i$-th red ball has the coordinates $(x_i, 0)$, where $x_i$ is a positive...
{"inputs": ["1 1\n1 2\n2 1\n", "1 2\n1 2\n2 1\n1 2\n"], "outputs": ["1", "1"]}
754
44
coding
Solve the programming task below in a Python markdown code block. Write a method that will search an array of strings for all strings that contain another string, ignoring capitalization. Then return an array of the found strings. The method takes two parameters, the query string and the array of strings to search, a...
{"functional": "_inputs = [['ab', ['za', 'ab', 'abc', 'zab', 'zbc']], ['aB', ['za', 'ab', 'abc', 'zab', 'zbc']], ['ab', ['za', 'aB', 'Abc', 'zAB', 'zbc']], ['abcd', ['za', 'aB', 'Abc', 'zAB', 'zbc']]]\n_outputs = [[['ab', 'abc', 'zab']], [['ab', 'abc', 'zab']], [['aB', 'Abc', 'zAB']], [['None']]]\nimport math\ndef _dee...
181
271
coding
Solve the programming task below in a Python markdown code block. JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≤ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum nu...
{"inputs": ["2\n24 27 3\n4 5 1000\n", "3\n5 5 2\n3 7 8\n8 11 1\n"], "outputs": ["2\n1", "0\n1\n-1\n"]}
592
64
coding
Solve the programming task below in a Python markdown code block. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \l...
{"inputs": ["5\n4 7\n5 5\n2 3\n5 8\n2 1", "5\n4 7\n5 5\n2 6\n5 8\n2 1", "5\n4 7\n5 5\n2 3\n6 8\n2 1", "5\n4 7\n5 5\n2 12\n5 8\n2 1", "5\n0 7\n5 5\n2 12\n5 8\n2 1", "5\n0 6\n8 9\n3 1\n6 16\n0 0", "5\n0 7\n5 5\n2 12\n5 16\n2 1", "5\n0 7\n5 5\n3 12\n5 16\n2 1"], "outputs": ["2 1\n2 3\n4 7\n5 5\n5 8\n", "2 1\n2 6\n4 7\n5 5...
262
379
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.     Please complete the following python code...
{"functional": "def check(candidate):\n assert candidate(coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]) == True\n assert candidate(coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]) == False\n\n\ncheck(Solution().checkStraightLine)"}
95
86
coding
Solve the programming task below in a Python markdown code block. Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For exam...
{"inputs": ["a\n", "z\n", "a\n", "z\n", "ee\n", "iq\n", "iq\n", "ee\n"], "outputs": ["aa\n", "zz\n", "aa\n", "zz\n", "eee\n", "qiq\n", "qiq\n", "eee"]}
403
71
coding
Solve the programming task below in a Python markdown code block. There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = E, and west if S_i = W. You will appoint on...
{"inputs": ["5\nWEEWW\n", "8\nWWWWWEEE\n", "12\nWEWEWEEEWWWE\n"], "outputs": ["1\n", "3\n", "4\n"]}
333
46
coding
Solve the programming task below in a Python markdown code block. In this Kata, two players, Alice and Bob, are playing a palindrome game. Alice starts with `string1`, Bob starts with `string2`, and the board starts out as an empty string. Alice and Bob take turns; during a turn, a player selects a letter from his or h...
{"functional": "_inputs = [['abc', 'xyz'], ['abc', 'axy'], ['abc', 'bax'], ['btzgd', 'svjyb'], ['eyfjy', 'ooigv'], ['mctimp', 'eyqbnh'], ['qtkxttl', 'utvohqk']]\n_outputs = [[2], [2], [2], [2], [1], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retu...
472
233
coding
Solve the programming task below in a Python markdown code block. Aayush has recently started teaching Latin Dance. Today, he will be teaching Salsa. For this, he needs to divide the people attending his dance class into pairs. Usually in Salsa, the dance pairs consist of one girl and one boy. But Aayush doesn't find t...
{"inputs": ["2\n5 8\n7 10"], "outputs": ["5\n6\n"]}
412
24
coding
Solve the programming task below in a Python markdown code block. Let f be a function, such that, for an array A of size M, f(A) is defined as f(A) = \sum_{i=1}^{M}\sum_{j=1, j \ne i}^{j=M} (A_{i}\cdot A_{j}) You are given an array C of size N. In one operation on the array, you can: Choose an index i (1≤ i ≤ |C|) Se...
{"inputs": ["2\n2\n1 2\n2\n1 3\n"], "outputs": ["6\n12\n"]}
760
29
coding
Solve the programming task below in a Python markdown code block. There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself. Vasya h...
{"inputs": ["1\n0\n", "1\n0\n", "3\n5 0 -5\n", "3\n5 0 -5\n", "4\n0 0 0 0\n", "3\n6 -1 -5\n", "4\n-1 0 1 0\n", "4\n1 2 3 -6\n"], "outputs": ["0\n", "0", "1\n", "1", "0\n", "2\n", "2\n", "3\n"]}
486
115
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings,...
{"functional": "def check(candidate):\n assert candidate(s1 = \"xx\", s2 = \"yy\") == 1\n assert candidate(s1 = \"xy\", s2 = \"yx\") == 2\n assert candidate(s1 = \"xx\", s2 = \"xy\") == -1\n\n\ncheck(Solution().minimumSwap)"}
144
76
coding
Solve the programming task below in a Python markdown code block. Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed dir...
{"inputs": ["1\n1\n0\n", "1\n1\n1\n", "2\n1 2\n0 0\n", "2\n1 2\n1 1\n", "2\n2 1\n0 1\n", "2\n1 2\n1 0\n", "2\n2 1\n1 1\n", "2\n1 2\n0 1\n"], "outputs": ["1\n", "0\n", "3\n", "3\n", "0\n", "2\n", "1\n", "2\n"]}
511
126
coding
Solve the programming task below in a Python markdown code block. To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes. The parking lot before the office consists of one line ...
{"inputs": ["3\n", "4\n", "5\n", "6\n", "7\n", "6\n", "5\n", "7\n"], "outputs": ["24", "132", "672", "3264", "15360", "3264\n", "672\n", "15360\n"]}
392
86
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Eidi gifts are a tradition in which children receive money from elder relatives during the Eid celebration. Chef has three children (numbered $1, 2,...
{"inputs": ["5\n5 7 10 10 20 50\n5 5 5 20 10 20\n10 1 17 5 10 15\n3 6 3 8 10 9\n8 5 5 50 10 10"], "outputs": ["FAIR\nNOT FAIR\nNOT FAIR\nNOT FAIR\nFAIR"]}
576
103
coding
Solve the programming task below in a Python markdown code block. One day, Ahmed_Hossam went to Hemose and said "Let's solve a gym contest!". Hemose didn't want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can't solve it... Could you help him? ...
{"inputs": ["3\n2 4\n3 7\n2 6\n4 2\n3 11\n2 1 7\n"], "outputs": ["1\n2\n3\n"]}
687
45
coding
Solve the programming task below in a Python markdown code block. We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day. Find ...
{"inputs": ["SRR", "RRR", "RSS", "SSR", "RST", "SRS", "TSR", "USR"], "outputs": ["2\n", "3\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
189
68
coding
Solve the programming task below in a Python markdown code block. The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to ...
{"inputs": ["2\n1 2\n", "3\n2 1\n2 3\n", "4\n1 4\n2 4\n3 4\n", "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 4\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 1\n", "8\n1 4\n3 2\n7 3\n4 5\n6 5\n6 7\n8 4\n"], "outputs": ["0\n1\n", "0\n2\n", "2\n1 2 3\n", ...
408
262
coding
Solve the programming task below in a Python markdown code block. Zubin is the dark messiah. He roams the streets at night, helping the poor and the innocent from evil. He's Batman. Ghosh is Zubin's nemesis. He's the Riddler to Zubin's Batman. He delights in torturing people with his puzzles. Tonight, Ghosh has gotten ...
{"inputs": ["10\n\n562189\n8112316\n9855612318\n8548\n12385561\n118\n0\n452157848\n44512\n855"], "outputs": ["2988369\n52526037\n94213633266\n29900\n82470764\n195\n1\n3717187680\n187585\n2138"]}
236
151
coding
Solve the programming task below in a Python markdown code block. An array is defined to be `odd-heavy` if it contains at least one odd element and every element whose value is `odd` is greater than every even-valued element. eg. ``` Array [11,4,9,2,8] is odd-heavy because:- its odd elements [11,9] are greater than...
{"functional": "_inputs = [[[0, 2, 19, 4, 4]], [[1, -2, -1, 2]], [[-3, 2, 1, 3, -1, -2]], [[3, 4, -2, -3, -2]], [[-1, 1, -2, 2, -2, -2, -4, 4]], [[-1, -2, 21]], [[0, 0, 0, 0]], [[0, -1, 1]], [[0, 2, 3]], [[0]], [[]], [[1]], [[0, 1, 2, 3, 4, 0, -2, -1, -4, -3]], [[1, -1, 3, -1]], [[1, -1, 2, -2, 3, -3, 0]], [[3]], [[2, ...
225
432
coding
Solve the programming task below in a Python markdown code block. Write a function getMean that takes as parameters an array (arr) and 2 integers (x and y). The function should return the mean between the mean of the the first x elements of the array and the mean of the last y elements of the array. The mean should be...
{"functional": "_inputs = [[[1, 3, 2, 4], 2, 3], [[1, 3, 2], 2, 2], [[1, 3, 2, 4], 1, 2], [[1, 3, 2, 4], 2, 8], [[1, -1, 2, -1], 2, 3]]\n_outputs = [[2.5], [2.25], [-1], [-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_to...
274
255
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays servers and tasks of lengths n​​​​​​ and m​​​​​​ respectively. servers[i] is the weight of the i​​​​​​th​​​​ server, and tasks[j] is the time needed to process the j​​​​​​th​...
{"functional": "def check(candidate):\n assert candidate(servers = [3,3,2], tasks = [1,2,3,2,1,2]) == [2,2,0,2,1,2]\n assert candidate(servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]) == [1,4,1,4,1,3,2]\n\n\ncheck(Solution().assignTasks)"}
342
113
coding
Solve the programming task below in a Python markdown code block. Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up...
{"inputs": ["2 1 4\n", "2 1 2\n", "5 2 1\n", "2 1 1\n", "6 2 4\n", "2 1 3\n", "5 1 5\n", "6 1 4\n"], "outputs": ["4\n", "2\n", "2\n", "1\n", "8\n", "3\n", "20\n", "20\n"]}
659
104
coding
Solve the programming task below in a Python markdown code block. Given A, B, and C as the sides of a triangle, find whether the triangle is *scalene*. Note: A triangle is said to be *scalene* if all three sides of the triangle are distinct. It is guaranteed that the sides represent a valid triangle. ------ Input For...
{"inputs": ["4\n2 3 4\n1 2 2\n2 2 2\n3 5 6\n"], "outputs": ["YES\nNO\nNO\nYES"]}
428
43
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef Aditi keeps changing the flavours of her dishes and she wants to analyse feedback from her customers in order to improve her performance. The cu...
{"inputs": ["4 3\n1 3 2 4\n1 4\n2 3\n2 4"], "outputs": ["NO\nNO\nYES"]}
768
38
coding
Solve the programming task below in a Python markdown code block. Two sisters, A and B, play the piano every day. During the day, they can play in any order. That is, A might play first and then B, or it could be B first and then A. But each one of them plays the piano exactly once per day. They maintain a common log, ...
{"inputs": ["4\nAB\nABBA\nABAABB\nAA"], "outputs": ["yes\nyes\nno\nno"]}
394
28
coding
Solve the programming task below in a Python markdown code block. There are n stone quarries in Petrograd. Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last f...
{"inputs": ["2\n2 0\n3 2\n", "2\n2 0\n5 2\n", "2\n2 0\n1 2\n", "2\n2 0\n2 2\n", "2\n2 0\n4 2\n", "2\n3 0\n4 2\n", "2\n2 1\n3 2\n", "4\n1 1\n1 1\n1 1\n1 1\n"], "outputs": ["tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "bolik\n"]}
364
150
coding
Solve the programming task below in a Python markdown code block. Shefin gives you a string S and you have to find a non-empty string P such that: P is a substring of S. No non-empty substring of P is a prefix of S. No non-empty substring of P is a suffix of S. For all such possible strings, find the length of the l...
{"inputs": ["2\nabcdab\naaa\n"], "outputs": ["2\n-1\n"]}
484
22
coding
Solve the programming task below in a Python markdown code block. You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to...
{"inputs": ["x\nww", "y\nww", "y\nvw", "z\nvw", "z\nvv", "{\nvv", "z\nwv", "y\nwv"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
363
80
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. Your task is to perform a flood fi...
{"functional": "def check(candidate):\n assert candidate(image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2) == [[2,2,2],[2,2,0],[2,0,1]]\n assert candidate(image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0) == [[0,0,0],[0,0,0]]\n\n\ncheck(Solution().floodFill)"}
237
130
coding
Solve the programming task below in a Python markdown code block. You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that...
{"inputs": ["z\n", "abc\n", "abcc\n", "abcd\n", "xxxyyxx\n", "xxxyxxx\n", "hfihihhfh\n", "hgihihhfh\n"], "outputs": ["YES\nz", "YES\nabc", "YES\nacbc\n", "NO\n", "YES\nxxxxyxy\n", "YES\nxxxxxxy\n", "NO\n", "NO\n"]}
341
97
coding
Solve the programming task below in a Python markdown code block. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the o...
{"inputs": ["2\n6 6\n", "2\n3 6\n", "2\n511 5\n", "2\n511 6\n", "2\n605 6\n", "2\n511 32\n", "3\n83 504 68\n", "3\n136 452 68\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "3 1\n", "3 1\n"]}
244
140
coding
Solve the programming task below in a Python markdown code block. Your task is to define a function that understands basic mathematical expressions and solves them. For example: ```python calculate("1 + 1") # => 2 calculate("18 + 4*6") # => 42 calculate("245 - 826") # => -581 calculate("09 + 000482") # ...
{"functional": "_inputs = [['1 + 1'], ['9 - 4'], ['1 - 4'], ['3 * 4'], ['9 / 3'], ['26 + 73'], ['524 + 277'], ['1 / 2'], ['2 / 5'], ['1 + 2 + 3 + 4 + 5 + 6'], ['123 - 3 - 20 - 100'], ['123 * 987 * 135 * 246'], ['200 / 2 / 10 / 5'], ['1+2-3+4-5+6-7+8-9+10'], ['5*2/3*9/10*123/8'], ['1*2*3/1/2/3+1+2+3-1-2-3'], ['1+2 * 4']...
334
528
coding
Solve the programming task below in a Python markdown code block. The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work. Given a sequence of n integers p_1,...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "2 2 1\n1 0\n", "2 1 1\n0 0\n", "2 1 1\n0 0\n", "2 2 1\n1 0\n", "2 1 1\n0 1\n", "2 1 1\n10 11\n"], "outputs": ["1\n", "1", "1\n", "0\n", "0", "1", "1\n", "11\n"]}
354
130
coding
Solve the programming task below in a Python markdown code block. Write ```python smaller(arr) ``` that given an array ```arr```, you have to return the amount of numbers that are smaller than ```arr[i]``` to the right. For example: ```python smaller([5, 4, 3, 2, 1]) == [4, 3, 2, 1, 0] smaller([1, 2, 0]) == [1, 1, 0] ...
{"functional": "_inputs = [[[5, 4, 3, 2, 1]], [[1, 2, 3]], [[1, 2, 0]], [[1, 2, 1]], [[1, 1, -1, 0, 0]], [[5, 4, 7, 9, 2, 4, 4, 5, 6]]]\n_outputs = [[[4, 3, 2, 1, 0]], [[0, 0, 0]], [[1, 1, 0]], [[0, 1, 0]], [[3, 3, 0, 0, 0]], [[4, 1, 5, 5, 0, 0, 0, 0, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(...
248
316
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will remove the left-most duplicates from a list of integers and return the result. ```python # Remove the 3's at indices 0 and 3 # followed by removing a 4 at index 1 solve([3, 4, 4, 3, 6, 3]) # => [4, 6, 3] ``` More examples can be ...
{"functional": "_inputs = [[[3, 4, 4, 3, 6, 3]], [[1, 2, 1, 2, 1, 2, 3]], [[1, 2, 3, 4]], [[1, 1, 4, 5, 1, 2, 1]]]\n_outputs = [[[4, 6, 3]], [[1, 2, 3]], [[1, 2, 3, 4]], [[4, 5, 2, 1]]]\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...
129
262
coding
Solve the programming task below in a Python markdown code block. From an array A containing N integers, you construct a binary string S of length (N - 1) as follows. For all 1 ≤ i < N: If A_{i} < A_{i+1}, then S_{i} = 0. If A_{i} > A_{i+1}, then S_{i} = 1. Given the string S, determine the count of indices i (1 ≤ i ≤...
{"inputs": ["3\n2\n0\n7\n000111\n6\n11100\n"], "outputs": ["1\n1\n2\n"]}
554
39
coding
Solve the programming task below in a Python markdown code block. Mr. Scrooge has a sum of money 'P' that he wants to invest. Before he does, he wants to know how many years 'Y' this sum 'P' has to be kept in the bank in order for it to amount to a desired sum of money 'D'. The sum is kept for 'Y' years in the bank wh...
{"functional": "_inputs = [[1000, 0.05, 0.18, 1100], [1000, 0.01625, 0.18, 1200], [1000, 0.05, 0.18, 1000]]\n_outputs = [[3], [14], [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, (l...
386
234
coding
Solve the programming task below in a Python markdown code block. Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a3. A tower consisting of blocks with...
{"inputs": ["8\n", "2\n", "7\n", "9\n", "1\n", "4\n", "3\n", "6\n"], "outputs": ["7 7\n", "2 2\n", "7 7\n", "7 7\n", "1 1\n", "4 4\n", "3 3\n", "6 6\n"]}
522
86
coding
Solve the programming task below in a Python markdown code block. Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible by $m$ are...
{"inputs": ["7\n1 1\n0 1\n101 4\n920 40\n335186385 972\n18 7\n1372032350266432 10\n", "7\n1 1\n10 1\n111 4\n1439 40\n335186385 379\n87 7\n1372032350266432 6\n", "7\n1 1\n0 1\n101 4\n920 40\n335186385 972\n137 7\n1372032350266432 10\n", "7\n1 2\n10 1\n111 4\n1439 40\n335186385 379\n87 7\n1372032350266432 6\n", "7\n1 1\n...
374
777
coding
Solve the programming task below in a Python markdown code block. After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations. You're given a number X represented in base b_{x} and a number Y represented in base b...
{"inputs": ["1 3\n1\n1 2\n1\n", "1 3\n1\n1 2\n1\n", "1 2\n1\n1 40\n1\n", "1 9\n2\n1 10\n2\n", "1 2\n1\n1 40\n1\n", "1 9\n2\n1 10\n2\n", "1 8\n2\n1 10\n2\n", "2 2\n1 0\n1 3\n1\n"], "outputs": ["=\n", "=", "=\n", "=\n", "=", "=", "=\n", ">\n"]}
602
148
coding
Solve the programming task below in a Python markdown code block. You are given positive integers N and K. You have to construct an array A of length N such that : 1 ≤ A_{i} ≤ 10^{18} \sum_{i=1}^{N} \sum_{j=i}^{N} F(i,j) = K, where F(i,j) denotes the [gcd] of all elements of the subarray A[i, j]. If multiple such ar...
{"inputs": ["3\n1 5\n2 4\n3 1\n"], "outputs": ["5\n1 2\n-1\n"]}
542
33
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We have two special characters: The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Given a binary array bits that ends with 0, return true if the las...
{"functional": "def check(candidate):\n assert candidate(bits = [1,1,1,0]) == False\n\n\ncheck(Solution().isOneBitCharacter)"}
109
38
coding
Solve the programming task below in a Python markdown code block. Implement a function which takes a string, and returns its hash value. Algorithm steps: * `a` := sum of the ascii values of the input characters * `b` := sum of every difference between the consecutive characters of the input (second char minus first c...
{"functional": "_inputs = [['int main(int argc, char *argv[]) { return 0; }'], [\" Yo - What's Good?! \"], [' df af asd '], ['global hash'], ['section .text'], ['hash:'], [' xor eax, eax'], [' ret'], ['; -----> end of hash <-----'], ['int hash(const char *str);'], [''], [' '], [' '], [' '], [' ']]\n_outputs...
226
318
coding
Solve the programming task below in a Python markdown code block. Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781...
{"inputs": ["17819\n1010\n10011\n7865275925328748785018788\n0", "17819\n0110\n10011\n7865275925328748785018788\n0", "17819\n0110\n10011\n4852349612300523475741654\n0", "17819\n0110\n00011\n4852349612300523475741654\n0", "17819\n0110\n01011\n6299136610007038575852406\n0", "17819\n0110\n01011\n8858159281710306483280973\n...
353
465
coding
Solve the programming task below in a Python markdown code block. Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and o...
{"inputs": ["1\n2 75\n", "1\n543 1\n", "1\n531 2\n", "1\n531 0\n", "1\n6 176\n", "1\n543 0\n", "1\n2 176\n", "1\n723 1\n"], "outputs": ["2\n", "1\n", "2\n", "0\n", "6\n", "0\n", "2\n", "1\n"]}
307
117
coding
Solve the programming task below in a Python markdown code block. Alice is playing Air Hockey with Bob. The first person to earn seven points wins the match. Currently, Alice's score is A and Bob's score is B. Charlie is eagerly waiting for his turn. Help Charlie by calculating the minimum number of points that will b...
{"inputs": ["4\n0 0\n2 5\n5 2\n4 3"], "outputs": ["7\n2\n2\n3\n"]}
490
35
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. A circular binary string is called *good* if it contains at least one character '1' and there is an integer $d$ such that for each character '1', the distance...
{"inputs": ["2\n6\n110011\n4\n0001"], "outputs": ["2\n0"]}
347
30
coding
Solve the programming task below in a Python markdown code block. Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the spoon and r...
{"inputs": ["3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\nbdfhj\ncacac\nopqrs\nddddd\nindia\nyucky"], "outputs": ["There is a spoon!\nThere is a spoon!\nThere is indeed no spoon!"]}
475
97
coding
Solve the programming task below in a Python markdown code block. A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road. A spanning tree is a set of...
{"inputs": ["2 3 4\n1 2\n", "2 4 1\n1 2\n", "2 2 1\n1 2\n", "2 3 1\n1 2\n", "2 3 4\n1 2\n", "2 4 1\n1 2\n", "2 3 1\n1 2\n", "2 2 1\n1 2\n"], "outputs": ["3\n", "4\n", "2\n", "3\n", "3", "4", "3", "2"]}
516
130
coding
Solve the programming task below in a Python markdown code block. Chef wants to buy a stock whose price was S rupees when the market opened. He will buy the stock if and only if its price is in the range [A, B]. The price of the stock has changed by C\% by the time he was trying to buy the stock. Will he be able to buy...
{"inputs": ["3\n100 93 108 7\n100 94 100 -7\n183 152 172 -17"], "outputs": ["Yes\nNo\nNo"]}
469
57
coding
Solve the programming task below in a Python markdown code block. Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0. There are also n cards, each card has 2 attributes: length l_{i} and co...
{"inputs": ["1\n1\n1\n", "1\n2\n2\n", "1\n1\n1\n", "1\n2\n2\n", "1\n1\n2\n", "1\n4\n2\n", "1\n6\n2\n", "1\n5\n2\n"], "outputs": ["1\n", "-1\n", "1\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]}
628
102
coding
Solve the programming task below in a Python markdown code block. In a tournament, $n$ players play against each other exactly once. Each game results in exactly one player winning. There are no ties. You have been given a scorecard containing the scores of each player at the end of the tournament. The score of a playe...
{"inputs": ["5\n3\n-1 -1 2\n3\n-1 -1 -1\n4\n0 1 2 3\n2\n1 1\n4\n-1 -1 -1 2\n"], "outputs": ["2\n7\n1\n0\n12\n"]}
550
68
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. In a far away dystopian world, the measure of the quality of a person’s life is the numbers of likes he gets for an article about their life. For a person to stay alive, he has to acquire at le...
{"inputs": ["2\n5 1 5 1\n9 4 3 2", "2\n5 2 5 1\n9 4 3 2", "2\n5 1 5 1\n4 2 2 2", "2\n5 1 5 1\n2 4 3 2", "2\n5 2 5 1\n9 3 3 2", "2\n5 3 5 1\n9 4 3 2", "2\n5 2 5 1\n1 4 5 2", "2\n5 4 5 1\n9 4 3 2"], "outputs": ["ALIVE AND KICKING\nALIVE AND KICKING\n", "ALIVE AND KICKING\nALIVE AND KICKING\n", "ALIVE AND KICKING\nALIVE A...
495
286
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots, a_n$ and an integer $k$. You are asked to divide this array into $k$ non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let $f(i)$ be the index of subarray the...
{"inputs": ["4 1\n3 0 0 1\n", "4 1\n3 -1 6 0\n", "4 1\n3 -2 6 0\n", "4 1\n3 -2 1 0\n", "4 1\n2 -2 1 0\n", "4 1\n3 -2 2 0\n", "4 1\n0 -2 1 0\n", "4 1\n6 -2 1 0\n"], "outputs": ["4\n", "8\n", "7\n", "2\n", "1\n", "3\n", "-1\n", "5\n"]}
464
150
coding
Solve the programming task below in a Python markdown code block. Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of th...
{"inputs": ["1\n3", "1\n1", "1\n2", "1\n7", "1\n6", "1\n4", "1\n8", "1\n5"], "outputs": ["1", "2\n", "-1\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
179
77
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An additive number is a string whose digits can form an additive sequence. A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must...
{"functional": "def check(candidate):\n assert candidate(\"112358\") == True \n assert candidate(\"199100199\") == True \n\n\ncheck(Solution().isAdditiveNumber)"}
151
54
coding
Solve the programming task below in a Python markdown code block. Your task in order to complete this Kata is to write a function which formats a duration, given as a number of seconds, in a human-friendly way. The function must accept a non-negative integer. If it is zero, it just returns `"now"`. Otherwise, the dur...
{"functional": "_inputs = [[0], [1], [62], [120], [3600], [3662], [15731080], [132030240], [205851834], [253374061], [242062374], [101956166], [33243586]]\n_outputs = [['now'], ['1 second'], ['1 minute and 2 seconds'], ['2 minutes'], ['1 hour'], ['1 hour, 1 minute and 2 seconds'], ['182 days, 1 hour, 44 minutes and 40 ...
508
440
coding
Solve the programming task below in a Python markdown code block. Problem Statement It is 2042 and we are surrounded by cyborgs everywhere. Geneo is one such cyborg with a human body and an electronic brain. To monitor skills and health of Geneo he is posed with questions everyday. On one fine day Geneo was asked the f...
{"inputs": ["2\n10 6\nabcdefghij\n10 1\nqwertyuiop"], "outputs": ["10 1\n159 1"]}
475
39
coding
Solve the programming task below in a Python markdown code block. You are wandering in the explorer space of the 2050 Conference. The explorer space can be viewed as an undirected weighted grid graph with size n× m. The set of vertices is \{(i, j)|1≤ i≤ n, 1≤ j≤ m\}. Two vertices (i_1,j_1) and (i_2, j_2) are connected...
{"inputs": ["2 2 3\n1\n3\n4 2\n", "2 2 4\n1\n2\n1 4\n", "2 2 4\n1\n4\n4 2\n", "2 2 4\n2\n2\n1 4\n", "2 2 6\n1\n4\n4 2\n", "2 2 4\n1\n2\n2 4\n", "2 2 6\n1\n4\n4 0\n", "2 2 4\n1\n4\n2 4\n"], "outputs": ["-1 -1\n-1 -1\n", "4 4\n4 6\n", "4 4\n10 6\n", "4 6\n4 6\n", "6 6\n12 8\n", "4 4\n6 8\n", "2 0\n8 0\n", "4 4\n6 10\n"]}
730
219
coding
Solve the programming task below in a Python markdown code block. There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is e...
{"inputs": ["9 1 3 7 6\n.#..#..", "4 1 3 7 6\n.#..#..", "8 1 3 7 6\n.#..#..", "1 1 3 7 6\n.#..#..", "8 1 4 7 6\n.#..#..", "8 2 4 7 6\n.#..#..", "5 1 3 7 6\n.#..#..", "0 1 3 7 6\n.#..#.."], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
400
166
coding
Solve the programming task below in a Python markdown code block. In Uttu's college, a semester is said to be a: Overload semester if the number of credits taken > 65. Underload semester if the number of credits taken < 35. Normal semester otherwise Given the number of credits X taken by Uttu, determine whether the s...
{"inputs": ["4\n65\n80\n23\n58\n"], "outputs": ["Normal\nOverload\nUnderload\nNormal\n"]}
393
34
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices. Return true if it is po...
{"functional": "def check(candidate):\n assert candidate(s1 = \"bank\", s2 = \"kanb\") == True\n assert candidate(s1 = \"attack\", s2 = \"defend\") == False\n assert candidate(s1 = \"kelb\", s2 = \"kelb\") == True\n assert candidate(s1 = \"abcd\", s2 = \"dcba\") == False\n\n\ncheck(Solution().areAlmostEqual...
124
96
coding
Solve the programming task below in a Python markdown code block. Chef has a string of size $N$ which consists only lowercase English alphabet. The chef doesn't like the consonant alphabet at all. So he is thinking of changing every single consonant alphabet to any vowel alphabet. There is some cost for performing this...
{"inputs": ["2\naeiou\ndbcc"], "outputs": ["0\n6"]}
345
20
coding
Solve the programming task below in a Python markdown code block. Marin wants you to count number of permutations that are beautiful. A beautiful permutation of length $n$ is a permutation that has the following property: $$ \gcd (1 \cdot p_1, \, 2 \cdot p_2, \, \dots, \, n \cdot p_n) > 1, $$ where $\gcd$ is the greate...
{"inputs": ["7\n1\n2\n3\n4\n5\n6\n1000\n"], "outputs": ["0\n1\n0\n4\n0\n36\n665702330\n"]}
422
52
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: - The string does not contain characters other than A, C, G and T. - The string does not contain AGC as a substring. - The conditi...
{"inputs": ["5", "6", "8", "9", "7", "6", "5", "4"], "outputs": ["865\n", "3247\n", "45719\n", "171531\n", "12185\n", "3247\n", "865\n", "230"]}
281
86
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. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. $N$ integers $A_{1}, A_{2}, \ldots, A_{N}$ are placed in a circle in such a way that for each valid $i$, $A_{i}$ and $A_{i+1}$ are adjacent, and $A_{...
{"inputs": ["1\n3\n10 10 1"], "outputs": ["32"]}
563
23
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 tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white. You are also given an integer carpetLen, the length of a single carpet that ca...
{"functional": "def check(candidate):\n assert candidate(tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10) == 9\n assert candidate(tiles = [[10,11],[1,1]], carpetLen = 2) == 2\n\n\ncheck(Solution().maximumWhiteTiles)"}
128
93
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n)...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,6], target = 5) == 2\n assert candidate(nums = [1,3,5,6], target = 2) == 1\n assert candidate(nums = [1,3,5,6], target = 7) == 4\n\n\ncheck(Solution().searchInsert)"}
105
88
coding
Solve the programming task below in a Python markdown code block. In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 10^9. At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all r...
{"inputs": ["1 1\n4\n", "1 1\n4\n", "2 2\n1 2\n", "2 1\n5 1\n", "2 2\n1 4\n", "2 3\n6 7\n", "2 3\n6 7\n", "2 1\n5 1\n"], "outputs": ["4\n", "4", "1\n", "5\n", "1\n", "7\n", "7", "5"]}
426
111
coding
Solve the programming task below in a Python markdown code block. problem There are n cards with one integer from 1 to n and one blank card. Of these n + 1 cards, k cards are given, but 1 ≤ k ≤ n. You can write one integer from 1 to n on a blank card. I want to make a continuous sequence of integers as long as possibl...
{"inputs": ["7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n1\n7\n0 0", "9 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n1\n4\n7\n0 0", "7 5\n6\n2\n3\n7\n1\n7 5\n6\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n4\n6\n0 0", "9 5\n6\n2\n4\n3\n1\n7 5\n5\n2\n1\n4\n7\n0 0", "9 5\n6\n3\n4\n7\n0\n7 5\n...
382
318
coding
Solve the programming task below in a Python markdown code block. The queen can be moved any number of unoccupied squares in a straight line vertically, horizontally, or diagonally, thus combining the moves of the rook and bishop. The queen captures by occupying the square on which an enemy piece sits. (wikipedia: http...
{"functional": "_inputs = [[7]]\n_outputs = [[[]]]\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 return all(_deep_eq(...
685
155
coding
Solve the programming task below in a Python markdown code block. Given an integer, $n$, print the following values for each integer $\boldsymbol{i}$ from $\mbox{1}$ to $n$: Decimal Octal Hexadecimal (capitalized) Binary Function Description Complete the print_formatted function in the editor below. print_for...
{"inputs": ["17\n"], "outputs": [" 1 1 1 1\n 2 2 2 10\n 3 3 3 11\n 4 4 4 100\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 10 8 1000\n 9 11 9 1001\n 10 12 A 1010\n 11 13 B 1011\n 12 14...
463
288
coding
Solve the programming task below in a Python markdown code block. Parsa has a humongous tree on $n$ vertices. On each vertex $v$ he has written two integers $l_v$ and $r_v$. To make Parsa's tree look even more majestic, Nima wants to assign a number $a_v$ ($l_v \le a_v \le r_v$) to each vertex $v$ such that the beaut...
{"inputs": ["3\n2\n1 7\n3 8\n1 2\n3\n1 3\n10 6\n7 9\n1 2\n2 3\n6\n3 1\n12 20\n6 19\n3 16\n5 17\n3 17\n3 3\n6 5\n1 5\n2 6\n4 6\n", "3\n2\n0 6\n3 8\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n12 21\n12 19\n3 12\n11 0\n3 0\n3 5\n6 5\n1 5\n2 6\n4 6\n", "3\n2\n1 6\n3 2\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n8 20\n12 19\n...
619
826
coding
Solve the programming task below in a Python markdown code block. In ChefLand, human brain speed is measured in bits per second (bps). Chef has a threshold limit of X bits per second above which his calculations are prone to errors. If Chef is currently working at Y bits per second, is he prone to errors? If Chef is p...
{"inputs": ["7 9\n", "6 6\n", "53 8\n", "31 53\n"], "outputs": ["YES", "NO", "NO", "YES\n"]}
413
46
coding
Solve the programming task below in a Python markdown code block. Chefina has an array A consisting of N positive integers. A permutation subsequence of length M is a subsequence that represents a permutation of length M. Now, Chefina asks Chef to find the count of permutation subsequences in array A. The count can ...
{"inputs": ["2\n5\n1 2 3 2 4\n6\n1 3 5 8 9 8\n"], "outputs": ["7\n1"]}
494
41
coding
Solve the programming task below in a Python markdown code block. A recent lab accident resulted in the creation of an extremely dangerous virus that replicates so rapidly it's hard to predict exactly how many cells it will contain after a given period of time. However, a lab technician made the following observations ...
{"inputs": ["2 4 1\n"], "outputs": ["3\n"]}
430
18
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays nums1 and nums2 sorted in non-decreasing order and an integer k. Define a pair (u, v) which consists of one element from the first array and one element from the second array. Return t...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,7,11], nums2 = [2,4,6], k = 3) == [[1,2],[1,4],[1,6]]\n assert candidate(nums1 = [1,1,2], nums2 = [1,2,3], k = 2) == [[1,1],[1,1]]\n\n\ncheck(Solution().kSmallestPairs)"}
140
106
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game with a number line and some segments. Takahashi is standing on the number line and he is initially at coordinate 0. Aoki has N segments. The i-th segment is [L_i,R_i], that is, a segment consisting of points with coord...
{"inputs": ["3\n2 2\n3 4\n5 6", "3\n1 2\n3 4\n5 6", "3\n2 2\n3 4\n10 6", "3\n3 2\n3 4\n20 6", "3\n3 4\n3 4\n20 6", "3\n3 4\n3 4\n28 6", "3\n3 2\n3 4\n14 6", "3\n1 4\n3 4\n48 6"], "outputs": ["12\n", "12", "22\n", "42\n", "40\n", "56\n", "30\n", "96\n"]}
418
171
coding
Solve the programming task below in a Python markdown code block. Recently Chef joined a new company. In this company, the employees have to work for X hours each day from Monday to Thursday. Also, in this company, Friday is called Chill Day — employees only have to work for Y hours (Y < X) on Friday. Saturdays and Sun...
{"inputs": ["3\n10 5\n12 2\n8 7\n"], "outputs": ["45\n50\n39\n"]}
452
35
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is no...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]) == [-1,0,0,1]\n assert candidate(nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]) == [-1,0,-1,0,0,0,-1]\n\n\ncheck(Solution().getCoprimes)"}
284
126
coding
Solve the programming task below in a Python markdown code block. ## Description You are a *Fruit Ninja*, your skill is cutting fruit. All the fruit will be cut in half by your knife. For example: ``` [ "apple", "pear", "banana" ] --> ["app", "le", "pe", "ar", "ban", "ana"] ``` As you see, all fruits are cu...
{"functional": "_inputs = [[['apple', 'pear', 'banana']], [['apple', 'pear', 'banana', 'bomb']], [[]]]\n_outputs = [[['app', 'le', 'pe', 'ar', 'ban', 'ana']], [['app', 'le', 'pe', 'ar', 'ban', 'ana', 'bomb']], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
449
216
coding
Solve the programming task below in a Python markdown code block. Neo has a complex matrix script. The matrix script is a $N$ X $\mbox{M}$ grid of strings. It consists of alphanumeric characters, spaces and symbols (!,@,#,$,%,&). To decode the script, Neo needs to read each column and select only the alphanumeric cha...
{"inputs": ["7 3\nTsi\nh%x\ni #\nsM \n$a \n#t%\nir!\n"], "outputs": ["This is Matrix# %!\n"]}
341
45
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $...
{"inputs": ["1\n1000\n", "1\n1000\n", "3\n1 3 5\n", "3\n2 3 5\n", "3\n2 3 1\n", "3\n1 3 5\n", "5\n4 3 2 2 3\n", "5\n4 3 2 3 3\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "3\n", "2\n", "4\n"]}
506
124
coding
Solve the programming task below in a Python markdown code block. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be n...
{"inputs": ["7 3\n4 2 2", "6 2\n1 4 1", "100 2\n100", "110 2\n110", "7 3\n2 2 2", "7 3\n2 1 2", "7 3\n0 1 2", "7 3\n0 1 1"], "outputs": ["0\n", "1\n", "99\n", "109\n", "0\n", "0\n", "0\n", "0\n"]}
299
129
coding
Solve the programming task below in a Python markdown code block. CQXYM found a rectangle A of size n × m. There are n rows and m columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation. A...
{"inputs": ["1\n5 4\n1000\n0000\n0110\n0001\n0001\n", "1\n5 4\n1000\n0000\n1110\n0001\n0000\n", "1\n5 4\n1011\n0000\n1010\n0000\n1000\n", "1\n5 4\n1000\n0010\n0110\n0001\n0001\n", "1\n5 4\n1011\n0000\n1010\n0001\n1000\n", "1\n5 4\n1000\n0100\n0110\n0101\n0000\n", "1\n5 4\n1011\n0000\n1010\n1001\n1000\n", "1\n5 4\n0011\...
639
306
coding
Solve the programming task below in a Python markdown code block. In Aramic language words can only represent objects. Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $x$ of a word $...
{"inputs": ["3\namer arem mrea\n", "3\namer mera mrea\n", "3\nrema mera mrea\n", "3\nrema mera erma\n", "3\nrema arem erma\n", "3\nrema aerm erma\n", "3\namer arem mrea\n", "5\na aa aaa ab abb\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2"]}
373
116
coding
Solve the programming task below in a Python markdown code block. Problem statement Of the string set $ S $ that meets the following conditions, configure $ 1 $ with the largest number of elements. * The length of the string contained in $ S $ is $ 1 $ or more and $ N $ or less. * The lengths of the strings contained...
{"inputs": ["2"], "outputs": ["2\n0\n11"]}
418
17
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string of numbers in sequence and your task will be to return the missing number. If there is no number missing or there is an error in the sequence, return `-1`. For example: ```Haskell missing("123567") = 4 missing("...
{"functional": "_inputs = [['123567'], ['899091939495'], ['9899101102'], ['599600601602'], ['8990919395'], ['998999100010011003'], ['99991000110002'], ['979899100101102'], ['900001900002900004900005900006']]\n_outputs = [[4], [92], [100], [-1], [-1], [1002], [10000], [-1], [900003]]\nimport math\ndef _deep_eq(a, b, tol...
213
335
coding
Solve the programming task below in a Python markdown code block. Set Given the sequence a_1, a_2, .., a_N. How many values ​​are there in this sequence? input N a_1 a_2 ... a_N output Output the number of types of values ​​in the sequence. Constraint * 1 \ leq N \ leq 10 ^ 5 * 1 \ leq a_i \ leq 10 ^ 9 Inp...
{"inputs": ["6\n8 5 9 1 2 1", "6\n8 5 9 0 2 1", "6\n1 2 9 0 2 0", "6\n1 5 9 0 2 1", "6\n1 5 9 0 2 0", "6\n8 6 9 1 2 1", "6\n1 2 15 0 2 0", "6\n-1 1 0 0 7 1"], "outputs": ["5\n", "6\n", "4\n", "5\n", "5\n", "5", "4\n", "4\n"]}
149
159
coding
Solve the programming task below in a Python markdown code block. You are given a tree that is built in a following way: initially there is single vertex 1. All the other vertices are added one by one, from vertex 2 to vertex N, by connecting it to one of those that have been added before. You are to find the diameter ...
{"inputs": ["2\n3\n1\n1\n5\n1\n2\n3\n3"], "outputs": ["1\n2\n1\n2\n3\n3"]}
323
38
coding
Solve the programming task below in a Python markdown code block. Chef is playing badminton today. The service rules of this singles game of badminton are as follows: 1. The player who starts the game serves from the right side of their court. 2. Whenever a player wins a point, they serve next. 3. If the server has won...
{"inputs": ["4\n2\n9\n53\n746"], "outputs": ["2\n5\n27\n374"]}
411
32
coding
Solve the programming task below in a Python markdown code block. # Do you ever wish you could talk like Siegfried of KAOS ? ## YES, of course you do! https://en.wikipedia.org/wiki/Get_Smart # Task Write the function ```siegfried``` to replace the letters of a given sentence. Apply the rules using the course not...
{"functional": "_inputs = [[1, 'City civilians'], [1, 'Centre receiver'], [1, 'Chatanooga choo choo crashed'], [1, 'Capital city cats chew cheese'], [2, 'Photo of 5 pheasants with graphs'], [3, 'Meet me at the same place at noon'], [3, 'The time is now'], [3, 'Be quite quiet'], [3, 'Aardvarks are nice most of the time'...
389
618
coding
Solve the programming task below in a Python markdown code block. You have two integers $l$ and $r$. Find an integer $x$ which satisfies the conditions below: $l \le x \le r$. All digits of $x$ are different. If there are multiple answers, print any of them. -----Input----- The first line contains two integers...
{"inputs": ["1 1\n", "5 5\n", "5 5\n", "1 1\n", "0 1\n", "0 0\n", "7 10\n", "6 39\n"], "outputs": ["1\n", "5\n", "5\n", "1\n", "0\n", "0\n", "7\n", "6\n"]}
216
88
coding
Solve the programming task below in a Python markdown code block. # Task You're given a two-dimensional array of integers `matrix`. Your task is to determine the smallest non-negative integer that is not present in this array. # Input/Output - `[input]` 2D integer array `matrix` A non-empty rectangular matrix. ...
{"functional": "_inputs = [[[[0, 2], [5, 1]]], [[[4, 5, 3, 21, 3, 8], [2, 2, 6, 5, 10, 9], [7, 5, 6, 8, 2, 6], [1, 4, 7, 8, 9, 0], [1, 3, 6, 5, 5, 1], [2, 7, 3, 4, 4, 3]]], [[[4, 5, 3, -4, 3, 8], [2, 0, 6, 5, 4, 9], [7, 5, 6, 8, 2, 6], [1, 4, 7, 8, 9, 11], [1, 3, 10, 5, 5, 1], [12, 7, 3, 4, 4, 3]]], [[[1, 2], [3, 4]]],...
182
598
coding
Solve the programming task below in a Python markdown code block. You are given a string, and you have to validate whether it's a valid Roman numeral. If it is valid, print True. Otherwise, print False. Try to create a regular expression for a valid Roman numeral. Input Format A single line of input containing a stri...
{"inputs": ["CDXXI\n"], "outputs": ["True\n"]}
181
16
coding
Solve the programming task below in a Python markdown code block. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n...
{"inputs": ["5\n1\n1\n2\n1 2\n5\n1 4 2 3 5\n5\n2 1 5 3 4\n10\n7 4 8 1 6 10 3 5 2 9\n"], "outputs": ["0\n1\n1\n4\n6\n"]}
706
80
coding
Solve the programming task below in a Python markdown code block. Cyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests. Then, if they get good marks she will reward them with candies :) However, ...
{"inputs": ["2\n2 0\n000 0", "2\n1 0\n000 0", "2\n2 0\n100 0", "2\n1 0\n010 0", "2\n1 0\n011 0", "2\n3 0\n000 3", "2\n4 1\n010 0", "2\n6 0\n100 1"], "outputs": ["0 2\n0 0\n", "0 1\n0 0\n", "0 2\n0 100\n", "0 1\n0 10\n", "0 1\n0 11\n", "0 3\n0 0\n", "4 0\n0 10\n", "0 6\n100 0\n"]}
435
197