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. In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and wr...
{"inputs": ["0 3 3\n", "0 0 1\n", "0 1 1\n", "3 0 3\n", "1 1 1\n", "1 0 3\n", "0 1 3\n", "1 0 7\n"], "outputs": ["2\n", "2\n", "2\n", "1 000000001\n", "2\n", "1 000000001\n", "2\n", "1 000000001\n"]}
coding
378
Solve the programming task below in a Python markdown code block. We just discovered a new data structure in our research group: a suffix three! It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in. It's super ...
{"inputs": ["8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_okama_kenpo\nang_halaman_doon_ay_sarisari_singkamasu\nsi_roy_mustang_ay_namamasu\n", "8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_o...
coding
541
Solve the programming task below in a Python markdown code block. Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that $f(\varnothing) = 0$). Y...
{"inputs": ["1 1\n45 70\n", "1 1\n45 70\n", "1 1\n-35 -8\n", "1 1\n-35 -8\n", "1 1\n45 113\n", "1 1\n-40 -8\n", "1 1\n-79 -51\n", "1 1\n-79 -51\n"], "outputs": ["26\n", " 26\n", "28\n", " 28\n", "69...
coding
592
Solve the programming task below in a Python markdown code block. Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security sy...
{"inputs": ["1\n0\n", "1\n0\n", "2\n0 1\n", "2\n0 1\n", "3\n0 2 0\n", "3\n0 2 1\n", "3\n0 2 1\n", "3\n0 2 0\n"], "outputs": ["0\n", "0", "0\n", "0", "1\n", "1\n", "1", "1"]}
coding
576
Please solve the programming task below using a self-contained code snippet in a markdown code block. In some array arr, the values were in arithmetic progression: the values arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1. A value from arr was removed that was not the first or last value in the ar...
{"functional": "def check(candidate):\n assert candidate(arr = [5,7,11,13]) == 9\n assert candidate(arr = [15,13,12]) == 14\n\n\ncheck(Solution().missingNumber)"}
coding
114
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 the maximum length of a subarray that appears in both arrays.   Please complete the following python code precisely: ```python class Solution: def findLength(self, ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]) == 3\n assert candidate(nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]) == 5\n\n\ncheck(Solution().findLength)"}
coding
79
Solve the programming task below in a Python markdown code block. Recall that string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly zero or all) characters. For example, for the string $a$="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow...
{"inputs": ["v\n", "o\n", "o\n", "v\n", "n\n", "u\n", "p\n", "t\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
473
Solve the programming task below in a Python markdown code block. Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his newly desi...
{"inputs": ["3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -", "3\n4\ntilak +\ntilak +\ntilak -\ntilaj +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -", "3\n4\ntilak +\nkalit +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -...
coding
615
Solve the programming task below in a Python markdown code block. A series or sequence of numbers is usually the product of a function and can either be infinite or finite. In this kata we will only consider finite series and you are required to return a code according to the type of sequence: |Code|Type|Example| |-|...
{"functional": "_inputs = [[[3, 5, 8, 1, 14, 3]], [[3, 5, 8, 9, 14, 23]], [[3, 5, 8, 8, 14, 14]], [[14, 9, 8, 5, 3, 1]], [[14, 14, 8, 8, 5, 3]], [[8, 8, 8, 8, 8, 8]], [[8, 9]], [[8, 8, 8, 8, 8, 9]], [[9, 8]], [[9, 9, 9, 8, 8, 8]], [[3, 5, 8, 1, 14, 2]]]\n_outputs = [[0], [1], [2], [3], [4], [5], [1], [2], [3], [4], [0]...
coding
335
Solve the programming task below in a Python markdown code block. Frieza wants to become immortal. In order to do that he must acquire all the seven dragon balls. In a legendary fight, he is able to defeat Kami, the Guardian of the dragon balls. Now he has come across a case that contains the dragon balls and he needs ...
{"inputs": ["2\nkrillinisdead\nfuturetrunks"], "outputs": ["122111221\n132114"]}
coding
629
Solve the programming task below in a Python markdown code block. You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of ...
{"inputs": ["1\n4 9\n4 4 2 6", "1 \n4 7\n4 0 2 6", "1 \n4 7\n0 0 0 0", "1 \n4 0\n9 1 1 1", "1 \n4 8\n0 1 1 1", "1 \n4 9\n4 4 2 6", "1 \n4 14\n4 4 2 6", "1 \n4 14\n4 1 2 6"], "outputs": ["1 4", "1 3\n", "7 6\n", "2 3\n", "6 3\n", "1 4\n", "4 2\n", "4 1\n"]}
coding
343
Solve the programming task below in a Python markdown code block. Problem description. Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the string with mini...
{"inputs": ["1\n9"], "outputs": ["XXXDDD"]}
coding
242
Solve the programming task below in a Python markdown code block. We have a string S of length N consisting of A, B, and C. You can do the following operation on S zero or more times: - Choose i (1 \leq i \leq |S| - 1) such that S_i \neq S_{i + 1}. Replace S_i with the character (among A, B, and C) that is different f...
{"inputs": ["1\nA\n", "1\nB\n", "1\nC\n", "2\nAB\n", "2\nAC\n", "2\nBA\n", "2\nBC\n", "2\nCA\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
313
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. There are two players A, B playing a game. Player A has a string s with him, and player B has string t with him. Both s and t consist only of lower case English letters and a...
{"inputs": ["3\nab\nab\naba\ncde\nab\ncd"], "outputs": ["B\nA\nB"]}
coding
657
Solve the programming task below in a Python markdown code block. Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided tha...
{"inputs": ["z\na\n", "a\nb\n", "a\na\n", "b\nb\n", "b\na\n", "ac\na\n", "z\nww\n", "ab\nb\n"], "outputs": ["z\n", "-1\n", "-1\n", "-1", "b", "ac\n", "z\n", "ba\n"]}
coding
547
Solve the programming task below in a Python markdown code block. In this Kata, you will be given an integer array and your task is to return the sum of elements occupying prime-numbered indices. ~~~if-not:fortran The first element of the array is at index `0`. ~~~ ~~~if:fortran The first element of an array is at i...
{"functional": "_inputs = [[[]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]]\n_outputs = [[0], [7], [13], [21], [21], [33], [47]]\nimport math\ndef _deep_eq(...
coding
199
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e., 0 <= i < n). In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 ...
{"functional": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 6) == 9\n\n\ncheck(Solution().minOperations)"}
coding
198
Solve the programming task below in a Python markdown code block. Exceptions Errors detected during execution are called exceptions. Examples: ZeroDivisionError This error is raised when the second argument of a division or modulo operation is zero. >>> a = '1' >>> b = '0' >>> print int(a) / int(b) >>> ZeroDivisi...
{"inputs": ["3\n1 0\n2 $\n3 1\n"], "outputs": ["Error Code: integer division or modulo by zero\nError Code: invalid literal for int() with base 10: '$'\n3\n"]}
coding
402
Solve the programming task below in a Python markdown code block. Chef Dengklek will open a new restaurant in the city. The restaurant will be open for N days. He can cook M different types of dish. He would like to cook a single dish every day, such that for the entire N days, he only cook at most K distinct types of ...
{"inputs": ["4\n1 1 1\n2 2 2\n4 3 2\n5 7 3"], "outputs": ["1\n4\n45\n5887"]}
coding
267
Solve the programming task below in a Python markdown code block. You are given an array $a$ of $n$ elements. Your can perform the following operation no more than $n$ times: Select three indices $x,y,z$ $(1 \leq x < y < z \leq n)$ and replace $a_x$ with $a_y - a_z$. After the operation, $|a_x|$ need to be less than $...
{"inputs": ["3\n5\n5 -4 2 -1 2\n3\n4 3 2\n3\n-3 -2 -1\n"], "outputs": ["3\n1 4 5\n2 4 5\n3 4 5\n-1\n0\n"]}
coding
590
Solve the programming task below in a Python markdown code block. A balanced parenthesis string is defined as follows: - The empty string is balanced - If P is balanced, (P) is also - If P and Q are balanced, PQ is also balanced You are given two even integers n$n$ and k$k$. Find any balanced paranthesis string of len...
{"inputs": ["2\n4 2\n8 6"], "outputs": ["-1\n(())(())"]}
coding
375
Solve the programming task below in a Python markdown code block. One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appointed Judg...
{"inputs": ["2 1\n", "4 1\n", "1 1\n", "1 2\n", "2 2\n", "7 3\n", "6 3\n", "4 2\n"], "outputs": ["-1\n", "4\n1 2\n2 3\n3 4\n4 1\n", "-1\n", "-1\n", "-1\n", "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3\n", "-1\n", "-1\n"]}
coding
376
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of size n. Consider a non-empty subarray from nums that has the maximum possible bitwise AND. In other words, let k be the maximum value of the bitwise AND of any subarray of nums....
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,3,2,2]) == 2\n assert candidate(nums = [1,2,3,4]) == 1\n\n\ncheck(Solution().longestSubarray)"}
coding
153
Solve the programming task below in a Python markdown code block. Lot of museum allow you to be a member, for a certain amount `amount_by_year` you can have unlimitted acces to the museum. In this kata you should complete a function in order to know after how many visit it will be better to take an annual pass. The f...
{"functional": "_inputs = [[40, 15], [30, 10], [80, 15]]\n_outputs = [[3], [3], [6]]\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 F...
coding
112
Solve the programming task below in a Python markdown code block. ###BACKGROUND: Jacob recently decided to get healthy and lose some weight. He did a lot of reading and research and after focusing on steady exercise and a healthy diet for several months, was able to shed over 50 pounds! Now he wants to share his succes...
{"functional": "_inputs = [['K', 200, 10], ['M', 0, 10], ['M', -5, 10], ['F', 160, 0], ['F', 160, -10], [',', 0, 1100], ['??', -10, -10], ['llama', 1, -10], ['F', -461.9, 0.0], ['M', 250, 5], ['F', 190, 8], ['M', 405, 12], ['F', 130, 7]]\n_outputs = [['Invalid gender'], ['Invalid weight'], ['Invalid weight'], ['Invalid...
coding
408
Solve the programming task below in a Python markdown code block. You are standing near a very strange machine. If you put C cents in the machine, the remaining money in your purse will transform in an unusual way. If you have A dollars and B cents remaining in your purse after depositing the C cents, then after the tr...
{"inputs": ["2\n0 12 1\n1 1 6", "2\n0 12 0\n1 1 6", "2\n0 12 0\n2 1 6", "2\n0 56 0\n1 1 21", "2\n0 56 0\n1 0 21", "2\n0 56 1\n0 0 21", "2\n0 56 2\n0 0 21", "2\n1 33 1\n15 2 5"], "outputs": ["23\n33\n", "1\n33\n", "1\n34\n", "1\n37\n", "1\n38\n", "2\n0\n", "100\n0\n", "65\n6\n"]}
coding
568
Solve the programming task below in a Python markdown code block. Your task is to create a function that does four basic mathematical operations. The function should take three arguments - operation(string/char), value1(number), value2(number). The function should return result of numbers after applying the chosen o...
{"functional": "_inputs = [['+', 4, 7], ['-', 15, 18], ['*', 5, 5], ['/', 49, 7]]\n_outputs = [[11], [-3], [25], [7]]\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 ...
coding
166
Solve the programming task below in a Python markdown code block. Problem statement N first-year students of the Faculty of Information Science and Technology of R University take the final exam of the lecture called Programming Exercise 1. The test is a perfect score of m. In other words, the score that one student c...
{"inputs": ["5 100", "5 110", "5 111", "6 110", "9 110", "9 100", "5 101", "9 000"], "outputs": ["0 0 0 100 100\n", "0 0 0 110 110\n", "0 0 0 111 111\n", "0 0 0 0 110 110\n", "0 0 0 0 0 110 110 110 110\n", "0 0 0 0 0 100 100 100 100\n", "0 0 0 101 101\n", "0 0 0 0 0 0 0 0 0\n"]}
coding
352
Please solve the programming task below using a self-contained code snippet in a markdown code block. The red-green-blue color "#AABBCC" can be written as "#ABC" in shorthand. For example, "#15c" is shorthand for the color "#1155cc". The similarity between the two colors "#ABCDEF" and "#UVWXYZ" is -(AB - UV)2 - (CD ...
{"functional": "def check(candidate):\n assert candidate(color = \"#09f166\") == \"#11ee66\"\n assert candidate(color = \"#4e3fe1\") == \"#5544dd\"\n\n\ncheck(Solution().similarRGB)"}
coding
184
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can be rotated to be equal to another domino...
{"functional": "def check(candidate):\n assert candidate(dominoes = [[1,2],[2,1],[3,4],[5,6]]) == 1\n assert candidate(dominoes = [[1,2],[1,2],[1,1],[1,2],[2,2]]) == 3\n\n\ncheck(Solution().numEquivDominoPairs)"}
coding
168
Solve the programming task below in a Python markdown code block. You have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest. There are $N$ submissions, numbered $1$ through $N$. For each valid $i...
{"inputs": ["1\n5\n1 3\n4 4\n4 10\n1 11\n2 7"], "outputs": ["2"]}
coding
418
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once. 24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earl...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4]) == \"23:41\"\n assert candidate(arr = [5,5,5,5]) == \"\"\n assert candidate(arr = [0,0,0,0]) == \"00:00\"\n assert candidate(arr = [0,0,1,0]) == \"10:00\"\n\n\ncheck(Solution().largestTimeFromDigits)"}
coding
168
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)"}
coding
143
Solve the programming task below in a Python markdown code block. Everybody is worried about Rakesh as the boy does not have much knowledge about the real world. He can not go from one place to another on his own. It's high time he learned to explore the city. He is going to a relative's house situated on the other sid...
{"inputs": ["2\n20 20\n4 5\n13\nLLUUUUURRRRRR\n10 10\n3 4\n7\nUDUDDRR"], "outputs": ["Case 1: REACHED\nCase 2: DANGER"]}
coding
744
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of strings dict where all the strings are of the same length. Return true if there are 2 strings that only differ by 1 character in the same index, otherwise return false.   Please complete the following ...
{"functional": "def check(candidate):\n assert candidate(dict = [\"abcd\",\"acbd\", \"aacd\"]) == True\n assert candidate(dict = [\"ab\",\"cd\",\"yz\"]) == False\n assert candidate(dict = [\"abcd\",\"cccc\",\"abyd\",\"abab\"]) == True\n\n\ncheck(Solution().differByOne)"}
coding
89
Please solve the programming task below using a self-contained code snippet in a markdown code block. A square matrix is said to be an X-Matrix if both of the following conditions hold: All the elements in the diagonals of the matrix are non-zero. All other elements are 0. Given a 2D integer array grid of size n x n...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]) == True\n assert candidate(grid = [[5,7,0],[0,3,1],[0,5,0]]) == False\n\n\ncheck(Solution().checkXMatrix)"}
coding
123
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array tasks where tasks[i] = [actuali, minimumi]: actuali is the actual amount of energy you spend to finish the ith task. minimumi is the minimum amount of energy you require to begin the ith task. ...
{"functional": "def check(candidate):\n assert candidate(tasks = [[1,2],[2,4],[4,8]]) == 8\n assert candidate(tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]) == 32\n assert candidate(tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]) == 27\n\n\ncheck(Solution().minimumEffort)"}
coding
185
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is going on a road trip and needs to apply for inter-district and inter-state travel e-passes. It takes A minutes to fill each inter-district e-pass appl...
{"inputs": ["3\n2 1 2\n00\n2 1 1\n01\n4 2 1\n1101"], "outputs": ["2\n2\n5"]}
coding
464
Solve the programming task below in a Python markdown code block. Welcome to PC Koshien, players. This year marks the 10th anniversary of Computer Koshien, but the number of questions and the total score will vary from year to year. Scores are set for each question according to the difficulty level. When the number of ...
{"inputs": ["1\n1\n0\n5\n0\n5\n2\n1\n4\n1", "1\n1\n0\n5\n0\n6\n2\n1\n4\n1", "1\n2\n4\n4\n5\n6\n7\n8\n9\n10", "1\n2\n8\n4\n5\n6\n7\n8\n9\n10", "1\n2\n8\n4\n3\n6\n7\n8\n9\n10", "1\n2\n8\n3\n3\n6\n7\n8\n9\n10", "1\n2\n8\n3\n3\n6\n7\n5\n9\n10", "1\n2\n8\n4\n3\n6\n7\n5\n9\n10"], "outputs": ["20\n", "21\n", "56\n", "60\n", "...
coding
190
Solve the programming task below in a Python markdown code block. VK gave a problem to Chef, but Chef is too lazy, so he asked you to solve the problem for him. The statement of the problem follows. Consider an integer with $N$ digits (in decimal notation, without leading zeroes) $D_1, D_2, D_3, \dots, D_N$. Here, $D_1...
{"inputs": ["1\n2 3"], "outputs": ["6"]}
coding
527
Solve the programming task below in a Python markdown code block. Aiz Onsen has a bathhouse and a pool. To use the bathhouse, you need to buy a bathing ticket, and to use the pool, you need to buy a pool ticket. Prices for these tickets may vary from day to day. In addition, Aiz Onsen has the following rules. * Ticket...
{"inputs": ["2\n100 000 1 1\n1000 500 5 2", "2\n100 000 1 1\n1010 500 5 2", "2\n110 000 1 1\n1010 500 5 2", "2\n100 100 1 1\n1000 500 5 2", "2\n110 000 1 2\n1010 500 10 2", "2\n110 000 1 2\n1010 500 17 2", "2\n110 000 2 4\n1010 500 17 2", "2\n110 000 2 4\n0010 500 17 2"], "outputs": ["100\n4800\n", "100\n4840\n", "110\...
coding
475
Solve the programming task below in a Python markdown code block. Mr. Pr and Ms. Ad are at $a$ and $b$ respectively on an infinite number line. Mr. Pr wants to meet Ms. Ad. Mr. Pr can choose to move $c$ or $d$ units in 1 second. If Mr. Pr moves $c$ units then Ms. Ad will move $d$ units and vice versa. (Both of them al...
{"inputs": ["2\n3 4 1 2\n10 20 3 7"], "outputs": ["YES\nNO"]}
coding
350
Solve the programming task below in a Python markdown code block. A group of $n$ friends living in an $m$-dimensional hyperspace want to meet up at some central location. The hyperspace is in the form of an $m$-dimensional grid, and each person can only move along grid lines. For example, to go from $(0,0)\rightarrow(1...
{"inputs": ["3 2\n1 1\n2 2\n3 3\n"], "outputs": ["2 2\n"]}
coding
630
Solve the programming task below in a Python markdown code block. Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks. The student...
{"inputs": ["1 3\n", "3 2\n", "5 0\n", "4 2\n", "6 4\n", "6 3\n", "7 3\n", "5 4\n"], "outputs": ["9\n", "8\n", "10\n", "9\n", "15\n", "14\n", "15\n", "14\n"]}
coding
334
Solve the programming task below in a Python markdown code block. There are N towns numbered 1 to N and M roads. The i-th road connects Town A_i and Town B_i bidirectionally and has a length of C_i. Takahashi will travel between these towns by car, passing through these roads. The fuel tank of his car can contain at mo...
{"inputs": ["4 0 0\n1\n2 1", "4 0 1\n1\n2 1", "4 0 1\n1\n2 1\n", "3 2 5\n1 2 3\n2 2 3\n2\n3 2\n1 3", "3 2 5\n2 2 3\n2 3 3\n2\n3 2\n1 3", "3 2 5\n1 2 3\n1 3 3\n2\n3 2\n1 3", "3 2 5\n1 2 3\n1 3 3\n2\n1 2\n1 3", "3 2 2\n1 2 3\n1 3 0\n2\n3 2\n1 3"], "outputs": ["-1\n", "-1", "-1\n", "-1\n-1\n", "0\n-1\n", "1\n0\n", "0\n0\n...
coding
634
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array rolls of length n and an integer k. You roll a k sided dice numbered from 1 to k, n times, where the result of the ith roll is rolls[i]. Return the length of the shortest sequence of rol...
{"functional": "def check(candidate):\n assert candidate(rolls = [4,2,1,2,3,3,2,4,1], k = 4) == 3\n assert candidate(rolls = [1,1,2,2], k = 2) == 2\n assert candidate(rolls = [1,1,3,2,2,2,3,3], k = 4) == 1\n\n\ncheck(Solution().shortestSequence)"}
coding
133
Solve the programming task below in a Python markdown code block. In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic perform...
{"inputs": ["1\n5\n3\n", "1\n1\n2\n", "1\n1\n1\n", "1\n1\n1\n", "1\n1\n2\n", "1\n1\n3\n", "1\n2\n3\n", "1\n2\n4\n"], "outputs": ["-1\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
505
Solve the programming task below in a Python markdown code block. You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}]. Is it possible to partition A into two non-empty [subsequences] S_{1} and S_{2} such that sum(S_{1}) \times sum(S_{2}) is odd? Here, sum(S_{1}) denotes the sum of elements in S_{1}, and sum(S_{2...
{"inputs": ["4\n4\n1 1 2 2\n6\n1 2 4 6 8 10\n2\n3 5\n3\n1 3 5"], "outputs": ["YES\nNO\nYES\nNO"]}
coding
635
Solve the programming task below in a Python markdown code block. For encoding an even-length binary string into a sequence of A, T, C, and G, we iterate from left to right and replace the characters as follows: 00 is replaced with A 01 is replaced with T 10 is replaced with C 11 is replaced with G Given a binary stri...
{"inputs": ["4\n2\n00\n4\n0011\n6\n101010\n4\n1001\n"], "outputs": ["A\nAG\nCCC\nCT"]}
coding
445
Solve the programming task below in a Python markdown code block. $n$ fishermen have just returned from a fishing vacation. The $i$-th fisherman has caught a fish of weight $a_i$. Fishermen are going to show off the fish they caught to each other. To do so, they firstly choose an order in which they show their fish (e...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "3\n4 2 1\n", "3\n4 9 1\n", "3\n4 3 1\n", "3\n4 6 1\n", "3\n4 2 1\n", "4\n1 1 4 9\n"], "outputs": ["0\n", "0\n", "6\n", "6\n", "0\n", "0\n", "6\n", "20\n"]}
coding
469
Solve the programming task below in a Python markdown code block. In the wake of the npm's `left-pad` debacle, you decide to write a new super padding method that superceds the functionality of `left-pad`. Your version will provide the same functionality, but will additionally add right, and justified padding of string...
{"functional": "_inputs = [['test', 10], ['test', 10, 'x'], ['test', 10, 'xO'], ['test', 10, 'xO-'], ['some other test', 10, 'nope'], ['some other test', 10, '> '], ['test', 7, '>nope'], ['test', 7, '^more complex'], ['test', 7, ''], ['test', 10, '< '], ['test', 3], ['test', 3, '> '], ['test', 10, ''], ['test', 10, '>'...
coding
482
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices. You must perform an operation shift(c, x), where c is a character and x is a digit, that returns...
{"functional": "def check(candidate):\n assert candidate(s = \"a1c1e1\") == \"abcdef\"\n assert candidate(s = \"a1b2c3d4e\") == \"abbdcfdhe\"\n\n\ncheck(Solution().replaceDigits)"}
coding
212
Solve the programming task below in a Python markdown code block. The goal of this Kata is to remind/show you, how Z-algorithm works and test your implementation. For a string str[0..n-1], Z array is of same length as string. An element Z[i] of Z array stores length of the longest substring starting from str[i] which ...
{"functional": "_inputs = [['ababcaba'], [''], ['aaaaaaaa'], ['ababababab'], ['aaaa$aaaa'], ['abracadabra']]\n_outputs = [[[8, 0, 2, 0, 0, 3, 0, 1]], [[]], [[8, 7, 6, 5, 4, 3, 2, 1]], [[10, 0, 8, 0, 6, 0, 4, 0, 2, 0]], [[9, 3, 2, 1, 0, 4, 3, 2, 1]], [[11, 0, 0, 1, 0, 1, 0, 4, 0, 0, 1]]]\nimport math\ndef _deep_eq(a, b,...
coding
345
Solve the programming task below in a Python markdown code block. An electronics shop sells red and blue lamps. A red lamp costs X rupees and a blue lamp costs Y rupees. Chef is going to buy exactly N lamps from this shop. Find the minimum amount of money Chef needs to pay such that at least K of the lamps bought are ...
{"inputs": ["4\n2 2 5 1\n4 1 3 1\n3 0 4 7\n5 2 3 4\n"], "outputs": ["10\n6\n12\n15\n"]}
coding
364
Solve the programming task below in a Python markdown code block. Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, so...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n0 1\n", "2\n0 1\n", "2\n0 0\n", "3\n1 0 0\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]}
coding
384
Solve the programming task below in a Python markdown code block. Chef's current rating is X, and he wants to improve it. It is generally recommended that a person with rating X should solve problems whose difficulty lies in the range [X, X+200], i.e, problems whose difficulty is at least X and at most X+200. You find...
{"inputs": ["5\n1300 1500\n1201 1402\n300 4000\n723 805\n1330 512\n"], "outputs": ["YES\nNO\nNO\nYES\nNO\n"]}
coding
667
Solve the programming task below in a Python markdown code block. There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student h...
{"inputs": ["2 2\n2 0\n0 -1\n0 0\n1 1", "2 2\n2 0\n0 0\n0 -1\n1 0", "2 2\n2 0\n0 -1\n0 0\n1 0", "2 2\n2 0\n0 0\n0 -1\n1 1", "2 2\n2 1\n0 0\n0 -1\n1 1", "2 2\n2 0\n1 -1\n0 0\n1 1", "2 2\n2 0\n1 -1\n1 0\n1 1", "2 2\n2 0\n0 0\n-1 0\n1 0"], "outputs": ["1\n1\n", "2\n1\n", "2\n1\n", "2\n1\n", "2\n1\n", "1\n1\n", "1\n1\n", "...
coding
503
Solve the programming task below in a Python markdown code block. Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak. There is a sequence a that consists of n int...
{"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n-1\n", "1\n-2\n", "1\n-4\n", "1\n-5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
298
Solve the programming task below in a Python markdown code block. A hypergraph is a generalization of a graph, where an edge can connect any number of vertices. A k-uniform hypergraph is a hypergraph such that all its hyperedges have size k. For more information, see Wikipedia. Let's call a particular hypergraph a hyp...
{"inputs": ["4\n3\n4\n5\n8\n\n"], "outputs": ["1\n6\n25\n93268"]}
coding
492
Solve the programming task below in a Python markdown code block. Tom has finally taken over the business empire and now looking for a new Name of the business to make a new start. Joe (Tom's dear friend) suggested a string $S$ consisting of Uppercase and lowercase letters Tom wants to make some changes as pe...
{"inputs": ["CodeSprInT"], "outputs": [".c.d.s.p.r.n.t"]}
coding
408
Solve the programming task below in a Python markdown code block. The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palin...
{"inputs": ["3\nAAA\n", "3\nABA\n", "3\nBBB\n", "3\nBAA\n", "3\nAAB\n", "3\nBBA\n", "3\nBAB\n", "3\nABB\n"], "outputs": ["3\n", "1\n", "3\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
523
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the value of the bitwise OR of the sum of all possible subsequences in the array. A subsequence is a sequence that can be derived from another sequence by removing zero or more elem...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,0,3]) == 7\n assert candidate(nums = [0,0,0]) == 0\n\n\ncheck(Solution().subsequenceSumOr)"}
coding
103
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root node of a binary tree, your task is to create a string representation of the tree following a specific set of formatting rules. The representation should be based on a preorder traversal of the binary t...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4])) == \"1(2(4))(3)\"\n assert candidate(root = tree_node([1,2,3,None,4])) == \"1(2()(4))(3)\"\n\n\ncheck(Solution().tree2str)"}
coding
400
Solve the programming task below in a Python markdown code block. Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with coordinates (xv, yv) and (xp...
{"inputs": ["0 0\n5 0\n1 0 2 0\n3 0 4 0\n", "0 0\n2 0\n0 2 2 2\n1 1 1 0\n", "0 0\n3 0\n0 2 2 2\n1 0 2 0\n", "0 0\n3 0\n1 0 2 0\n0 2 2 2\n", "0 1\n5 0\n1 0 2 0\n3 0 4 0\n", "0 0\n3 0\n0 2 2 2\n1 1 1 0\n", "0 0\n4 0\n0 2 2 2\n1 0 2 0\n", "0 0\n2 0\n1 1 1 -1\n0 2 2 2\n"], "outputs": ["NO", "NO", "YES", "YES", "YES\n", "NO...
coding
661
Solve the programming task below in a Python markdown code block. Given are integer sequence of length N, A = (A_1, A_2, \cdots, A_N), and an integer K. For each X such that 1 \le X \le K, find the following value: \left(\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} (A_L+A_R)^X\right) \bmod 998244353 -----Constraint...
{"inputs": ["3 3\n1 2 3\n", "2 5\n1234 5678\n", "10 10\n1 1 1 1 1 1 1 1 1 1\n", "7 49\n54 467 215 289 425 19 141\n", "107 265\n90 386 93 4 172 493 454 221 132 60 123 482 181 64 236 365 371 394 458 175 456 310 254 429 274 495 316 126 383 364 352 215 140 335 180 362 374 345 112 45 107 154 221 20 211 307 203 113 52 263 35...
coding
440
Solve the programming task below in a Python markdown code block. ​A 1-indexed array is called *positive* if every element of the array is greater than or equal to the index on which it lies. Formally, an array B of size M is called positive if B_{i} ≥ i for each 1≤ i ≤ M. For example, the arrays [1], [2, 2], [3, 2, 4...
{"inputs": ["5\n3\n2 3 3\n4\n3 1 1 2\n3\n1 1 1\n5\n1 2 2 4 5\n6\n3 2 1 2 2 1\n"], "outputs": ["1\n2\n3\n2\n3\n"]}
coding
590
Solve the programming task below in a Python markdown code block. Given a time in $12$-hour AM/PM format, convert it to military (24-hour) time. Note: - 12:00:00AM on a 12-hour clock is 00:00:00 on a 24-hour clock. - 12:00:00PM on a 12-hour clock is 12:00:00 on a 24-hour clock. Example $\textbf{s}=\textbf{'...
{"inputs": ["07:05:45PM\n"], "outputs": ["19:05:45\n"]}
coding
339
Solve the programming task below in a Python markdown code block. Shaun is very much interested in Subarrays. Shaun wants to count the number of subarrays in his chosen array with sum being a multiple of $10^9$. Since, Shaun is interested in huge numbers.He chose his array such that it contains only $10^8$ and $9*10^8$...
{"inputs": ["2\n3\n100000000 900000000 100000000\n1\n900000000"], "outputs": ["2\n0"]}
coding
295
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell. You have two robots that can collect cherries for ...
{"functional": "def check(candidate):\n assert candidate(grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]) == 24\n assert candidate(grid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]) == 28\n assert candidate(grid = [[1,0,0,3],[0,0,0,3],[0,0,3,3],[9,0,3,3]]) == 22\n assert cand...
coding
260
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...
coding
181
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3. Note that the average of n elements is the sum of the n elements divided by n and rounded down t...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,6,10,12,15]) == 9\n assert candidate(nums = [1,2,4,7,10]) == 0\n\n\ncheck(Solution().averageValue)"}
coding
97
Solve the programming task below in a Python markdown code block. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≤ i, j ≤ n). In other words, let's con...
{"inputs": ["1 1\n-4\n", "2 4\n2 0\n", "2 4\n2 1\n", "3 3\n1 1 2\n", "3 7\n5 4 3\n", "3 5\n1 1 2\n", "3 7\n5 0 3\n", "3 3\n3 1 5\n"], "outputs": ["-4 -4\n", "2 2\n", "2 2\n", "1 1\n", "5 3\n", "1 2\n", "5 0\n", "1 5\n"]}
coding
595
Solve the programming task below in a Python markdown code block. Task: Given an array arr of strings complete the function landPerimeter by calculating the total perimeter of all the islands. Each piece of land will be marked with 'X' while the water fields are represented as 'O'. Consider each tile being a perfect 1 ...
{"functional": "_inputs = [[['OXOOOX', 'OXOXOO', 'XXOOOX', 'OXXXOO', 'OOXOOX', 'OXOOOO', 'OOXOOX', 'OOXOOO', 'OXOOOO', 'OXOOXX']], [['OXOOO', 'OOXXX', 'OXXOO', 'XOOOO', 'XOOOO', 'XXXOO', 'XOXOO', 'OOOXO', 'OXOOX', 'XOOOO', 'OOOXO']], [['XXXXXOOO', 'OOXOOOOO', 'OOOOOOXO', 'XXXOOOXO', 'OXOXXOOX']], [['XOOOXOO', 'OXOOOOO'...
coding
200
Solve the programming task below in a Python markdown code block. You are given an integer $n$. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by $7$. If there are multiple ways to do it, print any of them. If the given nu...
{"inputs": ["3\n42\n23\n377\n"], "outputs": ["42\n28\n378\n"]}
coding
362
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 an array of N integers. You should support the following queries on this array. 0 L R : Find the minimum integer in the range A_{L}, A_{L+1}, ..., A_{R}. 1 L R...
{"inputs": ["5 5\n1 5 2 3 4\n0 2 5\n1 1 5 6\n0 2 2\n1 2 5 3\n0 1 3"], "outputs": ["2\n4\n0"]}
coding
285
Solve the programming task below in a Python markdown code block. Andrzej was given a task: There are n jars with pills. In every jar there is a different type of pill and the amount of pills in each jar is infinite. One type of pill makes a person glow about 30 minutes after taking and none of the other types has any ...
{"functional": "_inputs = [[0], [1], [2], [4], [3], [16]]\n_outputs = [[0], [0], [0], [1], [1], [3]]\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) != ...
coding
309
Solve the programming task below in a Python markdown code block. Create a function with two arguments that will return an array of the first (n) multiples of (x). Assume both the given number and the number of times to count will be positive numbers greater than 0. Return the results as an array (or list in Python...
{"functional": "_inputs = [[1, 5], [2, 5], [3, 5], [50, 5], [100, 5]]\n_outputs = [[[1, 2, 3, 4, 5]], [[2, 4, 6, 8, 10]], [[3, 6, 9, 12, 15]], [[50, 100, 150, 200, 250]], [[100, 200, 300, 400, 500]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i...
coding
161
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents...
{"functional": "def check(candidate):\n assert candidate(equations = [[\"a\",\"b\"],[\"b\",\"c\"]], values = [2.0,3.0], queries = [[\"a\",\"c\"],[\"b\",\"a\"],[\"a\",\"e\"],[\"a\",\"a\"],[\"x\",\"x\"]]) == [6.00000,0.50000,-1.00000,1.00000,-1.00000]\n assert candidate(equations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"b...
coding
229
Solve the programming task below in a Python markdown code block. find the sum of the even fibonacci numbers till the given number(it is the value not index). INPUT: T test cases next T lines consists of a number n. OUTPUT: Output the sum value. 0<t<10 2<n<10^20 Example: if n=10 the numbers which are less than 10 are...
{"inputs": ["5\n14576\n145786\n1254478\n147852\n125478", "10\n457866622145522214789856\n321245663325\n12254\n14221\n14256\n145\n256\n125\n1254785632145632145\n14789666620000000"], "outputs": ["14328\n60696\n1089154\n60696\n60696", "390887039715493615101718\n112925716858\n14328\n14328\n14328\n188\n188\n44\n8899897080023...
coding
125
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences. Return the minimum number of subseq...
{"functional": "def check(candidate):\n assert candidate(nums = [3,6,1,2,5], k = 2) == 2\n assert candidate(nums = [1,2,3], k = 1) == 2\n assert candidate(nums = [2,2,4,5], k = 0) == 3\n\n\ncheck(Solution().partitionArray)"}
coding
144
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array arr. In one move, you can select a palindromic subarray arr[i], arr[i + 1], ..., arr[j] where i <= j, and remove that subarray from the given array. Note that after removing a subarray, ...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2]) == 2\n assert candidate(arr = [1,3,4,1,5]) == 3\n\n\ncheck(Solution().minimumMoves)"}
coding
144
Solve the programming task below in a Python markdown code block. Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible improvemen...
{"inputs": ["2\n2 1\n", "2\n2 1\n", "2\n1 2\n", "3\n2 1\n3 2\n", "3\n2 1\n3 2\n", "4\n1 2\n1 3\n1 4\n", "4\n1 2\n2 3\n3 4\n", "4\n1 2\n1 3\n3 4\n"], "outputs": ["1\n", "1\n", "1\n", "3\n", "3\n", "6\n", "7\n", "7\n"]}
coding
622
Solve the programming task below in a Python markdown code block. Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple of the s...
{"inputs": ["3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n3 5", "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n1 5", "3\n1\n2 3\n2\n4 5\n5 6\n1\n2 3\n3 5", "3\n1\n1 3\n2\n6 5\n5 6\n1\n2 6\n5 5", "3\n1\n2 3\n2\n4 5\n5 3\n1\n2 3\n3 5", "3\n1\n2 3\n2\n6 2\n5 6\n1\n2 6\n3 5", "3\n1\n2 1\n2\n6 5\n5 6\n1\n2 3\n1 5", "3\n1\n2 1\n2\n6 5\n5 3\n1\n2 3\n1 ...
coding
513
Solve the programming task below in a Python markdown code block. You are given positive integers $N$ and $D$. You may perform operations of the following two types: - add $D$ to $N$, i.e. change $N$ to $N+D$ - change $N$ to $\mathop{\mathrm{digitsum}}(N)$ Here, $\mathop{\mathrm{digitsum}}(x)$ is the sum of decimal dig...
{"inputs": ["3\n2 1\n9 3\n11 13\n"], "outputs": ["1 9\n3 2\n1 4"]}
coding
580
Solve the programming task below in a Python markdown code block. Bob is a lazy man. He needs you to create a method that can determine how many ```letters``` and ```digits``` are in a given string. Example: "hel2!lo" --> 6 "wicked .. !" --> 6 "!?..A" --> 1 Also feel free to reuse/extend the following starter c...
{"functional": "_inputs = [['n!!ice!!123'], ['de?=?=tttes!!t'], [''], ['!@#$%^&`~.'], ['u_n_d_e_r__S_C_O_R_E']]\n_outputs = [[7], [8], [0], [0], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if is...
coding
97
Solve the programming task below in a Python markdown code block. Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows n airports. All...
{"inputs": ["1 1 1\n1\n", "1 1 1\n0\n", "1 1 1\n1\n", "1 1 1\n0\n", "1 1 1\n2\n", "2 1 2\n01\n", "2 2 1\n01\n", "2 1 2\n10\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "1", "1", "1"]}
coding
558
Solve the programming task below in a Python markdown code block. Given a name, turn that name into a perfect square matrix (nested array with the amount of arrays equivalent to the length of each array). You will need to add periods (`.`) to the end of the name if necessary, to turn it into a matrix. If the name h...
{"functional": "_inputs = [[''], ['G'], ['Beyonce'], ['Franklin'], ['Bill'], ['Frank']]\n_outputs = [['name must be at least one letter'], [[['G']]], [[['B', 'e', 'y'], ['o', 'n', 'c'], ['e', '.', '.']]], [[['F', 'r', 'a'], ['n', 'k', 'l'], ['i', 'n', '.']]], [[['B', 'i'], ['l', 'l']]], [[['F', 'r', 'a'], ['n', 'k', '....
coding
162
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, replace each element with its rank. The rank represents how large the element is. The rank has the following rules: Rank is an integer starting from 1. The larger the element, the larg...
{"functional": "def check(candidate):\n assert candidate(arr = [40,10,20,30]) == [4,1,2,3]\n assert candidate(arr = [100,100,100]) == [1,1,1]\n assert candidate(arr = [37,12,28,9,100,56,80,5,12]) == [5,3,4,2,8,6,7,1,3]\n\n\ncheck(Solution().arrayRankTransform)"}
coding
121
Solve the programming task below in a Python markdown code block. Polycarp likes arithmetic progressions. A sequence $[a_1, a_2, \dots, a_n]$ is called an arithmetic progression if for each $i$ ($1 \le i < n$) the value $a_{i+1} - a_i$ is the same. For example, the sequences $[42]$, $[5, 5, 5]$, $[2, 11, 20, 29]$ and $...
{"inputs": ["3\n1 2 1\n", "3\n2 1 2\n", "3\n5 9 5\n", "3\n3 1 2\n", "3\n1 9 4\n", "3\n2 1 3\n", "3\n9 3 6\n", "3\n2 1 2\n"], "outputs": ["1\n", "1\n", "-1\n", "2\n", "-1\n", "2\n", "-1\n", "1\n"]}
coding
708
Solve the programming task below in a Python markdown code block. ## Grade book Complete the function so that it finds the mean of the three scores passed to it and returns the letter value associated with that grade. Numerical Score | Letter Grade --- | --- 90 <= score <= 100 | 'A' 80 <= score < 90...
{"functional": "_inputs = [[95, 90, 93], [100, 85, 96], [92, 93, 94], [100, 100, 100], [70, 70, 100], [82, 85, 87], [84, 79, 85], [70, 70, 70], [75, 70, 79], [60, 82, 76], [65, 70, 59], [66, 62, 68], [58, 62, 70], [44, 55, 52], [48, 55, 52], [58, 59, 60], [0, 0, 0]]\n_outputs = [['A'], ['A'], ['A'], ['A'], ['B'], ['B']...
coding
181
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers: You should build the array arr which has the following properties: arr has exac...
{"functional": "def check(candidate):\n assert candidate(n = 2, m = 3, k = 1) == 6\n assert candidate(n = 5, m = 2, k = 3) == 0\n assert candidate(n = 9, m = 1, k = 1) == 1\n\n\ncheck(Solution().numOfArrays)"}
coding
168
Solve the programming task below in a Python markdown code block. Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that w...
{"inputs": ["1\n4\n", "1\n4\n", "1\n1\n", "1\n87\n", "1\n87\n", "1\n79\n", "1\n41\n", "1\n52\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0", "0\n", "0\n", "0\n"]}
coding
298
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times: Choose two different indices i and j where 0 <= i, j < n. Simultaneously, rep...
{"functional": "def check(candidate):\n assert candidate(s = \"1010\", target = \"0110\") == True\n assert candidate(s = \"11\", target = \"00\") == False\n\n\ncheck(Solution().makeStringsEqual)"}
coding
240
Solve the programming task below in a Python markdown code block. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y to...
{"inputs": ["3\n3 1 3", "3\n3 1 5", "3\n1 1 5", "3\n1 1 8", "3\n0 1 8", "3\n0 1 2", "3\n0 1 1", "3\n1 1 1"], "outputs": ["15\n", "23\n", "11\n", "17\n", "8\n", "2\n", "1\n", "3\n"]}
coding
360
Solve the programming task below in a Python markdown code block. Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to choose some elements of this sequence (possibly none or all of them) and compute their MEX, i.e. the smallest positive integer which does not occur among the chosen elements. F...
{"inputs": ["1\n3 3\n1 2 4\n"], "outputs": ["3"]}
coding
388
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. You are given a string moves that represe...
{"functional": "def check(candidate):\n assert candidate(moves = \"UD\") == True\n assert candidate(moves = \"LL\") == False\n\n\ncheck(Solution().judgeCircle)"}
coding
228
Solve the programming task below in a Python markdown code block. Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the ch...
{"inputs": ["3 3 0 3\n0 2 3", "3 3 0 6\n0 2 3", "3 4 0 3\n1 2 3", "3 6 0 3\n0 2 3", "0 3 0 6\n0 2 3", "3 3 0 3\n1 2 3", "3 3 -1 6\n0 2 3", "3 3 -1 7\n0 2 3"], "outputs": ["2", "0", "2", "2", "0", "2", "0", "0"]}
coding
283
Solve the programming task below in a Python markdown code block. There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated g...
{"inputs": ["1\n100"], "outputs": ["NO"]}
coding
278
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, y...
{"inputs": ["3\n2\n4\n8"], "outputs": ["1\n2\n3"]}
coding
429
Solve the programming task below in a Python markdown code block. Chef decided to redecorate his house, and now needs to decide between two different styles of interior design. For the first style, tiling the floor will cost X_{1} rupees and painting the walls will cost Y_{1} rupees. For the second style, tiling the ...
{"inputs": ["4\n10 20 9 25\n10 20 9 20\n10 20 20 10\n100 43 85 61\n"], "outputs": ["30\n29\n30\n143"]}
coding
569