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. You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) ...
{"inputs": ["1\n920400783 7\n", "1\n718772242 7\n", "1\n718772242 8\n", "1\n718772242 3\n", "1\n718772242 5\n", "1\n589741341 5\n", "1\n589741341 9\n", "1\n459104377 9\n"], "outputs": ["131485833\n", "102681755\n", "89846534\n", "239590750\n", "143754452\n", "117948273\n", "65526818\n", "51011603\n"]}
coding
242
Solve the programming task below in a Python markdown code block. Your users passwords were all stole in the Yahoo! hack, and it turns out they have been lax in creating secure passwords. Create a function that checks their new password (passed as a string) to make sure it meets the following requirements: Between 8...
{"functional": "_inputs = [[''], ['password'], ['P1@p'], ['P1@pP1@p'], ['P1@pP1@pP1@pP1@pP1@pP1@p']]\n_outputs = [['not valid'], ['not valid'], ['not valid'], ['valid'], ['not valid']]\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, re...
coding
140
Solve the programming task below in a Python markdown code block. # Task Given a square `matrix`, your task is to reverse the order of elements on both of its longest diagonals. The longest diagonals of a square matrix are defined as follows: * the first longest diagonal goes from the top left corner to the bottom ri...
{"functional": "_inputs = [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[239]]], [[[1, 10], [100, 1000]]], [[[43, 455, 32, 103], [102, 988, 298, 981], [309, 21, 53, 64], [2, 22, 35, 291]]]]\n_outputs = [[[[9, 2, 7], [4, 5, 6], [3, 8, 1]]], [[[239]]], [[[1000, 100], [10, 1]]], [[[291, 455, 32, 2], [102, 53, 21, 981], [309, 29...
coding
258
Solve the programming task below in a Python markdown code block. You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it. Constraints * The length of S is 2 or 3. * S consists of lower...
{"inputs": ["bc", "cb", "cc", "dc", "cd", "ec", "fc", "cf"], "outputs": ["bc\n", "cb\n", "cc\n", "dc\n", "cd\n", "ec\n", "fc\n", "cf\n"]}
coding
144
Solve the programming task below in a Python markdown code block. JJ loves playing with averages. He has an array A of length N. He wants to divide the array A into two non-empty subsets P and Q such that the value of mean(P) + mean(Q) is as large as possible. (Note that each A_{i} must belong to either subset P or sub...
{"inputs": ["2\n2\n4 5\n5\n2 2 2 2 2\n"], "outputs": ["9.000000\n4.000000\n"]}
coding
540
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums of positive integers and a positive integer k. A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k. Return the number of non-empty beaut...
{"functional": "def check(candidate):\n assert candidate(nums = [2,4,6], k = 2) == 4\n assert candidate(nums = [1], k = 1) == 1\n\n\ncheck(Solution().beautifulSubsets)"}
coding
140
Solve the programming task below in a Python markdown code block. Hi there! You have to implement the `String get_column_title(int num) // syntax depends on programming language` function that takes an integer number (index of the Excel column) and returns the string represents the title of this column. #Intro In ...
{"functional": "_inputs = [[1], [26], [52], [53], [702]]\n_outputs = [['A'], ['Z'], ['AZ'], ['BA'], ['ZZ']]\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...
coding
615
Solve the programming task below in a Python markdown code block. You are given a string s consisting of |s| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace lette...
{"inputs": ["a\n", "a\n", "b\n", "thereisnoanswer\n", "thereisnoansweq\n", "thereisnoanswer\n", "aacceeggiikkmmooqqssuuwwyy\n", "abcdefghijklmnopqrstuvwxxx\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "abcdefghijklmnopqrstuvwxyz\n", "abcdefghijklmnopqrstuvwxyz\n"]}
coding
264
Solve the programming task below in a Python markdown code block. # Task Below we will define what and n-interesting polygon is and your task is to find its area for a given n. A 1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtained by taking the n - 1-interesting polyg...
{"functional": "_inputs = [[2], [3], [1], [5]]\n_outputs = [[5], [13], [1], [41]]\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 Fals...
coding
249
Solve the programming task below in a Python markdown code block. In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education. One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a tw...
{"inputs": ["1", "1\n", "2\n4\n5", "2\n4\n9", "2\n2\n9", "2\n4\n4", "2\n8\n4", "2\n6\n4"], "outputs": ["Hello World", "Hello World\n", "9\n", "13\n", "11\n", "8\n", "12\n", "10\n"]}
coding
281
Solve the programming task below in a Python markdown code block. Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your task is to determine which cat will reach the mouse first, assuming the mouse does not move and the cats travel at equal speed. If the cats arriv...
{"inputs": ["2\n1 2 3\n1 3 2\n"], "outputs": ["Cat B\nMouse C\n"]}
coding
648
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in ...
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5) == True\n assert candidate(matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20) == False\n\n\ncheck(Solution(...
coding
108
Solve the programming task below in a Python markdown code block. A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i...
{"inputs": ["3\n2 3 5\n3 7 1", "3\n1 3 3\n2 2 1", "3\n1 6 5\n0 1 3", "3\n2 1 5\n3 7 1", "3\n1 6 3\n2 2 1", "3\n0 1 5\n3 7 1", "3\n1 6 3\n2 1 1", "3\n0 1 5\n3 4 1"], "outputs": ["-1\n", "2\n", "0\n", "-1\n", "2\n", "-1\n", "2\n", "-1\n"]}
coding
727
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string text and an array of strings words, return an array of all index pairs [i, j] so that the substring text[i...j] is in words. Return the pairs [i, j] in sorted order (i.e., sort them by their first coord...
{"functional": "def check(candidate):\n assert candidate(text = \"thestoryofleetcodeandme\", words = [\"story\",\"fleet\",\"leetcode\"]) == [[3,7],[9,13],[10,17]]\n assert candidate(text = \"ababa\", words = [\"aba\",\"ab\"]) == [[0,1],[0,2],[2,3],[2,4]]\n\n\ncheck(Solution().indexPairs)"}
coding
124
Solve the programming task below in a Python markdown code block. Given the sum and gcd of two numbers, return those two numbers in ascending order. If the numbers do not exist, return `-1`, (or `NULL` in C, `tuple (-1,-1)` in C#, `pair (-1,-1)` in C++,`None` in Rust, `array {-1,-1} ` in Java and Golang). ``` For exam...
{"functional": "_inputs = [[6, 3], [8, 2], [10, 3], [12, 4], [12, 5], [50, 10], [50, 4], [10, 5], [100, 5], [1000, 5]]\n_outputs = [[[3, 3]], [[2, 6]], [-1], [[4, 8]], [-1], [[10, 40]], [-1], [[5, 5]], [[5, 95]], [[5, 995]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float...
coding
251
Solve the programming task below in a Python markdown code block. The following problem is well-known: given integers n and m, calculate $2^{n} \operatorname{mod} m$, where 2^{n} = 2·2·...·2 (n factors), and $x \operatorname{mod} y$ denotes the remainder of division of x by y. You are asked to solve the "reverse" pr...
{"inputs": ["1\n1\n", "1\n2\n", "2\n1\n", "2\n2\n", "2\n3\n", "2\n4\n", "2\n5\n", "3\n8\n"], "outputs": ["1\n", "0\n", "1\n", "2\n", "3\n", "0\n", "1\n", "0\n"]}
coding
298
Solve the programming task below in a Python markdown code block. Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a_1, a_2, ..., a_{n}. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise a_{...
{"inputs": ["1\n10\n", "1\n19\n", "1\n19\n", "1\n10\n", "1\n19\n", "1\n35\n", "1\n14\n", "1\n70\n"], "outputs": ["chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n"]}
coding
488
Please solve the programming task below using a self-contained code snippet in a markdown code block. Convert a non-negative integer num to its English words representation.   Please complete the following python code precisely: ```python class Solution: def numberToWords(self, num: int) -> str: ```
{"functional": "def check(candidate):\n assert candidate(num = 123) == \"One Hundred Twenty Three\"\n assert candidate(num = 12345) == \"Twelve Thousand Three Hundred Forty Five\"\n assert candidate(num = 1234567) == \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n\n\ncheck(Solution(...
coding
60
Solve the programming task below in a Python markdown code block. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that ...
{"inputs": ["2 1 5\nA\n6 5 5\nB\n10 9 0\n", "2 1 5\nA\n6 3 5\nB\n10 9 0\n", "2 1 5\nA\n6 3 2\nB\n10 9 0\n", "2 1 5\nA\n10 3 2\nB\n10 9 0\n", "2 1 5\nA\n10 3 2\nB\n10 9 1\n", "2 1 1\nG\n2 1 9\nRdepya\n2 1 8\n", "2 1 1\nG\n2 1 9\nRdepyb\n2 1 8\n", "2 1 1\nG\n1 1 9\nRdepyb\n2 1 4\n"], "outputs": ["15\n", "15\n", "6\n", "0...
coding
728
Solve the programming task below in a Python markdown code block. Chef is playing a game which contains a binary string. He can perform one operation only: - Toggle the i_th bit of the string (0 to 1 or 1 to 0) By performing operations on the string (can be zero times), you have to convert the string with no adjacent ...
{"inputs": ["1\n4\n1011"], "outputs": ["1"]}
coding
217
Solve the programming task below in a Python markdown code block. A valid email address meets the following criteria: It's composed of a username, domain name, and extension assembled in this format: username@domain.extension The username starts with an English alphabetical character, and any subsequent characters ...
{"inputs": ["2 \nDEXTER <dexter@hotmail.com>\nVIRUS <virus!@variable.:p>\n"], "outputs": ["DEXTER <dexter@hotmail.com>\n"]}
coding
461
Solve the programming task below in a Python markdown code block. Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different ...
{"inputs": ["1\n1 1 1\n1\n1 1 1\n", "1\n0 1 1\n1\n1 1 1\n", "1\n9 10 7\n1\n7 1 3\n", "1\n15 10 7\n1\n7 1 3\n", "1\n16 10 7\n1\n7 1 3\n", "1\n16 10 7\n1\n9 1 3\n", "1\n16 10 7\n1\n8 1 3\n", "1\n500 500 1\n1\n1 1 500\n"], "outputs": ["4\n", "2\n", "114\n", "150\n", "156\n", "156\n", "156\n", "1000000\n"]}
coding
645
Solve the programming task below in a Python markdown code block. Matrix of given integers a1,1 a1,2 ... a1, n a2,1 a2,2 ... a2, n :: an, 1 an, 2 ... an, n Then, create a program that outputs the maximum value of the sum of one or more consecutive terms (submatrix) in the vertical and horizontal directions and ends...
{"inputs": ["3\n1 -2 3\n-1 5 6\n7 8 -9", "3\n1 -2 3\n-1 5 6\n7 8 -2", "3\n1 -2 5\n-1 2 1\n6 2 -3", "3\n-2 -7 3\n0 0 1\n45 0 0", "3\n2 -4 5\n0 2 0\n1 4 -25", "3\n1 -2 3\n-4 5 6\n7 8 -9", "3\n1 -2 3\n-1 5 6\n6 8 -15", "3\n1 -2 5\n-1 3 1\n6 8 -25"], "outputs": ["19\n", "25\n", "11\n", "46\n", "7\n", "16", "18\n", "16\n"]}
coding
266
Solve the programming task below in a Python markdown code block. Madoka's father just reached $1$ million subscribers on Mathub! So the website decided to send him a personalized award — The Mathhub's Bit Button! The Bit Button is a rectangular table with $n$ rows and $m$ columns with $0$ or $1$ in each cell. After e...
{"inputs": ["5\n3 3\n100\n011\n011\n3 3\n110\n111\n110\n1 5\n01111\n4 5\n11111\n01010\n01000\n01000\n3 2\n11\n00\n11\n"], "outputs": ["YES\nNO\nYES\nNO\nYES\n"]}
coding
585
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered a tree w...
{"inputs": ["2\n1 2 7\n", "2\n1 2 3\n", "2\n1 2 10\n", "2\n2 1 1000000000\n", "2\n2 1 1010000000\n", "2\n2 1 1000000001\n", "4\n1 2 4\n3 1 2\n1 4 7\n", "4\n1 2 4\n1 3 47\n1 4 7447\n"], "outputs": ["0", "0", "0", "0", "0", "0", "16", "24"]}
coding
638
Solve the programming task below in a Python markdown code block. There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i. Takahashi will begin at (...
{"inputs": ["2 2 3\n1 0 3\n2 1 4\n1 2 5", "2 2 3\n1 0 3\n2 1 8\n1 2 5", "3 2 3\n1 0 5\n2 2 4\n1 2 5", "2 2 3\n1 0 5\n2 1 4\n1 2 5", "3 2 3\n1 0 5\n2 1 4\n1 2 5", "2 2 3\n1 1 3\n2 1 4\n1 2 5", "2 2 3\n1 1 3\n2 1 4\n1 2 5\n", "2 5 5\n1 1 3\n2 4 20\n2 2 1\n1 3 4\n1 4 2"], "outputs": ["5\n", "8\n", "9\n", "5\n", "5\n", "8"...
coding
559
Solve the programming task below in a Python markdown code block. Your Goal is to create a function that takes two strings, a guess and a phone number. Based on the guess, the function should display a portion of the phone number: guess_my_number('052', '123-451-2345') would return the string: '#2#-#5#-2##5...
{"functional": "_inputs = [['0'], ['01'], ['012'], ['0123'], ['01234'], ['012345']]\n_outputs = [['###-###-####'], ['1##-##1-####'], ['12#-##1-2###'], ['123-##1-23##'], ['123-4#1-234#'], ['123-451-2345']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return m...
coding
275
Solve the programming task below in a Python markdown code block. The Ackermann function is a famous function that played a big role in computability theory as the first example of a total computable function that is not primitive recursive. Since then the function has been a bit simplified but is still of good use. D...
{"functional": "_inputs = [[1, 1], [4, 0], [3, 3]]\n_outputs = [[3], [13], [61]]\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...
coding
255
Solve the programming task below in a Python markdown code block. Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she ...
{"inputs": ["1\n2\n", "1\n4\n", "1\n0\n", "1\n-3\n", "2\n0 3\n", "2\n0 0\n", "1\n7500\n", "1\n5507\n"], "outputs": ["2\n", "4\n", "0\n", "3\n", "3\n", "0\n", "7500\n", "5507\n"]}
coding
374
Please solve the programming task below using a self-contained code snippet in a markdown code block. A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. The result may be large, so ...
{"functional": "def check(candidate):\n assert candidate(n = 3) == 4\n assert candidate(n = 5) == 13\n\n\ncheck(Solution().waysToStep)"}
coding
117
Solve the programming task below in a Python markdown code block. >When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: Give you two number `m` and `n`(two positive integer, m < n), make a triangle pattern wit...
{"functional": "_inputs = [[1, 12], [1, 100]]\n_outputs = [[''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
coding
313
Solve the programming task below in a Python markdown code block. Takahashi's house has only one socket. Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets. One power strip with A sockets can extend one empty socket into A empty sockets. Find the minimum num...
{"inputs": ["8 4", "4 9", "2 5", "7 9", "2 9", "4 1", "2 8", "2 7"], "outputs": ["1\n", "3\n", "4\n", "2\n", "8\n", "0\n", "7\n", "6\n"]}
coding
177
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 < i < arr.length - 1 such that: ...
{"functional": "def check(candidate):\n assert candidate(arr = [2,1]) == False\n assert candidate(arr = [3,5,5]) == False\n assert candidate(arr = [0,3,2,1]) == True\n\n\ncheck(Solution().validMountainArray)"}
coding
151
Solve the programming task below in a Python markdown code block. There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordi...
{"inputs": ["5 6\n", "2 2\n", "1 6\n", "2 3\n", "1 0\n", "9 5\n", "8 3\n", "2 6\n"], "outputs": ["NO", "NO", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
245
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below. In the American keyboard: the first row consists of the cha...
{"functional": "def check(candidate):\n assert candidate(words = [\"Hello\",\"Alaska\",\"Dad\",\"Peace\"]) == [\"Alaska\",\"Dad\"]\n assert candidate(words = [\"omk\"]) == []\n assert candidate(words = [\"adsdf\",\"sfd\"]) == [\"adsdf\",\"sfd\"]\n\n\ncheck(Solution().findWords)"}
coding
128
Solve the programming task below in a Python markdown code block. Ehab has an array $a$ of length $n$. He has just enough free time to make a new array consisting of $n$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence? A sequence $a$ is a subsequ...
{"inputs": ["2\n2\n1 1\n1\n1\n", "2\n2\n1 1\n1\n1\n", "1\n5\n1 3 4 5 2\n", "1\n5\n1 3 4 5 2\n", "1\n5\n2 3 4 5 2\n", "1\n5\n1 3 4 8 2\n", "1\n5\n1 3 4 5 1\n", "1\n5\n3 3 4 5 2\n"], "outputs": ["1\n1\n", "1\n1\n", "5\n", "5\n", "4\n", "5\n", "4\n", "4\n"]}
coding
421
Solve the programming task below in a Python markdown code block. In this Kata, you will check if it is possible to convert a string to a palindrome by changing one character. For instance: ```Haskell solve ("abbx") = True, because we can convert 'x' to 'a' and get a palindrome. solve ("abba") = False, because we ca...
{"functional": "_inputs = [['abba'], ['abbaa'], ['abbx'], ['aa'], ['ab'], ['abcba']]\n_outputs = [[False], [True], [True], [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 isins...
coding
189
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1.   Please complete the following python code precisely: ```python class Solution: ...
{"functional": "def check(candidate):\n assert candidate(mat = [[0,0,0],[0,1,0],[0,0,0]]) == [[0,0,0],[0,1,0],[0,0,0]]\n assert candidate(mat = [[0,0,0],[0,1,0],[1,1,1]]) == [[0,0,0],[0,1,0],[1,2,1]]\n\n\ncheck(Solution().updateMatrix)"}
coding
82
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n picture consisting of black 'B' and white 'W' pixels and an integer target, return the number of black lonely pixels. A black lonely pixel is a character 'B' that located at a specific position (r, c) w...
{"functional": "def check(candidate):\n assert candidate(picture = [[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"W\",\"B\",\"W\",\"B\",\"W\"]], target = 3) == 6\n assert candidate(picture = [[\"W\",\"W\",\"B\"],[\"W\",\"W\",\"B\"],[\"W\...
coding
142
Solve the programming task below in a Python markdown code block. In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those sequences, ...
{"inputs": ["0 4", "2 1", "0 1", "2 5", "2 2", "0 5", "0 2", "3 1"], "outputs": ["0 0 0 0\n", "1\n", "0\n", "1 2 2 2 2\n", "1 2\n", "0 0 0 0 0\n", "0 0\n", "2\n"]}
coding
278
Solve the programming task below in a Python markdown code block. We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not. You are given an even string S consisting of lowercase English letters. Find the length...
{"inputs": ["xxxy", "xxwx", "yyxx", "xxvx", "xxyy", "yyxw", "yyyx", "yywx"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
270
Solve the programming task below in a Python markdown code block. We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally. Takahashi is standing at Vertex u, and Aoki is standing at Vertex v. Now, they will play a game of tag as follows: - 1. If Takahashi and Aoki are standing at the ...
{"inputs": ["2 1 2\n1 2", "2 1 2\n1 2\n", "5 4 5\n1 2\n1 3\n2 4\n1 5", "5 4 1\n1 2\n1 3\n3 4\n3 5", "5 4 1\n1 2\n2 3\n1 4\n3 5", "5 4 5\n1 2\n1 5\n2 4\n1 5", "5 4 5\n2 2\n1 3\n1 4\n1 5", "5 5 1\n1 2\n2 3\n1 4\n3 5"], "outputs": ["0", "0\n", "2\n", "1\n", "0\n", "2\n", "1\n", "2\n"]}
coding
473
Solve the programming task below in a Python markdown code block. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k. You're given a set of n distinct pos...
{"inputs": ["1 1\n1\n", "1 1\n2\n", "1 2\n2\n", "2 2\n4 2\n", "2 1\n2 1\n", "2 2\n1 3\n", "2 1\n4 1\n", "2 4\n1 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]}
coding
257
Please solve the programming task below using a self-contained code snippet in a markdown code block. Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: [4,5,6,7,0,1,2] if it was rotated 4 times. [0,1,2,4,5,6,7] if it wa...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,5,1,2]) == 1\n assert candidate(nums = [4,5,6,7,0,1,2]) == 0\n assert candidate(nums = [11,13,15,17]) == 11\n\n\ncheck(Solution().findMin)"}
coding
228
Solve the programming task below in a Python markdown code block. Rose loves to play games. This problem is about a game he recently played. In the game there are N locations, numbered 0 through N-1. Each location has one entrance and one exit. You are given an array aka A with N elements.For each i, A[i] describes the...
{"inputs": ["10\n2\n1 -1\n3\n1 0 -1\n3\n0 1 2\n37\n29 33 28 16 -1 11 10 14 6 31 7 35 34 8 15 17 26 12 13 22 1 20 2 21 -1 5 19 9 18 4 25 32 3 30 23 10 27\n48\n17 43 20 41 42 15 18 35 -1 31 7 33 23 33 -1 -1 0 33 19 12 42 -1 -1 9 9 -1 39 -1 31 46 -1 20 44 41 -1 -1 12 -1 36 -1 -1 6 47 10 2 4 1 29\n6\n3 1 1 2 -1 4\n47\n15 1...
coding
372
Solve the programming task below in a Python markdown code block. Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda a_{i} and bottle volume b_{i} (a_{i} ≤ b_{i}). Nick has decided to pour all remaining soda into minimal number of bottles, moreover he h...
{"inputs": ["1\n1\n1\n", "1\n1\n2\n", "1\n1\n1\n", "1\n1\n2\n", "1\n2\n2\n", "1\n1\n100\n", "1\n1\n100\n", "1\n50\n100\n"], "outputs": ["1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0", "1 0\n", "1 0\n", "1 0\n"]}
coding
537
Solve the programming task below in a Python markdown code block. You are using at most A number of 1s and at most B number of 2s. How many different evaluation results are possible when they are formed in an expression containing only addition + sign and multiplication * sign are allowed? Note that, multiplication ta...
{"inputs": ["4\n0 0\n2 2\n0 2\n2 0\n"], "outputs": ["0\n6\n2\n2\n"]}
coding
496
Solve the programming task below in a Python markdown code block. You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the...
{"inputs": ["4\n4 2\ndcba\n3 1\nabc\n4 3\naaaa\n9 3\nabaabaaaa\n", "4\n4 4\nabcd\n3 1\nabc\n4 3\naaaa\n9 3\nabaabaaaa\n", "4\n4 2\nabcd\n3 1\nabc\n4 1\naaaa\n9 3\nabaabaaaa\n", "4\n4 2\ndcba\n3 1\nabc\n4 3\naaaa\n9 3\nabbabaaaa\n", "4\n4 4\nabcd\n3 1\nabc\n4 1\naaaa\n9 3\nabaabaaaa\n", "4\n4 2\ndcba\n3 1\nabc\n4 3\naaa...
coding
490
Solve the programming task below in a Python markdown code block. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: - A_i \neq B_i, for every i such that 1\leq i\leq N. - A_i \neq...
{"inputs": ["1 2", "2 6", "0 2", "2 4", "1 4", "3 4", "1 1", "1 6"], "outputs": ["2\n", "630\n", "1\n", "84\n", "12\n", "264\n", "0\n", "30\n"]}
coding
279
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"]}
coding
508
Solve the programming task below in a Python markdown code block. You have an array $a$ of length $n$. You can exactly once select an integer $len$ between $1$ and $n - 1$ inclusively, and then sort in non-decreasing order the prefix of the array of length $len$ and the suffix of the array of length $n - len$ independe...
{"inputs": ["1\n4\n1 3 2 4\n", "1\n7\n1 2 3 5 4 6 7\n", "3\n3\n2 2 1\n4\n3 1 2 1\n5\n1 2 2 4 4\n"], "outputs": ["YES\n", "YES\n", "YES\nYES\nNO\n"]}
coding
552
Solve the programming task below in a Python markdown code block. You are given a problemset consisting of $n$ problems. The difficulty of the $i$-th problem is $a_i$. It is guaranteed that all difficulties are distinct and are given in the increasing order. You have to assemble the contest which consists of some prob...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 3\n", "2\n1 3\n", "2\n2 3\n", "2\n1 3\n", "2\n1 2\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "1\n", "2\n"]}
coding
747
Solve the programming task below in a Python markdown code block. Chef likes to solve difficult tasks. This time, he tried to solve the Big Famous Unsolvable $A+B=C$. One of his friends played a prank on Chef and randomly shuffled the bits in $A$ and $B$ (independently in each number). However, the funny thing is that ...
{"inputs": ["2\n1 2 3\n369 428 797"], "outputs": ["2\n56"]}
coding
555
Solve the programming task below in a Python markdown code block. A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an int...
{"inputs": ["2 1\n11\n", "2 1\n11\n", "4 2\n1001\n", "4 2\n1001\n", "5 4\n11011\n", "5 4\n10001\n", "5 4\n11011\n", "5 4\n10001\n"], "outputs": ["1\n", "1\n", "-1\n", "-1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
528
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, you have two types of operation: Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists). Choose an index i in the ...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabc\") == 3\n assert candidate(s = \"cbbd\") == 3\n assert candidate(s = \"dddaaa\") == 2\n\n\ncheck(Solution().minimizedStringLength)"}
coding
156
Solve the programming task below in a Python markdown code block. You are given a graph with N vertices (numbered 1 to N) and M bidirectional edges, which doesn't contain multiple edges or self-loops — that is, the given graph is a simple undirected graph. For each pair of vertices a, b such that 1 ≤ a, b ≤ N, it is p...
{"inputs": ["3\n2 0\n5 4\n3 2\n1 4\n5 3\n4 2\n6 3\n1 2\n3 2\n1 3\n"], "outputs": ["1\n0\n3\n"]}
coding
490
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. During a boring night at the restaurant, Chef decided to play with spaghetti. He has $R-L+1$ spaghetti: exactly one spaghetti with each length betwee...
{"inputs": ["2\n1 2\n3 5"], "outputs": ["3\n7"]}
coding
354
Solve the programming task below in a Python markdown code block. Chef has a sequence $A_1, A_2, \ldots, A_N$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$ You have to help him to ...
{"inputs": ["3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2"], "outputs": ["2\n1\n2"]}
coding
458
Solve the programming task below in a Python markdown code block. Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates ...
{"inputs": ["1 1 -100 100\n-99\n99\n", "1 1 -100 100\n99\n-99\n", "3 2 10 40\n8 1 15\n16 22", "3 2 10 40\n8 1 15\n16 23", "3 0 10 40\n8 1 15\n16 23", "0 0 10 40\n8 1 15\n16 23", "3 3 10 40\n8 1 15\n16 23", "3 0 10 61\n8 1 15\n16 23"], "outputs": ["No War\n", "War\n", "No War\n", "No War\n", "No War\n", "No War\n", "No ...
coding
467
Solve the programming task below in a Python markdown code block. Your task is to define a function that understands basic mathematical expressions and solves them. For example: ```python calculate("1 + 1") # => 2 calculate("18 + 4*6") # => 42 calculate("245 - 826") # => -581 calculate("09 + 000482") # ...
{"functional": "_inputs = [['1 + 1'], ['9 - 4'], ['1 - 4'], ['3 * 4'], ['9 / 3'], ['26 + 73'], ['524 + 277'], ['1 / 2'], ['2 / 5'], ['1 + 2 + 3 + 4 + 5 + 6'], ['123 - 3 - 20 - 100'], ['123 * 987 * 135 * 246'], ['200 / 2 / 10 / 5'], ['1+2-3+4-5+6-7+8-9+10'], ['5*2/3*9/10*123/8'], ['1*2*3/1/2/3+1+2+3-1-2-3'], ['1+2 * 4']...
coding
334
Solve the programming task below in a Python markdown code block. You would like to get the 'weight' of a name by getting the sum of the ascii values. However you believe that capital letters should be worth more than mere lowercase letters. Spaces, numbers, or any other character are worth 0. Normally in ascii a...
{"functional": "_inputs = [['Joe'], ['CJ'], ['cj'], ['George Washington'], ['Billy Bob Joe'], ['King George II'], ['r2d2'], ['R2D2'], ['C3PO']]\n_outputs = [[254], [205], [141], [1275], [909], [1012], [150], [214], [322]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\...
coding
206
Solve the programming task below in a Python markdown code block. Farmer Feb has three fields with potatoes planted in them. He harvested x potatoes from the first field, y potatoes from the second field and is yet to harvest potatoes from the third field. Feb is very superstitious and believes that if the sum of potat...
{"inputs": ["2\n1 3\n4 3", "2\n1 3\n3 3", "2\n1 3\n1 6", "2\n1 3\n2 6", "2\n1 3\n3 6", "2\n1 4\n4 3", "2\n2 3\n3 3", "2\n1 4\n2 3"], "outputs": ["1\n4", "1\n1\n", "1\n4\n", "1\n3\n", "1\n2\n", "2\n4\n", "2\n1\n", "2\n2\n"]}
coding
328
Solve the programming task below in a Python markdown code block. Read problems statements in [Russian] and [Bengali]. You are given two binary strings S and P. You need to convert S into P using the following operation any number of times (possibly zero): Pick three binary values X, Y, and Z, such that at least one ...
{"inputs": ["2\n4\n1001\n0101\n3\n111\n000"], "outputs": ["YES\nNO"]}
coding
446
Solve the programming task below in a Python markdown code block. In this Kata, you will be given directions and your task will be to find your way back. ```Perl solve(["Begin on Road A","Right on Road B","Right on Road C","Left on Road D"]) = ['Begin on Road D', 'Right on Road C', 'Left on Road B', 'Left on Road A'] ...
{"functional": "_inputs = [[['Begin on 3rd Blvd', 'Right on First Road', 'Left on 9th Dr']], [['Begin on Road A', 'Right on Road B', 'Right on Road C', 'Left on Road D']], [['Begin on Road A']]]\n_outputs = [[['Begin on 9th Dr', 'Right on First Road', 'Left on 3rd Blvd']], [['Begin on Road D', 'Right on Road C', 'Left ...
coding
204
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid. A uni-value grid is a grid where all the elements of it are equal. Return ...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,4],[6,8]], x = 2) == 4\n assert candidate(grid = [[1,5],[2,3]], x = 1) == 5\n assert candidate(grid = [[1,2],[3,4]], x = 2) == -1\n\n\ncheck(Solution().minOperations)"}
coding
130
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.   Please complete the following python code precis...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,2,1], nums2 = [2,2]) == [2]\n assert candidate(nums1 = [4,9,5], nums2 = [9,4,9,8,4]) == [9,4]\n\n\ncheck(Solution().intersection)"}
coding
90
Solve the programming task below in a Python markdown code block. At the end of a busy day, The Chef and his assistants play a game together. The game is not just for fun but also used to decide who will have to clean the kitchen. The Chef is a Game Master, so his concern is how to manage the game but not how to win th...
{"inputs": ["1\n5 2 3\n1 4\n3 5\n1 5", "1\n5 2 3\n1 4\n3 5\n0 5", "1\n5 2 3\n1 3\n3 5\n1 5", "1\n5 2 3\n2 4\n3 5\n0 5", "1\n5 2 3\n2 4\n2 5\n0 5", "1\n5 2 3\n2 4\n2 8\n0 5", "1\n4 2 3\n1 6\n3 9\n1 5", "1\n5 2 3\n5 4\n2 5\n0 3"], "outputs": ["1", "0\n", "4\n", "1\n", "2\n", "6\n", "7\n", "5\n"]}
coding
608
Solve the programming task below in a Python markdown code block. An integer $\boldsymbol{d}$ is a divisor of an integer $n$ if the remainder of $n\div d=0$. Given an integer, for each digit that makes up the integer determine whether it is a divisor. Count the number of divisors occurring within the integer. Ex...
{"inputs": ["2\n12\n1012\n"], "outputs": ["2\n3\n"]}
coding
483
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7. Note: A string is palindromic if it reads the same forward...
{"functional": "def check(candidate):\n assert candidate(s = \"103301\") == 2\n assert candidate(s = \"0000000\") == 21\n assert candidate(s = \"9999900000\") == 2\n\n\ncheck(Solution().countPalindromes)"}
coding
139
Solve the programming task below in a Python markdown code block. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm...
{"inputs": ["2\n4 6\n", "2\n3 3\n", "2\n4 5\n", "2\n3 4\n", "2\n2 5\n", "2\n2 2\n", "2\n3 2\n", "2\n4 3\n"], "outputs": ["12\n", "3\n", "20\n", "12\n", "10\n", "2\n", "6\n", "12\n"]}
coding
500
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an initial array arr, every day you produce a new array using the array of the previous day. On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i: If an element...
{"functional": "def check(candidate):\n assert candidate([6,2,3,4]) == [6,3,3,4]\n assert candidate([1,6,3,4,3,5]) == [1,4,4,4,4,5]\n\n\ncheck(Solution().transformArray)"}
coding
166
Please solve the programming task below using a self-contained code snippet in a markdown code block. Imagine you have a special keyboard with the following keys: A: Print one 'A' on the screen. Ctrl-A: Select the whole screen. Ctrl-C: Copy selection to buffer. Ctrl-V: Print buffer on screen appending it after what h...
{"functional": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 7) == 9\n\n\ncheck(Solution().maxA)"}
coding
129
Solve the programming task below in a Python markdown code block. You have been speeding on a motorway and a police car had to stop you. The policeman is a funny guy that likes to play games. Before issuing penalty charge notice he gives you a choice to change your penalty. Your penalty charge is a combination of num...
{"functional": "_inputs = [[['45', '30', '50', '1']], [['100', '10', '1']], [['32', '3']], [['70', '46', '4', '19']], [['71', '82', '42', '34', '90']], [['31', '97', '6', '78']], [['72', '7', '7', '78', '79', '709', '94']]]\n_outputs = [['1304550'], ['100101'], ['323'], ['1944670'], ['3442718290'], ['3167897'], ['70972...
coding
248
Solve the programming task below in a Python markdown code block. To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: - 1 yen (the currency of Japan) - 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... - 9 yen, 9^2(=81) yen, 9^3(=729) yen,...
{"inputs": ["1", "0", "8", "2", "5", "6", "4", "9"], "outputs": ["1\n", "0\n", "3\n", "2\n", "5\n", "1\n", "4\n", "1\n"]}
coding
257
Please solve the programming task below using a self-contained code snippet in a markdown code block. Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible. Return t...
{"functional": "def check(candidate):\n assert candidate(arr = [9,12,3,7,15], target = 5) == 2\n assert candidate(arr = [1000000,1000000,1000000], target = 1) == 999999\n assert candidate(arr = [1,2,4,8,16], target = 0) == 0\n\n\ncheck(Solution().closestToTarget)"}
coding
141
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an unsorted integer array nums. Return the smallest positive integer that is not present in nums. You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.   Please complete the follo...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,0]) == 3\n assert candidate(nums = [3,4,-1,1]) == 2\n assert candidate(nums = [7,8,9,11,12]) == 1\n\n\ncheck(Solution().firstMissingPositive)"}
coding
90
Solve the programming task below in a Python markdown code block. There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N. On this sequence, Snuke can perform the following operation: - Choose K consecutive elements in the sequence. Then, replace the value of each...
{"inputs": ["3 3\n1 2 3\n", "4 3\n2 3 1 4\n", "8 3\n7 3 1 8 4 6 2 5\n"], "outputs": ["1\n", "2\n", "4\n"]}
coding
320
Solve the programming task below in a Python markdown code block. Bob has an account in the Bobby Bank. His current account balance is W rupees. Each month, the office in which Bob works deposits a fixed amount of X rupees to his account. Y rupees is deducted from Bob's account each month as bank charges. Find hi...
{"inputs": ["3\n100 11 1 10\n999 25 36 9\n2500 100 125 101\n"], "outputs": ["200\n900\n-25"]}
coding
532
Solve the programming task below in a Python markdown code block. Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest. There are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows about Snack...
{"inputs": ["2\n7\n2 1 1 5 5 5 5\n5\n5 1 3 2 1"], "outputs": ["2\n1"]}
coding
572
Solve the programming task below in a Python markdown code block. Chef has two integers X and Y. Chef wants to perform some operations to make X and Y equal. In one operation, Chef can either: set X := X + 1 or set Y := Y + 2 Find the minimum number of operations required to make X and Y equal. ------ Input Format -...
{"inputs": ["5\n3 4\n5 5\n7 3\n5 2\n7 12\n"], "outputs": ["1\n0\n2\n3\n5\n\n"]}
coding
432
Solve the programming task below in a Python markdown code block. This is the harder version of the problem. In this version, $1 \le n \le 10^6$ and $0 \leq a_i \leq 10^6$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems Christmas is coming, and our pr...
{"inputs": ["1\n1\n", "1\n1\n", "1\n25\n", "1\n835\n", "1\n2103\n", "1\n2103\n", "1\n2140\n", "3\n4 8 5\n"], "outputs": ["-1\n", "-1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "9\n"]}
coding
678
Solve the programming task below in a Python markdown code block. - Kids drink toddy. - Teens drink coke. - Young adults drink beer. - Adults drink whisky. Make a function that receive age, and return what they drink. **Rules:** - Children under 14 old. - Teens under 18 old. - Young under 21 old. - Adults have 21 or...
{"functional": "_inputs = [[13], [0], [17], [15], [14], [20], [18], [22], [21]]\n_outputs = [['drink toddy'], ['drink toddy'], ['drink coke'], ['drink coke'], ['drink coke'], ['drink beer'], ['drink beer'], ['drink whisky'], ['drink whisky']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
coding
189
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given a tree consisting of n nodes numbered from 1 to n. The weights of edges of the tree can be any binary integer satisfying following Q conditions. Each conditi...
{"inputs": ["3\n3 2\n1 2\n1 3\n1 2 0\n1 3 0\n3 0\n1 2\n2 3\n3 1\n1 2\n2 3\n1 2 1"], "outputs": ["1\n4\n2"]}
coding
670
Solve the programming task below in a Python markdown code block. Chef published a blog post, and is now receiving many queries about it. On day $i$, he receives $Q_i$ queries. But Chef can answer at most $k$ queries in a single day. Chef always answers the maximum number of questions that he can on any given day (not...
{"inputs": ["2\n6 5\n10 5 5 3 2 1\n1 1\n100"], "outputs": ["6\n101"]}
coding
709
Solve the programming task below in a Python markdown code block. In mathematics, the factorial of integer 'n' is written as 'n!'. It is equal to the product of n and every integer preceding it. For example: **5! = 1 x 2 x 3 x 4 x 5 = 120** Your mission is simple: write a function that takes an integer 'n' and returns...
{"functional": "_inputs = [[-1]]\n_outputs = [[None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_...
coding
175
Solve the programming task below in a Python markdown code block. Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly n apple trees. Tree number i is located in a position x_{i} and has a_...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n0 0\n", "1\n1 0\n", "1\n2 1\n", "1\n-1 1\n", "1\n-1 1\n", "1\n-1 4\n"], "outputs": ["1", "1\n", "0\n", "0\n", "1\n", "1", "1\n", "4\n"]}
coding
580
Solve the programming task below in a Python markdown code block. You are given a chessboard consisting of $n$ rows and $n$ columns. Rows are numbered from bottom to top from $1$ to $n$. Columns are numbered from left to right from $1$ to $n$. The cell at the intersection of the $x$-th column and the $y$-th row is deno...
{"inputs": ["50 50 1\n1 50\n", "50 50 1\n1 50\n", "50 41 1\n1 50\n", "50 50 1\n2 50\n", "50 47 1\n1 50\n", "50 50 1\n2 23\n", "5 3 5\n4 4\n3 5\n2 4\n3 4\n3 5\n", "5 5 5\n4 4\n3 5\n2 4\n3 4\n3 5\n"], "outputs": ["49\n", "49\n", "40\n", "48\n", "46\n", "21\n", "0\n1\n2\n2\n1\n", "0\n2\n3\n3\n2\n"]}
coding
551
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D grid of size m x n, you should find the matrix answer of size m x n. The cell answer[r][c] is calculated by looking at the diagonal values of the cell grid[r][c]: Let leftAbove[r][c] be the number of disti...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,2,3],[3,1,5],[3,2,1]]) == [[1,1,0],[1,0,1],[0,1,1]]\n assert candidate(grid = [[1]]) == [[0]]\n\n\ncheck(Solution().differenceOfDistinctValues)"}
coding
290
Solve the programming task below in a Python markdown code block. Given two words and a letter, return a single word that's a combination of both words, merged at the point where the given letter first appears in each word. The returned word should have the beginning of the first word and the ending of the second, with...
{"functional": "_inputs = [['hello', 'world', 'l'], ['coding', 'anywhere', 'n'], ['jason', 'samson', 's'], ['wonderful', 'people', 'e'], ['person', 'here', 'e'], ['apowiejfoiajsf', 'iwahfeijouh', 'j'], ['abcdefxxxyzz', 'abcxxxyyyxyzz', 'x'], ['12345654321', '123456789', '6'], ['JiOdIdA4', 'oopopopoodddasdfdfsd', 'd'], ...
coding
196
Solve the programming task below in a Python markdown code block. There is an array of $n$ integers. There are also $2$ disjoint sets, $\mbox{A}$ and $\mbox{B}$, each containing $m$ integers. You like all the integers in set $\mbox{A}$ and dislike all the integers in set $\mbox{B}$. Your initial happiness is $\mbox{o}$...
{"inputs": ["3 2\n1 5 3\n3 1\n5 7\n"], "outputs": ["1\n"]}
coding
446
Solve the programming task below in a Python markdown code block. Laurel and Hardy have $n$ piles of chocolates with each pile containing some number of chocolates. The piles are arranged from left to right in a non decreasing order based on the number of chocolates in each pile. They play the following game. For eve...
{"inputs": ["5\n1 1 2 2 3\n"], "outputs": ["5\n"]}
coding
446
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n cars at given miles away from the starting mile 0, traveling to reach the mile target. You are given two integer array position and speed, both of length n, where position[i] is the starting mile of the it...
{"functional": "def check(candidate):\n assert candidate(target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]) == 3\n\n\ncheck(Solution().carFleet)"}
coding
219
Solve the programming task below in a Python markdown code block. There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is e...
{"inputs": ["9 1 3 7 6\n.#..#..", "4 1 3 7 6\n.#..#..", "8 1 3 7 6\n.#..#..", "1 1 3 7 6\n.#..#..", "8 1 4 7 6\n.#..#..", "8 2 4 7 6\n.#..#..", "5 1 3 7 6\n.#..#..", "0 1 3 7 6\n.#..#.."], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
400
Solve the programming task below in a Python markdown code block. You are given an array ${A}$ of size $N$. You are asked to answer ${Q}$ queries. Each query is of the form : ${ij x}$ You need to print Yes if ${x}$ divides the value returned from $find(i,j)$ function, otherwise print No. find(int i,int j) { ...
{"inputs": ["4\n2 3 4 5\n2\n1 2 4\n1 3 7\n"], "outputs": ["Yes\nNo\n"]}
coding
326
Solve the programming task below in a Python markdown code block. Hector the hacker has stolen some information, but it is encrypted. In order to decrypt it, he needs to write a function that will generate a decryption key from the encryption key which he stole (it is in hexadecimal). To do this, he has to determine th...
{"functional": "_inputs = [['47b'], ['2533'], ['1ba9']]\n_outputs = [[1080], [9328], [6912]]\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): ...
coding
253
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, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0. For every two consecutive 0's, merge all the nodes lying...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([0,3,1,0,4,5,2,0])), list_node([4,11]))\n assert is_same_list(candidate(head = list_node([0,1,0,3,0,2,2,0])), list_node([1,3,4]))\n\n\ncheck(Solution().mergeNodes)"}
coding
180
Solve the programming task below in a Python markdown code block. Burenka and Tonya are playing an old Buryat game with a chip on a board of $n \times m$ cells. At the beginning of the game, the chip is located in the lower left corner of the board. In one move, the player can move the chip to the right or up by any o...
{"inputs": ["6\n1 1\n1 4\n5 6\n2 2\n6 3\n999999999 1000000000\n"], "outputs": ["Tonya\nBurenka\nBurenka\nTonya\nBurenka\nBurenka\n"]}
coding
549
Solve the programming task below in a Python markdown code block. # Task You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from digit `3` to digit `5` always skipping the digit `4`. This defect shows up in all positions (ones, tens, hundre...
{"functional": "_inputs = [[13], [15], [55], [2005], [1500], [999999], [165826622]]\n_outputs = [[12], [13], [40], [1462], [1053], [531440], [69517865]]\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 ...
coding
285
Solve the programming task below in a Python markdown code block. You are given a permutation $p$ of $n$ integers $1$, $2$, ..., $n$ (a permutation is an array where each element from $1$ to $n$ occurs exactly once). Let's call some subsegment $p[l, r]$ of this permutation special if $p_l + p_r = \max \limits_{i = l}^...
{"inputs": ["3\n1 3 2\n", "3\n2 3 1\n", "3\n3 2 1\n", "3\n2 1 3\n", "3\n1 2 3\n", "3\n3 1 2\n", "3\n1 3 2\n", "5\n3 4 1 5 2\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1", "2\n"]}
coding
271
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\n0 1\n", "2\n0 2\n", "2\n73 37\n", "2\n73 37\n", "2\n129 37\n", "2\n129 16\n", "2\n129 20\n"], "outputs": ["1\n", "1\n", "2\n", "36\n", "36\n", "92\n", "113\n", "109\n"]}
coding
682