problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. You are given Name of chef's friend and using chef's new method of calculating value of string , chef have to find the value of all the names. Since chef is busy , he asked you to do the work from him . The method is a function $f(x)$ as follows - - $f...
{"inputs": ["1\ncodechef"], "outputs": ["173"]}
coding
324
Solve the programming task below in a Python markdown code block. There is a tree with N vertices numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Initially, each vertex is uncolored. Takahashi and Aoki is playing a game by painting the vertices. In this game, they alternately perform th...
{"inputs": ["3\n1 2\n1 3", "3\n0 2\n2 3", "3\n1 1\n2 3", "3\n1 1\n2 2", "3\n1 2\n2 3", "4\n1 2\n2 3\n2 3", "4\n1 2\n1 3\n2 4", "4\n1 2\n2 3\n2 2"], "outputs": ["First\n", "First\n", "First\n", "First\n", "First", "First\n", "Second\n", "First\n"]}
coding
375
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef is playing a game. Currently in the game, he is at a field full of stones. There are total N kinds of stones. There is unlimited supply of each kind of stone. Chef knows that one stone...
{"inputs": ["1\n3 0\n3 8 2\n4 4 0", "1\n3 6\n3 6 3\n3 4 1", "1\n3 5\n3 6 3\n3 4 1", "1\n3 5\n3 6 3\n2 4 1", "1\n3 6\n5 6 3\n3 5 1", "1\n1 0\n3 8 2\n4 4 0", "1\n1 0\n5 8 2\n4 4 0", "1\n3 0\n6 8 2\n4 4 0"], "outputs": ["0\n", "6\n", "3\n", "2\n", "5\n", "0\n", "0\n", "0\n"]}
coding
500
Solve the programming task below in a Python markdown code block. Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size $l\times b$ into smaller identical pieces such that each piece is a square having maximum possible side length with no left over piece of bread. Inp...
{"inputs": ["2\n2 2\n6 9\n"], "outputs": ["1\n6\n"]}
coding
319
Solve the programming task below in a Python markdown code block. Consider the number triangle below, in which each number is equal to the number above plus the number to the left. If there is no number above, assume it's a `0`. The triangle has `5` rows and the sum of the last row is `sum([1,4,9,14,14]) = 42`. You w...
{"functional": "_inputs = [[4], [5], [6], [7], [8], [20]]\n_outputs = [[14], [42], [132], [429], [1430], [6564120420]]\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
227
Solve the programming task below in a Python markdown code block. Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by con...
{"inputs": ["2\n1\n", "4\n1\n", "9\n3\n", "2\n0\n", "2\n0\n", "9\n3\n", "4\n1\n", "2\n1\n"], "outputs": ["1", "1", "3", "0", "0", "3", "1", "1"]}
coding
418
Solve the programming task below in a Python markdown code block. Chef has many friends, but his best friend is Hemant. They both love to watch anime. In fact, their weekends are meant for that only. Also, Hemant is highly into games, of which Chef is unaware. Hemant once gave a game to Chef and asked him to determine ...
{"inputs": ["3\n1\n3\n7"], "outputs": ["B\nA\nB"]}
coding
294
Solve the programming task below in a Python markdown code block. Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no surp...
{"inputs": ["3 1\n1 3 2\n", "3 1\n1 3 1\n", "3 1\n1 3 3\n", "2 1\n1 2 1\n", "2 1\n1 2 2\n", "3 2\n1 2 2\n1 3 2\n", "3 2\n1 2 1\n1 3 3\n", "3 2\n2 3 3\n1 3 3\n"], "outputs": ["2 0 2 \n", "0 1 1 \n", "3 3 0 \n", "0 1 \n", "2 0 \n", "2 0 2 \n", "3 1 0 \n", "3 3 0 \n"]}
coding
642
Solve the programming task below in a Python markdown code block. The title is a reference to the very first Educational Round from our writers team, Educational Round 18. There is a bag, containing colored balls. There are $n$ different colors of balls, numbered from $1$ to $n$. There are $\mathit{cnt}_i$ balls of co...
{"inputs": ["1\n3\n1 2 4\n", "3\n3\n1 1 1\n1\n9\n2\n4 7\n"], "outputs": ["3\n", "1\n1\n2\n"]}
coding
586
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef loves brackets. So much so, that rather than just use plain brackets like (), {}, or [], he has invented his own notation that allows him to use many more types of brackets. Each type of ...
{"inputs": ["11\n-1 -2 9 2 -3 -4 3 4 8 8 1 "], "outputs": ["12"]}
coding
524
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation. Note: You are not allowed to use any built-in function which evaluates strings as...
{"functional": "def check(candidate):\n assert candidate(s = \"1 + 1\") == 2\n assert candidate(s = \" 2-1 + 2 \") == 3\n assert candidate(s = \"(1+(4+5+2)-3)+(6+8)\") == 23\n\n\ncheck(Solution().calculate)"}
coding
94
Solve the programming task below in a Python markdown code block. Peter loves any kinds of cheating. A week before ICPC, he broke into Doctor's PC and sneaked a look at all the problems that would be given in ICPC. He solved the problems, printed programs out, and brought into ICPC. Since electronic preparation is stri...
{"inputs": ["3\n19 22 1\n7\n93 26 38 43 66 4 3", "3\n19 22 1\n7\n93 26 38 43 36 4 3", "3\n19 22 0\n7\n93 26 38 3 66 80 1", "3\n19 22 0\n7\n93 26 38 43 36 4 3", "3\n19 22 1\n7\n93 26 38 3 66 80 1", "3\n19 20 2\n7\n56 26 2 43 31 12 7", "3\n19 22 0\n7\n93 26 38 43 36 4 2", "3\n19 44 1\n7\n93 26 38 3 66 80 1"], "outputs": ...
coding
553
Solve the programming task below in a Python markdown code block. Sultan, the freestyle wrestler, you all know him. He broke multiple records in the history of all wrestling leagues. Now 20 years have passed, Sultan has grown old. He has two sons, he wants them to be like him. Sultan being orthodox goes to his astrolog...
{"inputs": ["2\n7\n2 3\n4 5 7 8 9 10 14\n6\n5 7\n1 2 8 9 10 11"], "outputs": ["Yes\nMultan\nNo"]}
coding
599
Solve the programming task below in a Python markdown code block. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum ...
{"inputs": ["1\n1\n45", "1\n15\n0", "1\n56\n2", "1\n1\n50", "1\n1\n50\n", "1\n6\n-10", "1\n28\n-1", "1\n111\n2"], "outputs": ["0\n", "15\n", "54\n", "0", "0\n", "16\n", "29\n", "109\n"]}
coding
262
Solve the programming task below in a Python markdown code block. We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weigh...
{"inputs": ["3\n2 5\n4 2\n6 3", "3\n1 5\n4 4\n6 3", "3\n1 5\n4 2\n6 3", "4\n1 5\n2 6\n0 7\n4 8", "4\n1 5\n0 6\n0 7\n4 8", "4\n1 3\n0 6\n0 7\n4 8", "4\n1 5\n2 6\n3 7\n4 8", "4\n1 3\n0 6\n-1 7\n4 8"], "outputs": ["8\n", "9\n", "7", "7\n", "5\n", "4\n", "10", "3\n"]}
coding
318
Solve the programming task below in a Python markdown code block. Let's denote a function $f(x)$ in such a way: we add $1$ to $x$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, $f(599) = 6$: $599 + 1 = 600 \rightarrow 60 \rightarrow 6$; $f(7) = 8$: $7 + 1 ...
{"inputs": ["1\n", "9\n", "3\n", "5\n", "5\n", "1\n", "9\n", "3\n"], "outputs": ["9\n", "9\n", "9\n", "9\n", "9\n", "9\n", "9\n", "9\n"]}
coding
479
Solve the programming task below in a Python markdown code block. You are given a sequence of n integers a1, a2, ..., an and an integer d. Find the length of the shortest non-empty contiguous subsequence with sum of elements at least d. Formally, you should find the smallest positive integer k with the following proper...
{"inputs": ["2\n5 5\n1 2 3 1 -5\n5 1\n1 2 3 1 -5"], "outputs": ["2\n1"]}
coding
322
Solve the programming task below in a Python markdown code block. In order to write a string, Atilla needs to first learn all letters that are contained in the string. Atilla needs to write a message which can be represented as a string $s$. He asks you what is the minimum alphabet size required so that one can write ...
{"inputs": ["5\n1\na\n4\ndown\n10\ncodeforces\n3\nbcf\n5\nzzzzz\n"], "outputs": ["1\n23\n19\n6\n26\n"]}
coding
400
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.   Please complete the follo...
{"functional": "def check(candidate):\n assert candidate(nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]) == [3,4]\n assert candidate(nums = [[1,2,3],[4,5,6]]) == []\n\n\ncheck(Solution().intersection)"}
coding
89
Solve the programming task below in a Python markdown code block. The Fibonacci sequence $F_0, F_1, \ldots$ is a special infinite sequence of non-negative integers, where $F_0 = 0$, $F_1 = 1$ and for each integer $n \ge 2$, $F_n = F_{n-1} + F_{n-2}$. Consider the sequence $D$ of the last decimal digits of the first $N$...
{"inputs": ["1\n9"], "outputs": ["3"]}
coding
558
Solve the programming task below in a Python markdown code block. A young boy John is playing with eight triangular panels. These panels are all regular triangles of the same size, each painted in a single color; John is forming various octahedra with them. While he enjoys his playing, his father is wondering how many...
{"inputs": ["blue blue blue blue bluf blue blue blue\nred blue blue blue blue blue blue blue\nred red blue blue blue blue blue blue", "blue blue blue blue bluf clue blue blue\nred blue blue blue blue blue blue blue\nred red blue blue blue blue blue blue", "blue blue blue blue bluf cleu blue blue\nred blue blue blue blu...
coding
261
Solve the programming task below in a Python markdown code block. In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages...
{"inputs": ["1\n0\n", "2\n1\n0\n", "2\n1\n2\n", "2\n0\n1\n", "2\n1\n1\n", "2\n0\n0\n", "2\n0\n2\n", "2\n2\n0\n"], "outputs": ["Exemplary pages.\n", "Unrecoverable configuration.\n", "Unrecoverable configuration.\n", "Unrecoverable configuration.\n", "Exemplary pages.\n", "Exemplary pages.\n", "1 ml. from cup #1 to cup ...
coding
567
Solve the programming task below in a Python markdown code block. There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ d...
{"inputs": ["2\n4 0\n5 0\n", "2\n4 0\n5 0\n", "2\n5 2\n4 0\n", "2\n0 2\n4 0\n", "2\n-1 2\n4 0\n", "3\n1 9\n2 1\n4 1\n", "3\n2 1\n0 4\n4 1\n", "3\n1 1\n0 3\n3 1\n"], "outputs": ["1\n", "1\n", "3\n", "4\n", "5\n", "11\n", "6\n", "5\n"]}
coding
438
Solve the programming task below in a Python markdown code block. Cheffina challanges chef to rearrange the given array as arr[i] > arr[i+1] < arr[i+2] > arr[i+3].. and so on…, i.e. also arr[i] < arr[i+2] and arr[i+1] < arr[i+3] and arr[i] < arr[i+3] so on.. Chef accepts the challenge, chef starts coding but his code i...
{"inputs": ["2\n4\n4 1 6 3\n5\n4 5 1 6 3"], "outputs": ["3 1 6 4\n3 1 5 4 6"]}
coding
290
Solve the programming task below in a Python markdown code block. Vasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits. But since EatForces takes care of the security of its users, user passwor...
{"inputs": ["1\nA00\n", "1\na00\n", "1\n825\n", "1\n000\n", "1\n0a0\n", "1\n0aa\n", "1\n00A\n", "1\n001\n"], "outputs": ["Aa0\n", "aA0\n", "aA5\n", "aA0\n", "Aa0\n", "0Aa\n", "a0A\n", "aA1\n"]}
coding
644
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chefland has $7$ days in a week. Chef is very conscious about his work done during the week. There are two ways he can spend his energy during the week. The ...
{"inputs": ["3\n1 2 3 1\n6 2 3 1\n1 2 8 1"], "outputs": ["14\n19\n14"]}
coding
535
Solve the programming task below in a Python markdown code block. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees locate...
{"inputs": ["4\n10 4\n15 1\n19 3\n20 1\n", "4\n10 4\n15 1\n19 3\n20 1\n", "1\n1000000000 1000000000\n", "1\n1000000000 1000000000\n", "1\n1010000000 1000000000\n", "1\n1010000000 1000010000\n", "1\n1110000000 1000010000\n", "1\n1110000000 1000000000\n"], "outputs": ["4\n", "4\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n...
coding
540
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. The problem is completely unrelated to its problem code :). Let us build an infinite string D that is simply a concatenation of the decimal representations of all positive integers without lea...
{"inputs": ["2\n78910\n9930"], "outputs": ["7\n2679"]}
coding
458
Solve the programming task below in a Python markdown code block. You are given two non-empty strings $s$ and $t$, consisting of Latin letters. In one move, you can choose an occurrence of the string $t$ in the string $s$ and replace it with dots. Your task is to remove all occurrences of the string $t$ in the string...
{"inputs": ["8\nabababacababa\naba\nddddddd\ndddd\nxyzxyz\nxyz\nabc\nabcd\nabacaba\nabaca\nabc\ndef\naaaaaaaa\na\naaaaaaaa\naa\n", "3\nabacabadabacabaeabacabadabacabafabacabadabacabac\naba\nabacabadabacabaabacabadabaabaabacabaa\naba\nabacabadaababaaabacaaab\naba\n", "6\ncgleetgjqctvoln\ntttt\nqcmivmmvgifpnm\nmmmm\nxxxr...
coding
742
Solve the programming task below in a Python markdown code block. You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes cl...
{"inputs": ["2\n6\n1 3 11 8 1 8\n2\n3 2\n100 1\n5\n0 5 100 3 3\n2\n5 5\n95 1\n", "2\n6\n1 3 11 8 1 8\n2\n3 2\n000 1\n5\n0 5 100 3 3\n2\n5 5\n95 1\n", "2\n6\n3 1 2 3 1 8\n2\n3 2\n000 1\n5\n3 5 100 2 3\n2\n30 5\n90 2\n", "2\n6\n1 3 11 8 1 8\n2\n0 2\n000 1\n5\n0 5 100 3 3\n2\n5 5\n95 1\n", "2\n6\n1 3 11 8 1 8\n2\n3 2\n100...
coding
728
Solve the programming task below in a Python markdown code block. There are n cities in Berland. Each city has its index — an integer number from 1 to n. The capital has index r1. All the roads in Berland are two-way. The road system is such that there is exactly one path from the capital to each city, i.e. the road ma...
{"inputs": ["2 2 1\n2\n", "2 1 2\n1\n", "3 1 3\n1 2\n", "3 2 3\n2 2\n", "4 2 3\n3 2 2\n", "4 2 3\n2 1 3\n", "4 2 3\n3 2 1\n", "5 2 3\n2 4 2 3\n"], "outputs": ["1\n", "2\n", "2 3\n", "2 3\n", "3 3 2\n", "3 1 3\n", "3 3 1\n", "2 4 3 3\n"]}
coding
385
Solve the programming task below in a Python markdown code block. Problem: You are given n natural numbers a1,a2,a3…… an. Let SOD of a number be defined as the Sum of Digits of that number. Compute the value of { [ SOD(a1) + SOD(a2) + …….. SOD(an) ] % 9 } – { [ SOD( a1 + a2 + ….. an ) ] % 9 } Input: The first line ...
{"inputs": ["44\n9242491309192363508454348881448\n95499654020\n109758011410598474817655293640390075049706107889887302348716784557022182\n73075996487581437057821509555280826186715408365459266016843977808929\n845366999775902\n435255049317799578761128574212522387250\n8636285886998451585180940820839696261305830044600366108...
coding
268
Solve the programming task below in a Python markdown code block. There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall squares, and the other...
{"inputs": ["5 2 0\n2 1\n4 2", "3 4 2\n2 2\n2 4", "3 4 2\n2 2\n2 8", "5 4 2\n2 1\n4 2", "3 4 2\n2 3\n1 4", "9 2 0\n2 1\n4 2", "8 2 0\n2 1\n4 4", "5 4 0\n2 1\n7 4"], "outputs": ["5\n", "2\n", "4\n", "12\n", "3\n", "9\n", "8\n", "35\n"]}
coding
471
Solve the programming task below in a Python markdown code block. In music, if you double (or halve) the pitch of any note you will get to the same note again. "Concert A" is fixed at 440 Hz, and every other note is defined based on that. 880 Hz is also an A, as is 1760 Hz, as is 220 Hz. There are 12 notes in Western...
{"functional": "_inputs = [[440], [220], [880], [523.25], [261.625], [1046.5]]\n_outputs = [['A'], ['A'], ['A'], ['C'], ['C'], ['C']]\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
396
Solve the programming task below in a Python markdown code block. You are given an array of $n$ integers: $a_1, a_2, \ldots, a_n$. Your task is to find some non-zero integer $d$ ($-10^3 \leq d \leq 10^3$) such that, after each number in the array is divided by $d$, the number of positive numbers that are presented in t...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n-1\n", "1\n-1\n", "1\n-2\n", "1\n777\n", "2\n1 0\n"], "outputs": ["0", "0", "1\n", "-1", "-1", "-1\n", "1", "1"]}
coding
566
Solve the programming task below in a Python markdown code block. Given is a three-digit integer N. Does N contain the digit 7? If so, print Yes; otherwise, print No. -----Constraints----- - 100 \leq N \leq 999 -----Input----- Input is given from Standard Input in the following format: N -----Output----- If N conta...
{"inputs": ["3", "6", "8", "9", "4", "1", "5", "2"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
120
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. Constraints * 1 \leq K \leq N\leq 10 * S is...
{"inputs": ["5\norrer\n2", "5\nrorre\n2", "5\norrer\n1", "5\nrerro\n1", "5\nrerro\n2", "5\nerror\n4", "5\norrer\n4", "5\nserro\n1"], "outputs": ["*rr*r\n", "*o***\n", "o****\n", "r*rr*\n", "*e***\n", "***o*\n", "***e*\n", "s****\n"]}
coding
188
Please solve the programming task below using a self-contained code snippet in a markdown code block. Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses. Every house can be warmed, as long as the house is within the heater's warm radius r...
{"functional": "def check(candidate):\n assert candidate(houses = [1,5], heaters = [2]) == 3\n\n\ncheck(Solution().findRadius)"}
coding
150
Solve the programming task below in a Python markdown code block. You are given several queries. In the i-th query you are given a single positive integer n_{i}. You are to represent n_{i} as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittin...
{"inputs": ["1\n4\n", "1\n12\n", "1\n12\n", "2\n6\n8\n", "2\n6\n4\n", "2\n8\n1\n", "2\n8\n4\n", "2\n6\n8\n"], "outputs": ["1\n", "3\n", "3\n", "1\n2\n", "1\n1\n", "2\n-1\n", "2\n1\n", "1\n2\n"]}
coding
352
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (right or left). If the current direction is right, move to the right ...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,None,1,1,1,None,None,1,1,None,1,None,None,None,1,None,1])) == 3\n assert candidate(root = tree_node([1,1,1,None,1,None,None,1,1,None,1])) == 4\n assert candidate(root = tree_node([1])) == 0\n\n\ncheck(Solution().longestZigZag)"}
coding
234
Solve the programming task below in a Python markdown code block. # Task Sorting is one of the most basic computational devices used in Computer Science. Given a sequence (length ≤ 1000) of 3 different key values (7, 8, 9), your task is to find the minimum number of exchange operations necessary to make the sequen...
{"functional": "_inputs = [[[7, 7, 8, 8, 9, 9]], [[9, 7, 8, 8, 9, 7]], [[8, 8, 7, 9, 9, 9, 8, 9, 7]], [[9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7]], [[9, 9, 9, 7, 7, 8, 9, 7, 8, 9, 7, 9]], [[9, 9, 7, 7, 8, 8]], [[9, 7, 9]], [[8, 7, 8]], [[7, 8, 7, 8]], [[8, 8, 7, 8]], [[8, 8, 7, 7, 8]]]\n_outputs = [[0], [1], [4], [6...
coding
480
Solve the programming task below in a Python markdown code block. Given a string of words, you need to find the highest scoring word. Each letter of a word scores points according to its position in the alphabet: `a = 1, b = 2, c = 3` etc. You need to return the highest scoring word as a string. If two words score t...
{"functional": "_inputs = [['man i need a taxi up to ubud'], ['what time are we climbing up the volcano'], ['take me to semynak'], ['massage yes massage yes massage'], ['take two bintang and a dance please']]\n_outputs = [['taxi'], ['volcano'], ['semynak'], ['massage'], ['bintang']]\nimport math\ndef _deep_eq(a, b, tol...
coding
123
Solve the programming task below in a Python markdown code block. There are a total of W x H squares, with H rows vertically and W columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and outputs the maximum rectangular area consisting of only the unmarked squares. ...
{"inputs": ["10 7\n...*....**\n..........\n**....**..\n........*.\n..*.......\n**........\n.*........\n..........\n....*..***\n...*....*.\n10 4\n..*....*..\n.*.*...*..\n..*..*****\n*...*..*..\n..*..*...*\n..........\n.***.*..**\n..*..*...*\n..*..*...*\n****...***\n2 2\n...\n...\n0 0", "10 6\n...*....**\n..........\n**....
coding
504
Solve the programming task below in a Python markdown code block. An input string S of length N is transferred through the network using a special protocol. The protocol can send the string through a series of operations. In one operation, we can choose a lowercase english alphabet C and do one of the following: Trans...
{"inputs": ["2\n5\ncbcdc\n6\naabeee\n"], "outputs": ["5\n4\n"]}
coding
462
Solve the programming task below in a Python markdown code block. Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose ...
{"inputs": ["1 1\n1 1\n", "2 1\n1 2\n", "1 1\n1 1\n", "2 1\n1 2\n", "2 1\n1 1\n", "1 1\n2 1\n", "6 2\n1 6\n1 4\n", "6 2\n1 6\n1 4\n"], "outputs": ["0\n", "01\n", "0", "01", "01\n", "0\n", "010101\n", "010101"]}
coding
754
Solve the programming task below in a Python markdown code block. You are given an array $a$ of $n$ elements. You can apply the following operation to it any number of times: Select some subarray from $a$ of even size $2k$ that begins at position $l$ ($1\le l \le l+2\cdot{k}-1\le n$, $k \ge 1$) and for each $i$ betwee...
{"inputs": ["5\n3\n1 1 1\n2\n2 1\n5\n4 4 4 2 4\n4\n4 2 1 3\n1\n1\n"], "outputs": ["0\n1\n1\n2\n0\n"]}
coding
733
Solve the programming task below in a Python markdown code block. One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·...
{"inputs": ["1 1\n0 0\n", "1 1\n0 1\n", "1 1\n1 0\n", "1 1\n1 1\n", "1 1\n0 0\n", "1 1\n0 1\n", "1 1\n1 0\n", "1 1\n1 1\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n"]}
coding
520
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Given a board of N rows and M columns, place the minimum number of knights such that every cell either contains a knight or is attacked by at least one knight. Like in stand...
{"inputs": ["1\n2 4"], "outputs": ["4"]}
coding
362
Solve the programming task below in a Python markdown code block. Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following conditi...
{"inputs": ["3\n1 2 0", "3\n3 2 1", "3\n0 2 0", "3\n0 1 0", "3\n1 2 1", "3\n2 2 1", "3\n3 4 1", "3\n3 7 1"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
388
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of integers distance. You start at the point (0, 0) on an X-Y plane, and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[...
{"functional": "def check(candidate):\n assert candidate(distance = [2,1,1,2]) == True\n assert candidate(distance = [1,2,3,4]) == False\n assert candidate(distance = [1,1,1,1]) == True\n\n\ncheck(Solution().isSelfCrossing)"}
coding
149
Solve the programming task below in a Python markdown code block. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. For each square, you will perform either of the following operations once: - Decrease the height of the square by 1. - Do nothing. Determine i...
{"inputs": ["1\n1\n", "4\n1 5 2 1", "4\n1 5 2 2", "4\n0 5 2 2", "4\n0 8 2 2", "4\n0 8 4 2", "4\n0 1 4 2", "4\n0 1 4 1"], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
244
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. Chef is busy preparing for the next lunchtime, so he has given you the following task. You are given an array a consisting of n positive integers. The goodness of the array a...
{"inputs": ["2\n5\n18 6 4 3 12\n5\n12 4 6 16 28 "], "outputs": ["6\n4"]}
coding
690
Solve the programming task below in a Python markdown code block. Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who loo...
{"inputs": ["2\n3 0\n3\n0 1 1\n1\n1000\n0", "2\n3 2\n3\n0 1 1\n1\n0000\n0", "2\n1 0\n3\n0 1 1\n1\n1000\n0", "2\n2 0\n3\n0 1 1\n0\n1100\n0", "2\n1 0\n3\n0 1 1\n0\n1100\n0", "2\n3 2\n3\n0 0 1\n1\n1000\n0", "2\n6 4\n3\n0 1 2\n1\n0000\n0", "2\n0 4\n3\n0 1 2\n1\n0000\n0"], "outputs": ["2\nNA\n2\n", "3\nNA\nNA\n", "NA\nNA\n2...
coding
397
Solve the programming task below in a Python markdown code block. Stack likes the number 3 a lot. He has two non-negative integers A and B. In one operation, Stack can do either of the following: A:=|A-B| (change A to |A-B|) B:=|A-B| (change B to |A-B|) Note that |X| denotes absolute value of X. For example |-7| ...
{"inputs": ["2\n0 343\n1 1\n"], "outputs": ["0\n1\n"]}
coding
342
Solve the programming task below in a Python markdown code block. # Letterss of Natac In a game I just made up that doesn’t have anything to do with any other game that you may or may not have played, you collect resources on each turn and then use those resources to build things like roads, settlements and cities. If ...
{"functional": "_inputs = [['', 'bw']]\n_outputs = [[[False, '']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n retu...
coding
635
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and two integers x and y. You can perform two types of operations any number of times. Remove substring "ab" and gain x points. For example, when removing "ab" from "cabxbae" it becomes "c...
{"functional": "def check(candidate):\n assert candidate(s = \"cdbcbbaaabab\", x = 4, y = 5) == 19\n assert candidate(s = \"aabbaaxybbaabb\", x = 5, y = 4) == 20\n\n\ncheck(Solution().maximumGain)"}
coding
159
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighbo...
{"inputs": ["2\n---+-+-+++\n-------", "2\n+++-+-+---\n-------", "2\n-+--+++--+\n-------", "2\n-+-+-+-+-+\n-------", "2\n--++---+++\n-----+-", "2\n---+-+-+++\n-----+-", "2\n+-+-+-+--+\n-------", "2\n---+++-+-+\n-------"], "outputs": ["2\n3", "2\n3\n", "4\n3\n", "0\n3\n", "4\n2\n", "2\n2\n", "2\n3\n", "2\n3\n"]}
coding
401
Solve the programming task below in a Python markdown code block. We call a positive integer number fair if it is divisible by each of its nonzero digits. For example, $102$ is fair (because it is divisible by $1$ and $2$), but $282$ is not, because it isn't divisible by $8$. Given a positive integer $n$. Find the mini...
{"inputs": ["1\n239\n", "1\n2317839669\n", "1\n123456780079\n", "1\n8973589164975\n", "1\n9876543210000\n", "1\n1023456790441\n", "1\n1000000002897001\n", "1\n99999999999999999\n"], "outputs": ["240\n", "2317840224\n", "123456780720\n", "8973589166640\n", "9876543211080\n", "1023456791700\n", "1000000002898008\n", "999...
coding
361
Solve the programming task below in a Python markdown code block. Very simple, given a number, find its opposite. Examples: ``` 1: -1 14: -14 -34: 34 ``` ~~~if:sql You will be given a table: `opposite`, with a column: `number`. Return a table with a column: `res`. ~~~ Also feel free to reuse/extend the following star...
{"functional": "_inputs = [[1], [25.6], [0], [1425.2222], [-3.1458], [-95858588225]]\n_outputs = [[-1], [-25.6], [0], [-1425.2222], [3.1458], [95858588225]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ...
coding
106
Solve the programming task below in a Python markdown code block. Ichigo is receiving special training from Kisuke Urahara to beat Aizen. This time, Kisuke took (P * Q * R) identical cubes and made them into a big box of dimensions P x Q x R. Moreover, it happened quite by chance that P, Q, R were all pairwise coprime,...
{"inputs": ["3\n1 1 1\n2 1 3\n5 3 2\n"], "outputs": ["1\n5\n15\n"]}
coding
513
Solve the programming task below in a Python markdown code block. Archith was a making noise in digital logic class.Sir was very frustrated by the behaviour of Archith. Sir asked archith to meet him in staff room. As archith reached staff room sir gave a smile and asked to complete this assignment in one day if not he ...
{"inputs": ["20\n212245523\n546843625\n456431356\n546463364\n584651321\n352145896\n53\n2\n32\n32\n32692\n32646\n41354\n4351\n312\n524\n54365\n58421\n54213\n23452"], "outputs": ["odd\nodd\nodd\nodd\nodd\neven\neven\nodd\nodd\nodd\nodd\neven\neven\nodd\neven\nodd\nodd\neven\nodd\nodd"]}
coding
213
Solve the programming task below in a Python markdown code block. Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed t...
{"inputs": ["4\n", "6\n", "8\n", "2\n", "3\n", "7\n", "5\n", "1\n"], "outputs": ["3\n", "5\n", "4\n", "1\n", "2\n", "4\n", "3\n", "0\n"]}
coding
201
Solve the programming task below in a Python markdown code block. Ivan has got an array of n non-negative integers a_1, a_2, ..., a_{n}. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2^{a}_1, 2^{a}_2, ..., 2^{a}_{n} on a piece of paper. Now he wonders, what minimum number of...
{"inputs": ["1\n3\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n"], "outputs": ["3\n", "0\n", "1\n", "0\n", "1\n", "2\n", "4\n", "8\n"]}
coding
334
Solve the programming task below in a Python markdown code block. Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n) a group of size k. Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≤ k ≤ n)? Help him and p...
{"inputs": ["1\n1\n", "1\n0\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n14\n", "2\n1 0\n", "2\n0 1\n"], "outputs": ["0\n", "1\n", "0", "0", "0", "0", "2\n", "2\n"]}
coding
265
Solve the programming task below in a Python markdown code block. Batman is about to face Superman so he decides to prepare for the battle by upgrading his Batmobile. He manufactures multiple duplicates of his standard Batmobile each tweaked in a different way such that the maximum speed of each is never less than that...
{"inputs": ["2\n4\n1 2 3 4 5\n5\n1 10 100 1000 10000 100000"], "outputs": ["4\n5"]}
coding
310
Solve the programming task below in a Python markdown code block. Ted$Ted$ loves prime numbers. One day he is playing a game called legendary$legendary$ with his girlfriend Robin$Robin$. Ted$Ted$ writes a number N$N$ on a table and the number is in the form of : N = P1A1 * P2A2 * ……….. * PnAn Ted$Ted$ asks Robin$Robin...
{"inputs": ["1\n3\n2 3 5\n2 1 2\n1 1 1"], "outputs": ["540"]}
coding
635
Solve the programming task below in a Python markdown code block. In the advanced algorithm class, n2 students sit in n rows and n columns. One day, a professor who teaches this subject comes into the class, asks the shortest student in each row to lift up his left hand, and the tallest student in each column to lift u...
{"inputs": ["3\n1 2 3\n4 5 6\n7 5 9\n3\n1 2 3\n1 8 9\n4 5 6\n0", "3\n0 2 3\n4 5 7\n7 1 9\n3\n0 2 3\n7 8 6\n1 5 6\n0", "3\n1 1 3\n0 2 6\n7 9 9\n3\n1 4 3\n7 8 9\n4 8 6\n0", "3\n2 2 3\n4 4 6\n7 4 9\n3\n1 4 3\n7 8 9\n4 8 6\n0", "3\n1 2 3\n4 5 6\n7 8 9\n3\n1 2 3\n7 8 9\n4 5 6\n0", "3\n1 2 3\n4 5 6\n7 10 9\n3\n1 2 3\n7 8 9\n...
coding
311
Solve the programming task below in a Python markdown code block. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card wit...
{"inputs": ["3\n9 1\n5 4\n0 4\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0", "3\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 0\n1 8\n0", "3\n9 1\n5 4\n1 4\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0", "3\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 0\n1 1\n0", "3\n9 1\n5 4\n1 4\n3\n9 1\n6 4\n1 0\n3\n9 1\n5 5\n1 8\n0", "3\n9 1\n5 4\...
coding
686
Solve the programming task below in a Python markdown code block. You have two friends. You want to present each of them several positive integers. You want to present cnt_1 numbers to the first friend and cnt_2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that ...
{"inputs": ["3 1 2 3\n", "1 3 2 3\n", "1 1 2 3\n", "1 2 2 3\n", "2 1 2 3\n", "2 1 2 3\n", "1 2 2 3\n", "1 1 2 3\n"], "outputs": ["5\n", "4\n", "2\n", "3\n", "3\n", "3\n", "3\n", "2\n"]}
coding
461
Solve the programming task below in a Python markdown code block. Takahashi is at an all-you-can-eat restaurant. The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i. The restaurant has the following rules: - You can only order one dish at a time. The dish orde...
{"inputs": ["2 60\n10 10\n60 100\n", "2 60\n10 13\n100 100", "2 60\n10 13\n100 101", "2 60\n10 10\n000 100", "2 60\n10 20\n100 101", "2 60\n10 30\n100 101", "2 60\n10 10\n100 100", "2 60\n10 10\n100 100\n"], "outputs": ["110\n", "113\n", "114\n", "110\n", "121\n", "131\n", "110", "110\n"]}
coding
378
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [oldi, newi] indicates that you may perform the following operation any number of times: Replace a character o...
{"functional": "def check(candidate):\n assert candidate(s = \"fool3e7bar\", sub = \"leet\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]]) == True\n assert candidate(s = \"fooleetbar\", sub = \"f00l\", mappings = [[\"o\",\"0\"]]) == False\n assert candidate(s = \"Fool33tbaR\", sub = \"leetd\", mappin...
coding
166
Please solve the programming task below using a self-contained code snippet in a markdown code block. There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge bet...
{"functional": "def check(candidate):\n assert candidate(coins = [1,0,0,0,0,1], edges = [[0,1],[1,2],[2,3],[3,4],[4,5]]) == 2\n assert candidate(coins = [0,0,0,1,1,0,0,1], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]]) == 2\n\n\ncheck(Solution().collectTheCoins)"}
coding
268
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized. Return the maximum product of the sums of the two subtrees....
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,6])) == 110\n assert candidate(root = tree_node([1,None,2,3,4,None,None,5,6])) == 90\n assert candidate(root = tree_node([2,3,9,10,7,8,6,5,4,11,1])) == 1025\n assert candidate(root = tree_node([1,1])) == 1\n\n\ncheck(Soluti...
coding
185
Solve the programming task below in a Python markdown code block. There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If...
{"inputs": ["3\n0\n2\n1", "3\n0\n1\n0", "3\n0\n0\n0", "3\n0\n2\n2", "3\n0\n1\n2", "3\n0\n2\n0", "3\n1\n1\n0", "3\n1\n0\n0"], "outputs": ["-1\n", "1\n", "0\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]}
coding
297
Solve the programming task below in a Python markdown code block. Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the spoon and r...
{"inputs": ["3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\nbdfhj\ncacac\nopqrs\nddddd\nindia\nyucky"], "outputs": ["There is a spoon!\nThere is a spoon!\nThere is indeed no spoon!"]}
coding
475
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. For a positive, \textbf{even} integer N, we call a pair of arrays A and B to be interesting if they satisfy the following conditions : |A| = |B| = N/2 i.e. the lengt...
{"inputs": ["2\n2\n4"], "outputs": ["NO\nYES\n1 4\n2 3"]}
coding
666
Solve the programming task below in a Python markdown code block. You are given an integer m as a product of integers a_1, a_2, ... a_{n} $(m = \prod_{i = 1}^{n} a_{i})$. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n product...
{"inputs": ["1\n1\n", "1\n1\n", "1\n15\n", "1\n15\n", "2\n5 7\n", "2\n1 2\n", "2\n1 6\n", "2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "4\n", "2\n", "4\n", "2\n"]}
coding
430
Solve the programming task below in a Python markdown code block. You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i. How many kinds of items did you get? -----Constraints----- - 1 \leq N \leq 2\times 10^5 - S_i consists of lowercase English letters and has a length b...
{"inputs": ["4\na`aa\na\naaa\naa", "4\na`ab\na\naaa\naa", "4\nb`aa\na\naaa\naa", "4\nc`aa\na\naaa\naa", "4\n`caa\na\naaa\naa", "4\n`caa\na\naab\naa", "4\n`caa\na\nbaa\naa", "4\n`caa\n`\naab\naa"], "outputs": ["4\n", "4\n", "4\n", "4\n", "4\n", "4\n", "4\n", "4\n"]}
coding
159
Solve the programming task below in a Python markdown code block. A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
{"inputs": ["1\n", "9\n", "4\n", "1\n", "4\n", "9\n", "8\n", "2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
202
Solve the programming task below in a Python markdown code block. The Fair Nut lives in $n$ story house. $a_i$ people live on the $i$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/...
{"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n4\n", "1\n6\n", "1\n5\n", "2\n1 1\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "4"]}
coding
653
Solve the programming task below in a Python markdown code block. Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is ...
{"inputs": ["1\na 2400 2401\n", "1\nX 2400 2500\n", "1\nA 2400 2401\n", "1\na 2400 2455\n", "1\nx 2400 2401\n", "1\nb 2400 2401\n", "1\nx 2400 2401\n", "1\nb 2400 2401\n"], "outputs": ["YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]}
coding
529
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s of length n where s[i] is either: 'D' means decreasing, or 'I' means increasing. A permutation perm of n + 1 integers of all the integers in the range [0, n] is called a valid permutation if...
{"functional": "def check(candidate):\n assert candidate(s = \"DID\") == 5\n\n\ncheck(Solution().numPermsDISequence)"}
coding
176
Solve the programming task below in a Python markdown code block. You're given an array $a$. You should repeat the following operation $k$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. -----I...
{"inputs": ["2 5\n2 3\n", "2 5\n2 3\n", "2 5\n4 3\n", "2 1\n4 3\n", "3 5\n1 2 3\n", "3 7\n1 2 3\n", "3 1\n6 1 7\n", "3 1\n6 6 7\n"], "outputs": ["2\n1\n0\n0\n0\n", "2\n1\n0\n0\n0\n", "3\n1\n0\n0\n0\n", "3\n", "1\n1\n1\n0\n0\n", "1\n1\n1\n0\n0\n0\n0\n", "1\n", "6\n"]}
coding
407
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 two integers $N$ and $K$. You may perform the following operation any number of times (including zero): change $N$ to $N-K$, i.e. subtract $K$ f...
{"inputs": ["3\n5 2\n4 4\n2 5"], "outputs": ["1\n0\n2"]}
coding
441
Solve the programming task below in a Python markdown code block. Read problems statements in Russian here The Head Chef is studying the motivation and satisfaction level of his chefs . The motivation and satisfaction of a Chef can be represented as an integer . The Head Chef wants to know the N th smallest sum of o...
{"inputs": ["1\n3 1\n1 2 3\n4 5 6\n4", "1\n3 1\n1 4 3\n4 5 6\n4", "1\n6 1\n1 4 3\n4 5 6\n1", "1\n6 1\n0 4 3\n4 5 6\n1", "1\n3 1\n1 2 1\n4 5 6\n4", "1\n6 1\n0 8 6\n2 5 6\n1", "1\n8 1\n1 1 3\n4 6 2\n0", "1\n1 1\n2 8 2\n4 2 4\n0"], "outputs": ["7", "7\n", "5\n", "4\n", "6\n", "2\n", "9\n", "12\n"]}
coding
640
Solve the programming task below in a Python markdown code block. «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. ...
{"inputs": ["2\n2\n2\n2\n1\n", "1\n1\n1\n1\n1\n", "2\n3\n2\n2\n1\n", "1\n1\n1\n1\n0\n", "2\n3\n2\n2\n0\n", "2\n3\n4\n2\n0\n", "2\n3\n4\n4\n0\n", "10\n9\n8\n7\n6\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
332
Solve the programming task below in a Python markdown code block. Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its repr...
{"inputs": [".\n", "-.\n", "--\n", "..\n", ".--\n", "--.\n", ".--.\n", ".-..\n"], "outputs": ["0\n", "1\n", "2\n", "00\n", "02\n", "20\n", "020\n", "010\n"]}
coding
193
Solve the programming task below in a Python markdown code block. There are N piles where the i^{th} pile consists of A_{i} stones. Chef and Chefina are playing a game taking alternate turns with Chef starting first. In his/her turn, a player can choose any non-empty pile and remove exactly 1 stone from it. The ga...
{"inputs": ["2\n2\n5 10\n3\n1 1 3\n"], "outputs": ["CHEF\nCHEFINA\n"]}
coding
409
Solve the programming task below in a Python markdown code block. For a positive integer n let's define a function f: f(n) = - 1 + 2 - 3 + .. + ( - 1)^{n}n Your task is to calculate f(n) for a given integer n. -----Input----- The single line contains the positive integer n (1 ≤ n ≤ 10^15). -----Output----- Pr...
{"inputs": ["4\n", "5\n", "1\n", "2\n", "2\n", "1\n", "3\n", "6\n"], "outputs": ["2\n", "-3\n", "-1\n", "1\n", "1\n", "-1\n", "-2\n", "3\n"]}
coding
172
Solve the programming task below in a Python markdown code block. Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that: b is lexicographically greater than or equal to a. b_{i} ≥ 2. b is pairwise coprime: for every 1 ≤ i < j ≤ n, b_{i} and b_{j} are co...
{"inputs": ["3\n3 2 6\n", "3\n6 2 6\n", "3\n6 2 4\n", "3\n10 3 7\n", "3\n3 18 2\n", "3\n3 18 2\n", "3\n4 18 2\n", "3\n2 3 14\n"], "outputs": ["3 2 7\n", "6 5 7\n", "6 5 7\n", "10 3 7 ", "3 19 2 ", "3 19 2 ", "4 19 3\n", "2 3 17\n"]}
coding
398
Solve the programming task below in a Python markdown code block. Uttu got to know about an interesting two-player mobile game recently and invites his friend Gangwar to try it out with him. Gangwar, however, has been playing this game since it was out 5 years ago and is a Legendary Grandmaster at it. Uttu immediately ...
{"inputs": ["2\n10 10\n1 2"], "outputs": ["First"]}
coding
601
Solve the programming task below in a Python markdown code block. The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height a_{i} meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: fo...
{"inputs": ["1 99\n1\n", "1 99\n1\n", "1 65\n1\n", "1 99\n2\n", "3 1\n1 1 2\n", "3 1\n1 1 2\n", "3 1\n2 1 2\n", "3 1\n1 0 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "2\n+ 2 1\n+ 3 1\n", "2\n+ 2 1\n+ 3 1\n", "2\n+ 2 2\n+ 3 2\n", "2\n+ 2 2\n+ 3 1\n"]}
coding
464
Solve the programming task below in a Python markdown code block. In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array. For example, the array `arr = [0, 1, 2, 5, 1, 0]` has a peak at position `3` with a value of `5` (since `arr[3]` equal...
{"functional": "_inputs = [[[1, 2, 3, 6, 4, 1, 2, 3, 2, 1]], [[3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 3]], [[3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 2, 2, 1]], [[2, 1, 3, 1, 2, 2, 2, 2, 1]], [[2, 1, 3, 1, 2, 2, 2, 2]], [[2, 1, 3, 2, 2, 2, 2, 5, 6]], [[2, 1, 3, 2, 2, 2, 2, 1]], [[1, 2, 5, 4, 3, 2, 3, 6, 4, 1, 2, 3, 3, 4, 5, 3, 2, 1,...
coding
736
Solve the programming task below in a Python markdown code block. Given a number `n`, make a down arrow shaped pattern. For example, when `n = 5`, the output would be: 123454321 1234321 12321 121 1 and for `n = 11`, it would be: 123456789010987654321 1234567890987654321 ...
{"functional": "_inputs = [[5]]\n_outputs = [['123454321\\n 1234321\\n 12321\\n 121\\n 1']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len...
coding
343
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game. The board is a 3 x 3 array that consists of char...
{"functional": "def check(candidate):\n assert candidate(board = [\"O \",\" \",\" \"]) == False\n assert candidate(board = [\"XOX\",\" X \",\" \"]) == False\n assert candidate(board = [\"XOX\",\"O O\",\"XOX\"]) == True\n\n\ncheck(Solution().validTicTacToe)"}
coding
233
Solve the programming task below in a Python markdown code block. Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr c...
{"inputs": ["9 4 3\n", "1 0 0\n", "6 5 5\n", "5 4 0\n", "9 4 4\n", "6 0 5\n", "3 0 1\n", "9 3 4\n"], "outputs": ["4", "1", "1", "1", "5\n", "6\n", "2\n", "5\n"]}
coding
178
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times: Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1] XOR ....
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,1,3], maximumBit = 2) == [0,3,2,3]\n assert candidate(nums = [2,3,4,7], maximumBit = 3) == [5,2,6,5]\n assert candidate(nums = [0,1,2,2,5,7], maximumBit = 3) == [4,3,6,4,6,7]\n\n\ncheck(Solution().getMaximumXor)"}
coding
158
Solve the programming task below in a Python markdown code block. Kostya likes the number 4 much. Of course! This number has such a lot of properties, like: - Four is the smallest composite number; - It is also the smallest Smith number; - The smallest non-cyclic group has four elements; - Four is the maximal degree o...
{"inputs": ["5\n8044\n530\n436\n63\n4", "5\n554439\n54\n2354\n4\n0", "5\n163328\n620\n703\n36\n4", "5\n102891\n1947\n0\n134\n6", "5\n163328\n641\n703\n62\n4", "5\n163328\n425\n694\n3\n40", "5\n83423\n1947\n262\n82\n6", "5\n163328\n425\n694\n4\n40"], "outputs": ["2\n0\n1\n0\n1\n", "2\n1\n1\n1\n0\n", "0\n0\n0\n0\n1\n", "...
coding
438
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number o...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,3]) == 1\n assert candidate(nums = [3,4,5,1,2]) == 5\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().numOfWays)"}
coding
222
Solve the programming task below in a Python markdown code block. Chef got into a fight with the evil Dr Doof. Dr Doof has decided to destroy all even numbers from the universe using his Evil-Destroy-inator. Chef has $N$ integers with him. To stop Doof, Chef has to find an odd number which is an integer multiple of all...
{"inputs": ["2\n5\n1 2 5 4 3\n1\n7"], "outputs": ["NO\nYES"]}
coding
420