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. Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning o...
{"inputs": ["5 5 2 1\n", "1 1 2 2\n", "1 1 1 1\n", "3 1 3 4\n", "1 4 1 5\n", "5 4 1 4\n", "2 3 4 5\n", "2 2 5 4\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "1\n", "3\n", "4\n"]}
coding
390
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of positive integers nums. A triplet of three distinct indices (i, j, k) is called a single divisor triplet of nums if nums[i] + nums[j] + nums[k] is divisible by exactly one of nums[i]...
{"functional": "def check(candidate):\n assert candidate(nums = [4,6,7,3,2]) == 12\n assert candidate(nums = [1,2,2]) == 6\n assert candidate(nums = [1,1,1]) == 0\n\n\ncheck(Solution().singleDivisorTriplet)"}
coding
125
Solve the programming task below in a Python markdown code block. King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital. The mausoleum will be constructed from 2n...
{"inputs": ["3 0\n", "2 0\n", "3 0\n", "35 0\n", "30 0\n", "30 0\n", "35 0\n", "3 1\n2 > 3\n"], "outputs": ["9\n", "3\n", "9\n", "16677181699666569\n", "68630377364883\n", "68630377364883\n", "16677181699666569", "1\n"]}
coding
665
Solve the programming task below in a Python markdown code block. You are given a sequence $A_1, A_2, \ldots, A_N$. You want all the elements of the sequence to be equal. In order to achieve that, you may perform zero or more moves. In each move, you must choose an index $i$ ($1 \le i \le N$), then choose $j = i-1$ or ...
{"inputs": ["3\n5\n1 1 1 1 1\n4\n9 8 1 8\n2\n1 9"], "outputs": ["0\n2\n1"]}
coding
419
Solve the programming task below in a Python markdown code block. Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible by $m$ are...
{"inputs": ["7\n1 1\n0 1\n101 4\n920 40\n335186385 972\n18 7\n1372032350266432 10\n", "7\n1 1\n10 1\n111 4\n1439 40\n335186385 379\n87 7\n1372032350266432 6\n", "7\n1 1\n0 1\n101 4\n920 40\n335186385 972\n137 7\n1372032350266432 10\n", "7\n1 2\n10 1\n111 4\n1439 40\n335186385 379\n87 7\n1372032350266432 6\n", "7\n1 1\n...
coding
374
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n flights that are labeled from 1 to n. You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with ...
{"functional": "def check(candidate):\n assert candidate(bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5) == [10,55,45,25,25]\n assert candidate(bookings = [[1,2,10],[2,2,15]], n = 2) == [10,25]\n\n\ncheck(Solution().corpFlightBookings)"}
coding
142
Solve the programming task below in a Python markdown code block. Write a function `count_vowels` to count the number of vowels in a given string. ### Notes: - Return `nil` or `None` for non-string inputs. - Return `0` if the parameter is omitted. ### Examples: ```python count_vowels("abcdefg") => 2 count_vowels("a...
{"functional": "_inputs = [['abcdefg'], ['asdfdsafdsafds'], [''], ['asdfdsaf asdfsdaf 13243242 dsafdsafds'], ['aeiouAEIOU'], ['1213'], ['12 3'], ['ewqriwetruituofdsajflsd23423r5043'], ['asdfviosdfopsiewrwwer asdf asdfdsaf)(asdflkajdsf '], ['asdfdsaf asdfsasdfdsafgjlsdjf asdfdsf daf 13243242 dsafdsafds...
coding
133
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, ...
{"inputs": ["2\n9 2\n110001111\n4 1\n1001"], "outputs": ["2\n2"]}
coding
637
Solve the programming task below in a Python markdown code block. Elon Musk has succesfully built an automated staircase from Earth to Mars. Many people want to go to Mars, but that's not possible due to limited capacity of the staircase and logistics involved. Hence, Elon asks interested candidates to solve a tough ch...
{"inputs": ["2\n10 2 \n12 1\n"], "outputs": ["63\n10\n"]}
coding
383
Solve the programming task below in a Python markdown code block. Teddy and Freddy are two friends. Teddy has a pile of strings of size $N$. Each string $Si$ in the pile has length less or equal to $100$ ($len(Si) \leq 100$). Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size $M$. Tedd...
{"inputs": ["4\na\naa\naaa\naaaa\n5\naaaaa", "4\na\nabc\nabcd\nabcde\n5\naaaaa"], "outputs": ["4", "1"]}
coding
412
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array.   Please complete the following python code precisely: ```python cl...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,0,0,2,0,0,4]) == 6\n assert candidate(nums = [0,0,0,2,0,0]) == 9\n assert candidate(nums = [2,10,2019]) == 0\n\n\ncheck(Solution().zeroFilledSubarray)"}
coding
82
Solve the programming task below in a Python markdown code block. You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are ...
{"inputs": ["5\n0\n0\n0", "5\n0\n1\n0", "5\n1\n1\n0", "5\n2\n1\n0", "5\n0\n0\n1", "5\n0\n0\n2", "5\n0\n1\n2", "5\n1\n1\n2"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
coding
290
Solve the programming task below in a Python markdown code block. You are given $n$ dominoes. Each domino has a left and a right cell. Each cell can be colored either black or white. Some cells are already colored, while some aren't yet. The coloring is said to be valid if and only if it is possible to rearrange the d...
{"inputs": ["1\n?W\n", "1\nW?\n", "1\n?W\n", "2\n??\nW?\n", "2\n??\n?W\n", "2\n??\nW?\n", "4\nBB\n??\nW?\n??\n", "4\nBB\n??\n?W\n??\n"], "outputs": ["1\n", "1\n", "1", "2\n", "2\n", "2", "10\n", "10\n"]}
coding
467
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums. The next greater number of a number x is the first greater nu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1]) == [2,-1,2]\n assert candidate(nums = [1,2,3,4,3]) == [2,3,4,-1,4]\n\n\ncheck(Solution().nextGreaterElements)"}
coding
138
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are $N$ cars (numbered $1$ through $N$) on a circular track with length $N$. For each $i$ ($2 ≤ i ≤ N$), the $i$-th of them is at a distance $i...
{"inputs": ["3\n3\n1 1 1\n1 1 1\n3\n3 0 0\n10 0 0\n3\n3 3 3\n3 2 1"], "outputs": ["3\n30\n3"]}
coding
654
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Masha has $N$ minions. Each minion has two characteristics: power $a$ and endurance $b$. Masha thinks that a non-empty set of minions $\{m_{1}, m_{2}, \dots, m_{k}\}$ with ch...
{"inputs": ["2\n3\n1 4\n3 3\n2 1\n2\n3 5\n1 4"], "outputs": ["2\n0"]}
coding
535
Please solve the programming task below using a self-contained code snippet in a markdown code block. A critical point in a linked list is defined as either a local maxima or a local minima. A node is a local maxima if the current node has a value strictly greater than the previous node and the next node. A node is a ...
{"functional": "def check(candidate):\n assert candidate(head = list_node([3,1])) == [-1,-1]\n assert candidate(head = list_node([5,3,1,2,5,1,2])) == [1,3]\n assert candidate(head = list_node([1,3,2,2,3,2,2,2,7])) == [3,3]\n assert candidate(head = list_node([2,3,3,2])) == [-1,-1]\n\n\ncheck(Solution().node...
coding
254
Solve the programming task below in a Python markdown code block. Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: - a root node. - a binary tree called its left subtree. - a binary t...
{"inputs": ["9\n0 2 4\n1 0 3\n2 -1 -1\n3 0 0\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 0\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 1 4\n1 2 5\n2 -1 -1\n3 -1 -1\n4 3 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 1 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1",...
coding
512
Solve the programming task below in a Python markdown code block. Polycarp has come up with a new game to play with you. He calls it "A missing bigram". A bigram of a word is a sequence of two adjacent letters in it. For example, word "abbaaba" contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba". The game goes as...
{"inputs": ["4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ab bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ab bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa ab ab\n3\naa\n5\nbb ab bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ba bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa bb ba\n3\naa\...
coding
711
Solve the programming task below in a Python markdown code block. Chef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular time interva...
{"inputs": ["1\n4 2\n1 10 1\n10 20 2\n15 50 2\n20 30 2"], "outputs": ["3"]}
coding
468
Solve the programming task below in a Python markdown code block. It's Friday night, and Chuck is bored. He's already run 1,000 miles, stopping only to eat a family sized bag of Heatwave Doritos and a large fistful of M&Ms. He just can't stop thinking about kicking something! There is only one thing for it, Chuck hea...
{"functional": "_inputs = [[['*****************************************', '** _O_ * _O_ * _O_ * _O_ **', '** /(.)J * C(.)J * /(.)J * C(.)J **', '** _| |_ * _| |_ * _( )_ * _( )_ *']], [['*** _O_ ** _O_ ** _O_ ** _O_ ***', '*** /(.)J ** /(.)J ** C(.)J ** C(.)J ***', '*** _| ...
coding
303
Solve the programming task below in a Python markdown code block. Paul is an excellent coder and sits high on the CW leaderboard. He solves kata like a banshee but would also like to lead a normal life, with other activities. But he just can't stop solving all the kata!! Given an array (x) you need to calculate the Pa...
{"functional": "_inputs = [[['life', 'eating', 'life']], [['life', 'Petes kata', 'Petes kata', 'Petes kata', 'eating']], [['Petes kata', 'Petes kata', 'eating', 'Petes kata', 'Petes kata', 'eating']]]\n_outputs = [['Super happy!'], ['Super happy!'], ['Happy!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinst...
coding
193
Solve the programming task below in a Python markdown code block. You are given $4n$ sticks, the length of the $i$-th stick is $a_i$. You have to create $n$ rectangles, each rectangle will consist of exactly $4$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length an...
{"inputs": ["1\n2\n3 3 4 4 4 4 6 6\n", "1\n2\n3 3 4 4 4 4 6 6\n", "1\n2\n3 3 4 4 4 4 6 4\n", "1\n2\n3 3 4 4 8 4 6 6\n", "1\n2\n3 3 6 4 4 4 6 4\n", "1\n2\n3 3 6 4 4 7 6 4\n", "1\n2\n6 3 6 4 4 7 6 4\n", "1\n2\n3 3 4 4 4 4 1 6\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
470
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid. A code snippet is valid if all the following rules hold: The code must be wrapped in a valid clo...
{"functional": "def check(candidate):\n assert candidate(code = \"<DIV>This is the first line <![CDATA[<div>]]></DIV>\") == True\n assert candidate(code = \"<DIV>>> ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>\") == True\n assert candidate(code = \"<A> <B> </A> </B>\") == False\n\n\ncheck(Solution().isValid)"...
coding
418
Solve the programming task below in a Python markdown code block. You are given three integers $a$, $b$, and $c$. Determine if one of them is the sum of the other two. -----Input----- The first line contains a single integer $t$ ($1 \leq t \leq 9261$) — the number of test cases. The description of each test case co...
{"inputs": ["1\n14 5 14\n", "1\n19 18 16\n", "7\n1 4 3\n2 5 8\n9 11 20\n0 0 0\n20 20 20\n4 12 3\n15 7 8\n", "12\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "19\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10...
coding
307
Solve the programming task below in a Python markdown code block. For years you have been working hard in Santa's factory to manufacture gifts for kids in substandard work environments with no pay. You have finally managed to escape the factory and now you seek revenge. You are planning a heist with the Grinch to steal...
{"inputs": ["3\n4 9\n5 10\n42 9999999967"], "outputs": ["6\n1\n9999999966"]}
coding
313
Solve the programming task below in a Python markdown code block. Chef has a pepperoni pizza in the shape of a $N \times N$ grid; both its rows and columns are numbered $1$ through $N$. Some cells of this grid have pepperoni on them, while some do not. Chef wants to cut the pizza vertically in half and give the two hal...
{"inputs": ["2\n6\n100000\n100000\n100000\n100000\n010010\n001100\n4\n0011\n1100\n1110\n0001"], "outputs": ["2\n0"]}
coding
668
Solve the programming task below in a Python markdown code block. An array $a$ is good if for all pairs of adjacent elements, $a_i$ and $a_{i+1}$ ($1\le i \lt n$) are of different parity. Note that an array of size $1$ is trivially good. You are given an array of size $n$. In one operation you can select any pair of ...
{"inputs": ["1\n1\n9\n", "1\n10\n4 4 4 4 4 4 4 4 4 5\n", "3\n5\n1 7 11 2 13\n4\n1 2 3 4\n6\n1 1 1 2 2 3\n", "2\n10\n1 1 1 1 1 5 5 5 5 5\n11\n9 9 9 9 9 10 9 9 9 9 9\n", "1\n20\n1 2 3 4 4 5 5 6 6 7 7 9 9 9 9 10 10 124 241 241\n", "30\n1\n1\n1\n2\n2\n1 1\n2\n1 2\n2\n2 1\n2\n2 2\n3\n1 1 1\n3\n1 1 2\n3\n1 2 1\n3\n1 2 2\n3\n...
coding
472
Solve the programming task below in a Python markdown code block. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statue...
{"inputs": [".SSSSSSA\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\nMSSSSSSS\n", "S..SSSSA\n...S.S.S\n.SS.SS.S\nSS....SS\n.S.SSSS.\n...S.S.S\n..S..S..\nMSSSSS.S\n", ".SSSS.SA\n.SS.SSS.\n..S.SS..\nSSSS.SS.\nS.S.....\nS.S.SSSS\nS..SS..S\nMS.SS.SS\n", ".......A\n........\n........\n........\n.S......\nS.......
coding
570
Solve the programming task below in a Python markdown code block. Sevenkplus has a regular polygon. Each vertex of the polygon has a color, either white or black. Sevenkplus wants to count the number of isosceles triangles whose vertices are vertices of the regular polygon and have the same color. Input Format The...
{"inputs": ["5\n001\n0001\n10001\n111010\n1101010\n"], "outputs": ["Case 1: 0\nCase 2: 1\nCase 3: 1\nCase 4: 2\nCase 5: 3\n"]}
coding
336
Solve the programming task below in a Python markdown code block. Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N. Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds: * Choose two disti...
{"inputs": ["3\n1 3 3\n2 2 2", "3\n1 3 2\n2 2 3", "3\n1 3 6\n2 2 2", "3\n1 3 2\n3 2 3", "3\n1 3 6\n2 2 4", "3\n2 3 2\n3 2 3", "3\n1 3 6\n3 2 4", "3\n2 3 2\n5 2 3"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n"]}
coding
274
Solve the programming task below in a Python markdown code block. Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maxi...
{"inputs": ["2\n1 1\n", "2\n1 2\n", "2\n1 2\n", "2\n1 1\n", "2\n1 3\n", "2\n2 1\n", "2\n0 0\n", "2\n1 0\n"], "outputs": ["0", "1", "1\n", "0\n", "2\n", "1\n", "0\n", "1\n"]}
coding
381
Solve the programming task below in a Python markdown code block. Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers fr...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n-3\n", "1\n-4\n", "1\n-1\n", "2\n0 0\n", "2\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
255
Solve the programming task below in a Python markdown code block. ## Emotional Sort ( ︶︿︶) You'll have a function called "**sortEmotions**" that will return an array of **emotions** sorted. It has two parameters, the first parameter called "**arr**" will expect an array of **emotions** where an **emotion** will be one...
{"functional": "_inputs = [[[':D', 'T_T', ':D', ':('], True], [['T_T', ':D', ':(', ':('], True], [[':)', 'T_T', ':)', ':D', ':D'], True], [[':D', 'T_T', ':D', ':('], False], [['T_T', ':D', ':(', ':('], False], [[':)', 'T_T', ':)', ':D', ':D'], False], [[], False], [[], True]]\n_outputs = [[[':D', ':D', ':(', 'T_T']], [...
coding
439
Solve the programming task below in a Python markdown code block. Given an array $a$ of length $n$, you can do at most $k$ operations of the following type on it: choose $2$ different elements in the array, add $1$ to the first, and subtract $1$ from the second. However, all the elements of $a$ have to remain non-nega...
{"inputs": ["1\n3 1\n1 8 9\n", "1\n3 1\n3 1 9\n", "1\n3 1\n1 0 1\n", "2\n3 1\n3 1 4\n2 10\n1 0\n"], "outputs": ["0 8 10 \n", "2 1 10 \n", "0 0 2 \n", "2 1 5 \n0 1 \n"]}
coding
438
Solve the programming task below in a Python markdown code block. There are N points in a D-dimensional space. The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}). The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... ...
{"inputs": ["1 1\n1\n2\n3\n4\n5", "5 1\n0\n2\n3\n4\n5", "0 1\n1\n2\n3\n4\n5", "1 0\n1\n2\n3\n4\n5", "1 0\n1\n2\n3\n4\n4", "1 0\n1\n2\n3\n7\n4", "1 0\n1\n3\n3\n7\n4", "0 0\n1\n3\n3\n7\n4"], "outputs": ["0\n", "10\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
514
Solve the programming task below in a Python markdown code block. You are given a mysterious language (codenamed "Secret") available in "Custom Invocation" tab. Figure out what this language is and write a program which prints its name. Note that the program must be written in this language. Input This program has on...
{"inputs": ["1\n", "2\n", "0\n", "4\n", "8\n", "6\n", "3\n", "5\n"], "outputs": ["INTERCAL\n", "INTERCAL\n", "INTERCAL\n", "INTERCAL\n", "INTERCAL\n", "INTERCAL\n", "INTERCAL\n", "INTERCAL\n"]}
coding
127
Solve the programming task below in a Python markdown code block. # Introduction The Condi (Consecutive Digraphs) cipher was introduced by G4EGG (Wilfred Higginson) in 2011. The cipher preserves word divisions, and is simple to describe and encode, but it's surprisingly difficult to crack. # Encoding Algorithm The ...
{"functional": "_inputs = [['on', 'cryptogram', 10]]\n_outputs = [['jx']]\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
690
Solve the programming task below in a Python markdown code block. The Chef has bought $N$ boxes of Tiles. The number of tiles present in $i^{th}$ box is $i$ ($i $ varies from $1$ to $N$) . The Chef has two houses with $N$ rooms each, whose floors is a square with area $(i*i)$ ,i varies from $(1....N)$. He...
{"inputs": ["1\n16"], "outputs": ["4"]}
coding
362
Solve the programming task below in a Python markdown code block. You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7. -----Constraints----- - 1≤N≤10^3 -----Input----- The input is given from Standard Input in the following format: N -----Output----- Print the number of the pos...
{"inputs": ["8", "0", "2", "4", "9", "5", "7", "6"], "outputs": ["96\n", "1\n", "2\n", "8\n", "160\n", "16\n", "60\n", "30"]}
coding
139
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n]. Go through each index i in arr starting from index 0 and paint the cell ...
{"functional": "def check(candidate):\n assert candidate(arr = [1,3,4,2], mat = [[1,4],[2,3]]) == 2\n assert candidate(arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]]) == 3\n\n\ncheck(Solution().firstCompleteIndex)"}
coding
138
Solve the programming task below in a Python markdown code block. This semester, Chef took X courses. Each course has Y units and each unit has Z chapters in it. Find the total number of chapters Chef has to study this semester. ------ Input Format ------ - The first line will contain T, the number of test cases. T...
{"inputs": ["3\n1 1 1\n2 1 2\n1 2 3"], "outputs": ["1\n4\n6"]}
coding
322
Solve the programming task below in a Python markdown code block. Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permuta...
{"inputs": ["3\n", "5\n", "1\n", "2\n", "4\n", "6\n", "7\n", "8\n"], "outputs": ["18\n", "1800\n", "1\n", "0\n", "0\n", "0\n", "670320\n", "0\n"]}
coding
455
Solve the programming task below in a Python markdown code block. It is vacation time and Panda is in his hometown Pandaland. Panda is very bored so he started studying some interesting properties of natural numbers. Some days later he meet his friend Agham, who is pretty good in mathematics and tells him about interes...
{"inputs": ["100\n846930886 1804289383\n1681692777 1714636915\n424238335 1957747793\n719885386 1649760492\n596516649 1189641421\n1025202362 1350490027\n783368690 1102520059\n1967513926 2044897763\n1365180540 1540383426\n304089172 1303455736\n35005211 521595368\n294702567 1726956429\n336465782 861021530\n233665123 27872...
coding
277
Solve the programming task below in a Python markdown code block. Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints * $-1 \times 10^{100000} \leq A, B \l...
{"inputs": ["9 8", "2 9", "0 2", "0 0", "1 2", "2 2", "8 2", "0 9"], "outputs": ["17\n", "11\n", "2\n", "0\n", "3\n", "4\n", "10\n", "9\n"]}
coding
195
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is working at his dream workplace with $N-1$ of his friends! Like any dream workplace, this one also has dream work conditions. To ensure absolute happiness of the emplo...
{"inputs": ["1\n2 12"], "outputs": ["4 4"]}
coding
750
Solve the programming task below in a Python markdown code block. # Task You are given a string `s`. Every letter in `s` appears once. Consider all strings formed by rearranging the letters in `s`. After ordering these strings in dictionary order, return the middle term. (If the sequence has a even length `n`, def...
{"functional": "_inputs = [['abc'], ['abcd'], ['abcdx'], ['abcdxg'], ['abcdxgz']]\n_outputs = [['bac'], ['bdca'], ['cbxda'], ['cxgdba'], ['dczxgba']]\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 isi...
coding
204
Solve the programming task below in a Python markdown code block. Print all the integers that satisfies the following in ascending order: - Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers. -----Constraints----- - 1 \leq A \leq B \leq 10^9 ...
{"inputs": ["3 4 2", "1 4 4", "0 0 3", "1 1 4", "6 8 3", "3 6 2", "0 8 3", "1 4 1"], "outputs": ["3\n4\n", "1\n2\n3\n4\n", "0\n", "1\n", "6\n7\n8\n", "3\n4\n5\n6\n", "0\n1\n2\n6\n7\n8\n", "1\n4\n"]}
coding
225
Solve the programming task below in a Python markdown code block. To become the king of Codeforces, Kuroni has to solve the following problem. He is given $n$ numbers $a_1, a_2, \dots, a_n$. Help Kuroni to calculate $\prod_{1\le i<j\le n} |a_i - a_j|$. As result can be very big, output it modulo $m$. If you are not f...
{"inputs": ["2 2\n1 2\n", "2 2\n9 6\n", "2 2\n0 1\n", "2 5\n3 0\n", "2 5\n3 0\n", "2 2\n9 6\n", "2 2\n1 2\n", "2 2\n0 1\n"], "outputs": ["1", "1", "1", "3", "3\n", "1\n", "1\n", "1\n"]}
coding
555
Solve the programming task below in a Python markdown code block. You are given N points (x_i,y_i) located on a two-dimensional plane. Consider a subset S of the N points that forms a convex polygon. Here, we say a set of points S forms a convex polygon when there exists a convex polygon with a positive area that has t...
{"inputs": ["1\n0 100", "1\n0 101", "1\n0 111", "1\n1 111", "1\n2 111", "1\n2 101", "1\n4 101", "1\n0 001"], "outputs": ["0", "0", "0", "0", "0", "0", "0", "0"]}
coding
433
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.   Please complete the following python code precisely: ```pyt...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,7,8,2,3,1]) == [5,6]\n assert candidate(nums = [1,1]) == [2]\n\n\ncheck(Solution().findDisappearedNumbers)"}
coding
93
Solve the programming task below in a Python markdown code block. Given is an integer sequence of length N: A_1, A_2, \cdots, A_N. An integer sequence X, which is also of length N, will be chosen randomly by independently choosing X_i from a uniform distribution on the integers 1, 2, \ldots, A_i for each i (1 \leq i \l...
{"inputs": ["3\n1 2 3\n", "3\n2 1 2\n", "1\n78261382\n", "5\n9 7 4 4 1\n", "5\n4 5 7 10 9\n", "6\n7 4 4 2 6 1\n", "6\n6 3 4 5 5 5\n", "6\n1 1 1 1 1 1\n"], "outputs": ["2\n", "500000005\n", "1\n", "825396833\n", "966269851\n", "420386910\n", "880111120\n", "1\n"]}
coding
595
Solve the programming task below in a Python markdown code block. Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions: * He never visits a point with coordinate less than 0, or a point with coordinate greater than L. * He starts walking at a point w...
{"inputs": ["4\n1\n0\n4\n3", "4\n0\n0\n4\n3", "4\n0\n1\n4\n3", "4\n0\n0\n8\n3", "4\n0\n0\n8\n1", "4\n1\n0\n8\n1", "4\n1\n0\n0\n1", "4\n1\n0\n3\n3"], "outputs": ["1\n", "0\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n"]}
coding
422
Solve the programming task below in a Python markdown code block. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a ...
{"inputs": ["1\n1\n", "2\n2 1\n", "2\n1 2\n", "3\n1 3 2\n", "4\n2 3 4 1\n", "5\n5 4 3 2 1\n", "6\n4 3 6 5 1 2\n", "7\n2 1 5 7 3 4 6\n"], "outputs": ["1 \n", "2 1 \n", "1 2 \n", "1 3 2 \n", "4 1 2 3 \n", "5 4 3 2 1 \n", "5 6 2 1 4 3 \n", "2 1 5 6 3 7 4 \n"]}
coding
386
Solve the programming task below in a Python markdown code block. Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n", "2\n1 1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "2\n"]}
coding
572
Solve the programming task below in a Python markdown code block. PizzaForces is Petya's favorite pizzeria. PizzaForces makes and sells pizzas of three sizes: small pizzas consist of $6$ slices, medium ones consist of $8$ slices, and large pizzas consist of $10$ slices each. Baking them takes $15$, $20$ and $25$ minute...
{"inputs": ["1\n6\n", "1\n9\n", "1\n66\n", "1\n45\n", "1\n12\n", "1\n213\n", "1\n129\n", "1\n216\n"], "outputs": ["15\n", "25\n", "165\n", "115\n", "30\n", "535\n", "325\n", "540\n"]}
coding
659
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, return the number of good subarrays of nums. A good array is an array where the number of different integers in that array is exactly k. For example, [1,2,3,1,2] has 3 di...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1,2,3], k = 2) == 7\n assert candidate(nums = [1,2,1,3,4], k = 3) == 3\n\n\ncheck(Solution().subarraysWithKDistinct)"}
coding
135
Solve the programming task below in a Python markdown code block. Every great chef knows that lucky numbers are 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. Our chef has recently returned from the Lucky countr...
{"inputs": ["5\n7\n4\n11\n1\n15\n\n"], "outputs": ["7\n0\n7\n-1\n7"]}
coding
411
Solve the programming task below in a Python markdown code block. In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For e...
{"inputs": ["xlmw mw xli tmgxyvi xlex m xsso mr ilx xvmt.", "xlmw mw xli tmgxyvi xlex m ossx mr ilx xvmt.", "xlmw mw xli tmgxyvi xlex m ossx mr ilx xwmt.", "xlmw mw xli tmgxyvi xlex m orsx mr ilx xwmt.", "xlmw mw xli tmgxyvi xlex l orsx mr ilx xwmt.", "wmlx mw xli tmgxyvi xlex l orsx mr ilx xwmt.", "wmlx mw xli tmgxyvi...
coding
334
Solve the programming task below in a Python markdown code block. Bertown is a city with $n$ buildings in a straight line. The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length $n$, where the $i$-th character is "1" if there is a mine under the building ...
{"inputs": ["2\n1 1\n01000010\n5 1\n01101110\n", "2\n1 1\n01000110\n5 1\n01101110\n", "2\n2 1\n01000110\n5 1\n01101110\n", "2\n2 1\n01000110\n5 1\n01101101\n", "2\n2 1\n11000111\n5 1\n01101001\n", "2\n1 1\n01000110\n5 2\n01101110\n", "2\n1 1\n11000111\n5 1\n01101001\n", "2\n0 1\n11000111\n5 1\n00111001\n"], "outputs": ...
coding
563
Solve the programming task below in a Python markdown code block. You have two integers $l$ and $r$. Find an integer $x$ which satisfies the conditions below: $l \le x \le r$. All digits of $x$ are different. If there are multiple answers, print any of them. -----Input----- The first line contains two integers...
{"inputs": ["1 1\n", "5 5\n", "5 5\n", "1 1\n", "0 1\n", "0 0\n", "7 10\n", "6 39\n"], "outputs": ["1\n", "5\n", "5\n", "1\n", "0\n", "0\n", "7\n", "6\n"]}
coding
216
Solve the programming task below in a Python markdown code block. During their New Year holidays, Alice and Bob play the following game using an array $a$ of $n$ integers: Players take turns, Alice moves first. Each turn a player chooses any element and removes it from the array. If Alice chooses even value, then sh...
{"inputs": ["2\n3\n1 1 234872\n4\n5 2 7 3\n", "2\n3\n1 1 234872\n4\n5 2 7 3\n", "2\n3\n1 1 234872\n4\n5 2 7 2\n", "2\n3\n1 1 199277\n4\n2 0 7 3\n", "2\n3\n1 1 234872\n4\n1 0 7 2\n", "2\n3\n1 1 199277\n4\n2 0 7 1\n", "2\n3\n1 2 234872\n4\n5 2 7 2\n", "2\n3\n2 1 234872\n4\n5 2 7 3\n"], "outputs": ["Alice\nBob\n", "Alice\...
coding
650
Solve the programming task below in a Python markdown code block. Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells a_{i} theorems during the i-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given a...
{"inputs": ["1 1\n10\n0\n", "1 1\n10\n0\n", "1 1\n64\n0\n", "1 1\n423\n0\n", "1 1\n423\n0\n", "1 1\n105\n0\n", "2 2\n3 2\n1 0\n", "2 1\n3 2\n0 0\n"], "outputs": ["10\n", "10\n", "64\n", "423\n", "423\n", "105\n", "5\n", "3\n"]}
coding
542
Solve the programming task below in a Python markdown code block. Let's define $f(x)$ for a positive integer $x$ as the length of the base-10 representation of $x$ without leading zeros. I like to call it a digital logarithm. Similar to a digital root, if you are familiar with that. You are given two arrays $a$ and $b...
{"inputs": ["4\n1\n1\n1000\n4\n1 2 3 4\n3 1 4 2\n3\n2 9 3\n1 100 9\n10\n75019 709259 5 611271314 9024533 81871864 9 3 6 4865\n9503 2 371245467 6 7 37376159 8 364036498 52295554 169\n"], "outputs": ["2\n0\n2\n18\n"]}
coding
646
Solve the programming task below in a Python markdown code block. # Task Consider the following operation: We take a positive integer `n` and replace it with the sum of its `prime factors` (if a prime number is presented multiple times in the factorization of `n`, then it's counted the same number of times in the s...
{"functional": "_inputs = [[24], [35], [156], [4], [31]]\n_outputs = [[5], [7], [5], [4], [31]]\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
258
Solve the programming task below in a Python markdown code block. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's cons...
{"inputs": ["A\n", "F\n", "z\n", "a\n", "Z\n", "G\n", "H\n", "I\n"], "outputs": ["a\n", "f\n", "Z\n", "A\n", "z\n", "g\n", "h\n", "i\n"]}
coding
246
Solve the programming task below in a Python markdown code block. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and re...
{"inputs": ["2\n1 1", "2\n2 1", "2\n2 2", "2\n1 0", "2\n1 2", "2\n1 -1", "4\n1 2 1 1", "4\n1 2 2 1"], "outputs": ["6\n", "9\n", "12\n", "3\n", "9", "0\n", "268\n", "324\n"]}
coding
388
Solve the programming task below in a Python markdown code block. You are at your grandparents' house and you are playing an old video game on a strange console. Your controller has only two buttons and each button has a number written on it. Initially, your score is $0$. The game is composed of $n$ rounds. For each $...
{"inputs": ["6\n+-++--\n2\n9 7\n1 1\n", "1\n-\n1\n427470105 744658699\n", "8\n+-+---+-\n5\n2 1\n10 3\n7 9\n10 10\n5 3\n", "20\n+-----+--+--------+-\n2\n1000000000 99999997\n250000000 1000000000\n"], "outputs": ["YES\nYES\n", "NO\n", "YES\nNO\nNO\nNO\nYES\n", "NO\nYES\n"]}
coding
706
Solve the programming task below in a Python markdown code block. Alice, Bob and Charlie are playing Card Game for Three, as below: - At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearran...
{"inputs": ["caa\naccc\nca", "aac\naccc\nca", "caa\naccc\nac", "aac\naccb\nca", "caa\naccb\nca", "caa\naccb\nba", "caa\nacbc\nba", "caa\nacbc\naa"], "outputs": ["A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n"]}
coding
493
Solve the programming task below in a Python markdown code block. Each pizza consists of 4 slices. There are N friends and each friend needs exactly X slices. Find the minimum number of pizzas they should order to satisfy their appetite. ------ Input Format ------ - The first line of input will contain a single in...
{"inputs": ["4\n1 5\n2 6\n4 3\n3 5\n"], "outputs": ["2\n3\n3\n4\n"]}
coding
383
Solve the programming task below in a Python markdown code block. You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to...
{"inputs": ["2 0\n", "1 0\n", "5 0\n", "3 0\n", "6 0\n", "15 0\n", "2 1\n1 1 3\n", "7 1\n3 4 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "3\n", "-1\n"]}
coding
230
Solve the programming task below in a Python markdown code block. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. Y...
{"inputs": ["1\n2\n", "1\n1\n", "2\n1 1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 1\n", "3\n1 1 1\n", "3\n1 2 2\n"], "outputs": ["2\n\n", "1\n\n", "1 1\n\n", "2 1\n", "2 2\n\n", "2 1\n", "1 1 1\n\n", "2 1 2\n"]}
coding
508
Solve the programming task below in a Python markdown code block. # Task After a long night (work, play, study) you find yourself sleeping on a bench in a park. As you wake up and try to figure out what happened you start counting trees. You notice there are different tree sizes but there's always one size which is un...
{"functional": "_inputs = [[[1, 2, 2, 3, 3]], [[11, 2, 3, 3, 3, 11, 2, 2]], [[234, 76, 45, 99, 99, 99, 99, 45, 234, 234, 45, 45, 76, 234, 76]], [[1, 1, 1, 1, 1, 1, 1, 22, 22, 22, 22, 22, 22, 22, 3, 3, 3, 3, 3, 3]], [[10, 205, 3000, 3000, 10]], [[50, 408, 50, 50, 50, 50, 408, 408, 408, 680, 408, 680, 50, 408, 680, 50, 5...
coding
322
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. A new school in Byteland is now in the process of renewing some classrooms with new, stronger and better chairs, so that the students can stay still and pay attention to class :) However, due...
{"inputs": ["2\n1\n2", "2\n1\n4", "2\n1\n8", "2\n1\n0", "2\n0\n0", "2\n1\n6", "2\n1\n1", "2\n2\n0"], "outputs": ["1\n3", "1\n15\n", "1\n255\n", "1\n0\n", "0\n0\n", "1\n63\n", "1\n1\n", "3\n0\n"]}
coding
533
Solve the programming task below in a Python markdown code block. Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and all of mathematics. It states: Every even integer greater than 2 can be expressed as the sum of two primes. For example: `6 = 3 + 3` `8 = 3 + 5` `10 = 3 +...
{"functional": "_inputs = [[2], [4], [6], [8], [10], [52], [54], [56], [58], [100], [200], [1000], [5000]]\n_outputs = [[[]], [[[2, 2]]], [[[3, 3]]], [[[3, 5]]], [[[3, 7], [5, 5]]], [[[5, 47], [11, 41], [23, 29]]], [[[7, 47], [11, 43], [13, 41], [17, 37], [23, 31]]], [[[3, 53], [13, 43], [19, 37]]], [[[5, 53], [11, 47]...
coding
319
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values. Two nodes of a binary tree are cousins if they have the same depth with different parents. Return th...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([5,4,9,1,10,None,7])), tree_node([0,0,0,7,7,None,11]))\n assert is_same_tree(candidate(root = tree_node([3,1,2])), tree_node([0,0,0]))\n\n\ncheck(Solution().replaceValueInTree)"}
coding
179
Solve the programming task below in a Python markdown code block. You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need. Constraints * $ 1 \ le n \ le 10 ^ 9 $ Input $ n $ The integer $ ...
{"inputs": ["40", "41", "000", "010", "110", "111", "011", "581"], "outputs": ["3\n", "4\n", "0\n", "1\n", "5\n", "6\n", "2\n", "25\n"]}
coding
136
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, return the number of distinct subsequences of s which equals t. The test cases are generated so that the answer fits on a 32-bit signed integer.   Please complete the following python code p...
{"functional": "def check(candidate):\n assert candidate(s = \"rabbbit\", t = \"rabbit\") == 3\n assert candidate(s = \"babgbag\", t = \"bag\") == 5\n\n\ncheck(Solution().numDistinct)"}
coding
90
Solve the programming task below in a Python markdown code block. # Task A robot is standing at the `(0, 0)` point of the Cartesian plane and is oriented towards the vertical (y) axis in the direction of increasing y values (in other words, he's facing up, or north). The robot executes several commands each of which i...
{"functional": "_inputs = [[[4, 4, 3, 2, 2, 3]], [[7, 5, 4, 5, 2, 3]], [[10, 3, 10, 2, 5, 1, 2]], [[11, 8, 6, 6, 4, 3, 7, 2, 1]], [[5, 5, 5, 5]], [[34241, 23434, 2341]], [[9348, 2188, 9348]]]\n_outputs = [[True], [True], [False], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isin...
coding
349
Solve the programming task below in a Python markdown code block. Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatu...
{"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n2 2\n", "2\n8 2\n", "2\n4 2\n", "2\n16 2\n", "3\n2 5 8\n", "3\n2 4 8\n"], "outputs": ["3\n", "3", "2\n", "-4\n", "0\n", "-12\n", "11\n", "8\n"]}
coding
610
Solve the programming task below in a Python markdown code block. A very passive-aggressive co-worker of yours was just fired. While he was gathering his things, he quickly inserted a bug into your system which renamed everything to what looks like jibberish. He left two notes on his desk, one reads: "ABCDEFGHIJKLMNOPQ...
{"functional": "_inputs = [['Ifmmp'], ['Uif usjdl up uijt lbub jt tjnqmf'], [45], ['XiBu BcPvU dSbAz UfYu'], [['Hello there', 'World']], ['BMM DBQT NBZCF'], ['qVAamFt BsF gVo'], ['CodeWars RockZ'], [''], ['J ipqf zpv bsf ibwjoh b ojdf ebz']]\n_outputs = [['Hello'], ['The trick to this kata is simple'], ['Input is not a...
coding
204
Solve the programming task below in a Python markdown code block. # Task Define crossover operation over two equal-length strings A and B as follows: the result of that operation is a string of the same length as the input strings result[i] is chosen at random between A[i] and B[i]. Given array of strings `arr` ...
{"functional": "_inputs = [[['abc', 'aaa', 'aba', 'bab'], 'bbb'], [['aacccc', 'bbcccc'], 'abdddd'], [['a', 'b', 'c', 'd', 'e'], 'c'], [['aa', 'ab', 'ba'], 'bb'], [['a', 'b', 'c', 'd', 'e'], 'f'], [['aaa', 'aaa'], 'aaa']]\n_outputs = [[2], [0], [4], [1], [0], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isin...
coding
333
Solve the programming task below in a Python markdown code block. Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you ha...
{"inputs": ["5", "6", "4", "2", "8", "7", "9", "3"], "outputs": ["5\n", "6\n", "4\n", "2\n", "8\n", "7\n", "9\n", "3\n"]}
coding
312
Solve the programming task below in a Python markdown code block. Suppose you are given a string $s$ of length $n$ consisting of lowercase English letters. You need to compress it using the smallest possible number of coins. To compress the string, you have to represent $s$ as a concatenation of several non-empty stri...
{"inputs": ["3 3 1\naba\n", "3 3 0\naba\n", "3 3 1\naba\n", "4 1 1\nabcd\n", "4 1 2\nabcd\n", "4 2 3\nabdd\n", "4 1 3\nabcd\n", "4 1 3\nabdd\n"], "outputs": ["7\n", "6\n", "7\n", "4\n", "4\n", "8\n", "4\n", "4\n"]}
coding
599
Solve the programming task below in a Python markdown code block. Given an array of integers `a` and integers `t` and `x`, count how many elements in the array you can make equal to `t` by **increasing** / **decreasing** it by `x` (or doing nothing). *EASY!* ```python # ex 1 a = [11, 5, 3] t = 7 x = 2 count(a, t, x)...
{"functional": "_inputs = [[[11, 5, 3], 7, 2], [[-4, 6, 8], -7, -3]]\n_outputs = [[3], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r...
coding
268
Solve the programming task below in a Python markdown code block. # Task `EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task. To get a medal, your time mu...
{"functional": "_inputs = [['00:30:00', '00:15:00', '00:45:00', '01:15:00'], ['01:15:00', '00:15:00', '00:45:00', '01:15:00'], ['00:00:01', '00:00:10', '00:01:40', '01:00:00'], ['00:10:01', '00:00:10', '00:01:40', '01:00:00'], ['00:00:01', '00:00:02', '00:00:03', '00:00:04'], ['90:00:01', '60:00:02', '70:00:03', '80:00...
coding
481
Solve the programming task below in a Python markdown code block. A forest fire has been spotted at *fire*, a simple 2 element array with x, y coordinates. The forest service has decided to send smoke jumpers in by plane and drop them in the forest. The terrain is dangerous and surveyors have determined that there ar...
{"functional": "_inputs = [[[6, 8], [[3, 2], [6, 1], [7, 9]]], [[9, 2], [[1, 4], [9, 9], [5, 5]]]]\n_outputs = [[[7, 9]], [[5, 5]]]\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, ...
coding
279
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 you can perform the following operation any number of times on nums: Swap the positions of two elements nums[i] and nums[j] if gcd(nums[i], nums[j]) > 1 where gcd(nums[i], num...
{"functional": "def check(candidate):\n assert candidate(nums = [7,21,3]) == True\n assert candidate(nums = [5,2,6,2]) == False\n assert candidate(nums = [10,5,9,3,15]) == True\n\n\ncheck(Solution().gcdSort)"}
coding
139
Solve the programming task below in a Python markdown code block. Takahashi has received an undirected graph with N vertices, numbered 1, 2, ..., N. The edges in this graph are represented by (u_i, v_i). There are no self-loops and multiple edges in this graph. Based on this graph, Takahashi is now constructing a new ...
{"inputs": ["3 1\n1 2", "7 5\n1 2\n3 4\n3 5\n4 1\n2 6", "7 5\n1 2\n3 7\n3 5\n4 1\n2 6", "7 5\n1 2\n3 7\n3 5\n4 1\n2 2", "7 5\n1 2\n3 7\n6 5\n4 1\n2 2", "7 5\n1 2\n3 7\n3 7\n4 1\n2 3", "7 5\n1 2\n2 6\n6 5\n4 1\n2 2", "7 5\n2 2\n2 6\n6 5\n4 1\n2 2"], "outputs": ["7", "15\n", "8\n", "18\n", "13\n", "26\n", "25\n", "29\n"]...
coding
378
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. You are given a 0-indexed integer array vals of length n where vals[i] denote...
{"functional": "def check(candidate):\n assert candidate(vals = [1,3,2,1,3], edges = [[0,1],[0,2],[2,3],[2,4]]) == 6\n assert candidate(vals = [1,1,2,2,3], edges = [[0,1],[1,2],[2,3],[2,4]]) == 7\n assert candidate(vals = [1], edges = []) == 1\n\n\ncheck(Solution().numberOfGoodPaths)"}
coding
272
Solve the programming task below in a Python markdown code block. The bear has a string s = s_1s_2... s_{|}s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = s_{i}s_{i} + 1... s_{j} co...
{"inputs": ["a\n", "a\n", "`\n", "_\n", "^\n", "]\n", "\\\n", "[\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
486
Solve the programming task below in a Python markdown code block. ## Your Story "A *piano* in the home meant something." - *Fried Green Tomatoes at the Whistle Stop Cafe* You've just realized a childhood dream by getting a beautiful and beautiful-sounding upright piano from a friend who was leaving the country. You im...
{"functional": "_inputs = [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]]\n_outputs = [['white'], ['black'], ['black'], ['white'], ['white'], ['white'], ['white'], ['black'], ['white'], ['black'], ['white']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
coding
769
Solve the programming task below in a Python markdown code block. You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = a·10^{b}, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" ...
{"inputs": ["1\n", "1\n", "2\n", "3\n", "4\n", "16\n", ".1\n", "1.\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "4\n", "1.6E1\n", "1E-1\n", "1\n"]}
coding
247
Solve the programming task below in a Python markdown code block. Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers fro...
{"inputs": ["3\n", "5\n", "1\n", "2\n", "4\n", "6\n", "8\n", "6\n"], "outputs": ["2\n", "2\n", "1\n", "1\n", "1\n", "3\n", "2\n", "3\n"]}
coding
307
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the maximum value of $n$. You are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$. The positive integer is...
{"inputs": ["1\n387420490\n", "1\n506859788\n", "1\n132370398\n", "1\n230139648\n", "1\n152260256\n", "1\n586187597\n", "1\n100214312\n", "1\n218113389\n"], "outputs": ["387420490\n", "516560652\n", "133923132\n", "387420489\n", "172186884\n", "1162261467\n", "129140163\n", "387420489\n"]}
coding
578
Solve the programming task below in a Python markdown code block. For given integer n, count the totatives of n, that is, the positive integers less than or equal to n that are relatively prime to n. Input n An integer n (1 ≤ n ≤ 1000000000). Output The number of totatives in a line. Examples Input 6 Outp...
{"inputs": ["5", "2", "3", "6", "16", "31", "61", "59"], "outputs": ["4\n", "1\n", "2\n", "2", "8\n", "30\n", "60\n", "58\n"]}
coding
107
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]). The xor-beauty of the array is the XORing of the effective values of all th...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4]) == 5\n assert candidate(nums = [15,45,20,2,34,35,5,44,32,30]) == 34\n\n\ncheck(Solution().xorBeauty)"}
coding
170
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K (odd) to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. ...
{"inputs": ["4\n1\n3\n5\n7"], "outputs": ["*\n*\n**\n*\n*\n**\n* *\n**\n*\n*\n**\n* *\n* *\n* *\n**\n*"]}
coding
200
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. You are given a sequence $a$ consisting of $n$ positive integers. Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements...
{"inputs": ["6\n8\n1 1 2 6 3 2 1 1\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n1 1 1\n", "6\n8\n1 1 2 6 3 2 1 1\n3\n2 3 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 1\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 2\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1...
coding
743
Solve the programming task below in a Python markdown code block. In Chefland, each chicken has X legs and each duck has Y legs. Chef's farm can have exactly one type of bird. Given that the birds on the farm have a total of Z legs: Print CHICKEN, if the farm can have only chickens but not ducks. Print DUCK, if the f...
{"inputs": ["3\n2 3 5\n2 2 2\n3 4 6"], "outputs": ["NONE\nANY\nCHICKEN"]}
coding
501