problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one,...
{"inputs": ["50\n", "24\n", "545\n", "404\n", "685\n", "672\n", "258\n", "157\n"], "outputs": ["50\n50\n", "42\n42\n", "545\n455", "440\n440", "865\n865\n", "762\n762\n", "852\n528\n", "715\n715\n"]}
coding
290
Solve the programming task below in a Python markdown code block. You are given a string $s$, consisting only of Latin letters 'a', and a string $t$, consisting of lowercase Latin letters. In one move, you can replace any letter 'a' in the string $s$ with a string $t$. Note that after the replacement string $s$ might ...
{"inputs": ["3\naaaa\na\naa\nabc\na\nb\n"], "outputs": ["1\n-1\n2\n"]}
coding
469
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's college is conducting an online exam, where his camera will be monitored by one or more invigilators (supervisors). Once again, Chef failed to prepare ...
{"inputs": ["3\n1 10 10\n0 10\n2 2 10\n0 5\n7 10\n2 2 100\n0 5\n5 10"], "outputs": ["NO\nYES\nYES"]}
coding
736
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["2\n24\n68\n246\n81012\n141618\n2468\n10121416\n18202224\n26283032"]}
coding
233
Solve the programming task below in a Python markdown code block. Chef develops his own computer program for playing chess. He is at the very beginning. At first he needs to write the module that will receive moves written by the players and analyze it. The module will receive a string and it should report at first whe...
{"inputs": ["4\na1-b3\nd2-h8\na3 c4\nErrorError"], "outputs": ["Yes\nNo\nError\nError"]}
coding
398
Solve the programming task below in a Python markdown code block. Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G...
{"inputs": ["2 1\n1 1\n", "2 1\n1 1\n", "2 1\n2 1\n", "2 1\n2 2\n", "4 1\n1 2 2 2\n", "4 1\n1 2 2 2\n", "4 1\n1 1 2 2\n", "4 1\n1 2 2 4\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "2 3\n", "2 3\n", "3 4\n", "2 4\n"]}
coding
634
Solve the programming task below in a Python markdown code block. You have a fraction $\frac{a}{b}$. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. -----Input----- The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 10^5, 0 ≤ c ≤ 9). -...
{"inputs": ["1 2 0\n", "2 3 7\n", "1 7 7\n", "1 9 0\n", "1 3 0\n", "2 3 0\n", "1 2 5\n", "1 7 0\n"], "outputs": ["2", "-1", "6", "-1", "-1", "-1", "1", "-1"]}
coding
230
Solve the programming task below in a Python markdown code block. The number `1035` is the smallest integer that exhibits a non frequent property: one its multiples, `3105 = 1035 * 3`, has its same digits but in different order, in other words, `3105`, is one of the permutations of `1035`. The number `125874` is the f...
{"functional": "_inputs = [[10000, 7], [5000, 7], [10000, 4], [8000, 4], [5000, 3], [10000, 3]]\n_outputs = [[1], [0], [2], [1], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, ...
coding
489
Solve the programming task below in a Python markdown code block. Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across $n$ sessions follow the identity permutation (ie. in the first game he scores $1$ point,...
{"inputs": ["1\n2\n1 2\n", "1\n2\n1 2\n", "1\n4\n2 1 3 4\n", "1\n4\n2 1 3 4\n", "1\n3\n2 1 3 4\n", "1\n4\n2 1 2 4\n", "1\n3\n2 0 3 4\n", "1\n5\n1 3 4 2 5\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
647
Solve the programming task below in a Python markdown code block. ----- RANJANA QUIZ ----- Prof. Ranjana decided to conduct a quiz in her class. She divided all the students of her class into groups of three. Consider that no student was left out after the division. She gave different sets of questions to every group....
{"inputs": ["5\n6 5 4\n2 3 7\n4 6 5\n7 2 3\n5 3 1"], "outputs": ["1"]}
coding
326
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two s...
{"functional": "def check(candidate):\n assert candidate(a = \"x\", b = \"y\") == True\n assert candidate(a = \"abdef\", b = \"fecab\") == True\n assert candidate(a = \"ulacfd\", b = \"jizalu\") == True\n\n\ncheck(Solution().checkPalindromeFormation)"}
coding
232
Solve the programming task below in a Python markdown code block. Given: an array containing hashes of names Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand. Example: ``` ruby list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Mag...
{"functional": "_inputs = [[[{'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'}, {'name': 'Homer'}, {'name': 'Marge'}]], [[{'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'}]], [[{'name': 'Bart'}, {'name': 'Lisa'}]], [[{'name': 'Bart'}]], [[]]]\n_outputs = [['Bart, Lisa, Maggie, Homer & Marge'], ['Bart, Lisa & ...
coding
440
Solve the programming task below in a Python markdown code block. ```if-not:racket Write a function called `repeat_str` which repeats the given string `src` exactly `count` times. ``` ```if:racket Write a function called `repeat-string` which repeats the given string `str` exactly `count` times. ``` Also feel free to r...
{"functional": "_inputs = [[4, 'a'], [3, 'hello '], [2, 'abc']]\n_outputs = [['aaaa'], ['hello hello hello '], ['abcabc']]\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)):\...
coding
96
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string that has lowercase letters and numbers. Your task is to compare the number groupings and return the largest number. Numbers will not have leading zeros. For example, `solve("gh12cdy695m1") = 695`, because this i...
{"functional": "_inputs = [['gh12cdy695m1'], ['2ti9iei7qhr5'], ['vih61w8oohj5'], ['f7g42g16hcu5'], ['lu1j8qbbb85']]\n_outputs = [[695], [9], [61], [42], [85]]\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 ...
coding
152
Solve the programming task below in a Python markdown code block. Gru wants to distribute $N$ bananas to $K$ minions on his birthday. Gru does not like to just give everyone the same number of bananas, so instead, he wants to distribute bananas in such a way that each minion gets a $distinct$ amount of bananas. That is...
{"inputs": ["1\n6 3"], "outputs": ["1"]}
coding
319
Solve the programming task below in a Python markdown code block. You have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people for the task is x^{k}. Output the sum of costs over all non-empty subsets of people. -----Input----- Only line of input cont...
{"inputs": ["1 1\n", "3 2\n", "5 3\n", "5 3\n", "7 5\n", "3 3\n", "4 8\n", "1 1\n"], "outputs": ["1\n", "24\n", "800\n", "800\n", "181888", "54", "93320", "1\n"]}
coding
333
Solve the programming task below in a Python markdown code block. You are given a positive integer $N$. Print a numerical triangle of height $N-1$ like the one below: 1 22 333 4444 55555 ...... Can you do it using only arithmetic operations, a single for loop and print statement? Use no more than two lines. The ...
{"inputs": ["5\n"], "outputs": ["1\n22\n333\n4444\n"]}
coding
191
Solve the programming task below in a Python markdown code block. Given a non-negative number, return the next bigger polydivisible number, or an empty value like `null` or `Nothing`. A number is polydivisible if its first digit is cleanly divisible by `1`, its first two digits by `2`, its first three by `3`, and so o...
{"functional": "_inputs = [[0], [10], [11], [1234], [123220], [998], [999], [1234567890], [3608528850368400786036724], [3608528850368400786036725]]\n_outputs = [[1], [12], [12], [1236], [123252], [1020], [1020], [1236004020], [3608528850368400786036725], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isins...
coding
108
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: Pick any set of indices such that no two picked indices are adjacent. Flip the values at the picked indices (i.e. change 0 to 1 and 1 to 0). For example, conside...
{"inputs": ["3\n6\n101001\n5\n00000\n3\n111\n"], "outputs": ["1\n0\n2\n"]}
coding
419
Solve the programming task below in a Python markdown code block. You are given a multiset $S$ initially consisting of $n$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times. You will perform the following operation $k$ times: Add the element $\lceil\frac{a+b}{2}\rceil$...
{"inputs": ["1\n1 0\n0\n", "1\n1 0\n0\n", "1\n1 0\n1\n", "1\n1 1\n4\n", "1\n1 0\n2\n", "1\n1 1\n1\n", "1\n1 2\n4\n", "1\n1 0\n4\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "1\n"]}
coding
700
Solve the programming task below in a Python markdown code block. Chef has two binary strings A and B, both having length N. He can perform the following operation on A any number of times (possibly zero): Select any index i (1 ≤ i ≤ N - 1) and simultaneously set A_{i} := A_{i} \oplus A_{i + 1} and A_{i + 1} := A_{i} \...
{"inputs": ["3\n2\n00\n10\n3\n010\n000\n4\n0011\n0100\n"], "outputs": ["NO\nYES\nYES\n"]}
coding
559
Solve the programming task below in a Python markdown code block. On a planet called RUIZ LAND, which is ruled by the queen, Erika Ruiz. Each person on that planet has a strength value (strength value >0). That planet has a special rule made by the queen that a boy and a girl will form a couple if their Hate value is a...
{"inputs": ["2\n10 16"], "outputs": ["8 18"]}
coding
363
Solve the programming task below in a Python markdown code block. Lexicographic permutations are ordered combinations of a set of items ordered in a specific way. For instance, the first 8 permutations of the digits 0123, in lexicographic order, are: ``` 1st 0123 2nd 0132 3rd 0213 4th 0231 5th 0312 6th 0321 7th 1023 ...
{"functional": "_inputs = [[1, 1], [12, 5], [1000, 7], [1000, 8], [1000000, 10], [874, 7], [100, 5], [400, 6], [900, 8], [3000000, 10], [1234567, 10], [654321, 10], [100000, 9], [33333, 8]]\n_outputs = [['0'], ['02431'], ['1325460'], ['02436571'], ['2783915460'], ['1234560'], ['40231'], ['314250'], ['02354761'], ['8241...
coding
351
Solve the programming task below in a Python markdown code block. You are given n segments on a number line, numbered from 1 to n. The i-th segments covers all integer points from l_i to r_i and has a value w_i. You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it...
{"inputs": ["1 2\n1 2 10\n", "1 10\n1 10 23\n", "4 10\n6 10 4\n1 5 7\n2 6 5\n5 9 8\n", "4 10\n6 10 4\n1 5 7\n2 9 5\n5 9 8\n", "4 10\n6 10 4\n1 5 2\n2 9 5\n5 9 4\n", "4 10\n6 10 4\n1 5 7\n1 9 5\n5 9 8\n", "4 10\n6 10 4\n1 5 7\n2 9 5\n6 9 8\n", "4 10\n6 10 4\n1 5 7\n2 9 7\n6 9 8\n"], "outputs": ["0\n", "0\n", "3\n", "3\n...
coding
350
Please solve the programming task below using a self-contained code snippet in a markdown code block. Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [positioni, amounti] depicts amounti fruits at the position positioni. fruits is already sorted b...
{"functional": "def check(candidate):\n assert candidate(fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4) == 9\n assert candidate(fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4) == 14\n assert candidate(fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2) == 0\n\n\ncheck(Solution().maxTot...
coding
216
Solve the programming task below in a Python markdown code block. $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints * $ 1 \leq N \leq 10^5 $ * $ 1 \leq T...
{"inputs": ["2 4\n0 1\n1 2", "2 2\n0 0\n1 2", "2 4\n0 1\n1 3", "2 2\n1 1\n1 2", "2 4\n0 1\n1 1", "2 2\n0 0\n0 2", "2 4\n1 1\n1 3", "2 2\n1 1\n0 2"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
229
Solve the programming task below in a Python markdown code block. There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly thr...
{"inputs": ["2\n2 2\n", "2\n1 1\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n", "2\n1 2\n", "2\n2 2\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1", "0", "1", "0"]}
coding
414
Solve the programming task below in a Python markdown code block. As the title suggests, this is the hard-core version of another neat kata. The task is simple to explain: simply sum all the numbers from the first parameter being the beginning to the second parameter being the upper limit (possibly included), going i...
{"functional": "_inputs = [[2, 6, 2], [1, 5, 1], [1, 5, 3], [-1, -5, -3], [16, 15, 3], [-24, -2, 22], [-2, 4, 658], [780, 6851543, 5], [9383, 71418, 2], [20, 673388797, 5]]\n_outputs = [[12], [15], [5], [-5], [0], [-26], [-2], [4694363402480], [1253127200], [45345247259849570]]\nimport math\ndef _deep_eq(a, b, tol=1e-5...
coding
267
Solve the programming task below in a Python markdown code block. Return a new array consisting of elements which are multiple of their own index in input array (length > 1). Some cases: ``` [22, -6, 32, 82, 9, 25] => [-6, 32, 25] [68, -1, 1, -7, 10, 10] => [-1, 10] [-56,-85,72,-26,-14,76,-27,72,35,-21,-67,87,0,2...
{"functional": "_inputs = [[[22, -6, 32, 82, 9, 25]], [[68, -1, 1, -7, 10, 10]], [[11, -11]], [[-56, -85, 72, -26, -14, 76, -27, 72, 35, -21, -67, 87, 0, 21, 59, 27, -92, 68]], [[28, 38, -44, -99, -13, -54, 77, -51]], [[-1, -49, -1, 67, 8, -60, 39, 35]]]\n_outputs = [[[-6, 32, 25]], [[-1, 10]], [[-11]], [[-85, 72, 0, 6...
coding
200
Solve the programming task below in a Python markdown code block. Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as fo...
{"inputs": ["aaac\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n2\n2\nvxxyz\n2\n3\n4\n-", "ca`a\n3\n1\n2\n2\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n0\n2\nvwxyz\n2\n3\n4\n-", "aaac\n3\n1\n2\n1\nvwxyz\n2\n2\n4\n-", "ca`a\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "ca`a\n3\n1\n2\n2\nvwxyz\n2\n2\n4\n...
coding
335
Solve the programming task below in a Python markdown code block. Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; L — move...
{"inputs": ["1\nR\n0 0\n", "1\nU\n0 1\n", "1\nR\n1 0\n", "1\nR\n0 1\n", "1\nU\n0 0\n", "1\nU\n1 0\n", "1\nR\n1 0\n", "1\nU\n0 1\n"], "outputs": ["-1\n", "0\n", "0\n", "1\n", "-1\n", "1\n", "0\n", "0\n"]}
coding
715
Solve the programming task below in a Python markdown code block. Alice likes word "nineteen" very much. She has a string s and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get str...
{"inputs": ["n\n", "n\n", "m\n", "ni\n", "ni\n", "in\n", "nine\n", "nine\n"], "outputs": ["0", "0\n", "0\n", "0", "0\n", "0\n", "0", "0\n"]}
coding
271
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three charac...
{"functional": "def check(candidate):\n assert candidate(s = \"PPALLP\") == True\n assert candidate(s = \"PPALLL\") == False\n\n\ncheck(Solution().checkRecord)"}
coding
166
Solve the programming task below in a Python markdown code block. The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the s...
{"inputs": ["1 1 1\nX\n", "1 1 1\nX\n", "1 1 2\nX\n", "1 1 1\nX\n", "1 1 2\nX\n", "1 2 2\nX.\n", "1 2 2\n.X\n", "1 2 2\nX*\n"], "outputs": ["IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "RL\n", "LR\n", "IMPOSSIBLE\n"]}
coding
595
Solve the programming task below in a Python markdown code block. Make a function that receives a value, ```val``` and outputs the smallest higher number than the given value, and this number belong to a set of positive integers that have the following properties: - their digits occur only once - they are odd - they...
{"functional": "_inputs = [[12], [13], [99], [999999], [9999999999]]\n_outputs = [[15], [15], [105], [1023459], ['There is no possible number that fulfills those requirements']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=t...
coding
187
Solve the programming task below in a Python markdown code block. For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0. Constrai...
{"inputs": ["3 6\n1 2 3", "3 3\n1 2 3", "3 7\n1 2 3", "3 10\n1 2 3", "3 10\n0 2 3", "3 15\n1 2 3", "3 10\n1 2 0", "6 4\n1 2 0 2 3 2"], "outputs": ["3\n", "1\n", "0", "0\n", "0\n", "0\n", "0\n", "2\n"]}
coding
241
Solve the programming task below in a Python markdown code block. There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ...
{"inputs": ["4\n1 2\n1 3\n2 4", "4\n1 2\n2 3\n2 4", "4\n1 2\n2 3\n1 4", "4\n1 2\n4 3\n2 4", "4\n1 2\n4 3\n1 4", "4\n1 2\n1 3\n3 4", "4\n1 3\n2 3\n2 4", "4\n1 2\n2 4\n3 4"], "outputs": ["6\n", "2\n", "6\n", "6\n", "6\n", "6\n", "6\n", "6\n"]}
coding
503
Solve the programming task below in a Python markdown code block. The hamming distance of two equal-length strings is the number of positions, in which the two string differ. In other words, the number of character substitutions required to transform one string into the other. For this first Kata, you will write a fu...
{"functional": "_inputs = [['100101', '101001'], ['1010', '0101'], ['100101011011010010010', '101100010110010110101']]\n_outputs = [[2], [4], [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_tol=tol)\n if isinst...
coding
200
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...
coding
472
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition o...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,4]) == [2,3]\n assert candidate(nums = [1,1]) == [1,2]\n\n\ncheck(Solution().findErrorNums)"}
coding
146
Solve the programming task below in a Python markdown code block. Chef Zidane likes the number 9. He has a number N, and he wants to turn it into a multiple of 9. He cannot add or remove digits, and he can only change one digit at a time. The only allowed operation is to increment or decrement a digit by one, and doing...
{"inputs": ["4\n1989\n86236\n90210\n99999999999999999999999999999999999999988"], "outputs": ["0\n2\n3\n2"]}
coding
456
Solve the programming task below in a Python markdown code block. Timur initially had a binary string$^{\dagger}$ $s$ (possibly of length $0$). He performed the following operation several (possibly zero) times: Add ${0}$ to one end of the string and ${1}$ to the other end of the string. For example, starting from the...
{"inputs": ["1\n1\n1\n", "9\n3\n100\n4\n0111\n5\n10101\n6\n101010\n7\n1010110\n1\n1\n2\n10\n2\n11\n10\n1011011010\n"], "outputs": ["1\n", "1\n2\n5\n0\n3\n1\n0\n2\n4\n"]}
coding
687
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == [24,12,8,6]\n assert candidate(nums = [-1,1,0,-3,3]) == [0,0,9,0,0]\n\n\ncheck(Solution().productExceptSelf)"}
coding
122
Solve the programming task below in a Python markdown code block. Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X. X. .X XX XX Bishwocks don't attack any squares an...
{"inputs": ["0\n0\n", "0\nX\n", "X\n0\n", "X\nX\n", "X\n0\n", "0\nX\n", "X\nX\n", "0\n0\n"], "outputs": ["0", "0", "0", "0", "0\n", "0\n", "0\n", "0\n"]}
coding
405
Solve the programming task below in a Python markdown code block. You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved. Today you need to check a copy of a dialog between a client and a technical support manager. According to...
{"inputs": ["5\n4\nQQAA\n4\nQQAQ\n3\nQAA\n1\nQ\n14\nQAQQAQAAQQQAAA\n"], "outputs": ["Yes\nNo\nYes\nNo\nYes\n"]}
coding
511
Solve the programming task below in a Python markdown code block. As a New Year's gift, Dolphin received a string s of length 19. The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]. Dolphin wants to convert the comma-separated str...
{"inputs": ["happy,newyear,enjoy\n", "haiku,atcoder,tasks\n", "abcde,fghihgf,edcba\n", "mzbmw,yydiadt,coueg\n", "dbyfw,rpwbpuv,ifnua\n", "wyndm,tqvkgkb,tytsz\n", "twfle,sjzzszf,tzfpn\n", "cguem,rczqxyc,vdqnk\n"], "outputs": ["happy newyear enjoy\n", "haiku atcoder tasks\n", "abcde fghihgf edcba\n", "mzbmw yydiadt coueg...
coding
184
Solve the programming task below in a Python markdown code block. n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not alway...
{"inputs": ["4 6 2\n", "3 6 1\n", "3 3 3\n", "1 1 1\n", "3 3 3\n", "1 1 1\n", "3 8 3\n", "3 6 1\n"], "outputs": ["2\n", "3\n", "1\n", "1\n", "1\n", "1\n", "3\n", "3\n"]}
coding
378
Solve the programming task below in a Python markdown code block. After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are give...
{"inputs": ["3 0\n", "6 0\n", "4 0\n", "8 0\n", "3 0\n", "16 0\n", "13 0\n", "11 0\n"], "outputs": ["3 1\n", "3 20\n", "3 4\n", "3 56\n", "3 1", "3 560\n", "3 286\n", "3 165\n"]}
coding
539
Solve the programming task below in a Python markdown code block. You are given two positive integers a and b. You also have a number x, which is initially set to 0. At first, you can add a to x any number of times. After that, you can divide x by b any number of times as long as x is divisible by b. Print YES if you ...
{"inputs": ["4\n3 10\n9 6\n7 30\n8 12"], "outputs": ["NO\nYES\nNO\nYES"]}
coding
426
Solve the programming task below in a Python markdown code block. A subsequence of a string S is a string that can be obtained by deleting zero or more characters from S without changing the order of the remaining characters. For example, arc, artistic and (an empty string) are all subsequences of artistic; abc and ci ...
{"inputs": ["atcoddrregularcontest", "ssetabcrdpuflrrdaemtn", "nstcebmrmrteqbfcaress", "rdscrblracsfldraqdqso", "jrpddbrrqrrm_qnfsecec", "cenesebp_mrrprraddprj", "qsadmbdbqok^r`qtmore_", "atooddrregularccntest"], "outputs": ["b\n", "g\n", "d\n", "e\n", "a\n", "f\n", "c\n", "b\n"]}
coding
228
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected graph consisting of n nodes numbered from 0 to n - 1. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node. You are also given a 2D integer ar...
{"functional": "def check(candidate):\n assert candidate(vals = [1,2,3,4,10,-10,-20], edges = [[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]], k = 2) == 16\n assert candidate(vals = [-5], edges = [], k = 0) == -5\n\n\ncheck(Solution().maxStarSum)"}
coding
247
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a string $S$ with length $N$. Determine if it is possible to find two non-empty strings $A$ and $B$ which satisfy the following condit...
{"inputs": ["5\n6\ncabdab\n21\nyourcrushlovesyouback\n16\nwubbalubbadubdub\n5\nsplit\n7\nsplitit"], "outputs": ["YES\nNO\nYES\nNO\nYES"]}
coding
553
Solve the programming task below in a Python markdown code block. You came across this story while reading a book. Long a ago when the modern entertainment systems did not exist people used to go to watch plays in theaters, where people would perform live in front of an audience. There was a beautiful actress who had a...
{"inputs": ["2\nabc\naba"], "outputs": ["4\n6"]}
coding
477
Solve the programming task below in a Python markdown code block. You are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability. A Good Rectangle is defined as one where all squares lying on the inner border are of the same color. What is the...
{"inputs": ["1 3 1"], "outputs": ["6"]}
coding
162
Solve the programming task below in a Python markdown code block. Sort the given strings in alphabetical order, case **insensitive**. For example: ``` ["Hello", "there", "I'm", "fine"] --> ["fine", "Hello", "I'm", "there"] ["C", "d", "a", "B"]) --> ["a", "B", "C", "d"] ``` Also feel free to reuse/extend...
{"functional": "_inputs = [[['Hello', 'there', \"I'm\", 'fine']], [['C', 'd', 'a', 'B']], [['CodeWars']], [[]]]\n_outputs = [[['fine', 'Hello', \"I'm\", 'there']], [['a', 'B', 'C', 'd']], [['CodeWars']], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ret...
coding
111
Solve the programming task below in a Python markdown code block. **Steps** 1. Square the numbers that are greater than zero. 2. Multiply by 3 every third number. 3. Multiply by -1 every fifth number. 4. Return the sum of the sequence. **Example** `{ -2, -1, 0, 1, 2 }` returns `-6` ``` 1. { -2, -1, 0, 1 * 1, 2 * 2 ...
{"functional": "_inputs = [[[0, 2, 1, -6, -3, 3]], [[0]], [[1, 1, 1, 1, 1]], [[1, 1, -9, 9, 16, -15, -45, -73, 26]], [[1, -1, 10, -9, 16, 15, 45, -73, -26]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[-5, -5, -5, -5, -5, -5, -5]]]\n_outputs = [[31], [0], [5], [1665], [2584], [0], [-45]]\nimport math\ndef _deep_eq(a, ...
coding
204
Solve the programming task below in a Python markdown code block. A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them. ...
{"inputs": ["2 1\n0\n", "2 1\n5\n", "2 1\n0\n", "2 1\n5\n", "2 1\n8\n", "10 5\n0 0 1 0 2 0 0 1 0\n", "10 3\n1 1 1 1 2 1 1 1 1\n", "10 4\n0 0 6 2 7 1 6 4 0\n"], "outputs": ["0\n", "5\n", "0\n", "5\n", "8\n", "3\n", "3\n", "8\n"]}
coding
483
Solve the programming task below in a Python markdown code block. To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a soc...
{"inputs": ["4\n6 3 3\n1 2 3 2 2 2\n6 2 4\n1 1 2 2 2 2\n6 5 1\n6 5 4 3 2 1\n4 0 4\n4 4 4 3\n", "4\n6 3 3\n1 2 6 2 2 2\n6 2 4\n1 1 2 2 2 2\n6 5 1\n6 5 4 3 2 1\n4 0 4\n4 4 4 3\n", "4\n6 3 3\n1 2 6 2 2 2\n6 2 4\n1 1 2 2 2 2\n6 5 1\n6 5 4 1 2 1\n4 0 4\n4 4 4 3\n", "4\n6 3 3\n1 2 6 2 2 2\n6 2 4\n1 1 2 3 2 1\n6 5 1\n6 5 4 3 ...
coding
682
Solve the programming task below in a Python markdown code block. Polycarp has a poor memory. Each day he can remember no more than $3$ of different letters. Polycarp wants to write a non-empty string of $s$ consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it...
{"inputs": ["1\nvdjisjifreo\n", "6\nlollipops\nstringology\nabracadabra\ncodeforces\ntest\nf\n"], "outputs": ["4\n", "2\n4\n3\n4\n1\n1\n"]}
coding
459
Solve the programming task below in a Python markdown code block. Consider the range `0` to `10`. The primes in this range are: `2, 3, 5, 7`, and thus the prime pairs are: `(2,2), (2,3), (2,5), (2,7), (3,3), (3,5), (3,7),(5,5), (5,7), (7,7)`. Let's take one pair `(2,7)` as an example and get the product, then sum the ...
{"functional": "_inputs = [[0, 20], [2, 200], [2, 2000], [1000, 3000], [2000, 5000]]\n_outputs = [[14], [457], [17705], [12801], [25005]]\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, (...
coding
473
Solve the programming task below in a Python markdown code block. Given a binary number $S$ containing only of 1's and 0's, find two binary numbers $A$ and $B$ such that the sum of the number of 1's in $A$ and $B$ is minimum and $A-B=S$. If there are many such numbers, you can print any. The binary number $S$ has some...
{"inputs": ["1110000"], "outputs": ["10000000 10000"]}
coding
361
Solve the programming task below in a Python markdown code block. Little town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The d...
{"inputs": ["2 1 2 1\n1 2\n", "2 1 2 1\n1 2\n", "2 1 2 2\n1 2\n", "2 1 1 2\n1 2\n", "3 2 2 3\n1 2\n2 3\n", "3 2 1 3\n1 2\n2 3\n", "3 2 2 3\n1 2\n2 3\n", "3 2 1 3\n1 2\n2 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n"]}
coding
527
Solve the programming task below in a Python markdown code block. You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you o...
{"inputs": ["2\n5\n999 1 1 1 0\n5\n0 1 1 1 999\n"], "outputs": ["1001\n999\n"]}
coding
617
Solve the programming task below in a Python markdown code block. Write a function ```javascript tripledouble(num1,num2) ``` ```python triple_double(num1, num2) ``` which takes numbers `num1` and `num2` and returns `1` if there is a straight triple of a number at any place in `num1` and also a straight double of the ...
{"functional": "_inputs = [[451999277, 41177722899], [1222345, 12345], [12345, 12345], [666789, 12345667], [10560002, 100], [1112, 122]]\n_outputs = [[1], [0], [0], [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_tol...
coding
279
Solve the programming task below in a Python markdown code block. Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B. The territory of Country B is represented by a two-dimensional grid. The first place you occupy is a square on ...
{"inputs": ["2\n3\n5", "2\n3\n6", "2\n3\n4", "2\n6\n4", "2\n6\n5", "2\n6\n6", "2\n9\n6", "2\n0\n6"], "outputs": ["9\n", "10\n", "8\n", "11\n", "12\n", "13\n", "16\n", "7\n"]}
coding
340
Solve the programming task below in a Python markdown code block. The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lines. All t...
{"inputs": ["1\n[12:00 a.m.]: asZv MF\n", "1\n[10:41 a.m.]: apppmama\n", "1\n[10:41 a.m.]9 apppmama\n", "2\n[06:00 p.m.]: uNzO VN Nz h\n[06:00 a.m.]: bTJv\n", "2\n[11:35 a.m.]: ampapaammaamamaam\n[11:35 a.m.]: ppammpmmppmam\n", "3\n[05:33 p.m.]: apm\n[05:24 p.m.]: mapammmapaaa\n[06:01 p.m.]: mpmmmpa\n", "3\n[05:33 p.m....
coding
625
Solve the programming task below in a Python markdown code block. Write a function to calculate compound tax using the following table: For $10 and under, the tax rate should be 10%. For $20 and under, the tax rate on the first $10 is %10, and the tax on the rest is 7%. For $30 and under, the tax rate on the first $10...
{"functional": "_inputs = [[1], [10], [11], [15], [18], [21], [26], [30], [30.49], [35], [100], [1000000], [0], [-3], [None], ['monkey'], [[]], [{}]]\n_outputs = [[0.1], [1], [1.07], [1.35], [1.56], [1.75], [2], [2.2], [2.21], [2.35], [4.3], [30001.3], [0], [0], [0], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=...
coding
251
Solve the programming task below in a Python markdown code block. Congratulations !!! You have successfully completed the heist by looting all the gifts in Santa's locker. Now it's time to decide who gets to take all the gifts, you or the Grinch, there will be no splitting. So you and Grinch decide to play a game. To s...
{"inputs": ["7\n1\n2\n3\n4\n5\n6\n12"], "outputs": ["Grinch\nMe\nMe\nGrinch\nMe\nGrinch\nMe"]}
coding
303
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"]}
coding
760
Solve the programming task below in a Python markdown code block. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|. Strin...
{"inputs": ["b\n", "z\n", "y\n", "a\n", "c\n", "x\n", "d\n", "w\n"], "outputs": ["b\n", "z\n", "y\n", "a\n", "c\n", "x\n", "d\n", "w\n"]}
coding
334
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a linked list head, in which each node contains an integer value. Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them. Return the linked ...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([18,6,10,3])), list_node([18,6,6,2,10,1,3]))\n assert is_same_list(candidate(head = list_node([7])), list_node([7]))\n\n\ncheck(Solution().insertGreatestCommonDivisors)"}
coding
161
Solve the programming task below in a Python markdown code block. You are given an array of length n and a number k. Let's pick k non-overlapping non-empty subarrays of the initial array. Let si be the sum of the i-th subarray in order from left to right. Compute the maximum value of the following expression: |s1 - ...
{"inputs": ["4 2\n7 4 3 7", "4 2\n7 4 3 7"], "outputs": ["8", "8"]}
coding
374
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labeled from 0...
{"functional": "def check(candidate):\n assert candidate(boxes = [1,2,2,3,4], warehouse = [3,4,1,2]) == 4\n assert candidate(boxes = [3,5,5,2], warehouse = [2,1,3,4,5]) == 3\n assert candidate(boxes = [1,2,3], warehouse = [1,2,3,4]) == 3\n assert candidate(boxes = [4,5,6], warehouse = [3,3,3,3,3]) == 0\n\n\...
coding
212
Solve the programming task below in a Python markdown code block. Mr. Pr and Ms. Ad are at $a$ and $b$ respectively on an infinite number line. Mr. Pr wants to meet Ms. Ad. Mr. Pr can choose to move $c$ or $d$ units in 1 second. If Mr. Pr moves $c$ units then Ms. Ad will move $d$ units and vice versa. (Both of them a...
{"inputs": ["2\n3 4 1 2\n10 20 3 7"], "outputs": ["YES\nNO"]}
coding
349
Solve the programming task below in a Python markdown code block. In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short. The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string. Given a string S of length N and an inte...
{"inputs": ["18\nRETSULCAIDEMOGNAWD\n1\n18", "18\nDDEDDDMMMMMCCCCCCC\n1\n18", "18\nDWANGOMEDIACLUSTER\n1\n32", "18\nDDDDDDMMMMMCCCCCCC\n1\n29", "18\nDDEDDDMMNMMCCCCCCC\n1\n18", "18\nDDDDDDMMMMMCCCCCCC\n1\n11", "18\nDCDDDDMMMMMDCCCCCC\n1\n11", "18\nDDEDDDMMMMMCCCCCCC\n1\n11"], "outputs": ["0\n", "175\n", "1\n", "210\n",...
coding
521
Please solve the programming task below using a self-contained code snippet in a markdown code block. In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (except for the town ju...
{"functional": "def check(candidate):\n assert candidate(n = 2, trust = [[1,2]]) == 2\n assert candidate(n = 3, trust = [[1,3],[2,3]]) == 3\n assert candidate(n = 3, trust = [[1,3],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().findJudge)"}
coding
195
Solve the programming task below in a Python markdown code block. You have to create a function,named `insertMissingLetters`, that takes in a `string` and outputs the same string processed in a particular way. The function should insert **only after the first occurrence** of each character of the input string, all the...
{"functional": "_inputs = [['hello'], ['abcdefghijklmnopqrstuvwxyz'], ['hellllllllllllooooo'], ['pixxa'], ['xpixax'], ['z']]\n_outputs = [['hIJKMNPQRSTUVWXYZeFGIJKMNPQRSTUVWXYZlMNPQRSTUVWXYZloPQRSTUVWXYZ'], ['abcdefghijklmnopqrstuvwxyz'], ['hIJKMNPQRSTUVWXYZeFGIJKMNPQRSTUVWXYZlMNPQRSTUVWXYZllllllllllloPQRSTUVWXYZoooo']...
coding
239
Solve the programming task below in a Python markdown code block. Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A b...
{"inputs": ["5 2 6", "7 5 4", "5 3 6", "7 1 4", "3 3 6", "7 2 6", "4 2 6", "7 3 4"], "outputs": ["10\n", "8\n", "7\n", "11\n", "4\n", "14\n", "7", "8"]}
coding
240
Solve the programming task below in a Python markdown code block. We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum num...
{"inputs": ["ab\n", "bb\n", "ba\n", "ab\n", "aab\n", "abb\n", "bab\n", "bba\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "3\n", "2\n", "1\n", "0\n"]}
coding
246
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums, return the number of subarrays of nums having an even product.   Please complete the following python code precisely: ```python class Solution: def evenProduct(self, nums: Lis...
{"functional": "def check(candidate):\n assert candidate(nums = [9,6,7,13]) == 6\n assert candidate(nums = [7,3,5]) == 0\n\n\ncheck(Solution().evenProduct)"}
coding
71
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could p...
{"inputs": ["2\n2 4\n6 8", "2\n4 4\n6 8", "2\n2 7\n6 8", "2\n2 9\n3 7", "2\n1 0\n3 4", "2\n2 9\n4 7", "2\n1 0\n1 4", "2\n1 5\n3 42"], "outputs": ["6\n13\n", "1\n13\n", "24\n13\n", "38\n23\n", "0\n5\n", "38\n19\n", "0\n7\n", "13\n736\n"]}
coding
377
Solve the programming task below in a Python markdown code block. Taxis of Kharagpur are famous for making sharp turns. You are given the coordinates where a particular taxi was on a 2-D planes at N different moments: (x1, y1), (x2, y2), ..., (xN, yN). In between these coordinates, the taxi moves on a straight line. A ...
{"inputs": ["5\n3\n0 0\n1 1\n2 1\n3\n0 0\n1 0\n6 1\n3\n0 0\n1 0\n1 1\n4\n0 0\n1 0\n1 1\n6 1\n6\n0 0\n1 0\n1 1\n2 1\n2 2\n3 2"], "outputs": ["yes yes\nyes yes\nno yes\nno yes\nno no"]}
coding
737
Solve the programming task below in a Python markdown code block. Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number a_{i}, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder ...
{"inputs": ["2\n1 2\n", "2\n4 5\n", "2\n1 5\n", "2\n2 5\n", "2\n3 4\n", "2\n1 2\n", "2\n2 5\n", "2\n3 4\n"], "outputs": ["2 1", "5 4", "5 1", "5 2", "4 3", "2 1\n", "5 2\n", "4 3\n"]}
coding
591
Solve the programming task below in a Python markdown code block. Alice and Brown loves games. Today, they will play the following game. In this game, there are two piles initially consisting of X and Y stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice: - Take 2i ston...
{"inputs": ["1 0", "6 0", "2 0", "1 8", "4 0", "1 5", "3 0", "0 7"], "outputs": ["Brown\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n"]}
coding
281
Solve the programming task below in a Python markdown code block. # altERnaTIng cAsE <=> ALTerNAtiNG CaSe Define `String.prototype.toAlternatingCase` (or a similar function/method *such as* `to_alternating_case`/`toAlternatingCase`/`ToAlternatingCase` in your selected language; **see the initial solution for details**...
{"functional": "_inputs = [['hello world'], ['HELLO WORLD'], ['hello WORLD'], ['HeLLo WoRLD'], ['12345'], ['1a2b3c4d5e'], ['String.prototype.toAlternatingCase']]\n_outputs = [['HELLO WORLD'], ['hello world'], ['HELLO world'], ['hEllO wOrld'], ['12345'], ['1A2B3C4D5E'], ['sTRING.PROTOTYPE.TOaLTERNATINGcASE']]\nimport ma...
coding
322
Solve the programming task below in a Python markdown code block. Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i}...
{"inputs": ["1\n5\n", "1\n9\n", "1\n5\n", "1\n16\n", "1\n24\n", "1\n27\n", "1\n25\n", "1\n37\n"], "outputs": ["NO", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
495
Solve the programming task below in a Python markdown code block. Unscramble the eggs. The string given to your function has had an "egg" inserted directly after each consonant. You need to return the string before it became eggcoded. ## Example Kata is supposed to be for beginners to practice regular expressions, ...
{"functional": "_inputs = [['ceggodegge heggeregge'], ['FeggUNegg KeggATeggA'], ['egegggegg'], ['Heggeleggleggo weggoreggleggdegg'], ['seggceggreggameggbeggleggedegg egegggeggsegg'], ['egegggeggyegg beggreggeadegg'], ['veggegeggyeggmeggitegge onegg teggoaseggtegg']]\n_outputs = [['code here'], ['FUN KATA'], ['egg'], ['...
coding
99
Solve the programming task below in a Python markdown code block. There is a string $s$ of length $3$, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable. -----Input----- The f...
{"inputs": ["1\nvop\n", "1\nhac\n", "1\nNNy\n", "1\nHAC\n", "1\nyeQ\n", "1\nHAm\n", "1\nxxx\n", "1\nxxy\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
320
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box....
{"functional": "def check(candidate):\n assert candidate(boxes = \"110\") == [1,1,3]\n assert candidate(boxes = \"001011\") == [11,8,5,4,3,4]\n\n\ncheck(Solution().minOperations)"}
coding
183
Solve the programming task below in a Python markdown code block. Given N points of the form (x_{i}, y_{i}) on a 2-D plane. From each point, you draw 2 lines one horizontal and one vertical. Now some of the lines may overlap each other, therefore you are required to print the number of distinct lines you can see on th...
{"inputs": ["3\n4\n1 1\n1 0\n0 1\n0 0\n5\n0 0\n0 1\n0 2\n0 3\n0 4\n1\n10 10"], "outputs": ["4\n6\n2"]}
coding
493
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed strings word1 and word2. A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j]. Return true if it is ...
{"functional": "def check(candidate):\n assert candidate(word1 = \"ac\", word2 = \"b\") == False\n assert candidate(word1 = \"abcc\", word2 = \"aab\") == True\n assert candidate(word1 = \"abcde\", word2 = \"fghij\") == True\n\n\ncheck(Solution().isItPossible)"}
coding
140
Solve the programming task below in a Python markdown code block. The land of Programmers Army is surrounded by many islands. A unique number is associated with each island. The king of the islands is a very generous person, he donates a certain amount of gold coins to travelers for visiting each island that they visit...
{"inputs": ["1\n4\n10 2 5 50\n2\n1 3\n2 4"], "outputs": ["17\n57"]}
coding
584
Please solve the programming task below using a self-contained code snippet in a markdown code block. You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert: There must be e...
{"functional": "def check(candidate):\n assert candidate(baseCosts = [1,7], toppingCosts = [3,4], target = 10) == 10\n assert candidate(baseCosts = [2,3], toppingCosts = [4,5,100], target = 18) == 17\n assert candidate(baseCosts = [3,10], toppingCosts = [2,5], target = 9) == 8\n assert candidate(baseCosts =...
coding
250
Solve the programming task below in a Python markdown code block. A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers...
{"inputs": ["1\n3 1\n", "1\n3 1\n", "9\n8 11\n1 110\n6 3\n69 2\n1 2\n92 79\n8276 17989\n164 789\n6179509 2\n", "9\n8 6\n1 110\n5 3\n36 2\n1 2\n92 420\n8276 17989\n164 789\n16177647 9\n", "9\n8 11\n1 110\n6 3\n36 2\n1 2\n92 92\n8276 17989\n164 789\n20448260 4\n", "9\n8 11\n1 110\n6 3\n36 2\n1 2\n92 79\n8276 17989\n164 7...
coding
377
Solve the programming task below in a Python markdown code block. In this kata you will be given a random string of letters and tasked with returning them as a string of comma-separated sequences sorted alphabetically, with each sequence starting with an uppercase character followed by `n-1` lowercase characters, where...
{"functional": "_inputs = [['BfcFA'], ['ZpglnRxqenU'], ['NyffsGeyylB'], ['MjtkuBovqrU'], ['EvidjUnokmM'], ['HbideVbxncC']]\n_outputs = [['A,Bb,Ccc,Ffffff,Ffffff'], ['Eeeee,Ggggggg,Llllllllllll,Nnnnnnnnnnnnnn,Nnnnnnnnnnnnnn,Pppppppppppppppp,Qqqqqqqqqqqqqqqqq,Rrrrrrrrrrrrrrrrrr,Uuuuuuuuuuuuuuuuuuuuu,Xxxxxxxxxxxxxxxxxxxxx...
coding
253
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are n villages in a line in an area. There are two kinds of tribes A and B that reside there. A village can be either empty or occupied by one of the tribes. An empty v...
{"inputs": ["4\nA..A..B...B\n..A..\nA....A\n..B..B..B.."], "outputs": ["4 5\n1 0\n6 0\n0 7"]}
coding
334
Solve the programming task below in a Python markdown code block. problem Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hana...
{"inputs": ["4\n1\n1\n3\n12\n1\n6\n3\n8\n2\n0\n7\n2\n1\n0\n0", "4\n1\n1\n3\n12\n1\n6\n1\n8\n2\n0\n7\n2\n1\n0\n0", "4\n1\n1\n3\n17\n2\n6\n3\n8\n2\n0\n7\n2\n1\n0\n0", "4\n1\n2\n3\n12\n1\n6\n1\n8\n2\n0\n7\n2\n1\n0\n0", "4\n1\n1\n3\n17\n2\n6\n4\n8\n0\n0\n7\n4\n1\n0\n0", "4\n1\n2\n3\n12\n1\n6\n1\n8\n2\n1\n7\n2\n1\n0\n0", "4...
coding
441
Solve the programming task below in a Python markdown code block. Alice lives on a line. Today, she will travel to some place in a mysterious vehicle. Initially, the distance between Alice and her destination is D. When she input a number x to the vehicle, it will travel in the direction of the destination by a distanc...
{"inputs": ["4 1\n1 4 1 3\n2\n4 3", "4 1\n0 4 1 3\n2\n4 3", "4 10\n3 2 3 3\n2\n4 3", "4 16\n3 7 3 3\n2\n4 0", "4 10\n3 1 3 3\n2\n4 3", "4 10\n3 4 3 3\n2\n4 3", "4 10\n3 4 3 3\n2\n4 3\n", "5 9\n4 4 2 3 4\n5\n1 4 2 3 5"], "outputs": ["NO\nNO\n", "NO\nYES\n", "YES\nYES\n", "YES\nNO\n", "YES\nYES\n", "NO\nYES", "NO\nYES\n"...
coding
464
Solve the programming task below in a Python markdown code block. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow) * ...
{"inputs": ["3\n2\n2\n4", "3\n0\n42\n4", "3\n0\n37\n4", "3\n16\n2\n7", "3\n29\n2\n7", "3\n9\n99\n39", "3\n3\n127\n5", "3\n1\n169\n6"], "outputs": ["0\n0\n0\n", "0\n1\n0\n", "0\n2\n0\n", "1\n0\n0\n", "2\n0\n0\n", "0\n2\n3\n", "0\n3\n0\n", "0\n4\n0\n"]}
coding
618
Solve the programming task below in a Python markdown code block. We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ......
{"inputs": ["111 0\n-608", "111 0\n-624", "110 0\n-4833", "010 1\n-4464", "100 1\n-4199", "111 0\n-3124", "110 0\n-3872", "111 0\n-4743"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
390