task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels. The width of one level is defined as the length between the end-nodes (th...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,3,2,5,3,None,9])) == 4\n assert candidate(root = tree_node([1,3,2,5,None,None,9,6,None,7])) == 7\n assert candidate(root = tree_node([1,3,2,5])) == 2\n\n\ncheck(Solution().widthOfBinaryTree)"}
209
95
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. A...
{"inputs": ["2\n33\n", "2\n77\n", "2\n99\n", "2\n55\n", "2\n88\n", "2\n22\n", "2\n44\n", "2\n66\n"], "outputs": ["NO", "YES", "NO", "NO", "NO", "NO", "YES", "NO"]}
342
86
coding
Solve the programming task below in a Python markdown code block. "The zombies are lurking outside. Waiting. Moaning. And when they come..." "When they come?" "I hope the Wall is high enough." Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In pl...
{"inputs": ["1 1\nB\n", "1 1\nB\n", "3 7\n.......\n.......\n.BB.B..\n", "4 5\n..B..\n..B..\nB.B.B\nBBB.B\n", "3 7\n.......\n..../..\n.BB.B..\n", "3 7\n.......\n....0..\n.BB.B..\n", "3 7\n.......\n..0....\n.BB.B..\n", "3 7\n.......\n..0....\n..B.BB.\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"...
492
168
coding
Solve the programming task below in a Python markdown code block. Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the resta...
{"inputs": ["20\n", "60\n"], "outputs": ["15800\n", "47200\n"]}
215
32
coding
Solve the programming task below in a Python markdown code block. Consider the prime number `23`. If we sum the square of its digits we get: `2^2 + 3^2 = 13`, then for `13: 1^2 + 3^2 = 10`, and finally for `10: 1^2 + 0^2 = 1`. Similarly, if we start with prime number `7`, the sequence is: `7->49->97->130->10->1`. Gi...
{"functional": "_inputs = [[1, 25], [100, 1000], [100, 2000], [100, 3000], [100, 4000]]\n_outputs = [[4], [28], [47], [65], [95]]\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, tu...
281
218
coding
Solve the programming task below in a Python markdown code block. Positive integer $x$ is called divisor of positive integer $y$, if $y$ is divisible by $x$ without remainder. For example, $1$ is a divisor of $7$ and $3$ is not divisor of $8$. We gave you an integer $d$ and asked you to find the smallest positive inte...
{"inputs": ["2\n1\n2\n", "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n1\n4\n", "2\n2\n1\n"], "outputs": ["6\n15\n", "15\n15\n", "15\n55\n", "55\n55\n", "91\n55\n", "91\n91\n", "6\n55\n", "15\n6\n"]}
400
131
coding
Solve the programming task below in a Python markdown code block. There are $n$ students in a university. The number of students is even. The $i$-th student has programming skill equal to $a_i$. The coach wants to form $\frac{n}{2}$ teams. Each team should consist of exactly two students, and each student should belo...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n1 70\n", "2\n1 71\n", "2\n1 70\n", "2\n1 71\n", "2\n1 100\n", "2\n2 100\n"], "outputs": ["0\n", "0\n", "69\n", "70\n", "69\n", "70\n", "99\n", "98\n"]}
457
116
coding
Solve the programming task below in a Python markdown code block. Little chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem: Given an array A of non-negative integers, how many pairs of indices i and...
{"inputs": ["2\n3\n3 4 5\n4\n1 1 1 1", "2\n3\n3 8 5\n4\n1 1 1 1", "2\n3\n1 4 5\n4\n1 1 1 1", "2\n3\n1 3 0\n4\n1 1 2 1", "2\n3\n2 5 2\n4\n1 0 1 1", "2\n3\n1 1 3\n4\n0 2 6 1", "2\n3\n6 4 5\n4\n1 1 1 1", "2\n3\n3 8 5\n4\n1 1 0 1"], "outputs": ["3\n0", "3\n0\n", "1\n0\n", "0\n0\n", "2\n0\n", "0\n1\n", "3\n0\n", "3\n0\n"]}
322
221
coding
Solve the programming task below in a Python markdown code block. Chef has 3 numbers A, B and C. Chef wonders if it is possible to choose *exactly* two numbers out of the three numbers such that their sum is odd. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the num...
{"inputs": ["4\n1 2 3\n8 4 6\n3 3 9\n7 8 6\n"], "outputs": ["YES\nNO\nNO\nYES\n"]}
286
44
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2, or false otherwise.   Please complete the following py...
{"functional": "def check(candidate):\n assert candidate(arr = [3,1,3,6]) == False\n assert candidate(arr = [2,1,2,6]) == False\n assert candidate(arr = [4,-2,2,-4]) == True\n\n\ncheck(Solution().canReorderDoubled)"}
109
74
coding
Solve the programming task below in a Python markdown code block. problem Cryptography is all the rage at xryuseix's school. Xryuseix, who lives in a grid of cities, has come up with a new cryptography to decide where to meet. The ciphertext consists of the $ N $ character string $ S $, and the $ S_i $ character dete...
{"inputs": ["5\nAzaNA", "5\nAMazA", "5\nzAaNA", "5\nAzaAN", "5\nzAaNB", "5\nAMAza", "5\nAzaBN", "5\nzAaNC"], "outputs": ["1\nA\n", "3\nAAA\n", "1\nA\n", "1\nA\n", "1\nA\n", "3\nAAA\n", "1\nA\n", "1\nA\n"]}
375
112
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and two positive integers m and k. Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0. A subarray of nums is almost ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,6,7,3,1,7], m = 3, k = 4) == 18\n assert candidate(nums = [5,9,9,2,4,5,4], m = 1, k = 3) == 23\n assert candidate(nums = [1,2,1,2,1,2,1], m = 3, k = 3) == 0\n\n\ncheck(Solution().maxSum)"}
131
121
coding
Solve the programming task below in a Python markdown code block. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $n$ actions. The first action perfo...
{"inputs": ["1 1\n", "5 0\n", "3 2\n", "4 1\n", "7 7\n", "9 0\n", "4 1\n", "7 7\n"], "outputs": ["0", "3", "1", "2", "3", "6", "2\n", "3\n"]}
743
80
coding
Solve the programming task below in a Python markdown code block. You are given an array A of length N. Determine the count of subarrays of A which contain their length as an element. Formally, count the number of pairs (L, R) (1≤ L≤ R≤ N) such that: (R-L+1) \in \{A_{L}, A_{L+1}, \ldots, A_{R}\}. ------ Input Format...
{"inputs": ["3\n3\n1 2 1\n5\n2 3 1 3 5\n10\n10 7 4 4 2 9 2 1 9 3\n"], "outputs": ["4\n6\n15\n"]}
430
63
coding
Solve the programming task below in a Python markdown code block. You are given $\mbox{Q}$ queries. Each query consists of a single number $N$. You can perform any of the $2$ operations on $N$ in each move: 1: If we take 2 integers $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{b}$ where $N=a\times b$ $(a\n...
{"inputs": ["2\n3\n4\n"], "outputs": ["3\n3\n"]}
388
20
coding
Solve the programming task below in a Python markdown code block. Calculus class...is awesome! But you are a programmer with no time for mindless repetition. Your teacher spent a whole day covering differentiation of polynomials, and by the time the bell rang, you had already conjured up a program to automate the proce...
{"functional": "_inputs = [[[]]]\n_outputs = [[[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq...
401
153
coding
Solve the programming task below in a Python markdown code block. Your task is to determine how many files of the copy queue you will be able to save into your Hard Disk Drive. The files must be saved in the order they appear in the queue. ### Input: * Array of file sizes `(0 <= s <= 100)` * Capacity of the HD `(0 <...
{"functional": "_inputs = [[[4, 4, 4, 3, 3], 12], [[4, 4, 4, 3, 3], 11], [[4, 8, 15, 16, 23, 42], 108], [[13], 13], [[1, 2, 3, 4], 250], [[100], 500], [[11, 13, 15, 17, 19], 8], [[45], 12]]\n_outputs = [[3], [2], [6], [1], [4], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
234
302
coding
Solve the programming task below in a Python markdown code block. A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}. How many times will the ball make a bounce where the coordin...
{"inputs": ["3 6\n3 1 5", "2 6\n3 4 5", "3 6\n6 1 5", "1 6\n3 4 5", "3 6\n7 1 5", "3 6\n3 4 5", "3 6\n3 4 5\n", "4 9\n3 6 3 3"], "outputs": ["3\n", "2\n", "2\n", "2\n", "1\n", "2", "2\n", "3\n"]}
266
128
coding
Solve the programming task below in a Python markdown code block. Ito joined the Kyudo club after entering high school. At first, I had a hard time because the arrow didn't reach the target, but in the fall of my first year of high school, I managed to improve to the point where the arrow reached the target. One day, ...
{"inputs": ["20\n4\n6\n2\n1\n3\n8\n2\n0\n0", "20\n4\n6\n2\n1\n0\n8\n2\n0\n0", "20\n4\n6\n2\n1\n1\n8\n2\n0\n0", "20\n4\n3\n4\n1\n3\n8\n2\n0\n0", "20\n4\n6\n2\n2\n3\n8\n2\n0\n0", "20\n4\n6\n2\n1\n0\n8\n2\n1\n0", "20\n4\n3\n0\n1\n3\n8\n2\n0\n0", "20\n8\n6\n2\n2\n3\n8\n2\n0\n0"], "outputs": ["16\n2\n", "13\n2\n", "14\n2\n"...
362
238
coding
Solve the programming task below in a Python markdown code block. Oliver and Nova are true lovers. Inspite of knowing that Nova will die Oliver married her at the lake where they met. But they had a conflict about even and odd numbers. Nova likes the odd numbers and Oliver prefers even. One day they went to a fair wher...
{"inputs": ["1\n111"], "outputs": ["YESS(sunglass emo)"]}
422
22
coding
Solve the programming task below in a Python markdown code block. In computing, there are two primary byte order formats: big-endian and little-endian. Big-endian is used primarily for networking (e.g., IP addresses are transmitted in big-endian) whereas little-endian is used mainly by computers with microprocessors. ...
{"functional": "_inputs = [[153, 8], [255, 8], [256, 8], [1534, 32], [364334, 32], [2, 64], [164345, 64], [23, 128], [256245645346, 128], [6423, 256], [988847589347589798345, 256], [98, 512], [9827498275894278943758934789347, 512], [111, 1024], [859983475894789589772983457982345896389458937589738945435, 1024], [9834587...
326
1,836
coding
Solve the programming task below in a Python markdown code block. "What do you know about happiness?" — Yoda Chef is happy only if three conditions hold: - Chef finished cooking a delicious meal - Chef got AC for a programming problem with an almost correct code - Chef got a new problem with a sequence of integers Tod...
{"inputs": ["4\n4\n1 1 2 3\n4\n2 1 3 3\n5\n5 4 4 3 1\n5\n3 2 1 1 4"], "outputs": ["Truly Happy\nPoor Chef\nPoor Chef\nTruly Happy"]}
562
68
coding
Solve the programming task below in a Python markdown code block. A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots, p_N yen per item, respectively. (Yen is the currency of Japan.) Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of...
{"inputs": ["2 1\n2 1\n", "1 0\n1000", "1 1\n1001", "0 1\n1011", "1 1\n1010", "1 1\n1000", "1 1\n1000\n", "-1 1\n0111"], "outputs": ["1\n", "0\n", "1001\n", "1011\n", "1010\n", "1000", "1000\n", "111\n"]}
301
135
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1. You are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [xi, yi] means tha...
{"functional": "def check(candidate):\n assert candidate(n = 3, restrictions = [[0,1]], requests = [[0,2],[2,1]]) == [True,False]\n assert candidate(n = 3, restrictions = [[0,1]], requests = [[1,2],[0,2]]) == [True,False]\n assert candidate(n = 5, restrictions = [[0,1],[1,2],[2,3]], requests = [[0,4],[1,2],[3,...
295
133
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space.   Please co...
{"functional": "def check(candidate):\n assert candidate(nums = [2,2,1]) == 1\n assert candidate(nums = [4,1,2,1,2]) == 4\n assert candidate(nums = [1]) == 1\n\n\ncheck(Solution().singleNumber)"}
91
67
coding
Solve the programming task below in a Python markdown code block. Complete the function/method (depending on the language) to return `true`/`True` when its argument is an array that has the same nesting structures and same corresponding length of nested arrays as the first array. For example: ```python # should retur...
{"functional": "_inputs = [[[1, [1, 1]], [[2, 2], 2]], [[1, [1, 1]], [2, [2]]], [[[[], []]], [[[], []]]], [[[[], []]], [[1, 1]]], [[1, [[[1]]]], [2, [[[2]]]]], [[], 1], [[], {}], [[1, '[', ']'], ['[', ']', 1]]]\n_outputs = [[False], [False], [True], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(...
312
267
coding
Solve the programming task below in a Python markdown code block. We have N weights indexed 1 to N. The mass of the weight indexed i is W_i. We will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \leq T < N. Let S_1 be the sum...
{"inputs": ["3\n1 2 2", "3\n1 1 2", "3\n1 2 3", "3\n1 2 3\n", "4\n2 3 1 1", "4\n2 3 1 0", "4\n1 3 1 1", "4\n1 3 1 1\n"], "outputs": ["1\n", "0\n", "0", "0\n", "3\n", "2\n", "2", "2\n"]}
273
118
coding
Solve the programming task below in a Python markdown code block. Square Route Square root English text is not available in this practice contest. Millionaire Shinada, who has decided to build a new mansion, is wondering in which city to build the new mansion. To tell the truth, Mr. Shinada is a strange person who l...
{"inputs": ["3 3\n2\n1\n1\n2\n3\n1\n1 2\n7\n8\n3\n0 0", "3 3\n2\n1\n1\n2\n3\n1\n1 2\n1\n8\n3\n0 0", "3 3\n2\n1\n1\n2\n0\n1\n1 2\n7\n8\n26\n0 0", "3 3\n1\n2\n1\n2\n6\n1\n1 2\n10\n7\n6\n0 0", "3 3\n2\n1\n4\n2\n3\n1\n1 2\n7\n8\n26\n0 0", "3 3\n2\n1\n1\n2\n3\n1\n1 2\n7\n8\n26\n0 0", "3 3\n1\n0\n4\n2\n3\n2\n1 2\n10\n4\n2\n0...
558
308
coding
Solve the programming task below in a Python markdown code block. After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations. You're given a number X represented in base b_{x} and a number Y represented in base b...
{"inputs": ["1 3\n1\n1 2\n1\n", "1 3\n1\n1 2\n1\n", "1 2\n1\n1 40\n1\n", "1 9\n2\n1 10\n2\n", "1 2\n1\n1 40\n1\n", "1 9\n2\n1 10\n2\n", "1 8\n2\n1 10\n2\n", "2 2\n1 0\n1 3\n1\n"], "outputs": ["=\n", "=", "=\n", "=\n", "=", "=", "=\n", ">\n"]}
602
148
coding
Solve the programming task below in a Python markdown code block. Oranges on Cans square1001 You put a $ N $ can of aluminum on the table. E869120 You put $ M $ of oranges on each aluminum can on the table. How many oranges are on the aluminum can? input Input is given from standard input in the following format. ...
{"inputs": ["3 0", "2 1", "2 2", "3 2", "6 2", "9 2", "2 5", "4 5"], "outputs": ["0\n", "2\n", "4\n", "6\n", "12\n", "18\n", "10\n", "20\n"]}
195
82
coding
Solve the programming task below in a Python markdown code block. The Aizu Wakamatsu city office decided to lay a hot water pipeline covering the whole area of the city to heat houses. The pipeline starts from some hot springs and connects every district in the city. The pipeline can fork at a hot spring or a district,...
{"inputs": ["3 5\n0 8 25 56 0\n9 13 16 0 17\n20 9 16 10 22\n17 27 18 16\n2 4 0\n2 5\n21\n0 0", "3 5\n22 4 30 19 71\n5 12 11 0 8\n5 8 1 11 19\n17 21 19 16\n9 12 0\n19 3\n6\n0 0", "3 5\n0 8 30 19 44\n6 12 9 0 8\n30 8 16 4 22\n17 21 18 16\n7 12 0\n19 2\n21\n0 0", "3 5\n12 8 2 19 44\n5 12 16 0 8\n30 8 0 10 22\n17 21 18 16\...
591
632
coding
Solve the programming task below in a Python markdown code block. Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to find numbe...
{"inputs": ["1\n4\n1010"], "outputs": ["4"]}
467
19
coding
Solve the programming task below in a Python markdown code block. Kshitij has recently started solving problems on codechef. As he is real problem solving enthusiast, he wants continuous growth in number of problems solved per day. He started with $a$ problems on first day. He solves $d$ problems more than previous d...
{"inputs": ["1\n1 4 3 8 2"], "outputs": ["43"]}
378
23
coding
Solve the programming task below in a Python markdown code block. # Task You are given a decimal number `n` as a **string**. Transform it into an array of numbers (given as **strings** again), such that each number has only one nonzero digit and their sum equals n. Each number in the output array should be written w...
{"functional": "_inputs = [['7970521.5544'], ['7496314'], ['0'], ['6'], ['1.0000000000'], ['0000000000.1'], ['1010101'], ['1234567890.1234567890']]\n_outputs = [[['7000000', '900000', '70000', '500', '20', '1', '.5', '.05', '.004', '.0004']], [['7000000', '400000', '90000', '6000', '300', '10', '4']], [[]], [['6']], [[...
324
506
coding
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"]}
322
42
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and an integer k, rearrange s such that the same characters are at least distance k from each other. If it is not possible to rearrange the string, return an empty string "".   Please complete the fol...
{"functional": "def check(candidate):\n assert candidate(s = \"aabbcc\", k = 3) == \"abcabc\"\n assert candidate(s = \"aaabc\", k = 3) == \"\"\n assert candidate(s = \"aaadbbcc\", k = 2) == \"abacabcd\"\n\n\ncheck(Solution().rearrangeString)"}
95
83
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here ------ Problem Statement ------ Lira is a little girl form Bytenicut, a small and cozy village located in the country of Byteland.  As the village is located on a somewhat hidden and isolated area, li...
{"inputs": ["2\n0 0 0 100 100 0\n1 1 1 5 5 1", "2\n0 0 0 100 100 0\n1 2 1 5 5 1", "2\n0 0 0 111 000 1\n1 2 0 3 2 1", "2\n0 0 0 100 100 0\n1 2 1 5 5 2", "2\n0 0 0 100 100 0\n1 2 1 5 9 2", "2\n0 0 0 100 100 0\n1 2 1 5 9 1", "2\n0 0 0 100 100 0\n1 2 1 7 9 1", "2\n0 0 0 100 100 0\n1 1 0 5 5 1"], "outputs": ["2 1", "2 1\n",...
474
301
coding
Solve the programming task below in a Python markdown code block. You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number tha...
{"inputs": ["2 1 1\n0\n", "20 15 1\n6\n", "20 19 2\n16 13\n", "38 19 2\n16 13\n", "7 6 4\n3 5 0 8\n", "57 19 2\n16 13\n", "109 19 2\n16 3\n", "7 6 4\n3 5 0 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n"]}
651
156
coding
Solve the programming task below in a Python markdown code block. # Introduction The first century spans from the **year 1** *up to* and **including the year 100**, **The second** - *from the year 101 up to and including the year 200*, etc. # Task : Given a year, return the century it is in. Also feel free to reuse/...
{"functional": "_inputs = [[1705], [1900], [1601], [2000], [356], [89]]\n_outputs = [[18], [19], [17], [20], [4], [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 ...
102
204
coding
Solve the programming task below in a Python markdown code block. ## Task You will receive a string consisting of lowercase letters, uppercase letters and digits as input. Your task is to return this string as blocks separated by dashes (`"-"`). The elements of a block should be sorted with respect to the hierarchy li...
{"functional": "_inputs = [['heyitssampletestkk'], ['dasf6ds65f45df65gdf651vdf5s1d6g5f65vqweAQWIDKsdds'], ['SDF45648374RHF8BFVYg378rg3784rf87g3278bdqG'], [''], ['aaaaaaaaaa']]\n_outputs = [['aehiklmpsty-ekst-est'], ['adefgqsvwADIKQW1456-dfgsv156-dfs56-dfs56-dfs56-df56-d5-d'], ['bdfgqrBDFGHRSVY2345678-grF3478-gF3478-347...
305
348
coding
Solve the programming task below in a Python markdown code block. This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n8\n", "1\n6\n", "1\n9\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
432
85
coding
Solve the programming task below in a Python markdown code block. My friend wants a new band name for her band. She like bands that use the formula: "The" + a noun with the first letter capitalized, for example: `"dolphin" -> "The Dolphin"` However, when a noun STARTS and ENDS with the same letter, she likes to repea...
{"functional": "_inputs = [['knife'], ['tart'], ['sandles'], ['bed'], ['qq']]\n_outputs = [['The Knife'], ['Tartart'], ['Sandlesandles'], ['The Bed'], ['Qqq']]\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...
162
189
coding
Solve the programming task below in a Python markdown code block. Arkady and his friends love playing checkers on an $n \times n$ field. The rows and the columns of the field are enumerated from $1$ to $n$. The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an o...
{"inputs": ["3 3\n", "6 5\n", "1 1\n", "1 2\n", "1 1\n", "1 2\n", "2 2\n", "3 2\n"], "outputs": ["1\n", "13\n", "1\n", "1\n", "1", "1", "2\n", "5\n"]}
535
85
coding
Solve the programming task below in a Python markdown code block. Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters. Constraints * The number of characters in the sentence < 1200 Input A sentence in English is given in several lines. Output Prints the n...
{"inputs": ["This is ` pen.", "This si a pen.", "hTit si a pen.", "hTis ir a pen.", "hTis ri a pdn.", "hTis ri a odn.", "hTis ri a odo.", "hsiT rh a od.o"], "outputs": ["a : 0\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv :...
250
1,124
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S. You need to transform this string into another string of equal length consisting only of zeros, with the minimum number of operations. A single operation consists of taking some prefix of the string S and flipping all its...
{"inputs": ["01001001"], "outputs": ["6"]}
444
19
coding
Solve the programming task below in a Python markdown code block. Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly $n$ flowers. Vladimir went to a flower shop, and he was amazed to see that there are $m$ types of flowers being sold there, and there is unlim...
{"inputs": ["1\n20 1\n1585117 913999333\n", "1\n19 1\n1585117 913999333\n", "1\n7 1\n107402237 913999333\n", "1\n7 1\n107402237 913999333\n", "1\n11 1\n107402237 913999333\n", "1\n11 1\n159441243 913999333\n", "1\n20 1\n159441243 913999333\n", "1\n20 1\n110656646 913999333\n"], "outputs": ["17367572444\n", "16453573111...
625
340
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums consisting of 3 * n elements. You are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal...
{"functional": "def check(candidate):\n assert candidate(nums = [3,1,2]) == -1\n assert candidate(nums = [7,9,5,8,1,3]) == 1\n\n\ncheck(Solution().minimumDifference)"}
211
57
coding
Solve the programming task below in a Python markdown code block. Given a time in $12$-hour AM/PM format, convert it to military (24-hour) time. Note: - 12:00:00AM on a 12-hour clock is 00:00:00 on a 24-hour clock. - 12:00:00PM on a 12-hour clock is 12:00:00 on a 24-hour clock. Example $\textbf{s}=\textbf{'...
{"inputs": ["07:05:45PM\n"], "outputs": ["19:05:45\n"]}
339
29
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given three integers x, y, and z. You have x strings equal to "AA", y strings equal to "BB", and z strings equal to "AB". You want to choose some (possibly all or none) of these strings and concatenate them in...
{"functional": "def check(candidate):\n assert candidate(x = 2, y = 5, z = 1) == 12\n assert candidate(x = 3, y = 2, z = 2) == 14\n\n\ncheck(Solution().longestString)"}
159
66
coding
Solve the programming task below in a Python markdown code block. Chef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to successfully ...
{"inputs": ["1\n2 2"], "outputs": ["Yes"]}
429
16
coding
Solve the programming task below in a Python markdown code block. Monocarp has forgotten the password to his mobile phone. The password consists of $4$ digits from $0$ to $9$ (note that it can start with the digit $0$). Monocarp remembers that his password had exactly two different digits, and each of these digits app...
{"inputs": ["1\n1\n8\n", "1\n4\n0 1 4 7\n", "1\n4\n0 2 4 7\n", "1\n8\n0 1 2 4 5 6 8 9\n", "2\n8\n0 1 2 4 5 6 8 9\n1\n8\n", "3\n8\n0 1 2 4 5 6 8 9\n1\n8\n1\n8\n", "7\n1\n8\n1\n8\n1\n8\n1\n8\n1\n8\n1\n8\n1\n8\n", "7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"], "outputs": ["216\n", "90\n", "90\n", "6\n", "6\n216\n", "6\...
400
284
coding
Solve the programming task below in a Python markdown code block. Dima got into number sequences. Now he's got sequence a_1, a_2, ..., a_{n}, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0) = 0; f(2·x) = f(x); f(2·x + 1) = f(x) + 1. Di...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n7\n", "2\n1 1\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
342
87
coding
Solve the programming task below in a Python markdown code block. Years after the Ishval Civil War, the Ishvalan refugees have now found a safe place for themselves which is a rectangular piece of land, surrounded by fences. The land can be thought of as a 2d grid which extends $N$ units vertically and $M$ units horiz...
{"inputs": ["2\n7 8\n1 2 2\n5\n4 8\n6 5\n2 0 1\n1 4"], "outputs": ["6\n20"]}
681
45
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has three socks in his drawer. Each sock has one of 10 possible colours, which are represented by integers between 1 and 10. Specifically, the colours of...
{"inputs": ["5 4 3", "5 5 5"], "outputs": ["NO", "YES"]}
348
26
coding
Solve the programming task below in a Python markdown code block. You are given a string s. Among the different substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = ababc, a, bab and ababc are substrings...
{"inputs": ["y\n1", "{\n1", "|\n1", "x\n1", "}\n1", "w\n1", "z\n1", "z\n1\n"], "outputs": ["y\n", "{\n", "|\n", "x\n", "}\n", "w\n", "z", "z\n"]}
350
76
coding
Solve the programming task below in a Python markdown code block. The pair of integer numbers `(m, n)`, such that `10 > m > n > 0`, (below 10), that its sum, `(m + n)`, and rest, `(m - n)`, are perfect squares, is (5, 4). Let's see what we have explained with numbers. ``` 5 + 4 = 9 = 3² 5 - 4 = 1 = 1² (10 > 5 > 4 > 0...
{"functional": "_inputs = [[10], [30], [50], [100], [150], [200]]\n_outputs = [[[5, 4]], [[29, 20]], [[45, 36]], [[97, 72]], [[149, 140]], [[197, 28]]]\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 i...
471
228
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Tweedle-Dee and Tweedle-Dum are in a fierce battle playing even-odd nim. This novel game is played on N heaps. Heap i contains a_{i} stones. Like normal nim, Tweedle-Dee and...
{"inputs": ["1\n2 Dee\n2 2"], "outputs": ["Dum"]}
450
20
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k. The value of |x| is defined as: x if x >= 0. -x if x < 0.   Please complete the followi...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,1], k = 1) == 4\n assert candidate(nums = [1,3], k = 3) == 0\n assert candidate(nums = [3,2,1,5,4], k = 2) == 3\n\n\ncheck(Solution().countKDifference)"}
114
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half. Two strings are alike if they have the same number of vowels ('a', 'e'...
{"functional": "def check(candidate):\n assert candidate(s = \"book\") == True\n assert candidate(s = \"textbook\") == False\n\n\ncheck(Solution().halvesAreAlike)"}
148
45
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["3\n2\n3\n4"], "outputs": ["1121\n1222\n112131\n122232\n132333\n11213141\n12223242\n13233343\n14243444"]}
241
83
coding
Solve the programming task below in a Python markdown code block. # One is the loneliest number ## Task The range of vision of a digit is its own value. `1` can see one digit to the left and one digit to the right,` 2` can see two digits, and so on. Thus, the loneliness of a digit `N` is the sum of the digits which ...
{"functional": "_inputs = [[34315], [123456], [8854778], [65432165432], [0], [1], [11111]]\n_outputs = [[True], [True], [False], [False], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol...
312
220
coding
Solve the programming task below in a Python markdown code block. "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond i...
{"inputs": ["W\n", "Q\n", "A\n", "W\n", "Q\n", "A\n", "V\n", "R\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
290
70
coding
Solve the programming task below in a Python markdown code block. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem...
{"inputs": ["5\n", "4\n", "2\n", "3\n", "1\n"], "outputs": ["1", "2", "3", "1", "2"]}
156
41
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Run has given you a list of statements of the form "A+B=C", where A, B and C consist only of decimal digits and small latin letters from 'a' to 'f'. Moreover, the first symbol of A, B, C is alw...
{"inputs": ["3\n2+2=10\n1+2=a\n3+5=8"], "outputs": ["2"]}
278
30
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array arr. In one move, you can select a palindromic subarray arr[i], arr[i + 1], ..., arr[j] where i <= j, and remove that subarray from the given array. Note that after removing a subarray, ...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2]) == 2\n assert candidate(arr = [1,3,4,1,5]) == 3\n\n\ncheck(Solution().minimumMoves)"}
144
53
coding
Solve the programming task below in a Python markdown code block. Shubham recently learned the lexicographical order in strings. Now, he has two strings s1 and s2 of the equal size and Shubham wants to compare those two strings lexicographically. Help Shubham with the strings comparison. Note: Letters are case i...
{"inputs": ["2\nabc\nacb\nAB\nba"], "outputs": ["first\nfirst"]}
200
22
coding
Solve the programming task below in a Python markdown code block. Takahashi has received an undirected graph with N vertices, numbered 1, 2, ..., N. The edges in this graph are represented by (u_i, v_i). There are no self-loops and multiple edges in this graph. Based on this graph, Takahashi is now constructing a new ...
{"inputs": ["3 1\n1 2", "7 5\n1 2\n3 4\n3 5\n4 1\n2 6", "7 5\n1 2\n3 7\n3 5\n4 1\n2 6", "7 5\n1 2\n3 7\n3 5\n4 1\n2 2", "7 5\n1 2\n3 7\n6 5\n4 1\n2 2", "7 5\n1 2\n3 7\n3 7\n4 1\n2 3", "7 5\n1 2\n2 6\n6 5\n4 1\n2 2", "7 5\n2 2\n2 6\n6 5\n4 1\n2 2"], "outputs": ["7", "15\n", "8\n", "18\n", "13\n", "26\n", "25\n", "29\n"]...
378
227
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given two strings $S$ and $R$. You may reorder the characters in the string $R$ in any way; let's denote the resulting string by $R_{r}$. Thi...
{"inputs": ["4\naa\nababab\naaa\nramialsadaka\nsaid\nsryhieni\ncode\ncodeisfun"], "outputs": ["aaabbb\naaaaadiklmrs\nImpossible\ncodefinsu"]}
506
56
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given two integers $L$ and $R$. Find the smallest non-negative integer $N$ such that $$N \,\%\, L > N \,\%\, (L + 1) > \ldots > N \,\%\, (R ...
{"inputs": ["2\n4 6\n1 2"], "outputs": ["6\n-1"]}
470
23
coding
Solve the programming task below in a Python markdown code block. Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it? -----Input----- The input contains a single integer n (0 ≤ n ≤ 2000000000). -----Output----- Output a single integer. -----Examples----- Input 11 Output 2 Input 14 Ou...
{"inputs": ["0\n", "0\n", "1\n", "2\n", "3\n", "4\n", "7\n", "11\n"], "outputs": ["1\n", "1", "0\n", "0\n", "0\n", "1\n", "0\n", "2\n"]}
131
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows: Use the first appearance of all 26 lowercase English letters in ...
{"functional": "def check(candidate):\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\", message = \"vkbs bs t suepuv\") == \"this is a secret\"\n assert candidate(key = \"eljuxhpwnyrdgtqkviszcfmabo\", message = \"zwx hnfx lqantp mnoeius ycgk vcnjrdb\") == \"the five boxing wizards jump qui...
213
109
coding
Solve the programming task below in a Python markdown code block. Chef has an array A of length N. In one operation, Chef can remove any one element from the array. Determine the minimum number of operations required to make all the elements same. ------ Input Format ------ - The first line of input will contain ...
{"inputs": ["4\n3\n3 3 3\n6\n1 3 2 1 2 2\n4\n1 2 1 2\n5\n1 3 2 4 5\n"], "outputs": ["0\n3\n2\n4\n"]}
451
64
coding
Solve the programming task below in a Python markdown code block. With one die of 6 sides we will have six different possible results:``` 1, 2, 3, 4, 5, 6``` . With 2 dice of six sides, we will have 36 different possible results: ``` (1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(4,1),(1,5), (5,1), (1,6),(6,1),(2,2),(2,3),(3,...
{"functional": "_inputs = [[[6, 6]], [[5, 6, 4]], [[3, 15, 8, 20]], [[6]], [[3, 3]], [[20]], [[3, 6]]]\n_outputs = [[3], [5], [44], [0], [0], [1], [0]]\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 i...
695
218
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not. He has a positive integer X represented as a product of...
{"inputs": ["1\n3\n21 11 6"], "outputs": ["3"]}
513
22
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums containing n integers. At each second, you perform the following operation on the array: For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1,2]) == 1\n assert candidate(nums = [2,1,3,3,2]) == 2\n assert candidate(nums = [5,5,5,5]) == 0\n\n\ncheck(Solution().minimumSeconds)"}
148
75
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the number of longest increasing subsequences. Notice that the sequence has to be strictly increasing.   Please complete the following python code precisely: ```python class Solutio...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,4,7]) == 2\n assert candidate(nums = [2,2,2,2,2]) == 5\n\n\ncheck(Solution().findNumberOfLIS)"}
76
61
coding
Solve the programming task below in a Python markdown code block. "How did you get the deal,how did he agree?" "Its's simple Tom I just made him an offer he couldn't refuse" Ayush is the owner of a big construction company and a close aide of Don Vito The Godfather, recently with the help of the Godfather his company ...
{"inputs": ["2\n1\n2"], "outputs": ["2\n7"]}
296
18
coding
Solve the programming task below in a Python markdown code block. Write a function that takes a number or a string and gives back the number of **permutations without repetitions** that can generated using all of its element.; more on permutations [here](https://en.wikipedia.org/wiki/Permutation). For example, startin...
{"functional": "_inputs = [[2], [25], [342], [1397], [76853], ['a'], ['ab'], ['abc'], [737], [66666]]\n_outputs = [[1], [2], [6], [24], [120], [1], [2], [6], [3], [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_to...
185
227
coding
Solve the programming task below in a Python markdown code block. The Rumbling is a hypothetical cataclysmic event involving Karl Fritz's Wall Titans marching across the Earth, destroying all life upon it. Eren Yeager who possesses the Founding Titan has decided to begin The Rumbling to show the true power of the Eldia...
{"inputs": ["1\n5\nSENWS\n2 1"], "outputs": ["4"]}
750
21
coding
Solve the programming task below in a Python markdown code block. There are $n$ warriors in a row. The power of the $i$-th warrior is $a_i$. All powers are pairwise distinct. You have two types of spells which you may cast: Fireball: you spend $x$ mana and destroy exactly $k$ consecutive warriors; Berserk: you spen...
{"inputs": ["1 1\n2 1 2\n1\n1\n", "1 1\n2 1 2\n1\n1\n", "1 1\n2 2 2\n1\n1\n", "1 1\n2 1 0\n1\n1\n", "1 1\n2 4 2\n1\n1\n", "1 1\n2 4 1\n1\n1\n", "1 1\n2 7 1\n1\n1\n", "1 1\n2 2 1\n1\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
650
166
coding
Solve the programming task below in a Python markdown code block. For given a circle $c$ and a line $l$, print the coordinates of the cross points of them. Constraints * $p1$ and $p2$ are different * The circle and line have at least one cross point * $1 \leq q \leq 1,000$ * $-10,000 \leq cx, cy, x1, y1, x2, y2 \leq ...
{"inputs": ["2 0 1\n2\n0 1 4 1\n3 0 3 3", "2 0 2\n2\n0 1 4 1\n3 0 3 3", "2 0 2\n2\n0 1 4 2\n3 0 3 3", "2 0 2\n2\n0 1 4 2\n3 0 5 3", "2 0 2\n1\n0 1 4 2\n3 0 5 3", "2 0 2\n1\n0 1 4 0\n3 0 5 3", "2 0 2\n1\n0 1 8 0\n1 0 5 3", "2 0 2\n1\n0 2 8 0\n1 0 5 3"], "outputs": ["2.00000000 1.00000000 2.00000000 1.00000000\n3.0000000...
536
750
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and...
{"functional": "def check(candidate):\n assert candidate(widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"abcdefghijklmnopqrstuvwxyz\") == [3,60]\n assert candidate(widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"bbbcccd...
227
217
coding
Solve the programming task below in a Python markdown code block. Write a function that returns the number of '2's in the factorization of a number. For example, ```python two_count(24) ``` should return 3, since the factorization of 24 is 2^3 x 3 ```python two_count(17280) ``` should return 7, since the factorizatio...
{"functional": "_inputs = [[24], [17280], [222222222222], [256], [1], [2], [482848428248882482], [7], [7777777777777777], [84934656]]\n_outputs = [[3], [7], [1], [8], [0], [1], [1], [0], [0], [20]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isc...
159
267
coding
Solve the programming task below in a Python markdown code block. Given an array A of n non-negative integers. Find the number of ways to partition/divide the array into subarrays, such that mex in each subarray is not more than k. For example, mex of the arrays [1, 2] will be 0, and that of [0, 2] will be 1, and that...
{"inputs": ["3 1\n0 1 2\n\n", "10 3\n0 1 2 3 4 0 1 2 5 3\n\n"], "outputs": ["2", "379"]}
403
55
coding
Solve the programming task below in a Python markdown code block. Chef has a binary string S. He can modify it by choosing any subsequence of length 3 from it and deleting the first and last character of the subsequence. For example, if S = \textcolor{red}{11}01\textcolor{red}{0}1, Chef can choose the subsequence mark...
{"inputs": ["4\n101\n1010\n0000\n0001\n"], "outputs": ["101\n11\n0000\n01\n"]}
519
46
coding
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"]}
420
30
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars. Yo...
{"functional": "def check(candidate):\n assert candidate(customers = [8,3], boardingCost = 5, runningCost = 6) == 3\n assert candidate(customers = [10,9,6], boardingCost = 6, runningCost = 4) == 7\n assert candidate(customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92) == -1\n\n\ncheck(Solution().minOpe...
306
112
coding
Solve the programming task below in a Python markdown code block. You should write a simple function that takes string as input and checks if it is a valid Russian postal code, returning `true` or `false`. A valid postcode should be 6 digits with no white spaces, letters or other symbols. Empty string should also retu...
{"functional": "_inputs = [['142784'], ['642784'], ['111'], ['1111111'], ['AA5590'], [''], ['\\n245980'], ['245980\\n'], ['245980a'], ['24598a'], [' 310587 '], ['555555'], ['775255'], ['875555'], ['012345'], ['968345'], ['@68345']]\n_outputs = [[True], [True], [False], [False], [False], [False], [False], [False], [Fals...
191
333
coding
Solve the programming task below in a Python markdown code block. Takahashi participated in a contest on AtCoder. The contest had N problems. Takahashi made M submissions during the contest. The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA). The number of Takahashi's correct an...
{"inputs": ["1 0", "2 0", "0 0", "8 0", "3 0", "7 0", "6 0", "6 0\n"], "outputs": ["0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0", "0 0\n"]}
366
94
coding
Solve the programming task below in a Python markdown code block. Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Limak wants to prove how re...
{"inputs": ["4 of week\n", "6 of week\n", "1 of week\n", "2 of week\n", "3 of week\n", "5 of week\n", "7 of week\n", "6 of week\n"], "outputs": ["52\n", "53\n", "52\n", "52\n", "52\n", "53\n", "52\n", "53"]}
470
93
coding
Solve the programming task below in a Python markdown code block. Dmitry has an array of $n$ non-negative integers $a_1, a_2, \dots, a_n$. In one operation, Dmitry can choose any index $j$ ($1 \le j \le n$) and increase the value of the element $a_j$ by $1$. He can choose the same index $j$ multiple times. For each $...
{"inputs": ["5\n3\n0 1 3\n7\n0 1 2 3 4 3 2\n4\n3 0 0 0\n7\n4 6 2 3 5 0 5\n5\n4 0 1 0 4\n", "5\n3\n0 1 3\n7\n0 1 2 3 4 3 2\n4\n3 0 0 0\n7\n4 6 2 3 6 0 5\n5\n4 0 1 0 4\n", "5\n3\n0 1 3\n7\n0 1 2 3 4 3 2\n4\n3 0 0 0\n7\n4 0 2 3 5 0 5\n5\n4 0 1 0 4\n", "5\n3\n0 1 3\n7\n0 1 2 3 4 0 2\n4\n3 0 0 0\n7\n4 6 2 3 5 0 5\n5\n4 0 1 ...
698
1,086
coding
Solve the programming task below in a Python markdown code block. Let f be a function, such that, for an array A of size M, f(A) is defined as f(A) = \sum_{i=1}^{M}\sum_{j=1, j \ne i}^{j=M} (A_{i}\cdot A_{j}) You are given an array C of size N. In one operation on the array, you can: Choose an index i (1≤ i ≤ |C|) Se...
{"inputs": ["2\n2\n1 2\n2\n1 3\n"], "outputs": ["6\n12\n"]}
760
29
coding
Solve the programming task below in a Python markdown code block. The lust for throne and power in the kingdom of Numberland has ensued a series of battles between 2 mighty armies - The Composites and The Primes. The kings decide to send their armies in waves. Both the armies consist of warriors having either prime or ...
{"inputs": ["3\n5\n56 25 14 8 8\n53 29 17 5 7\n5\n28 17 42 15 9\n25 29 41 19 5\n8\n7 8 9 6 12 3 3 9\n8 7 11 3 5 5 5 7", "5\n2\n83 67 \n40 51 \n4\n26 69 50 21 \n37 79 67 61 \n3\n2 7 5 \n21 34 81 \n7\n26 69 50 21 34 81 67 \n66 23 56 25 15 12 62 \n9\n29 61 53 23 37 89 67 61 23 \n56 25 15 12 62 78 48 42 85", "10\n2\n31 61 ...
428
1,067
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer num, return true if num is a perfect square or false otherwise. A perfect square is an integer that is the square of an integer. In other words, it is the product of some integer with itself. ...
{"functional": "def check(candidate):\n assert candidate(num = 16) == True\n assert candidate(num = 14) == False\n\n\ncheck(Solution().isPerfectSquare)"}
108
44
coding
Solve the programming task below in a Python markdown code block. The first input array is the key to the correct answers to an exam, like ["a", "a", "b", "d"]. The second one contains a student's submitted answers. The two arrays are not empty and are the same length. Return the score for this array of answers, givi...
{"functional": "_inputs = [[['a', 'a', 'b', 'b'], ['a', 'c', 'b', 'd']], [['a', 'a', 'c', 'b'], ['a', 'a', 'b', '']], [['a', 'a', 'b', 'c'], ['a', 'a', 'b', 'c']], [['b', 'c', 'b', 'a'], ['', 'a', 'a', 'c']]]\n_outputs = [[6], [7], [16], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
273
256
coding
Solve the programming task below in a Python markdown code block. Chef has the binary representation S of a number X with him. He can modify the number by applying the following operation exactly once: Make X := X \oplus \lfloor \frac{X}{2^{Y}} \rfloor, where (1 ≤ Y ≤ |S|) and \oplus denotes the [bitwise XOR operation]...
{"inputs": ["4\n2\n10\n2\n11\n3\n101\n3\n110\n"], "outputs": ["2\n1\n2\n1\n"]}
684
42
coding
Solve the programming task below in a Python markdown code block. You are given a n × m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in whi...
{"inputs": ["1 1\n.\n", "1 1\n*\n", "1 2\n**\n", "1 3\n*.*\n", "2 1\n*\n*\n", "2 1\n.\n.\n", "1 3\n...\n", "2 1\n)\n*\n"], "outputs": ["0", "0", "0", "0", "0", "0", "0", "0\n"]}
222
104
coding
Solve the programming task below in a Python markdown code block. Santa Claus has received letters from $n$ different kids throughout this year. Of course, each kid wants to get some presents from Santa: in particular, the $i$-th kid asked Santa to give them one of $k_i$ different items as a present. Some items could h...
{"inputs": ["2\n2 2 1\n1 1\n", "2\n2 4 1\n1 1\n", "2\n2 8 1\n1 2\n", "2\n2 8 1\n1 1\n", "2\n2 3 1\n1 1\n", "2\n2 4 1\n1 2\n", "2\n2 4 1\n1 4\n", "2\n2 5 1\n1 1\n"], "outputs": ["124780545\n", "124780545\n", "499122177\n", "124780545\n", "124780545\n", "499122177\n", "124780545\n", "124780545\n"]}
688
214
coding
Solve the programming task below in a Python markdown code block. A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices. You are given a tree with n vertices and a positive number k. Find the number...
{"inputs": ["5 3\n1 2\n2 3\n3 4\n1 5\n", "5 6\n1 2\n2 3\n3 4\n4 5\n", "5 6\n1 2\n2 3\n3 4\n3 5\n", "5 2\n1 2\n2 3\n3 4\n2 5\n", "5 3\n1 2\n2 3\n3 4\n4 5\n", "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6\n", "10 3\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6\n", "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6...
366
291
coding
Solve the programming task below in a Python markdown code block. ​A 1-indexed array is called *positive* if every element of the array is greater than or equal to the index on which it lies. Formally, an array B of size M is called positive if B_{i} ≥ i for each 1≤ i ≤ M. For example, the arrays [1], [2, 2], [3, 2, 4...
{"inputs": ["5\n3\n2 3 3\n4\n3 1 1 2\n3\n1 1 1\n5\n1 2 2 4 5\n6\n3 2 1 2 2 1\n"], "outputs": ["1\n2\n3\n2\n3\n"]}
590
74