task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
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"]}
501
36
coding
Solve the programming task below in a Python markdown code block. There are n points on a straight line, and the i-th point among them is located at x_{i}. All these coordinates are distinct. Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring...
{"inputs": ["3\n1 4 7\n", "3\n1 4 6\n", "3\n1 2 6\n", "3\n1 3 6\n", "3\n1 4 7\n", "3\n1 3 6\n", "3\n1 4 6\n", "3\n1 2 6\n"], "outputs": ["0\n", "3\n", "3\n", "3\n", "0\n", "3\n", "3\n", "3\n"]}
301
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and...
{"functional": "def check(candidate):\n assert candidate(source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]) == 1\n assert candidate(source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []) == 2\n assert candidate(source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3]...
224
151
coding
Solve the programming task below in a Python markdown code block. Palindrome Problem Statement Find the number of palindromes closest to the integer n. Note that the non-negative integer x is the number of palindromes, which means that the character string in which x is expressed in decimal notation and the characte...
{"inputs": ["4", "8", "7", "6", "5", "1", "2", "3"], "outputs": ["4\n", "8\n", "7\n", "6\n", "5\n", "1\n", "2\n", "3\n"]}
215
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A cell (r, c) of an excel sheet is represented as a string "<col><row>" where: <col> denotes the column number c of the cell. It is represented by alphabetical letters. For example, the 1st column is denoted by 'A...
{"functional": "def check(candidate):\n assert candidate(s = \"K1:L2\") == [\"K1\",\"K2\",\"L1\",\"L2\"]\n assert candidate(s = \"A1:F1\") == [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"]\n\n\ncheck(Solution().cellsInRange)"}
287
81
coding
Solve the programming task below in a Python markdown code block. One day Prof. Slim decided to leave the kingdom of the GUC to join the kingdom of the GIU. He was given an easy online assessment to solve before joining the GIU. Citizens of the GUC were happy sad to see the prof leaving, so they decided to hack into th...
{"inputs": ["4\n7\n7 3 2 -11 -13 -17 -23\n6\n4 10 25 47 71 96\n6\n71 -35 7 -4 -11 -25\n6\n-45 9 -48 -67 -55 7\n", "8\n2\n-59 -9\n1\n11\n3\n-41 -26 -2\n3\n22 33 54\n3\n-56 -6 55\n5\n36 15 9 14 -71\n3\n-7 40 47\n5\n-19 54 -5 7 -29\n"], "outputs": ["NO\nYES\nYES\nNO\n", "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\n"]}
739
207
coding
Solve the programming task below in a Python markdown code block. In a recent [breakthrough] in mathematics, the proof utilized a concept called Height. Consider a fraction \frac{a}{b}. Its Height is defined as the maximum of its numerator and denominator. So, for example, the Height of \frac{3}{19} would be 19, and t...
{"inputs": ["3 19\n", "27 4\n"], "outputs": ["19\n", "27\n"]}
306
30
coding
Solve the programming task below in a Python markdown code block. Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n_1 balls and second player's box contains exactly n_2 balls. In one move first player can take from 1 to k_1 balls from his box and throw ...
{"inputs": ["2 2 1 2\n", "2 1 1 1\n", "5 7 4 1\n", "5 7 1 4\n", "1 1 1 1\n", "5 7 1 4\n", "5 7 4 1\n", "1 1 1 1\n"], "outputs": ["Second\n", "First\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n"]}
310
118
coding
Solve the programming task below in a Python markdown code block. For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M. Constraints * 1 ≤ m ≤ 100 * 1 ≤ n ≤ 109 Input m n Two integers m and n are given in a line. Output Print mn (mod 1,000,000,007) ...
{"inputs": ["2 1", "5 9", "2 2", "7 9", "3 3", "1 3", "3 1", "0 1"], "outputs": ["2\n", "1953125\n", "4\n", "40353607\n", "27\n", "1\n", "3\n", "0\n"]}
147
92
coding
Solve the programming task below in a Python markdown code block. The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single `100`, `50` or `25` dollar bill. An "Avengers" ticket costs `25 dollars`. Vasya is currently working a...
{"functional": "_inputs = [[[25, 25, 50]], [[25, 25, 50, 100]], [[25, 100]], [[25, 25, 25, 25, 25, 25, 25, 25, 25, 25]], [[50, 50, 50, 50, 50, 50, 50, 50, 50, 50]], [[100, 100, 100, 100, 100, 100, 100, 100, 100, 100]], [[25, 25, 25, 25, 50, 100, 50]], [[50, 100, 100]], [[25, 25, 100]], [[25, 25, 25, 25, 25, 25, 25, 50,...
551
887
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array arr, return the length of a maximum size turbulent subarray of arr. A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray. More formally, a ...
{"functional": "def check(candidate):\n assert candidate(arr = [9,4,2,10,7,8,8,1,9]) == 5\n assert candidate(arr = [4,8,12,16]) == 2\n assert candidate(arr = [100]) == 1\n\n\ncheck(Solution().maxTurbulenceSize)"}
205
85
coding
Solve the programming task below in a Python markdown code block. Is the number even? If the numbers is even return `true`. If it's odd, return `false`. Oh yeah... the following symbols/commands have been disabled! use of ```%``` use of ```.even?``` in Ruby use of ```mod``` in Python Also feel free to reuse/ext...
{"functional": "_inputs = [[2], [3], [14], [15], [26], [27]]\n_outputs = [[True], [False], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple))...
94
188
coding
Solve the programming task below in a Python markdown code block. We will define Ginkgo numbers and multiplication on Ginkgo numbers. A Ginkgo number is a pair <m, n> where m and n are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers. The multiplication on Ginkgo numbers is defined by <m, n> * <x...
{"inputs": ["8\n2 0\n1 2\n-3 1\n4 2\n0 -13\n-4 1\n-2 0\n2 0", "8\n10 -1\n0 2\n0 3\n4 0\n2 -25\n-4 0\n-2 0\n2 0", "8\n10 -1\n0 2\n0 3\n8 0\n2 -23\n-4 0\n-2 1\n2 0", "8\n2 0\n1 2\n-3 1\n4 2\n0 -13\n-4 1\n-2 0\n2 -1", "8\n10 -1\n0 2\n0 3\n4 1\n2 -23\n-4 0\n-2 0\n2 0", "8\n4 0\n0 2\n-3 1\n4 2\n0 -32\n-4 0\n-3 0\n2 -1", "8\...
635
462
coding
Solve the programming task below in a Python markdown code block. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions x_{i}, y_{i} (x_{i} < y_{i}) in the permuted array a. Let's define the value d_{i} = y_{i} - x_{i} — the distance bet...
{"inputs": ["2\n", "1\n", "3\n", "4\n", "4\n", "3\n", "8\n", "6\n"], "outputs": ["1 1 2 2\n", "1 1\n", "1 3 1 2 2 3\n", "1 3 3 1 2 4 2 4\n", "1 3 3 1 2 4 2 4 ", "1 3 1 2 2 3 ", "1 3 5 7 7 5 3 1 2 4 6 8 6 4 2 8 \n", "1 3 5 5 3 1 2 4 6 4 2 6 \n"]}
216
178
coding
Solve the programming task below in a Python markdown code block. Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from ...
{"inputs": ["1 0\n", "2 2\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "4 1\n1 2\n2 3\n3 4\n", "5 1\n1 2\n4 3\n5 3\n2 3\n", "7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n", "10 5\n6 4\n4 1\n7 5\n8 7\n2 6\n3 6\n8 6\n10 3\n4 9\n"], "outputs": ["1", "3\n", "3", "1", "9", "15", "91", "1023"]}
559
186
coding
Solve the programming task below in a Python markdown code block. There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the ...
{"inputs": ["6 2 1", "5 3 1", "5 3 2", "3 2 0", "7 2 1", "2 2 1", "7 3 2", "5 4 2"], "outputs": ["12\n", "144\n", "216\n", "2\n", "14\n", "4\n", "1488\n", "972\n"]}
283
105
coding
Solve the programming task below in a Python markdown code block. Humpy, the little elephant, has his birthday coming up. He invited all his cousins but doesn’t know how many of them are really coming as some of them are having exams coming up. He will only get to know how many of them are coming on the day of his birt...
{"inputs": ["2\n4 10 2\n2 2 3 1\n4 12 3\n6 5 7 3"], "outputs": ["YES\nNO"]}
383
44
coding
Solve the programming task below in a Python markdown code block. There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N oper...
{"inputs": ["3 4\n1 1\n2 2\n3 2", "3 4\n1 1\n2 3\n3 2", "3 4\n1 1\n4 3\n3 2", "3 5\n2 2\n1 1\n8 3", "3 3\n2 2\n1 0\n5 3", "3 3\n2 2\n1 0\n7 3", "3 4\n1 0\n2 1\n6 6", "3 0\n2 2\n0 0\n3 6"], "outputs": ["3\n", "2\n", "4\n", "8\n", "5\n", "7\n", "6\n", "0\n"]}
244
174
coding
Solve the programming task below in a Python markdown code block. The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vecto...
{"inputs": ["2\n", "1\n", "3\n", "0\n", "4\n", "2\n", "4\n", "1\n"], "outputs": ["++++\n+*+*\n++**\n+**+\n", "++\n+*\n", "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*\n", "+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\...
721
468
coding
Solve the programming task below in a Python markdown code block. B: Twins One twin was angry that it was not well known which of them was the older brother and which was the younger brother. Create a program that outputs "square1001" when "ani" is entered and "e869120" when "otouto" is entered. input You will be g...
{"inputs": ["ani"], "outputs": ["square1001"]}
187
16
coding
Solve the programming task below in a Python markdown code block. In this kata we want to convert a string into an integer. The strings simply represent the numbers in words. Examples: * "one" => 1 * "twenty" => 20 * "two hundred forty-six" => 246 * "seven hundred eighty-three thousand nine hundred and nineteen" => 7...
{"functional": "_inputs = [['zero'], ['one'], ['two'], ['three'], ['four'], ['five'], ['six'], ['seven'], ['eight'], ['nine'], ['ten'], ['twenty'], ['twenty-one'], ['thirty-seven'], ['forty-six'], ['fifty-nine'], ['sixty-eight'], ['seventy-two'], ['eighty-three'], ['ninety-four'], ['one hundred'], ['one hundred one'], ...
190
565
coding
Solve the programming task below in a Python markdown code block. This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and...
{"inputs": ["5\n3\n+-+\n5\n-+---\n4\n----\n7\n--+---+\n6\n+++---\n"], "outputs": ["2\n4\n2\n7\n4\n"]}
631
51
coding
Solve the programming task below in a Python markdown code block. An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9. -----Constraints----- - 0 \leq N < 10^{200000} - N is an integer. -----Input----- Inpu...
{"inputs": ["1", "2", "3", "9", "6", "8", "4", "0"], "outputs": ["No\n", "No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "Yes"]}
193
61
coding
Solve the programming task below in a Python markdown code block. “I am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!” Skyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and then go ...
{"inputs": ["3\n0 5\n4 -5\n0 10000001"], "outputs": ["1\n2\n1"]}
483
35
coding
Solve the programming task below in a Python markdown code block. Chef has with him an array A of length N. In one move, he can delete any element from A. Find the minimum number of deletions Chef must make so that the following condition holds: Let B denote the resulting array, and M be the length of B. Then, B_{i} \...
{"inputs": ["4\n4\n2 2 2 2\n5\n3 4 3 4 4\n5\n1 2 3 4 0\n6\n5 5 5 6 6 6\n"], "outputs": ["0\n2\n3\n3\n"]}
635
68
coding
Solve the programming task below in a Python markdown code block. A first-year student, came to your college. Being a good senior, you must tell him if it is possible to go from College Main Gate to Hostel for him. The college can be visualized on a 2D-plane. Suppose the College Main Gate is situated at origin i.e. at...
{"inputs": ["4\n1 2 1\n3 -5 2\n-9 -6 3\n-18 12 5\n"], "outputs": ["YES\nNO\nYES\nNO"]}
622
47
coding
Solve the programming task below in a Python markdown code block. Write a function that returns the count of characters that have to be removed in order to get a string with no consecutive repeats. *Note:* This includes any characters ## Examples ```python 'abbbbc' => 'abc' # answer: 3 'abbcca' => 'abca' # ...
{"functional": "_inputs = [['abcdefg'], ['aabbccddeeffgg'], ['abcdeefee'], ['122453124'], ['@*$##^^^*)*'], ['abmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmvxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
132
390
coding
Solve the programming task below in a Python markdown code block. Diana is planning to make a very long journey. Her journey consists of $N$ bus routes, numbered from $1 to N$ in the order she must take them. The buses themselves are very fast but do not run often. The $i-th$ bus route only runs every $Xi$ days. More ...
{"inputs": ["3\n3 10\n3 7 2\n4 100\n11 10 5 50\n1 1\n1"], "outputs": ["6\n99\n1"]}
688
51
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. It's a lockdown. You’re bored in your house and are playing golf in the hallway. The hallway has $N + 2$ tiles numbered from $0$ to $N+1$ from left to right...
{"inputs": ["3\n5 4 2\n5 3 2\n5 5 2"], "outputs": ["YES\nNO\nNO"]}
646
34
coding
Solve the programming task below in a Python markdown code block. Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ...
{"inputs": ["5\n", "9\n", "1\n", "0\n", "3\n", "4\n", "6\n", "7\n"], "outputs": ["0\n", "10\n", "0\n", "0\n", "0\n", "0\n", "10\n", "10\n"]}
289
73
coding
Solve the programming task below in a Python markdown code block. Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use them. Let’...
{"inputs": ["2 10 3\n100 3\n99 1\n", "2 100 2\n100 2\n100 2\n", "2 1000 1\n100 1\n100 1\n", "2 1000 1\n100 1\n100 2\n", "2 1001 0\n101 1\n100 2\n", "2 1000 1\n101 1\n100 2\n", "2 1001 1\n101 1\n100 2\n", "2 100 10\n100 11\n90 9\n"], "outputs": ["NO\n", "YES\n51 2\n0 1\n1 2\n", "YES\n1001 2\n0 1\n1 2\n", "YES\n501 2\n0 ...
628
316
coding
Solve the programming task below in a Python markdown code block. Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements. For example: ```python unique_in_order('AAA...
{"functional": "_inputs = [[''], ['A'], ['AA'], ['AAAABBBCCDAABBB'], ['AADD'], ['AAD'], ['ADD'], ['ABBCcAD'], [[1, 2, 3, 3]], [['a', 'b', 'b']]]\n_outputs = [[[]], [['A']], [['A']], [['A', 'B', 'C', 'D', 'A', 'B']], [['A', 'D']], [['A', 'D']], [['A', 'D']], [['A', 'B', 'C', 'c', 'A', 'D']], [[1, 2, 3]], [['a', 'b']]]\n...
164
283
coding
Solve the programming task below in a Python markdown code block. Let's call a sequence of integers $x_1, x_2, \dots, x_k$ MEX-correct if for all $i$ ($1 \le i \le k$) $|x_i - \operatorname{MEX}(x_1, x_2, \dots, x_i)| \le 1$ holds. Where $\operatorname{MEX}(x_1, \dots, x_k)$ is the minimum non-negative integer that doe...
{"inputs": ["4\n3\n0 2 1\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 0\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 1\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 1 3\n", "4\n3\n0 2 0\n2\n1 0\n5\n0 0 1 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 1\n2\n1 1\n5\n0 0 0 0 0\n4\n0 1 1 3\n", "4\n3\n1 2 0\n2\n1 0\n5\n0 0 1 0 0\n4\n0 1 2 3\n", "4...
664
444
coding
Solve the programming task below in a Python markdown code block. Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test ...
{"inputs": ["2\n5 3\n2 4 2 4 2\n8 5\n9 3 5 7 8 11 17 2"], "outputs": ["5\n3"]}
318
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such ...
{"functional": "def check(candidate):\n assert candidate(n = 8) == 6\n assert candidate(n = 1) == 1\n assert candidate(n = 4) == -1\n\n\ncheck(Solution().pivotInteger)"}
119
55
coding
Solve the programming task below in a Python markdown code block. Recently, the Fair Nut has written $k$ strings of length $n$, consisting of letters "a" and "b". He calculated $c$ — the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost hi...
{"inputs": ["1 1\na\na\n", "1 1\na\na\n", "2 4\naa\nbb\n", "2 4\nab\nbb\n", "2 4\nba\nbb\n", "2 5\nab\nbb\n", "2 4\naa\nbb\n", "3 3\naba\nbba\n"], "outputs": ["1", "1\n", "6\n", "5\n", "3\n", "5\n", "6\n", "8\n"]}
503
118
coding
Solve the programming task below in a Python markdown code block. Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to max...
{"inputs": ["V\n", "K\n", "K\n", "V\n", "VK\n", "VV\n", "KV\n", "KK\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n"]}
393
70
coding
Solve the programming task below in a Python markdown code block. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a i...
{"inputs": ["11\n", "111\n", "110\n", "100\n", "101\n", "1111\n", "1011\n", "1001\n"], "outputs": ["1\n", "11\n", "11", "10", "11\n", "111\n", "111", "101"]}
297
94
coding
Solve the programming task below in a Python markdown code block. Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a_0 + a_1x^1 + ... + a_{n}x^{n}. Numbers a_{i} are called coefficients of a polynomial, non-negative integer n is ...
{"inputs": ["2 2 2\n", "2 3 3\n", "1 1 1\n", "7 8 9\n", "3 3 3\n", "1 5 5\n", "1 2 2\n", "1 2 5\n"], "outputs": ["2\n", "1\n", "inf\n", "1\n", "2\n", "1\n", "1\n", "1\n"]}
286
102
coding
Solve the programming task below in a Python markdown code block. You are given two integers $n$ and $k$. You should create an array of $n$ positive integers $a_1, a_2, \dots, a_n$ such that the sum $(a_1 + a_2 + \dots + a_n)$ is divisible by $k$ and maximum element in $a$ is minimum possible. What is the minimum pos...
{"inputs": ["1\n7 99999999\n", "1\n2 33554431\n", "1\n2 69696969\n", "1\n7 99999999\n", "1\n2 69696969\n", "1\n2 33554431\n", "1\n2 54472221\n", "1\n7 49552848\n"], "outputs": ["14285715\n", "16777216\n", "34848485\n", "14285715\n", "34848485\n", "16777216\n", "27236111\n", "7078979\n"]}
418
213
coding
Solve the programming task below in a Python markdown code block. # Task The game starts with `n` people standing in a circle. The presenter counts `m` people starting with the first one, and gives `1` coin to each of them. The rest of the players receive `2` coins each. After that, the last person who received `1` co...
{"functional": "_inputs = [[5, 1], [8, 3], [75, 34], [82, 49], [73, 38], [86, 71], [61, 17], [42, 38], [29, 5], [64, 49], [61, 20], [88, 52]]\n_outputs = [[[5, 24]], [[7, 51]], [[35, 4238]], [[48, 5091]], [[61, 3996]], [[10, 6275]], [[26, 3000]], [[12, 1578]], [[28, 740]], [[43, 3327]], [[32, 2922]], [[59, 5856]]]\nimp...
653
352
coding
Solve the programming task below in a Python markdown code block. # Summation Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. For example: ```if-not:racket ~~~ summation(2) -> 3 1 + 2 summation(8) -> 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8...
{"functional": "_inputs = [[1], [8], [22], [100], [213]]\n_outputs = [[1], [36], [253], [5050], [22791]]\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)...
189
194
coding
Solve the programming task below in a Python markdown code block. Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him t_{j} minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the...
{"inputs": ["1 1 0\n2\n", "1 1 1\n1\n", "2 1 0\n2\n", "1 1 0\n4\n", "1 1 0\n5\n", "1 1 3\n5\n", "1 1 3\n5\n", "1 1 0\n5\n"], "outputs": ["0\n", "2\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
476
118
coding
Solve the programming task below in a Python markdown code block. Complete the function that takes two numbers as input, ```num``` and ```nth``` and return the `nth` digit of `num` (counting from right to left). ## Note - If ```num``` is negative, ignore its sign and treat it as a positive value - If ```nth``` is not ...
{"functional": "_inputs = [[5673, 4], [129, 2], [-2825, 3], [0, 20], [65, 0], [24, -8], [-456, 5], [-1234, 2], [-5540, 1], [678998, 0], [-67854, -57], [0, -3]]\n_outputs = [[5], [2], [8], [0], [-1], [-1], [0], [3], [0], [-1], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst...
253
285
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array target and an integer n. You have an empty stack with the two following operations: "Push": pushes an integer to the top of the stack. "Pop": removes the integer on the top of the stack...
{"functional": "def check(candidate):\n assert candidate(target = [1,3], n = 3) == [\"Push\",\"Push\",\"Pop\",\"Push\"]\n assert candidate(target = [1,2,3], n = 3) == [\"Push\",\"Push\",\"Push\"]\n assert candidate(target = [1,2], n = 4) == [\"Push\",\"Push\"]\n\n\ncheck(Solution().buildArray)"}
260
99
coding
Solve the programming task below in a Python markdown code block. You are given a matrix A that consists of N rows and M columns. Every number in the matrix is either zero or one. Calculate the number of such triples (i, j, h) where for all the pairs (x, y), where both x and y belong to [1; h] if y ≥ x, A[i+x-1][j+y-1]...
{"inputs": ["2 3\n011\n111"], "outputs": ["6"]}
350
22
coding
Solve the programming task below in a Python markdown code block. Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes ...
{"inputs": ["2 2\n00\n", "2 2\n00\n", "2 3\n00\n", "3 3\n010\n", "3 2\n010\n", "3 2\n000\n", "3 3\n000\n", "3 3\n000\n"], "outputs": ["0\n", "0", "0\n", "1\n", "1\n", "1\n", "0\n", "0"]}
574
113
coding
Solve the programming task below in a Python markdown code block. A number K$K$ is said to be magical if it can be represented as a power of 2 only.That is K$K$=2x$2^{x}$ for some natural number x$x$. Given a string of digits S$S$ of length N$N$, Let P be a valid arrangement of S. By valid arrangement we mean that it ...
{"inputs": ["2\n35566\n31"], "outputs": ["65536\n-1"]}
471
28
coding
Solve the programming task below in a Python markdown code block. The Chef has a huge square napkin of size 2n X 2n. He folds the napkin n-3 times. Each time he folds its bottom side over its top side, and then its right side over its left side. After each fold, the side length of the napkin is reduced by half. The Che...
{"inputs": ["3\n3\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n4\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n1000000000\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n\n"], "outputs": ["6\n22\n1"]}
771
250
coding
Solve the programming task below in a Python markdown code block. Platypus Perry is on a mission again. This time, Dr. Heinz Doofenshmirtz has plotted a bomb in the centre of Danville town. He wishes to rebuild the town. We need to defuse the bomb for Perry. As always, Dr. Heinz has given perry the key combination to ...
{"inputs": ["2\n987654321 123\n120000000 22"], "outputs": ["121401\n107748\n94095\n80442\n66789\n53136\n39483\n264\n440\n0\n0\n0\n0\n0\n0"]}
345
101
coding
Solve the programming task below in a Python markdown code block. Find the 2nd largest integer in array If the array has no 2nd largest integer then return nil. Reject all non integers elements and then find the 2nd largest integer in array find_2nd_largest([1,2,3]) => 2 find_2nd_largest([1,1,1,1,1]) => nil because a...
{"functional": "_inputs = [[[1, 2, 3]], [[1, 1, 1, 1, 1, 1, 1]], [[1, 'a', '2', 3, 3, 4, 5, 'b']], [[1, 'a', '2', 3, 3, 3333333333333333333334, 544444444444444444444444444444, 'b']]]\n_outputs = [[2], [None], [4], [3333333333333333333334]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin...
222
314
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x n rooms laid out in a 2D grid. Our valiant knight was initially positioned in the top-left r...
{"functional": "def check(candidate):\n assert candidate(dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]]) == 7\n assert candidate(dungeon = [[0]]) == 1\n\n\ncheck(Solution().calculateMinimumHP)"}
258
66
coding
Solve the programming task below in a Python markdown code block. This is a hard version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase...
{"inputs": ["1\nr\n", "1\nr\n", "1\ns\n", "2\ntj\n", "2\ntj\n", "2\nti\n", "2\nit\n", "5\nabcde\n"], "outputs": ["1\n1 \n", "1\n1 \n", "1\n1 \n", "2\n1 2 \n", "2\n1 2 \n", "2\n1 2 \n", "1\n1 1 \n", "1\n1 1 1 1 1 \n"]}
514
130
coding
Solve the programming task below in a Python markdown code block. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foo...
{"inputs": ["3 1\n4 2 1\n2 3 1", "3 6\n4 2 1\n2 3 1", "3 1\n8 2 1\n2 3 1", "3 8\n4 1 1\n2 3 1", "3 1\n2 2 1\n2 3 1", "3 6\n4 4 1\n2 3 1", "3 2\n8 2 1\n2 3 1", "3 1\n8 2 1\n1 3 1"], "outputs": ["4\n", "1\n", "7\n", "0\n", "3\n", "2\n", "6\n", "7\n"]}
565
174
coding
Solve the programming task below in a Python markdown code block. You are given a program that consists of $n$ instructions. Initially a single variable $x$ is assigned to $0$. Afterwards, the instructions are of two types: increase $x$ by $1$; decrease $x$ by $1$. You are given $m$ queries of the following format: ...
{"inputs": ["2\n8 4\n-+--+--+\n1 8\n2 8\n2 5\n1 1\n4 10\n+-++\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n", "2\n8 4\n-+--+--+\n2 8\n2 8\n2 5\n1 1\n4 10\n+-++\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n", "2\n8 4\n-+--+--+\n1 8\n2 8\n2 5\n2 1\n4 10\n+-++\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\...
628
878
coding
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"]}
586
52
coding
Solve the programming task below in a Python markdown code block. You have two strings, $a$ and $\boldsymbol{b}$. Find a string, $\boldsymbol{\mathrm{~S~}}$, such that: $\boldsymbol{\mathrm{~S~}}$ can be expressed as $s=s_{a}+s_{b}$ where $\boldsymbol{s_{a}}$ is a non-empty substring of $a$ and $s_{b}$ is a non-empty ...
{"inputs": ["3\nbac\nbac\nabc\ndef\njdfh\nfds\n"], "outputs": ["aba\n-1\ndfhfd\n"]}
625
35
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix". Chef has a matrix that consists of n rows, each...
{"inputs": ["4 4 6\n2 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 1", "4 4 6\n3 2\n3 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 6\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 2\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "3 6 2\n1 2\n3 0 \n6 2 \n4 3\n1 1\n5 3", "3 4 2\n1 2\n3 0 \n6 ...
661
349
coding
Solve the programming task below in a Python markdown code block. Recently in JEC ants have become huge, the Principal is on a journey to snipe them !! Principal has limited $N$ practice Bullets to practice so that he can be sure to kill ants. - The Practice ground has max length $L$. - There is a Limit X such that if ...
{"inputs": ["2\n1 10\n2 10"], "outputs": ["10\n4"]}
489
25
coding
Solve the programming task below in a Python markdown code block. Chef's pizza is the tastiest pizza to exist, and the reason for that is his special, juicy homegrown tomatoes. Tomatoes can be grown in rectangular patches of any side lengths. However, Chef only has a limited amount of land. Consider the entire town o...
{"inputs": ["2\n4\n10000000000"], "outputs": ["23\n227374950"]}
473
37
coding
Solve the programming task below in a Python markdown code block. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It...
{"inputs": ["aatt\n", "atatat\n", "doatdt\n", "taatta\n", "eoatdt\n", "taatua\n", "epatdt\n", "tbatua\n"], "outputs": ["a@t\n", "at@at\n", "do@dt\n", "ta@ta\n", "eo@dt\n", "ta@ua\n", "ep@dt\n", "tb@ua\n"]}
398
99
coding
Solve the programming task below in a Python markdown code block. You're given a sequence of N distinct integers. You need to find a subsequence of length K with the maximum possible median. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing o...
{"inputs": ["1\n5 3\n1 4 3 6 5"], "outputs": ["5\n1 6 5"]}
542
32
coding
Solve the programming task below in a Python markdown code block. Kiyora has $n$ whiteboards numbered from $1$ to $n$. Initially, the $i$-th whiteboard has the integer $a_i$ written on it. Koxia performs $m$ operations. The $j$-th operation is to choose one of the whiteboards and change the integer written on it to $b...
{"inputs": ["4\n3 2\n1 2 3\n4 5\n2 3\n1 2\n3 4 5\n1 1\n100\n1\n5 3\n1 1 1 1 1\n1000000000 1000000000 1000000000\n"], "outputs": ["12\n9\n1\n3000000002\n"]}
631
115
coding
Solve the programming task below in a Python markdown code block. You are given an array A of N integers . You want to convert the array A into a permutation of N integers. To do this, you can apply the following operation on array A exactly once . Pick an integer X, where 1 ≤ X ≤ 2\cdot 10^{7}. For each i , 1 ≤ i ≤ N...
{"inputs": ["2\n3\n2 7 1\n2\n2 2"], "outputs": ["YES 4\nNO"]}
528
30
coding
Solve the programming task below in a Python markdown code block. In Berland, $n$ different types of banknotes are used. Banknotes of the $i$-th type have denomination $10^{a_i}$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $1$. Let's denote $f(s)$ as the...
{"inputs": ["4\n3 1\n0 1 2\n2 777\n0 2\n3 60\n0 1 3\n10 0000000010\n0 1 2 3 4 5 6 7 8 9\n", "4\n3 1\n0 1 2\n2 777\n0 2\n3 60\n0 1 3\n10 0000000011\n0 1 2 3 4 5 6 7 8 9\n", "4\n3 2\n0 1 2\n2 777\n0 2\n3 60\n0 1 3\n10 0000000010\n0 1 2 3 4 5 6 7 8 9\n", "4\n3 2\n0 1 2\n2 983\n0 2\n3 60\n0 1 3\n10 0000000010\n0 1 2 3 4 5 ...
518
712
coding
Solve the programming task below in a Python markdown code block. Multiplication of Big Integers Given two integers $A$ and $B$, compute the product, $A \times B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the product in a line. Constraints * $-1 \times 10^{1...
{"inputs": ["1 1", "9 1", "6 1", "6 2", "6 4", "5 8", "5 16", "0 16"], "outputs": ["1\n", "9\n", "6\n", "12\n", "24\n", "40", "80\n", "0\n"]}
195
83
coding
Solve the programming task below in a Python markdown code block. Bob is a lazy man. He needs you to create a method that can determine how many ```letters``` and ```digits``` are in a given string. Example: "hel2!lo" --> 6 "wicked .. !" --> 6 "!?..A" --> 1 Also feel free to reuse/extend the following starter c...
{"functional": "_inputs = [['n!!ice!!123'], ['de?=?=tttes!!t'], [''], ['!@#$%^&`~.'], ['u_n_d_e_r__S_C_O_R_E']]\n_outputs = [[7], [8], [0], [0], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if is...
97
210
coding
Solve the programming task below in a Python markdown code block. We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is 0, and white if S_{i,j} is 1. We will cut the bar some nu...
{"inputs": ["3 5 8\n11100\n10101\n00111", "3 5 8\n11100\n00101\n00111", "3 5 4\n11100\n10001\n00110", "3 5 8\n11100\n10111\n00111", "3 0 8\n11100\n00101\n00111", "5 0 8\n11100\n00101\n00111", "8 0 8\n11100\n00101\n00111", "8 0 8\n11100\n00101\n01111"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]...
383
238
coding
Solve the programming task below in a Python markdown code block. Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew ...
{"inputs": ["1\n0\n1\n", "1\n1\n0\n", "2\n0 0\n1 2\n", "2\n0 0\n2 1\n", "2\n0 1\n0 2\n", "2\n0 2\n0 1\n", "2\n1 0\n0 2\n", "3\n0 0 0\n2 3 1\n"], "outputs": ["0\n", "1\n", "0\n", "4\n", "3\n", "1\n", "3\n", "6\n"]}
584
130
coding
Solve the programming task below in a Python markdown code block. Iahub got bored, so he invented a game to be played on paper.  He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values ak ...
{"functional": "_inputs = [[[1, 0, 0, 1, 0, 0]], [[1, 0, 0, 1]], [[1]], [[0]], [[1, 0, 0, 0, 1, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1]]]\n_o...
492
434
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array ribbons, where ribbons[i] represents the length of the ith ribbon, and an integer k. You may cut any of the ribbons into any number of segments of positive integer lengths, or perform no...
{"functional": "def check(candidate):\n assert candidate(ribbons = [9,7,5], k = 3) == 5\n assert candidate(ribbons = [7,5,9], k = 4) == 4\n assert candidate(ribbons = [5,7,9], k = 22) == 0\n\n\ncheck(Solution().maxLength)"}
250
88
coding
Solve the programming task below in a Python markdown code block. .task { background: #fff; color: #333; padding: 25px; box-sizing: border-box; font-family: Comfortaa, sans-serif !important; position: relative; } .task code, .task_code { display: inline-block; padding: 0; border-radius: 2px; margin:...
{"functional": "_inputs = [[10]]\n_outputs = [[3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(...
606
157
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be: 1 which means go to the cell to the right. (i.e go fr...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]) == 3\n assert candidate(grid = [[1,1,3],[3,2,2],[1,1,4]]) == 0\n assert candidate(grid = [[1,2],[4,3]]) == 1\n assert candidate(grid = [[2,2,2],[2,2,2]]) == 3\n assert candidate(grid = [[4]]) == 0\n...
340
141
coding
Solve the programming task below in a Python markdown code block. The [Chinese zodiac](https://en.wikipedia.org/wiki/Chinese_zodiac) is a repeating cycle of 12 years, with each year being represented by an animal and its reputed attributes. The lunar calendar is divided into cycles of 60 years each, and each year has a...
{"functional": "_inputs = [[1965], [1938], [1998], [2016], [1924], [1968], [2162], [6479], [3050], [6673], [6594], [9911], [2323], [3448], [1972]]\n_outputs = [['Wood Snake'], ['Earth Tiger'], ['Earth Tiger'], ['Fire Monkey'], ['Wood Rat'], ['Earth Monkey'], ['Water Dog'], ['Earth Goat'], ['Metal Dog'], ['Water Rooster...
365
301
coding
Solve the programming task below in a Python markdown code block. We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the lette...
{"inputs": ["ant\nobe\nrfc", "ddu\ncat\nion", "ant\nobe\nrcf", "ddu\ncat\nioo", "ddu\ncat\nooi", "una\nobe\nrcf", "edu\nbau\nooi", "una\npbe\nfdr"], "outputs": ["abc\n", "dan\n", "abf\n", "dao\n", "dai\n", "ubf\n", "eai\n", "ubr\n"]}
267
113
coding
Solve the programming task below in a Python markdown code block. There is a robot staying at $X=0$ on the $Ox$ axis. He has to walk to $X=n$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel. The $i$-th segment of the path (from $X=i-1$ to $X=i$...
{"inputs": ["1 1 1\n0\n", "1 1 1\n0\n", "2 1 1\n0 0\n", "2 1 1\n0 0\n", "2 0 1\n0 0\n", "3 1 1\n1 1 1\n", "3 1 1\n1 1 1\n", "4 1 1\n1 1 1 0\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "3\n", "3\n", "3\n"]}
706
138
coding
Solve the programming task below in a Python markdown code block. # Task Given an array of 2^(k) integers (for some integer `k`), perform the following operations until the array contains only one element: ``` On the 1st, 3rd, 5th, etc. iterations (1-based) replace each pair of consecutive elements with their sum; On...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[3, 3, 5, 5]]]\n_outputs = [[186], [64], [60]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n i...
310
245
coding
Solve the programming task below in a Python markdown code block. We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black? -----Constraints----- - 1 \leq N \leq 100 - 0 \leq A \leq N^2 -----Inputs----...
{"inputs": ["3\n2", "3\n3", "3\n0", "3\n1", "3\n6", "3\n5", "3\n7", "3\n9"], "outputs": ["7\n", "6\n", "9\n", "8\n", "3\n", "4\n", "2\n", "0\n"]}
163
78
coding
Solve the programming task below in a Python markdown code block. Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 Constraints * 1 \leq K \leq 32 * All values in input are integers. Input Input is given...
{"inputs": ["8", "1", "5", "8", "1", "5", "6", "16"], "outputs": ["5\n", "1\n", "1\n", "5\n", "1\n", "1\n", "2", "14\n"]}
191
63
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, find the length of the longest substring without repeating characters.   Please complete the following python code precisely: ```python class Solution: def lengthOfLongestSubstring(self, s: str) ...
{"functional": "def check(candidate):\n assert candidate(s = \"abcabcbb\") == 3\n assert candidate(s = \"bbbbb\") == 1\n assert candidate(s = \"pwwkew\") == 3\n\n\ncheck(Solution().lengthOfLongestSubstring)"}
66
64
coding
Solve the programming task below in a Python markdown code block. ## Check Digits Some numbers are more important to get right during data entry than others: a common example is product codes. To reduce the possibility of mistakes, product codes can be crafted in such a way that simple errors are detected. This is do...
{"functional": "_inputs = [['036532'], ['12388878'], ['111111111'], ['9735597355'], ['2356'], ['6789']]\n_outputs = [['0365327'], ['123888782'], ['1111111118'], ['97355973550'], ['23566'], ['6789X']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i...
573
261
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The diameter of a tree is the number of edges in the longest path in that tree. There is an undirected tree of n nodes labeled from 0 to n - 1. You are given a 2D array edges where edges.length == n - 1 and edges[i] =...
{"functional": "def check(candidate):\n assert candidate(edges = [[0,1],[0,2]]) == 2\n assert candidate(edges = [[0,1],[1,2],[2,3],[1,4],[4,5]]) == 4\n\n\ncheck(Solution().treeDiameter)"}
138
68
coding
Solve the programming task below in a Python markdown code block. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original...
{"inputs": ["BWBBW", "WWBBB", "WBBWB", "WBBXB", "BXBBW", "BXBWB", "BXWBB", "WXBBB"], "outputs": ["3\n", "1\n", "3\n", "3\n", "3\n", "4\n", "3\n", "2\n"]}
427
78
coding
Solve the programming task below in a Python markdown code block. Tom has finally taken over the business empire and now looking for a new Name of the business to make a new start. Joe (Tom's dear friend) suggested a string $S$ consisting of Uppercase and lowercase letters Tom wants to make some changes as pe...
{"inputs": ["CodeSprInT"], "outputs": [".c.d.s.p.r.n.t"]}
408
22
coding
Solve the programming task below in a Python markdown code block. Chouti is working on a strange math problem. There was a sequence of $n$ positive integers $x_1, x_2, \ldots, x_n$, where $n$ is even. The sequence was very special, namely for every integer $t$ from $1$ to $n$, $x_1+x_2+...+x_t$ is a square of some int...
{"inputs": ["2\n1\n", "2\n1\n", "2\n780\n", "2\n524\n", "2\n203\n", "2\n9900\n", "2\n9900\n", "4\n35 15\n"], "outputs": ["No\n", "No\n", "Yes\n4 780\n", "Yes\n16900 524\n", "Yes\n121 203\n", "Yes\n100 9900\n", "Yes\n100 9900 ", "Yes\n1 35 13 15\n"]}
690
154
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the ith stone. Alice and Bob t...
{"functional": "def check(candidate):\n assert candidate(stones = [2,1]) == True\n assert candidate(stones = [2]) == False\n assert candidate(stones = [5,1,2,4,3]) == False\n\n\ncheck(Solution().stoneGameIX)"}
179
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)   Please complete the f...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4])), list_node([2,1,4,3]))\n assert is_same_list(candidate(head = list_node([])), list_node([]))\n assert is_same_list(candidate(head = list_node([1])), list_node([1]))\n\n\ncheck(Solution().swapPairs)"}
134
89
coding
Solve the programming task below in a Python markdown code block. Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array $a=[1, 3, 3, 7]$ is good because there is the element $a_4=7$ which equals to the sum $1 + 3 + 3$. You are given an array $...
{"inputs": ["2\n4 5\n", "2\n2 2\n", "2\n1 1\n", "2\n1 5\n", "2\n1 2\n", "2\n5 1\n", "2\n1 5\n", "2\n1 1\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]}
756
110
coding
Solve the programming task below in a Python markdown code block. Chef is playing an easier variation of the board game ‘Risk’ with his friend Mike. There is an $N * M$ grid, depicting the world map. Each cell of the grid is either $1$ or $0$ where $1$ denotes that there is land on this cell, while $0$ denotes water. ...
{"inputs": ["3\n4 4\n1001\n0110\n0110\n1001\n2 2\n11\n11\n3 3\n100\n010\n001"], "outputs": ["2\n0\n1"]}
617
66
coding
Solve the programming task below in a Python markdown code block. You are given an array of n integers a1... an. The cost of a subsegment is the number of unordered pairs of distinct indices within the subsegment that contain equal elements. Split the given array into k non-intersecting non-empty subsegments so that th...
{"inputs": ["2 2\n2 2\n", "7 3\n1 1 3 3 4 2 1\n", "7 3\n1 1 3 3 1 2 1\n", "7 3\n1 1 2 3 4 2 1\n", "7 3\n1 2 2 3 4 2 1\n", "7 3\n1 1 3 3 6 2 1\n", "7 3\n1 2 2 3 4 1 1\n", "7 6\n1 1 3 3 1 2 1\n"], "outputs": ["0", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
429
187
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the ...
{"inputs": ["1\n", "1\n", "2\n", "6\n", "10\n", "25\n", "52\n", "57\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n", "1\n", "1\n"]}
315
75
coding
Solve the programming task below in a Python markdown code block. Most of the time when rounding a given number, it is customary to round to some multiple of a power of 10. However, there is no reason why we cannot use another multiple to do our rounding to. For example, you could round to the nearest multiple of 7, or...
{"inputs": ["26\n5 10\n4 10\n100 3\n123456 7\n49 7\n158854 50\n822992 101\n691238 345\n682373 49\n643378 53\n328697 62\n446656 228\n368684 130\n530193 371\n864163 325\n708578 207\n915093 485\n711860 28\n234554 366\n309089 25\n595700 393\n10 6\n9 19\n4 10\n11 2\n11 3"], "outputs": ["10\n0\n99\n123459\n49\n158850\n822948...
201
379
coding
Solve the programming task below in a Python markdown code block. Chef recently learned about ratios and proportions. He wrote some positive integers a, b, c, d on a paper. Chef wants to know whether he can shuffle these numbers so as to make some proportion? Formally, four numbers x, y, z, w are said to make a proport...
{"inputs": ["1 2 4 2"], "outputs": ["Possible"]}
236
18
coding
Solve the programming task below in a Python markdown code block. One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible gro...
{"inputs": ["7\n", "8\n", "9\n", "8\n", "9\n", "7\n", "10\n", "10\n"], "outputs": ["29", "92", "246", "92\n", "246\n", "29\n", "582", "582\n"]}
144
80
coding
Solve the programming task below in a Python markdown code block. poly The poly tool returns the coefficients of a polynomial with the given sequence of roots. print numpy.poly([-1, 1, 1, 10]) #Output : [ 1 -11 9 11 -10] roots The roots tool returns the roots of a polynomial with the given coefficients...
{"inputs": ["1.1 2 3\n0\n"], "outputs": ["3.0\n"]}
508
24
coding
Solve the programming task below in a Python markdown code block. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city a_{i}. Today the bus has completed m trips, each...
{"inputs": ["1 5 8\n1\n", "1 9 10\n1\n", "1 9 13\n1\n", "1 2 13\n1\n", "1 5 13\n1\n", "1 3 13\n1\n", "1 8 10\n1\n", "1 9 10\n2\n"], "outputs": ["3\n", "1\n", "4\n", "1\n", "3\n", "1\n", "2\n", "1\n"]}
440
125
coding
Solve the programming task below in a Python markdown code block. Apple considers any iPhone with a battery health of 80\% or above, to be in *optimal* condition. Given that your iPhone has X\% battery health, find whether it is in *optimal* condition. ------ Input Format ------ - The first line of input will cont...
{"inputs": ["4\n97\n42\n80\n10\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
367
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.   Please complete the following python code precisely: ```python # Definit...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,1,2])), list_node([1,2]))\n assert is_same_list(candidate(head = list_node([1,1,2,3,3])), list_node([1,2,3]))\n\n\ncheck(Solution().deleteDuplicates)"}
119
77
coding
Solve the programming task below in a Python markdown code block. Create a __moreZeros__ function which will __receive a string__ for input, and __return an array__ (or null terminated string in C) containing only the characters from that string whose __binary representation of its ASCII value__ consists of _more zeros...
{"functional": "_inputs = [['abcde'], ['thequickbrownfoxjumpsoverthelazydog'], ['THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'], ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_'], ['DIGEST'], ['abcdabcd'], ['Forgiveness is the fragrance that the violet sheds on the heal that has crushed it']]\n_outputs = [[['a...
157
393
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNu...
{"functional": "def check(candidate):\n assert candidate(orders = [[\"David\",\"3\",\"Ceviche\"],[\"Corina\",\"10\",\"Beef Burrito\"],[\"David\",\"3\",\"Fried Chicken\"],[\"Carla\",\"5\",\"Water\"],[\"Carla\",\"5\",\"Ceviche\"],[\"Rous\",\"3\",\"Ceviche\"]]) == [[\"Table\",\"Beef Burrito\",\"Ceviche\",\"Fried Chicke...
218
316