task_type
stringclasses
1 value
problem
stringlengths
261
3.34k
answer
stringlengths
35
6.15k
problem_tokens
int64
62
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. You went to the store, selling $n$ types of chocolates. There are $a_i$ chocolates of type $i$ in stock. You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy $x_i$...
{"inputs": ["2\n1 7\n", "2\n0 6\n", "2\n4 9\n", "2\n5 2\n", "2\n6 16\n", "2\n6 16\n", "2\n5 16\n", "2\n1 12\n"], "outputs": ["8\n", "6\n", "13\n", "3\n", "22", "22", "21\n", "13\n"]}
482
109
coding
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard version is the constraint on $n$. You are given an undirected complete graph on $n$ vertices. A complete graph is a graph where each pair of vertices is connected by an edge. You have to paint the edges ...
{"inputs": ["3\n", "4\n", "42\n", "13\n", "69\n", "100\n", "500\n", "1337\n"], "outputs": ["6\n", "50\n", "934067958\n", "456092424\n", "242481789\n", "878752271\n", "39656147\n", "520628749\n"]}
448
128
coding
Solve the programming task below in a Python markdown code block. Encryption System A programmer developed a new encryption system. However, his system has an issue that two or more distinct strings are `encrypted' to the same string. We have a string encrypted by his system. To decode the original string, we want to...
{"inputs": ["enw\nbbc\nabcdefghijklmnopqrst\nz\n#", "enw\ncbb\nabcdefggijklmnopqrst\nz\n#", "enw\ncbb\nabcsefggijklmnopqrdt\nz\n#", "enw\nabb\nabcdefghijklmnopqrst\nz\n#", "enw\nbcc\nabcdefghijklmnopqrst\nz\n#", "enw\ncbb\ntsrqponmlkjihgfedcba\nz\n#", "enw\nabb\ntsrqponmlkjihgfedcba\nz\n#", "enw\nbcc\ntsrqponmlkjihgfed...
686
845
coding
Solve the programming task below in a Python markdown code block. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation...
{"inputs": ["1 1\n", "3 2\n", "3 3\n", "0 2\n", "3 3\n", "0 2\n", "1 3\n", "1 6\n"], "outputs": ["1\n", "5\n", "7\n", "1\n", "7", "1", "4\n", "32\n"]}
215
85
coding
Solve the programming task below in a Python markdown code block. Chef is planning to buy a new car for his birthday. After a long search, he is left with 2 choices: Car 1: Runs on diesel with a fuel economy of x_{1} km/l Car 2: Runs on petrol with a fuel economy of x_{2} km/l Chef also knows that the current price o...
{"inputs": ["3\n10 5 3 20\n7 2 7 2\n1 5 3 2"], "outputs": ["-1\n0\n1"]}
554
43
coding
Solve the programming task below in a Python markdown code block. Consider an array containing cats and dogs. Each dog can catch only one cat, but cannot catch a cat that is more than `n` elements away. Your task will be to return the maximum number of cats that can be caught. For example: ```Haskell solve(['D','C','C...
{"functional": "_inputs = [[['D', 'C', 'C', 'D', 'C'], 1], [['C', 'C', 'D', 'D', 'C', 'D'], 2], [['C', 'C', 'D', 'D', 'C', 'D'], 1], [['D', 'C', 'D', 'C', 'C', 'D'], 3], [['C', 'C', 'C', 'D', 'D'], 3], [['C', 'C', 'C', 'D', 'D'], 2], [['C', 'C', 'C', 'D', 'D'], 1], [['C', 'C', 'C', 'D', 'D', 'D', 'C', 'D', 'D', 'D', 'C...
263
353
coding
Solve the programming task below in a Python markdown code block. Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits. For example: ```python sum_digits(10) # Returns 1 sum_digits(99) # Returns 18 sum_digits(-32) # Ret...
{"functional": "_inputs = [[10], [99], [-32], [1234567890], [0], [666], [100000002], [800000009]]\n_outputs = [[1], [18], [5], [45], [0], [18], [3], [17]]\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 i...
125
230
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word. For a given query word, the spell checker handles two categories of spelling mistakes: Capitalization: If the quer...
{"functional": "def check(candidate):\n assert candidate(wordlist = [\"KiTe\",\"kite\",\"hare\",\"Hare\"], queries = [\"kite\",\"Kite\",\"KiTe\",\"Hare\",\"HARE\",\"Hear\",\"hear\",\"keti\",\"keet\",\"keto\"]) == [\"kite\",\"KiTe\",\"KiTe\",\"Hare\",\"hare\",\"\",\"\",\"KiTe\",\"\",\"KiTe\"]\n assert candidate(wo...
129
129
coding
Solve the programming task below in a Python markdown code block. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model soluti...
{"inputs": ["2\n0 1\n", "2\n8 37\n", "2\n6 37\n", "2\n6 43\n", "2\n1 43\n", "2\n0 32\n", "2\n1 32\n", "2\n73 37\n"], "outputs": ["1", "29\n", "31\n", "37\n", "42\n", "32\n", "31\n", "36"]}
679
115
coding
Solve the programming task below in a Python markdown code block. Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop. They saw it for the first time but were already getting bored to see a bunch of sentence...
{"inputs": ["3 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\nCLICK 1"], "outputs": ["1\n2\n3\n2\n0\n1"]}
509
47
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. You must write an algorithm that runs in O(n) time and uses O(1) extra space.    Please complete the following python cod...
{"functional": "def check(candidate):\n assert candidate(n = 13) == [1,10,11,12,13,2,3,4,5,6,7,8,9]\n assert candidate(n = 2) == [1,2]\n\n\ncheck(Solution().lexicalOrder)"}
96
76
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order. An integer a is closer to x than an integer b if: |a - x| ...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4,5], k = 4, x = 3) == [1,2,3,4]\n assert candidate(arr = [1,2,3,4,5], k = 4, x = -1) == [1,2,3,4]\n\n\ncheck(Solution().findClosestElements)"}
136
95
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of...
{"inputs": ["7\n4\n", "7\n7\n", "4\n7\n", "4\n4\n", "47\n77\n", "47\n47\n", "47\n74\n", "444\n444\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n"]}
342
96
coding
Solve the programming task below in a Python markdown code block. Make multiple functions that will return the sum, difference, modulus, product, quotient, and the exponent respectively. Please use the following function names: addition = **add** multiply = **multiply** division = **divide** (both integer and floa...
{"functional": "_inputs = [[1, 2], [5, 7]]\n_outputs = [[3], [12]]\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 retu...
124
166
coding
Solve the programming task below in a Python markdown code block. You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}. You can apply the following operation to this permutation, any number of times (possibly zero): * Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, ...
{"inputs": ["4 4\n4 2 3 1", "4 1\n4 2 3 1", "4 2\n4 3 2 1", "4 3\n4 1 3 2", "4 2\n4 1 3 2", "4 3\n3 2 4 1", "4 3\n4 2 3 1", "4 5\n4 2 3 1"], "outputs": ["4\n2\n3\n1\n", "1\n2\n3\n4\n", "4\n3\n2\n1\n", "4\n1\n3\n2\n", "2\n1\n4\n3\n", "3\n2\n4\n1\n", "4\n2\n3\n1\n", "4\n2\n3\n1\n"]}
306
190
coding
Solve the programming task below in a Python markdown code block. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is...
{"inputs": ["1\n0\n", "1\n0\n", "3\n0 1 2\n", "3\n2 1 0\n", "3\n1 2 0\n", "3\n2 1 0\n", "3\n1 2 0\n", "3\n0 1 2\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "1\n", "3\n", "1\n", "3\n"]}
341
110
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. A competition with $N$ participants (numbered $1$ through $N$) is taking place in Chefland. There are $N-1$ rounds in the competition; in each round...
{"inputs": ["1\n3\n1110001101\n1010101011\n0000000011"], "outputs": ["4"]}
651
47
coding
Solve the programming task below in a Python markdown code block. A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square. For a given string $s$ determine if it is squar...
{"inputs": ["1\nzz\n", "1\nzz\n", "1\n{{\n", "1\nz{\n", "1\n{|\n", "1\n|{\n", "1\n||\n", "1\nz|\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]}
285
92
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The bitwise AND of an array nums is the bitwise AND of all integers in nums. For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1. Also, for nums = [7], the bitwise AND is 7. You are given an...
{"functional": "def check(candidate):\n assert candidate(candidates = [16,17,71,62,12,24,14]) == 4\n assert candidate(candidates = [8,8]) == 2\n\n\ncheck(Solution().largestCombination)"}
167
68
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a 0-indexed 8 x 8 chessboard, there can be multiple black queens and one white king. You are given a 2D integer array queens where queens[i] = [xQueeni, yQueeni] represents the position of the ith black queen on th...
{"functional": "def check(candidate):\n assert candidate(queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]) == [[0,1],[1,0],[3,3]]\n assert candidate(queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]) == [[2,2],[3,4],[4,4]]\n\n\ncheck(Solution().queensAttacktheKing)"}
173
136
coding
Solve the programming task below in a Python markdown code block. ## Terminal game move function In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice **two times**. ~~~if-not:sql Create a function for the terminal game that takes the current p...
{"functional": "_inputs = [[0, 4], [3, 6], [2, 5]]\n_outputs = [[8], [15], [12]]\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...
306
176
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list containing unique integer values and an integer array nums that is a subset of the linked list values. Return the number of connected components in nums where two values are con...
{"functional": "def check(candidate):\n assert candidate(head = list_node([0,1,2,3]), nums = [0,1,3]) == 2\n assert candidate(head = list_node([0,1,2,3,4]), nums = [0,3,1,4]) == 2\n\n\ncheck(Solution().numComponents)"}
146
81
coding
Solve the programming task below in a Python markdown code block. Would you want to fight against bears riding horses? Me neither. Limak is a grizzly bear. He is a general of the dreadful army of Bearland. The most important part of an army is the cavalry of course. The cavalry of Bearland consists of N warriors and ...
{"inputs": ["2\n6\n12 9 7 1 20 10\n3 6 4 7 5 5\n4\n5 17 10 1\n200 400 800 600"], "outputs": ["YES\nNO"]}
635
71
coding
Solve the programming task below in a Python markdown code block. We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly. More formally, you've...
{"inputs": ["4 1\n-1 1 1 0\n2 -2 -1 2\n2 4\n", "4 1\n0 1 1 -1\n2 -2 -1 2\n2 4\n", "4 1\n0 1 0 -1\n2 -2 -1 2\n2 4\n", "4 1\n0 1 0 -1\n1 -2 -1 2\n2 4\n", "4 1\n-1 1 1 -1\n2 -2 -3 2\n2 4\n", "4 1\n-1 1 1 -1\n2 -2 -3 2\n2 4\n", "4 1\n-1 1 1 -1\n2 -2 -1 2\n2 4\n", "4 1\n-1 1 0 -1\n2 -2 -1 2\n2 4\n"], "outputs": ["2\n", "2\n...
663
251
coding
Solve the programming task below in a Python markdown code block. There is a universal library, where there is a big waiting room with seating capacity for maximum $m$ people, each of whom completes reading $n$ books sequentially. Reading each book requires one unit of time. Unfortunately, reading service is provided ...
{"inputs": ["1 100 9\n11 2 10\n12 2 11\n0 0 0"], "outputs": ["9\n15\n16"]}
559
46
coding
Solve the programming task below in a Python markdown code block. A zero-indexed array ```arr``` consisting of n integers is given. The dominator of array ```arr``` is the value that occurs in more than half of the elements of ```arr```. For example, consider array ```arr``` such that ```arr = [3,4,3,2,3,1,3,3]``` The ...
{"functional": "_inputs = [[[3, 4, 3, 2, 3, 1, 3, 3]], [[1, 2, 3, 4, 5]], [[1, 1, 1, 2, 2, 2]], [[1, 1, 1, 2, 2, 2, 2]], [[]]]\n_outputs = [[3], [-1], [-1], [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, rel_tol=tol, abs_to...
202
243
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. Many people choose to obfuscate their email address when displaying it on the Web. One common way of doing this is by substituting the `@` and `.` characters for their literal equivalents in brackets. Example 1: ``` user_name@example.com => user_name [a...
{"functional": "_inputs = [['user_name@example.com'], ['af5134@borchmore.edu'], ['jim.kuback@ennerman-hatano.com'], ['sir_k3v1n_wulf@blingblong.net'], ['Hmm, this would be better with input validation...!']]\n_outputs = [['user_name [at] example [dot] com'], ['af5134 [at] borchmore [dot] edu'], ['jim [dot] kuback [at] ...
290
308
coding
Solve the programming task below in a Python markdown code block. Takahashi is standing on a multiplication table with infinitely many rows and columns. The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1). In one move, he can move from (i,j) to either (i+1,j) or (i,j+1). Given an...
{"inputs": ["5", "1", "2", "3", "6", "2\n", "83", "19"], "outputs": ["4\n", "0\n", "1\n", "2\n", "3\n", "1\n", "82\n", "18\n"]}
206
67
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)   Please complete the f...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4])), list_node([2,1,4,3]))\n assert is_same_list(candidate(head = list_node([])), list_node([]))\n assert is_same_list(candidate(head = list_node([1])), list_node([1]))\n\n\ncheck(Solution().swapPairs)"}
134
89
coding
Solve the programming task below in a Python markdown code block. It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she...
{"inputs": ["5 2\n", "1 1\n", "8 3\n", "7 1\n", "9 2\n", "1 2\n", "1 3\n", "1 4\n"], "outputs": ["10\n", "0\n", "27\n", "11\n", "26\n", "0\n", "0\n", "0\n"]}
429
90
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that: If t...
{"functional": "def check(candidate):\n assert candidate(title = \"capiTalIze tHe titLe\") == \"Capitalize The Title\"\n assert candidate(title = \"First leTTeR of EACH Word\") == \"First Letter of Each Word\"\n assert candidate(title = \"i lOve leetcode\") == \"i Love Leetcode\"\n\n\ncheck(Solution().capitali...
128
89
coding
Solve the programming task below in a Python markdown code block. The longer the code, the stronger the code. The power number (P) of a code determines the strength of a code. While computing the power number of a code we should ignore the keywords in the code. A few sample key words would be int, unsigned, string, et...
{"inputs": ["3\nababaac\nbabab\nabcbab\n1\nbab\n", "5\nlint maint lllint\nint maint lllintl\nlint maint lllint\nlint maint lllint\nlint maint lllint\n2\nint\nlint\n"], "outputs": ["5\n", "29\n"]}
713
74
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they ar...
{"inputs": ["3\naab", "3\nbac", "3\naaa", "3\nabb", "3\nbab", "3\ncac", "3\ndac", "3\naba"], "outputs": ["5\n", "7\n", "3\n", "5\n", "5\n", "5\n", "7\n", "5\n"]}
209
80
coding
Solve the programming task below in a Python markdown code block. Square Subsequences A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of ...
{"inputs": ["3\naaa\nabab\nbaaba"], "outputs": ["3\n3\n6"]}
319
24
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems. Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to fi...
{"inputs": ["0\n", "1\n", "1\n", "0\n", "110\n", "010\n", "000\n", "100\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "010\n", "010\n", "000\n", "100\n"]}
680
86
coding
Solve the programming task below in a Python markdown code block. Platypus Perry is on a mission again. This time, Dr. Heinz Doofenshmirtz has plotted a bomb in the centre of Danville town. He wishes to rebuild the town. We need to defuse the bomb for Perry. As always, Dr. Heinz has given perry the key combination to ...
{"inputs": ["2\n987654321 123\n120000000 22"], "outputs": ["121401\n107748\n94095\n80442\n66789\n53136\n39483\n264\n440\n0\n0\n0\n0\n0\n0"]}
345
101
coding
Solve the programming task below in a Python markdown code block. Linear Kingdom has exactly one tram line. It has `n` stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. ## Your ...
{"functional": "_inputs = [[4, [0, 2, 4, 4], [3, 5, 2, 0]], [2, [0, 2, 4, 4], [3, 5, 2, 0]], [1, [0, 2, 4, 4], [3, 5, 2, 0]], [10, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], [5, [0, 2, 4, 14, 2], [3, 5, 14, 0, 0]]]\n_outputs = [[6], [6], [3], [25], [16]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):...
376
345
coding
Solve the programming task below in a Python markdown code block. There is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates (0, 0). He will execute commands which are described by a string of capital Latin letters 'L', 'R', 'D', 'U'. When a com...
{"inputs": ["4\nL\nLUUDR\nLLUU\nDDDUUUUU\n", "4\nL\nUURDL\nLLUU\nDDDUUUUU\n", "4\nL\nUURDL\nLLUU\nUUUUUDDD\n", "4\nL\nLUUDR\nLLUU\nUUUUUDDD\n", "4\nL\nRUUDL\nLLUU\nUUUUUDDD\n", "4\nL\nUULDR\nLLUU\nUDUUUDDU\n", "4\nL\nRDUUL\nUULL\nUUUUUDDD\n", "4\nL\nRUUDL\nLLUU\nUUUUDDDU\n"], "outputs": ["-1 0\n-1 2\n0 0\n0 1\n", "-1 0...
624
298
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef recently learned about ratios and proportions. He wrote some positive integers a, b, c, d o...
{"inputs": ["1 2 4 2"], "outputs": ["Possible"]}
276
18
coding
Solve the programming task below in a Python markdown code block. Given a standard english sentence passed in as a string, write a method that will return a sentence made up of the same words, but sorted by their first letter. However, the method of sorting has a twist to it: * All words that begin with a lower case le...
{"functional": "_inputs = [['I, habitan of the Alleghanies, treating of him as he is in himself in his own rights'], ['take up the task eternal, and the burden and the lesson'], ['Land of the eastern Chesapeake'], ['And I send these words to Paris with my love'], ['O Liberty! O mate for me!'], ['With Egypt, India, Phen...
240
443
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list. The nodes in the linked list are sequentially assigned to non-empty groups whose lengths form the sequence of the natural numbers (1, 2, 3, 4, ...). The length of a group is th...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([5,2,6,3,9,1,7,3,8,4])), list_node([5,6,2,3,9,1,4,8,3,7]))\n assert is_same_list(candidate(head = list_node([1,1,0,6])), list_node([1,0,1,6]))\n assert is_same_list(candidate(head = list_node([2,1])), list_node([2,1]))\n\n\n...
259
133
coding
Solve the programming task below in a Python markdown code block. We have a square grid with N rows and M columns. Takahashi will write an integer in each of the squares, as follows: * First, write 0 in every square. * For each i=1,2,...,N, choose an integer k_i (0\leq k_i\leq M), and add 1 to each of the leftmost k_i...
{"inputs": ["4 3", "2 2", "1 3", "2 4", "0 3", "2 8", "1 8", "1 6"], "outputs": ["15584\n", "47\n", "20\n", "1053\n", "1\n", "257337\n", "1280\n", "256\n"]}
345
97
coding
Solve the programming task below in a Python markdown code block. Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix". Chef has a matrix that consists of n rows, each contains m elements. Initially, the element aij of matrix e...
{"inputs": ["4 4 6\n2 2\n3 2\n3 2\n4 3\n4 4\n4 3"], "outputs": ["3\n3\n-1\n4"]}
619
47
coding
Solve the programming task below in a Python markdown code block. Raccoon is fighting with a monster. The health of the monster is H. Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i. There is no other way to decrease the monster's health. Raccoon wins when the monster...
{"inputs": ["8 3\n3 0 6", "8 3\n3 1 6", "8 4\n3 1 6", "8 4\n4 1 6", "10 3\n4 4 6", "20 3\n3 5 6", "10 3\n4 0 6", "20 3\n3 3 6"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n"]}
261
130
coding
Solve the programming task below in a Python markdown code block. The auditorium of Stanford University is made up of L*R matrix (assume each coordinate has a chair). On the occasion of an event Chef was called as a chief guest. The auditorium was filled with males (M) and females (F), occupying one chair each. Our Che...
{"inputs": ["4 3 3\nMMF\nMMM\nFFM\nFFM\n2 F\n3 M\n1 M"], "outputs": ["yes\nno\nyes"]}
344
40
coding
Solve the programming task below in a Python markdown code block. You get a "text" and have to shift the vowels by "n" positions to the right. (Negative value for n should shift to the left.) "Position" means the vowel's position if taken as one item in a list of all vowels within the string. A shift by 1 would mean, t...
{"functional": "_inputs = [[None, 0], ['', 0], ['This is a test!', 0], ['This is a test!', 1], ['This is a test!', 3], ['This is a test!', 4], ['This is a test!', -1], ['This is a test!', -5], ['Brrrr', 99], ['AEIOUaeiou', 1]]\n_outputs = [[None], [''], ['This is a test!'], ['Thes is i tast!'], ['This as e tist!'], ['T...
229
296
coding
Solve the programming task below in a Python markdown code block. Given a square matrix, calculate the absolute difference between the sums of its diagonals. For example, the square matrix $\textbf{arr}$ is shown below: 1 2 3 4 5 6 9 8 9 The left-to-right diagonal = $1+5+9=15$. The right to left diagonal = $3...
{"inputs": ["3\n11 2 4\n4 5 6\n10 8 -12\n"], "outputs": ["15\n"]}
411
36
coding
Solve the programming task below in a Python markdown code block. Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclu...
{"inputs": ["1 1\n5\n", "1 2\n57\n", "1 2\n74\n", "1 2\n49\n", "1 2\n68\n", "1 2\n84\n", "1 2\n59\n", "2 1\n4\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
354
110
coding
Solve the programming task below in a Python markdown code block. Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently. Input A sequence of integers ai (1 ≤ ai ≤ 100). The number of integers is less than...
{"inputs": ["5\n6\n3\n5\n8\n7\n6\n3\n9\n7\n3\n4", "5\n5\n3\n5\n8\n7\n6\n3\n9\n7\n3\n4", "5\n5\n3\n5\n8\n5\n6\n3\n9\n7\n3\n4", "5\n9\n3\n5\n8\n7\n6\n3\n9\n7\n0\n4", "5\n6\n6\n9\n8\n7\n5\n3\n9\n7\n0\n4", "5\n6\n6\n9\n8\n7\n8\n3\n9\n7\n0\n4", "5\n6\n6\n5\n8\n7\n7\n3\n9\n7\n3\n4", "5\n6\n3\n5\n8\n5\n6\n6\n9\n1\n3\n4"], "ou...
130
260
coding
Solve the programming task below in a Python markdown code block. Cirno_9baka has a tree with $n$ nodes. He is willing to share it with you, which means you can operate on it. Initially, there are two chess pieces on the node $1$ of the tree. In one step, you can choose any piece, and move it to the neighboring node. ...
{"inputs": ["2 2\n2 1\n1 2\n1 1\n", "2 2\n1 2\n1 2\n1 1\n", "2 2\n2 1\n1 1\n1 1\n", "2 2\n2 1\n1 1\n2 1 2\n", "2 2\n1 2\n1 2\n2 1 2\n", "4 2\n1 2\n1 3\n2 4\n1 3\n1 4\n", "4 2\n1 2\n2 3\n3 4\n4 1 2 3 4\n1 1\n", "10 2\n5 6\n4 7\n7 1\n8 2\n6 9\n4 8\n10 5\n9 2\n3 5\n5 5 1 3 2 7\n3 7 8 4\n"], "outputs": ["2", "2", "0", "2",...
677
247
coding
Solve the programming task below in a Python markdown code block. Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab",...
{"inputs": ["r\na\n", "c\nh\n", "h\nb\n", "c\np\n", "n\ng\n", "a\nz\n", "r\ni\n", "t\nv\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
508
86
coding
Solve the programming task below in a Python markdown code block. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 ...
{"inputs": ["1 1\n4\n", "1 1\n4\n", "1 1\n7\n", "1 1\n6\n", "1 1\n44\n", "1 1\n44\n", "1 1\n14\n", "3 4\n1 2 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "3\n"]}
308
109
coding
Solve the programming task below in a Python markdown code block. SKIT’s canteen sells Patties in packages of 6, 9 or 20 . Thus, it is possible, for example, to buy exactly 15 Patties (with one package of 6 and a second package of 9), but it is not possible to buy exactly 16 Patties, since no non- negative integer comb...
{"inputs": ["2\n45\n1", "5\n1991\n991\n43\n57\n1000000"], "outputs": ["True\nFalse", "True\nTrue\nFalse\nTrue\nTrue"]}
310
56
coding
Solve the programming task below in a Python markdown code block. Abhi is a salesman. He was given two types of candies, which he is selling in N different cities. For the prices of the candies to be valid, Abhi's boss laid down the following condition: A given type of candy must have distinct prices in all N cities. ...
{"inputs": ["4\n3\n4 8 4 6 7 3\n3\n4 8 6 8 7 8\n2\n2 4 5 3\n4\n8 7 9 8 4 6 2 8\n"], "outputs": ["Yes\nNo\nYes\nNo"]}
641
75
coding
Solve the programming task below in a Python markdown code block. Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a numb...
{"inputs": ["8\n", "6\n", "1\n", "7\n", "3\n", "9\n", "0\n", "2\n"], "outputs": ["40\n", "14\n", "0\n", "25\n", "0\n", "58\n", "0\n", "0\n"]}
360
74
coding
Solve the programming task below in a Python markdown code block. The problem set at CODE FESTIVAL 20XX Finals consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As proble...
{"inputs": ["2", "3", "8", "5", "9", "6", "4", "7"], "outputs": ["2\n", "1\n2\n", "1\n3\n4\n", "2\n3\n", "2\n3\n4\n", "1\n2\n3\n", "1\n3", "1\n2\n4"]}
234
82
coding
Solve the programming task below in a Python markdown code block. Snackdown 2019 is coming! There are two rounds (round A and round B) after the qualification round. From both of them, teams can qualify to the pre-elimination round. According to the rules, in each of these two rounds, teams are sorted in descending ord...
{"inputs": ["2\n5 1\n3 5 2 4 5\n6 4\n6 5 4 3 2 1"], "outputs": ["2\n4"]}
448
44
coding
Solve the programming task below in a Python markdown code block. Indian National Olympiad in Informatics 2015 A string is any nonempty sequence of 0s and 1s. Examples of strings are 00, 101, 111000, 1, 0, 01. The length of a string is the number of symbols in it. For example, the length of 111000 is 6. If u and v are ...
{"inputs": ["3 176"], "outputs": ["6"]}
556
16
coding
Solve the programming task below in a Python markdown code block. Convert a hash into an array. Nothing more, Nothing less. ``` {name: 'Jeremy', age: 24, role: 'Software Engineer'} ``` should be converted into ``` [["name", "Jeremy"], ["age", 24], ["role", "Software Engineer"]] ``` ```if:python,javascript,crystal **...
{"functional": "_inputs = [[{'name': 'Jeremy'}], [{'name': 'Jeremy', 'age': 24}], [{'name': 'Jeremy', 'age': 24, 'role': 'Software Engineer'}], [{'product': 'CodeWars', 'power_level_over': 9000}], [{}]]\n_outputs = [[[['name', 'Jeremy']]], [[['age', 24], ['name', 'Jeremy']]], [[['age', 24], ['name', 'Jeremy'], ['role',...
127
280
coding
Solve the programming task below in a Python markdown code block. There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. Here, h_1 < h_2 < \cdots < h_N holds. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reac...
{"inputs": ["5 6\n1 2 3 4 5", "8 5\n1 3 4 6 10 11 12 13", "8 5\n1 3 4 6 10 11 12 14", "8 3\n1 3 4 6 10 11 12 13", "8 3\n2 3 4 8 10 11 12 13", "8 5\n1 3 4 5 10 11 12 13", "2 1100100000001\n91876 1100011", "2 0100010000100\n13404 1101001"], "outputs": ["20", "58\n", "62\n", "48\n", "44\n", "62", "2116436178226\n", "12828...
390
268
coding
Solve the programming task below in a Python markdown code block. Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited n...
{"inputs": ["1 1\n", "1 9\n", "1 2\n", "4 2\n", "9 3\n", "8 2\n", "1 3\n", "1 4\n"], "outputs": ["1\n", "9\n", "2\n", "3\n", "7\n", "4\n", "3\n", "4\n"]}
487
86
coding
Solve the programming task below in a Python markdown code block. A pair of nodes, $(a,b)$, is a similar pair if the following conditions are true: node $a$ is the ancestor of node $b$ $abs(a-b)\leq k$ Given a tree where each node is labeled from $1$ to $n$, find the number of similar pairs in the tree. For example,...
{"inputs": ["5 2\n3 2\n3 1\n1 4\n1 5\n"], "outputs": ["4\n"]}
514
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n. Continuously replace n with the sum of its prime factors. Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n. Ret...
{"functional": "def check(candidate):\n assert candidate(n = 15) == 5\n assert candidate(n = 3) == 3\n\n\ncheck(Solution().smallestValue)"}
102
45
coding
Solve the programming task below in a Python markdown code block. Santa puts all the presents into the huge sack. In order to let his reindeers rest a bit, he only takes as many reindeers with him as he is required to do. The others may take a nap. Two reindeers are always required for the sleigh and Santa himself. Ad...
{"functional": "_inputs = [[0], [1], [5], [30], [31], [60], [61], [90], [91], [120], [121], [150], [151], [180]]\n_outputs = [[2], [3], [3], [3], [4], [4], [5], [5], [6], [6], [7], [7], [8], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo...
258
249
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Today is chef's friend's birthday. He wants to give a gift to his friend. So he was desperately searching for some gift here and there. Fortunately, he found an array a of size n lying around...
{"inputs": ["4\n2 1\n1 2\n3 2\n2 6 5\n3 3\n2 4 5\n4 2\n1 2 4 5"], "outputs": ["YES\nYES\nNO\nYES"]}
518
58
coding
Solve the programming task below in a Python markdown code block. An acrostic is a text in which the first letter of each line spells out a word. It is also a quick and cheap way of writing a poem for somebody, as exemplified below : Write a program that reads an acrostic to identify the "hidden" word. Specifically,...
{"functional": "_inputs = [[['Jolly', 'Amazing', 'Courteous', 'Keen']], [['Marvelous', 'Excellent', 'Gifted']]]\n_outputs = [['JACK'], ['MEG']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstanc...
142
185
coding
Solve the programming task below in a Python markdown code block. Petya has an array of integers $a_1, a_2, \ldots, a_n$. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it. Petya likes to challenge himself, so he wants to sort array using only $3$-cycles. More fo...
{"inputs": ["7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 2 3\n3\n2 1 3\n3\n3 1 2\n4\n2 1 4 3\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\nYES\nYES\n"]}
722
76
coding
Solve the programming task below in a Python markdown code block. There are $n$ athletes in front of you. Athletes are numbered from $1$ to $n$ from left to right. You know the strength of each athlete — the athlete number $i$ has the strength $s_i$. You want to split all athletes into two teams. Each team must have a...
{"inputs": ["5\n5\n3 1 2 7 4\n6\n2 2 3 2 1 3\n4\n7 9 3 0\n2\n1 1000\n3\n000 150 85\n", "5\n5\n1 1 2 7 4\n6\n2 2 3 2 2 5\n4\n7 9 3 0\n2\n1 1000\n3\n000 150 85\n", "5\n5\n3 1 2 7 4\n6\n2 2 3 2 1 3\n4\n2 9 3 0\n2\n1 1000\n3\n000 150 85\n", "5\n5\n1 1 2 7 4\n6\n2 2 3 3 4 5\n4\n7 9 3 0\n2\n0 1000\n3\n000 150 85\n", "5\n5\n3...
676
624
coding
Solve the programming task below in a Python markdown code block. Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left. There were $n$ classes of that subject during the s...
{"inputs": ["2\n7\n", "2\n0\n", "2\n0\n", "2\n7\n", "2\n5\n", "2\n4\n", "2\n1\n", "2\n2\n"], "outputs": ["0 7 \n", "0 0 \n", "0 0\n", "0 7\n", "0 5\n", "0 4\n", "0 1\n", "0 2\n"]}
582
104
coding
Solve the programming task below in a Python markdown code block. Kevin is noticing his space run out! Write a function that removes the spaces from the values and returns an array showing the space decreasing. For example, running this function on the array ['i', 'have','no','space'] would produce ['i','ihave','ihaven...
{"functional": "_inputs = [[['kevin', 'has', 'no', 'space']], [['this', 'cheese', 'has', 'no', 'holes']]]\n_outputs = [[['kevin', 'kevinhas', 'kevinhasno', 'kevinhasnospace']], [['this', 'thischeese', 'thischeesehas', 'thischeesehasno', 'thischeesehasnoholes']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isins...
97
232
coding
Solve the programming task below in a Python markdown code block. In this kata you will create a function to check a non-negative input to see if it is a prime number. The function will take in a number and will return True if it is a prime number and False if it is not. A prime number is a natural number greater tha...
{"functional": "_inputs = [[0], [1], [2], [11], [12], [61], [571], [573], [25]]\n_outputs = [[False], [False], [True], [True], [False], [True], [True], [False], [False]]\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_...
108
210
coding
Solve the programming task below in a Python markdown code block. ## A square of squares You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks! However, sometimes, you can't arrange them into a square. Ins...
{"functional": "_inputs = [[-1], [25], [26]]\n_outputs = [[False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fa...
278
169
coding
Solve the programming task below in a Python markdown code block. You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i =...
{"inputs": ["1\n4\n", "1\n5\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n97\n", "1\n97\n", "1\n32\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0", "0\n", "0", "0\n"]}
547
87
coding
Solve the programming task below in a Python markdown code block. I decided to plant vegetables in the vegetable garden. There were n seeds, so I sown n seeds one by one a day over n days. All seeds sprout and grow quickly. I can't wait for the harvest time. One day, when I was watering the seedlings as usual, I notic...
{"inputs": ["5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 7\n0", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 8\n0", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 5\n0", "5\n1 2 3 9 4 5\n6\n1 3...
453
462
coding
Solve the programming task below in a Python markdown code block. **This Kata is intended as a small challenge for my students** All Star Code Challenge #29 Your friend Nhoj has dislexia, but can easily read messages if the words are written backwards. Create a function called `reverseSentence()/reverse_sentence()`...
{"functional": "_inputs = [['Hello !Nhoj Want to have lunch?'], ['1 2 3 4 5'], ['CodeWars'], ['CodeWars rules!'], ['']]\n_outputs = [['olleH johN! tnaW ot evah ?hcnul'], ['1 2 3 4 5'], ['sraWedoC'], ['sraWedoC !selur'], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, floa...
181
231
coding
Solve the programming task below in a Python markdown code block. Teja likes cricket very much and likes to watch it all the time, but he is bored of watching the matches alone and asks his friend to give him company. But his friend doesn’t know how to read cricket scores so Teja decided to teach him. To make him under...
{"inputs": ["3\n1 1\n4 1\n7 6", "3\n1 1\n9 1\n7 6"], "outputs": ["YES", "NO"]}
421
42
coding
Solve the programming task below in a Python markdown code block. It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number a_{i} written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, ...
{"inputs": ["4\n2\n1 2\n3\n1 20 12\n3\n32697 4 98\n9\n1 2 4 1 4 6 7 8 6\n", "4\n2\n1 1\n3\n1 7 12\n3\n32697 67 98\n9\n1 2 4 1 4 6 7 8 6\n", "4\n2\n1 2\n3\n1 11 12\n3\n32697 4 98\n9\n1 2 4 1 4 6 7 8 6\n", "4\n2\n1 1\n3\n1 20 12\n3\n1011 67 98\n9\n1 2 3 4 4 6 7 8 6\n", "4\n2\n1 1\n3\n1 20 12\n3\n5275 67 98\n9\n1 2 3 4 4 ...
603
545
coding
Solve the programming task below in a Python markdown code block. A tetromino is a figure formed by joining four squares edge to edge. We will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively: a60bcb8e9e8f22e3af51049eda063392.png Snuke has many tetrominos. The n...
{"inputs": ["1 1 1 0 0 0 0", "4 0 1 0 0 0 0", "0 3 0 0 1 0 0", "0 3 0 0 2 0 0", "6 0 2 0 0 0 0", "2 5 1 0 1 2 2", "1 4 0 0 4 0 3", "0 0 0 0 1 0 0"], "outputs": ["1\n", "4\n", "3\n", "5\n", "6\n", "7\n", "8\n", "0\n"]}
390
158
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. --- # Story The Pied Piper has been enlisted to play his magical tune and coax all the rats out of town. But some of the rats are deaf and are going the wrong way! # Kata Task How many deaf rats are there? # Legend * ```P``` = The Pied Piper * ```...
{"functional": "_inputs = [['~O~O~O~O P'], ['P O~ O~ ~O O~'], ['~O~O~O~OP~O~OO~'], ['O~~OO~~OO~~OO~P~OO~~OO~~OO~~O'], ['~OP'], ['PO~'], ['O~P'], ['P~O'], [' P'], ['P '], [' P '], ['P']]\n_outputs = [[0], [1], [2], [8], [0], [0], [1], [1], [0], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b,...
225
279
coding
Solve the programming task below in a Python markdown code block. There is a robot staying at $X=0$ on the $Ox$ axis. He has to walk to $X=n$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel. The $i$-th segment of the path (from $X=i-1$ to $X=i$...
{"inputs": ["1 1 1\n0\n", "1 1 1\n0\n", "2 1 1\n0 0\n", "2 1 1\n0 0\n", "2 0 1\n0 0\n", "3 1 1\n1 1 1\n", "3 1 1\n1 1 1\n", "4 1 1\n1 1 1 0\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "3\n", "3\n", "3\n"]}
706
138
coding
Solve the programming task below in a Python markdown code block. Given a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty...
{"functional": "_inputs = [['3D2a5d2f'], ['4D1a8d4j3k'], ['4D2a8d4j2f'], ['3n6s7f3n'], ['0d4n8d2b'], ['0c3b1n7m'], ['7m3j4ik2a'], ['3A5m3B3Y'], ['5M0L8P1'], ['2B'], ['7M1n3K'], ['A4g1b4d'], ['111111'], ['4d324n2'], ['5919nf3u'], ['2n1k523n4i'], ['6o23M32d'], ['1B44n3r'], ['M21d1r32'], ['23M31r2r2'], ['8494mM25K2A'], ['...
302
824
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that n...
{"functional": "def check(candidate):\n assert candidate(num = \"327\") == 2\n assert candidate(num = \"094\") == 0\n assert candidate(num = \"0\") == 0\n assert candidate(num = \"9999999999999\") == 101\n\n\ncheck(Solution().numberOfCombinations)"}
133
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a linked list, return the list after sorting it in ascending order.   Please complete the following python code precisely: ```python # Definition for singly-linked list. # class ListNode: # def _...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([4,2,1,3])), list_node([1,2,3,4]))\n assert is_same_list(candidate(head = list_node([-1,5,3,4,0])), list_node([-1,0,3,4,5]))\n assert is_same_list(candidate(head = list_node([])), list_node([]))\n\n\ncheck(Solution().sortLis...
109
105
coding
Solve the programming task below in a Python markdown code block. Akash and Akhil are playing a game. They have $N$ balls numbered from $0$ to $N-1$. Akhil asks Akash to reverse the position of the balls, i.e., to change the order from say, 0,1,2,3 to 3,2,1,0. He further asks Akash to reverse the position of the balls ...
{"inputs": ["2\n3 1\n5 2\n"], "outputs": ["2\n4\n"]}
386
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.   Please c...
{"functional": "def check(candidate):\n assert candidate(pushed = [1,2,3,4,5], popped = [4,5,3,2,1]) == True\n assert candidate(pushed = [1,2,3,4,5], popped = [4,3,5,1,2]) == False\n\n\ncheck(Solution().validateStackSequences)"}
94
87
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin and Russian. Translations in Vietnamese to be uploaded soon. You are given an integer N. Consider a vector a of length N^{2} accessible via 0-based indexing. Let's call the following transformation a TVT-transformati...
{"inputs": ["2\n1\n2"], "outputs": ["YES\n1\nYES\n1 1 1 -1"]}
341
28
coding
Solve the programming task below in a Python markdown code block. # Definition A **_Tidy number_** *is a number whose* **_digits are in non-decreasing order_**. ___ # Task **_Given_** a number, **_Find if it is Tidy or not_** . ____ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codew...
{"functional": "_inputs = [[12], [102], [9672], [2789], [2335]]\n_outputs = [[True], [False], [False], [True], [True]]\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 ...
638
191
coding
Solve the programming task below in a Python markdown code block. Chef is playing an easier variation of the board game ‘Risk’ with his friend Mike. There is an $N * M$ grid, depicting the world map. Each cell of the grid is either $1$ or $0$ where $1$ denotes that there is land on this cell, while $0$ denotes water. ...
{"inputs": ["3\n4 4\n1001\n0110\n0110\n1001\n2 2\n11\n11\n3 3\n100\n010\n001"], "outputs": ["2\n0\n1"]}
617
66
coding
Solve the programming task below in a Python markdown code block. Limak is a little polar bear. He has n balls, the i-th ball has size t_{i}. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: No two friends can get balls of ...
{"inputs": ["3\n3 1 2\n", "3\n1 1 2\n", "3\n2 3 2\n", "3\n1 2 1\n", "3\n1 2 3\n", "3\n1 1 1\n", "3\n2 2 3\n", "3\n1 2 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
537
118
coding
Solve the programming task below in a Python markdown code block. You are a *khm*mad*khm* scientist and you decided to play with electron distribution among atom's shells. You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons. ---...
{"functional": "_inputs = [[1], [10], [11], [22], [23], [47], [50], [52], [60], [61]]\n_outputs = [[[1]], [[2, 8]], [[2, 8, 1]], [[2, 8, 12]], [[2, 8, 13]], [[2, 8, 18, 19]], [[2, 8, 18, 22]], [[2, 8, 18, 24]], [[2, 8, 18, 32]], [[2, 8, 18, 32, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, floa...
265
299
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≤ s...
{"inputs": ["1\n3\n2 1 2"], "outputs": ["4"]}
317
20
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays startTime and endTime and given an integer queryTime. The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i]. Return the number of students do...
{"functional": "def check(candidate):\n assert candidate(startTime = [1,2,3], endTime = [3,2,7], queryTime = 4) == 1\n assert candidate(startTime = [4], endTime = [4], queryTime = 4) == 1\n assert candidate(startTime = [4], endTime = [4], queryTime = 5) == 0\n assert candidate(startTime = [1,1,1,1], endTime...
130
195
coding
Solve the programming task below in a Python markdown code block. Alice gave Bob 3 integers N, K, and S. Help Bob find an S-good sequence. A sequence B of length N is called S-good if the following conditions are met: B_{i} \in \{-1, 0, 1\} for each 1 ≤ i ≤ N \sum_{i=1}^N B_{i}\cdot K^{i-1} = S If there are multiple ...
{"inputs": ["3\n4 2 15\n3 6 36\n5 5 7"], "outputs": ["1 1 1 1\n0 0 1\n-2"]}
497
47
coding
Solve the programming task below in a Python markdown code block. ### Task You've just moved into a perfectly straight street with exactly ```n``` identical houses on either side of the road. Naturally, you would like to find out the house number of the people on the other side of the street. The street looks something...
{"functional": "_inputs = [[1, 3], [3, 3], [2, 3], [3, 5], [7, 11], [10, 22], [20, 3400], [9, 26], [20, 10]]\n_outputs = [[6], [4], [5], [8], [16], [35], [6781], [44], [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, rel_tol=tol, a...
367
248
coding
Solve the programming task below in a Python markdown code block. In 21XX, humanity finally began a plan to relocate to Mars. Selected as the first group of immigrants to Mars, you are assigned to the Administrative Center of Mars to deal with various problems that occur on Mars. The biggest problem at the moment of th...
{"inputs": ["4 5 1 3 4\n1 2 5\n2 3 9\n2 4 5\n1 3 8\n1 4 8\n0 0 0 0 0", "4 5 1 3 4\n1 2 5\n2 3 9\n2 4 5\n1 3 3\n1 4 8\n0 0 0 0 0", "6 5 1 3 4\n1 2 5\n4 3 5\n2 3 5\n1 3 8\n1 4 8\n0 0 0 0 0", "4 5 1 3 4\n1 2 5\n2 3 5\n2 4 5\n1 3 8\n2 4 8\n0 0 0 0 0", "4 5 1 3 4\n0 2 5\n2 3 9\n2 4 5\n1 2 3\n1 4 8\n0 0 0 0 0", "4 5 1 3 4\n0...
698
453
coding
Solve the programming task below in a Python markdown code block. Given are integers a,b,c and d. If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y? -----Constraints----- - -10^9 \leq a \leq b \leq 10^9 - -10^9 \leq c \leq d \leq 10^9 - All values ...
{"inputs": ["1 0 1 1", "0 0 0 1", "0 5 0 2", "8 6 1 2", "1 2 1 1", "1 2 1 1\n", "0 0 0 0\n", "1 6 1 -1"], "outputs": ["1\n", "0\n", "10\n", "16\n", "2", "2\n", "0\n", "6\n"]}
209
113
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, where parents[i] is the parent of node i. Since n...
{"functional": "def check(candidate):\n assert candidate(parents = [-1,2,0,2,0]) == 3\n assert candidate(parents = [-1,2,0]) == 2\n\n\ncheck(Solution().countHighestScoreNodes)"}
200
59
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.   Please complete the following python code precisel...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == 24\n assert candidate(root = tree_node([1])) == 0\n\n\ncheck(Solution().sumOfLeftLeaves)"}
143
63