task_type
stringclasses
1 value
problem
stringlengths
261
3.34k
answer
stringlengths
35
6.15k
problem_tokens
int64
62
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. There are N positive integers arranged in a circle. Now, the i-th number is A_i. Takahashi wants the i-th number to be B_i. For this objective, he will repeatedly perform the following operation: * Choose an integer i such that 1 \leq i \leq N. * Let a...
{"inputs": ["3\n1 1 1\n13 1 7", "3\n2 1 1\n13 5 7", "3\n2 1 1\n13 1 7", "3\n2 1 1\n13 2 7", "3\n2 1 1\n13 2 0", "3\n1 1 1\n13 2 0", "3\n1 1 1\n13 3 0", "3\n1 1 1\n13 4 0"], "outputs": ["4\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
366
166
coding
Solve the programming task below in a Python markdown code block. Given an array $a$, consisting of $n$ integers, find: $$\max\limits_{1 \le i < j \le n} LCM(a_i,a_j),$$ where $LCM(x, y)$ is the smallest positive integer that is divisible by both $x$ and $y$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, ...
{"inputs": ["2\n2 5\n", "2\n1 1\n", "2\n1 1\n", "2\n2 5\n", "2\n3 5\n", "3\n13 35 77\n", "4\n12 9 1 8\n", "4\n12 9 1 8\n"], "outputs": ["10", "1", "1\n", "10\n", "15\n", "1001", "72", "72\n"]}
282
121
coding
Solve the programming task below in a Python markdown code block. Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them. Recently, she was presented with an array $a$ of the size of $10^9$ elements that is filled as follows: $a_1 = -1$ $a_2 = 2...
{"inputs": ["1\n682736 1001010010\n", "1\n580408 1001010010\n", "1\n1042324 1001010010\n", "1\n4162847 1001001010\n", "1\n1133909 1001010010\n", "1\n6379767 1001001010\n", "1\n1133909 1001010011\n", "1\n6379767 1001101010\n"], "outputs": ["500846373\n", "500795209\n", "501026167\n", "498419082\n", "499938051\n", "49731...
664
284
coding
Solve the programming task below in a Python markdown code block. In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks. More precisely, two different numbers $a$ and $b$ are friends if $gcd(a,b)$, $\frac{a}{gcd(a,b)}$, $\frac{b}{gcd(a,b)}$ can form sides o...
{"inputs": ["3\n1 5 7\n", "3\n1 5 5\n", "3\n1 5 10\n", "3\n1 5 10\n", "6\n30 432 8 193 7 1\n", "6\n30 432 8 243 7 1\n", "6\n30 216 8 243 7 1\n", "6\n41 216 8 243 8 1\n"], "outputs": ["1\n3\n4\n", "1\n3\n3\n", "1\n3\n3\n", "1\n3\n3\n", "8\n76\n4\n39\n4\n1\n", "8\n76\n4\n48\n4\n1\n", "8\n42\n4\n48\n4\n1\n", "11\n42\n4\n4...
396
229
coding
Solve the programming task below in a Python markdown code block. You are given $n$ strings $s_1, s_2, \ldots, s_n$ consisting of lowercase Latin letters. In one operation you can remove a character from a string $s_i$ and insert it to an arbitrary position in a string $s_j$ ($j$ may be equal to $i$). You may perform ...
{"inputs": ["1\n2\nz\ny\n", "1\n2\na\ne\n", "1\n2\nz\ny\n", "1\n2\na\ne\n", "1\n1\nz\ny\n", "1\n2\nxx\nz\n", "1\n2\naa\nb\n", "1\n2\naa\na\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
421
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree with n nodes. Each node is assigned a unique value from 1 to n. You are also given an array queries of size m. You have to perform m independent queries on the tree where in the...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,3,4,2,None,6,5,None,None,None,None,None,7]), queries = [4]) == [2]\n assert candidate(root = tree_node([5,8,9,2,1,3,7,4,6]), queries = [3,2,4,8]) == [3,2,3,2]\n\n\ncheck(Solution().treeQueries)"}
265
105
coding
Solve the programming task below in a Python markdown code block. There is a fair going on in Chefland. Chef wants to visit the fair along with his N friends. Chef manages to collect K passes for the fair. Will Chef be able to enter the fair with all his N friends? A person can enter the fair using one pass, and each...
{"inputs": ["4\n5 8\n6 3\n2 2\n1 2\n"], "outputs": ["YES\nNO\nNO\nYES\n"]}
446
36
coding
Solve the programming task below in a Python markdown code block. For an array $b$ of length $m$ we define the function $f$ as $ f(b) = \begin{cases} b[1] & \quad \text{if } m = 1 \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise,} \end{cases} $ where $\oplus$ is bitwise exclus...
{"inputs": ["3\n8 4 1\n2\n2 3\n1 2\n", "3\n6 4 1\n2\n2 3\n1 2\n", "3\n8 4 1\n2\n2 3\n2 2\n", "3\n8 0 1\n2\n2 3\n2 2\n", "3\n8 1 1\n2\n2 3\n2 2\n", "3\n8 4 1\n2\n1 3\n1 2\n", "3\n8 4 1\n2\n1 3\n2 2\n", "3\n8 0 1\n2\n2 2\n2 2\n"], "outputs": ["5\n12\n", "5\n6\n", "5\n4\n", "1\n0\n", "1\n1\n", "12\n12\n", "12\n4\n", "0\n0...
592
218
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. ------ Sereja and Arrays ------ Sereja have an array that consist of n integers a1, a2, ..., an (0 ≤ ai ≤ 1). Sereja can make next operation: fix some integer i (1 ≤ i ≤ n - k + 1) subtra...
{"inputs": ["3\n3 3\n5 2\n5 1"], "outputs": ["2\n8\n32"]}
370
29
coding
Solve the programming task below in a Python markdown code block. Snuke loves puzzles. Today, he is working on a puzzle using S- and c-shaped pieces. In this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below: Snuke decided to create as many Scc groups as possible by putti...
{"inputs": ["1 6\n", "12345 678901\n"], "outputs": ["2\n", "175897\n"]}
208
40
coding
Solve the programming task below in a Python markdown code block. Paul is an excellent coder and sits high on the CW leaderboard. He solves kata like a banshee but would also like to lead a normal life, with other activities. But he just can't stop solving all the kata!! Given an array (x) you need to calculate the Pa...
{"functional": "_inputs = [[['life', 'eating', 'life']], [['life', 'Petes kata', 'Petes kata', 'Petes kata', 'eating']], [['Petes kata', 'Petes kata', 'eating', 'Petes kata', 'Petes kata', 'eating']]]\n_outputs = [['Super happy!'], ['Super happy!'], ['Happy!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinst...
193
220
coding
Solve the programming task below in a Python markdown code block. **Introduction**  Little Petya very much likes sequences. However, recently he received a sequence as a gift from his mother.  Petya didn't like it at all! He decided to make a single replacement. After this replacement, Petya would like to the sequence ...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[4, 2, 1, 3, 5]], [[2, 3, 4, 5, 6]], [[2, 2, 2]], [[42]], [[5, 6, 1, 2, 3, 1, 3, 45, 7, 1000000000]], [[1, 1, 1]], [[1]], [[134]]]\n_outputs = [[[1, 1, 2, 3, 4]], [[1, 1, 2, 3, 4]], [[1, 2, 3, 4, 5]], [[1, 2, 2]], [[1]], [[1, 1, 1, 2, 3, 3, 5, 6, 7, 45]], [[1, 1, 2]], [[2]...
365
366
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a numeric string num, representing a very large palindrome. Return the smallest palindrome larger than num that can be created by rearranging its digits. If no such palindrome exists, return an empty str...
{"functional": "def check(candidate):\n assert candidate(num = \"1221\") == \"2112\"\n assert candidate(num = \"32123\") == \"\"\n assert candidate(num = \"45544554\") == \"54455445\"\n\n\ncheck(Solution().nextPalindrome)"}
103
81
coding
Solve the programming task below in a Python markdown code block. Krishnakant is standing at $(0,0)$ in the Cartesian plane. He wants to go to the point $(x,y)$ in the same plane using only horizontal and vertical moves of $1$ unit. There are many ways of doing this, and he is writing down all such ways. Each way compr...
{"inputs": ["2\n2 2 2\n2 2 3\n"], "outputs": ["HVVH\nVHHV\n"]}
393
32
coding
Solve the programming task below in a Python markdown code block. ## Task In your favorite game, you must shoot a target with a water-gun to gain points. Each target can be worth a different amount of points. You are guaranteed to hit every target that you try to hit. You cannot hit consecutive targets though beca...
{"functional": "_inputs = [[[1, 2, 3, 4]], [[1, 3, 1]], [[5, 5, 5, 5, 5]], [[36, 42, 93, 29, 0, 33, 15, 84, 14, 24, 81, 11]], [[73, 80, 40, 86, 14, 96, 10, 56, 61, 84, 82, 36, 85]], [[11, 82, 47, 48, 80, 35, 73, 99, 86, 32, 32]], [[26, 54, 36, 35, 63, 58, 31, 80, 59, 61, 34, 54, 62, 73, 89, 7, 98, 91, 78]], [[0, 0, -1,...
447
477
coding
Solve the programming task below in a Python markdown code block. We have N bricks arranged in a row from left to right. The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it. Among them, you can break at most N-1 bricks of your choice. Let us say there are K bricks remaining. Snuke will be sa...
{"inputs": ["1\n2", "1\n0", "1\n4", "1\n5", "1\n3", "1\n6", "1\n7", "1\n1"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0"]}
305
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move if you are located at index i: If nums[i] is positive, move nums[...
{"functional": "def check(candidate):\n assert candidate(nums = [2,-1,1,2,2]) == True\n assert candidate(nums = [-1,2]) == False\n assert candidate(nums = [-2,1,-1,-2,-2]) == False\n\n\ncheck(Solution().circularArrayLoop)"}
240
72
coding
Solve the programming task below in a Python markdown code block. Given an array of bird sightings where every element represents a bird type id, determine the id of the most frequently sighted type. If more than 1 type has been spotted that maximum amount, return the smallest of their ids. Example $arr=[1,1,2,2,3]...
{"inputs": ["6\n1 4 4 4 5 3\n", "11\n1 2 3 4 5 4 3 2 1 3 4\n"], "outputs": ["4\n", "3\n"]}
484
57
coding
Solve the programming task below in a Python markdown code block. We have an array of length $n$. Initially, each element is equal to $0$ and there is a pointer located on the first element. We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointer is not on the ...
{"inputs": ["1\n1\n1\n", "1\n2\n2 2\n", "1\n2\n-800372697 800372697\n", "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0\n"], "outputs": ["No\n", "No\n", "No\n", "No\nYes\nNo\nNo\nYes\nYes\nYes\n"]}
677
152
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m (that is, find the smallest such sequence). Return [m,n...
{"functional": "def check(candidate):\n assert candidate([1,2,4,7,10,11,7,12,6,7,16,18,19]) == [3,9]\n\n\ncheck(Solution().subSort)"}
126
62
coding
Solve the programming task below in a Python markdown code block. Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol...
{"inputs": ["4\nhello\nhello\nhello\nhelloo\nhello\nhlllloo\nhello\nhelo\n", "4\nhello\nhello\nhello\nhelloo\nhemlo\nhlllloo\nhello\nhelo\n", "4\nhello\nhello\nolleh\nhelloo\nhemlo\nhlllloo\nhello\nhelo\n", "4\nhello\nhdllo\nolkeh\nhelmoo\nhemlo\nhlllloo\nhello\nhelo\n", "4\nhello\nhello\nolleh\nhelmoo\nhemlo\nhlllloo\...
546
304
coding
Solve the programming task below in a Python markdown code block. We have a sequence A of N non-negative integers. Compute the sum of \prod _{i = 1} ^N \dbinom{B_i}{A_i} over all sequences B of N non-negative integers whose sum is at most M, and print it modulo (10^9 + 7). Here, \dbinom{B_i}{A_i}, the binomial coeffici...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n2\n", "1 1\n2000\n", "3 5\n1 2 1\n", "1 1999\n2000\n", "1 1000000000\n0\n", "10 998244353\n31 41 59 26 53 58 97 93 23 84\n"], "outputs": ["2\n", "1\n", "0\n", "0\n", "8\n", "0\n", "1000000001\n", "642612171\n"]}
618
178
coding
Solve the programming task below in a Python markdown code block. An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly o...
{"functional": "_inputs = [[[1, 2, 3, 4, 6, 7, 8, 9]]]\n_outputs = [[5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
221
175
coding
Solve the programming task below in a Python markdown code block. It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$). You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful. A number is c...
{"inputs": ["1\n688 10\n", "1\n701 10\n", "1\n5828 1\n", "1\n9772 1\n", "1\n4955 2\n", "1\n2388 2\n", "1\n2388 4\n", "1\n2388 1\n"], "outputs": ["688\n", "701\n", "6666\n", "9999\n", "4994\n", "2422\n", "2388\n", "3333\n"]}
421
148
coding
Solve the programming task below in a Python markdown code block. After a lot of hard work, Goyal has finally completed his app. But before he launches it, he needs to test it. His friends are helping him on this. Whenever a friend uses the app, his name is recorded in the logs. At the end of the day, Goyal makes a "Ha...
{"inputs": ["7\nArjun Mohit Karan Mohit Mohit Ajay Karan"], "outputs": ["Mohit 3\nKaran 2\nArjun 1\nAjay 1"]}
290
45
coding
Solve the programming task below in a Python markdown code block. Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. ...
{"inputs": ["2 2 0 4\n", "2 2 2 1\n", "6 7 5 8\n", "6 7 5 9\n", "6 7 5 7\n", "0 0 0 0\n", "1 1 0 4\n", "5 5 3 1\n"], "outputs": ["-1", "-1", "-1", "1", "-1", "-1", "2", "-1"]}
620
111
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location. Two squares are called adjacent if they are next to ...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1],[1,2]], row = 0, col = 0, color = 3) == [[3,3],[3,2]]\n assert candidate(grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3) == [[1,3,3],[2,3,3]]\n assert candidate(grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2) == [[2,2,...
211
170
coding
Solve the programming task below in a Python markdown code block. Everybody know that you passed to much time awake during night time... Your task here is to define how much coffee you need to stay awake after your night. You will have to complete a function that take an array of events in arguments, according to thi...
{"functional": "_inputs = [[[]], [['cw']], [['CW']], [['cw', 'CAT']], [['cw', 'CAT', 'DOG']], [['cw', 'CAT', 'cw=others']]]\n_outputs = [[0], [1], [2], [3], ['You need extra sleep'], [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,...
238
209
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...
{"inputs": ["1\n1\n0\n", "1\n0\n1\n", "1\n0\n1\n", "1\n1\n0\n", "2\n0 2\n0 1\n", "2\n0 1\n0 2\n", "2\n0 0\n2 1\n", "2\n0 0\n1 2\n"], "outputs": ["1", "0", "0\n", "1\n", "1", "3", "4", "0"]}
647
112
coding
Solve the programming task below in a Python markdown code block. An array is defined to be `inertial`if the following conditions hold: ``` a. it contains at least one odd value b. the maximum value in the array is even c. every odd value is greater than every even value that is not the maximum value. ``` eg:- ``` S...
{"functional": "_inputs = [[[]], [[581, -384, 140, -287]], [[11, 4, 20, 9, 2, 8]]]\n_outputs = [[False], [False], [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)\n if isinstance(a, (list, tuple)):\n...
238
202
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an array of strings words. You should add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in words. If two such substrings overlap, you should wrap them toge...
{"functional": "def check(candidate):\n assert candidate(s = \"abcxyz123\", words = [\"abc\",\"123\"]) == \"<b>abc</b>xyz<b>123</b>\"\n assert candidate(s = \"aaabbb\", words = [\"aa\",\"b\"]) == \"<b>aaabbb</b>\"\n\n\ncheck(Solution().addBoldTag)"}
139
95
coding
Solve the programming task below in a Python markdown code block. There are $n$ red balls kept on the positive $X$ axis, and $m$ blue balls kept on the positive $Y$ axis. You are given the positions of the balls. For each $i$ from $1$ to $n$, the $i$-th red ball has the coordinates $(x_i, 0)$, where $x_i$ is a positive...
{"inputs": ["1 1\n1 2\n2 1\n", "1 2\n1 2\n2 1\n1 2\n"], "outputs": ["1", "1"]}
754
44
coding
Solve the programming task below in a Python markdown code block. When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a $2 \times n$ grid where each row is a permutation of the numbers $1,2,3,\ldots,n$. The...
{"inputs": ["2\n4\n1 4 2 3\n3 2 1 4\n8\n2 6 5 1 4 3 7 8\n3 8 7 5 1 2 4 6\n", "2\n4\n1 4 2 3\n3 2 1 4\n8\n2 6 5 1 4 3 7 8\n3 8 7 5 1 2 4 6\n"], "outputs": ["2\n8\n", "\n2\n8\n"]}
574
131
coding
Solve the programming task below in a Python markdown code block. Chef wants to rent a car to travel to his restaurant which is N kilometers away. He can either rent a petrol car or a diesel car. One litre of petrol costs X rupees and one litre of diesel costs Y rupees. Chef can travel A kilometers with one litre of p...
{"inputs": ["4\n20 10 8 2 4\n50 12 12 4 3\n40 3 15 8 40\n21 9 9 2 9\n"], "outputs": ["DIESEL\nPETROL\nANY\nDIESEL\n"]}
589
74
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. A strange grid has been recovered from an old book. It has $5$ columns and infinite number of rows. The bottom row is considered as the first row. First few rows of the grid are like this: .............. .............. 20 22 24 26 28 11 13 15 17 19 ...
{"inputs": ["6 3\n"], "outputs": ["25\n"]}
286
17
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers. The array is sorted if $a_1 \le a_2 \le \dots \le a_n$. You want to make the array $a$ sorted by applying the following operation exactly once: choose an integer $x$, then for every $i \in [1, n]$,...
{"inputs": ["2\n2\n1 2\n2\n1 2\n", "2\n3\n1 2 3\n3\n1 2 3\n", "8\n5\n5 3 3 3 5\n4\n5 3 4 5\n8\n1 2 3 4 5 6 7 8\n6\n10 5 4 3 2 1\n3\n3 3 1\n3\n42 43 42\n2\n100000000 99999999\n6\n29613295 52036613 75100585 78027446 81409090 73215\n"], "outputs": ["0\n0\n", "0\n0\n", "4\n-1\n0\n8\n2\n-1\n100000000\n40741153\n"]}
676
241
coding
Solve the programming task below in a Python markdown code block. Petya organized a strange birthday party. He invited $n$ friends and assigned an integer $k_i$ to the $i$-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are $m$ unique presents available, the $j$-th present c...
{"inputs": ["1\n1 1\n1\n1\n", "1\n1 1\n1\n0\n", "1\n1 1\n1\n1\n", "2\n5 4\n2 3 4 3 2\n3 5 6 20\n5 5\n5 5 3 2 1\n7 40 90 160 250\n", "2\n5 4\n2 2 4 3 2\n3 5 6 20\n5 5\n5 5 3 2 1\n7 40 90 160 423\n", "2\n5 4\n2 4 4 1 2\n4 5 12 20\n5 5\n5 4 1 3 1\n7 40 90 91 160\n", "2\n5 4\n2 3 4 3 2\n3 5 9 20\n5 5\n5 5 3 2 1\n7 40 90 16...
738
384
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.   Please complete the following python code pr...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1],[1,0,1],[1,1,1]]) == 9\n assert candidate(grid = [[1,1,0,0]]) == 1\n\n\ncheck(Solution().largest1BorderedSquare)"}
106
69
coding
Solve the programming task below in a Python markdown code block. Take a sentence (string) and reverse each word in the sentence. Do not reverse the order of the words, just the letters in each word. If there is punctuation, it should be interpreted as a regular character; no special rules. If there is spacing before...
{"functional": "_inputs = [['How now brown cow'], ['racecar'], ['Hi mom'], [' '], [' '], ['go away'], ['I like noodles'], ['The red pen wrote on the wall'], ['Green trucks drive fast'], ['Pink trucks drive slow']]\n_outputs = [['woH won nworb woc'], ['racecar'], ['iH mom'], [' '], [' '], ['og yawa'], ['I ekil seldoon...
140
276
coding
Solve the programming task below in a Python markdown code block. Gru wants to distribute $N$ bananas to $K$ minions on his birthday. Gru does not like to just give everyone the same number of bananas, so instead, he wants to distribute bananas in such a way that each minion gets a $distinct$ amount of bananas. That is...
{"inputs": ["1\n6 3"], "outputs": ["1"]}
319
16
coding
Solve the programming task below in a Python markdown code block. Tim is visiting his grandma for two days and is bored due to the lack of the electricity over there. That's why he starts to play with grandma's colorful candle collection. He aligned the $N$ candles from left to right. The $\boldsymbol{i}$th candle fro...
{"inputs": ["4 3\n1 1\n3 2\n2 2\n4 3\n"], "outputs": ["2\n"]}
385
32
coding
Solve the programming task below in a Python markdown code block. JJ loves playing with averages. He has an array A of length N. He wants to divide the array A into two non-empty subsets P and Q such that the value of mean(P) + mean(Q) is as large as possible. (Note that each A_{i} must belong to either subset P or sub...
{"inputs": ["2\n2\n4 5\n5\n2 2 2 2 2\n"], "outputs": ["9.000000\n4.000000\n"]}
540
48
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree and a positive integer k. The level sum in the tree is the sum of the values of the nodes that are on the same level. Return the kth largest level sum in the tree (not necessari...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,8,9,2,1,3,7,4,6]), k = 2) == 13\n assert candidate(root = tree_node([1,2,None,3]), k = 1) == 3\n\n\ncheck(Solution().kthLargestLevelSum)"}
194
83
coding
Solve the programming task below in a Python markdown code block. You are given an array of $n$ non-negative integers $a_1, a_2, \ldots, a_n$. You can make the following operation: choose an integer $x \geq 2$ and replace each number of the array by the remainder when dividing that number by $x$, that is, for all $1 \l...
{"inputs": ["4\n4\n2 5 6 8\n3\n1 1 1\n5\n4 1 7 0 8\n4\n5 9 17 5\n"], "outputs": ["YES\nYES\nNO\nYES\n"]}
541
61
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 all the arithmetic subsequences of nums. A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two con...
{"functional": "def check(candidate):\n assert candidate(nums = [2,4,6,8,10]) == 7\n assert candidate(nums = [7,7,7,7,7]) == 16\n\n\ncheck(Solution().numberOfArithmeticSlices)"}
244
64
coding
Solve the programming task below in a Python markdown code block. Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeated...
{"inputs": ["4\n1 4\n4 3\n2 3", "4\n1 2\n4 2\n2 3", "4\n1 4\n4 3\n2 1", "4\n1 4\n4 3\n2 2", "4\n1 4\n4 2\n2 2", "4\n1 3\n4 2\n2 3", "4\n1 4\n4 2\n4 2", "4\n1 3\n4 2\n2 1"], "outputs": ["Snuke\n", "Fennec\n", "Snuke\n", "Snuke\n", "Snuke\n", "Snuke\n", "Snuke\n", "Fennec\n"]}
411
174
coding
Solve the programming task below in a Python markdown code block. According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment....
{"inputs": ["6 10\n4 6 4 1 9 3\n", "6 10\n4 3 4 1 9 3\n", "6 10\n4 3 4 2 9 3\n", "6 10\n4 3 2 2 9 3\n", "6 10\n4 3 0 2 9 3\n", "6 10\n5 6 4 1 9 3\n", "5 1\n24 30 18 9 76\n", "5 1\n24 28 18 9 76\n"], "outputs": ["30\n", "30\n", "30\n", "30\n", "30\n", "30\n", "0\n", "0\n"]}
281
198
coding
Solve the programming task below in a Python markdown code block. Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates ...
{"inputs": ["1 1 -100 100\n-99\n99\n", "1 1 -100 100\n99\n-99\n", "3 2 10 40\n8 1 15\n16 22", "3 2 10 40\n8 1 15\n16 23", "3 0 10 40\n8 1 15\n16 23", "0 0 10 40\n8 1 15\n16 23", "3 3 10 40\n8 1 15\n16 23", "3 0 10 61\n8 1 15\n16 23"], "outputs": ["No War\n", "War\n", "No War\n", "No War\n", "No War\n", "No War\n", "No ...
467
231
coding
Solve the programming task below in a Python markdown code block. There is a group of N friends who wish to enroll in a course together. The course has a maximum capacity of M students that can register for it. If there are K other students who have already enrolled in the course, determine if it will still be possible...
{"inputs": ["3\n2 50 27\n5 40 38\n100 100 0\n"], "outputs": ["Yes\nNo\nYes\n"]}
360
44
coding
Solve the programming task below in a Python markdown code block. Hofstadter sequences are a family of related integer sequences, among which the first ones were described by an American professor Douglas Hofstadter in his book Gödel, Escher, Bach. ### Task Today we will be implementing the rather chaotic recursive s...
{"functional": "_inputs = [[1], [3], [7], [10], [100], [1000]]\n_outputs = [[1], [2], [5], [6], [56], [502]]\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 le...
231
196
coding
Solve the programming task below in a Python markdown code block. ##Overview Write a helper function that takes in a Time object and converts it to a more human-readable format. You need only go up to '_ weeks ago'. ```python to_pretty(0) => "just now" to_pretty(40000) => "11 hours ago" ``` ##Specifics - The output ...
{"functional": "_inputs = [[0], [1], [30], [90], [180], [4000], [40000], [140000], [400000], [1000000], [10000000]]\n_outputs = [['just now'], ['a second ago'], ['30 seconds ago'], ['a minute ago'], ['3 minutes ago'], ['an hour ago'], ['11 hours ago'], ['a day ago'], ['4 days ago'], ['a week ago'], ['16 weeks ago']]\ni...
278
273
coding
Solve the programming task below in a Python markdown code block. problem There are n cards with one integer from 1 to n and one blank card. Of these n + 1 cards, k cards are given, but 1 ≤ k ≤ n. You can write one integer from 1 to n on a blank card. I want to make a continuous sequence of integers as long as possibl...
{"inputs": ["7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n1\n7\n0 0", "9 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n1\n4\n7\n0 0", "7 5\n6\n2\n3\n7\n1\n7 5\n6\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n4\n6\n0 0", "9 5\n6\n2\n4\n3\n1\n7 5\n5\n2\n1\n4\n7\n0 0", "9 5\n6\n3\n4\n7\n0\n7 5\n...
382
318
coding
Solve the programming task below in a Python markdown code block. You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). Initially, each cell of this grid is either empty, contains an ant or an anteater. Each ant is moving in a fixed direction: up, down, left or right....
{"inputs": ["10\n3 3\nR--\n---\n--U\n1 4\nR--R\n2 2\n--\n--\n1 4\nR--L\n1 4\n-R-L\n1 4\n-R#L\n3 3\nR-D\n-#-\nR-U\n3 3\nR-D\n---\nR#U\n3 3\n-D-\nR-L\n-U-\n1 7\nRLLLLLL\n"], "outputs": ["1\n0\n0\n0\n1\n0\n3\n2\n6\n3"]}
645
136
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n. Let even denote the number of even indices in the binary representation of n with value 1. Let odd denote the number of odd indices in the binary representation of n with value 1. N...
{"functional": "def check(candidate):\n assert candidate(n = 17) == [2,0]\n assert candidate(n = 2) == [0,1]\n\n\ncheck(Solution().evenOddBit)"}
120
51
coding
Solve the programming task below in a Python markdown code block. There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is neces...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "2 1\n9 13\n", "2 2\n9 13\n", "3 3\n3 8 6\n", "2 0\n17 10\n", "2 0\n17 13\n", "2 1\n17 13\n"], "outputs": ["1 1\n1 1\n", "1 1\n1 1\n", "1 2\n1 1\n2 2\n", "1 2\n1 1\n2 2\n", "2 1\n2 3\n", "1 2\n1 1\n2 2\n", "1 2\n1 1\n2 2\n", "1 2\n1 1\n2 2\n"]}
526
192
coding
Solve the programming task below in a Python markdown code block. This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of upperca...
{"inputs": ["FC", "DF", "EF", "FD", "FE", "GE", "GD", "ED"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
211
62
coding
Solve the programming task below in a Python markdown code block. Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of i...
{"inputs": ["2\n3\n5 7 10\n3\n3 3 4\n", "1\n2\n4294967296 4294967296\n"], "outputs": ["YES\nNO\n", "NO\n"]}
593
65
coding
Solve the programming task below in a Python markdown code block. Chef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however, the tot...
{"inputs": ["4\n1 1\n2\n2 4\n1 1\n3 6\n3 4 2\n3 6\n3 4 3"], "outputs": ["-1\n1\n2\n3"]}
529
53
coding
Solve the programming task below in a Python markdown code block. The life goes up and down, just like nice sequences. Sequence t_1, t_2, ..., t_{n} is called nice if the following two conditions are satisfied: t_{i} < t_{i} + 1 for each odd i < n; t_{i} > t_{i} + 1 for each even i < n. For example, sequences (2, ...
{"inputs": ["2\n5 1\n", "2\n5 1\n", "2\n5 2\n", "2\n5 4\n", "2\n10 10\n", "2\n10 10\n", "5\n2 8 4 7 7\n", "5\n1 1 1 4 3\n"], "outputs": ["1\n", "1", "1\n", "1\n", "0\n", "0", "2\n", "1\n"]}
559
116
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. There is a complete binary tree with 2n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2n - 1 - 1] has two children where: ...
{"functional": "def check(candidate):\n assert candidate(n = 3, queries = [[5,3],[4,7],[2,3]]) == [4,5,3]\n assert candidate(n = 2, queries = [[1,2]]) == [2]\n\n\ncheck(Solution().cycleLengthQueries)"}
295
72
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, you have two types of operation: Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists). Choose an index i in the ...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabc\") == 3\n assert candidate(s = \"cbbd\") == 3\n assert candidate(s = \"dddaaa\") == 2\n\n\ncheck(Solution().minimizedStringLength)"}
156
61
coding
Solve the programming task below in a Python markdown code block. Error Handling is very important in coding and seems to be overlooked or not implemented properly. #Task Your task is to implement a function which takes a string as input and return an object containing the properties vowels and consonants. The vowels...
{"functional": "_inputs = [['Test'], ['Here is some text'], ['To be a Codewarrior or not to be'], ['To Kata or not to Kata'], ['aeiou'], ['TEst'], ['HEre Is sOme text'], [['To Kata or not to Kata']], [None], ['Test '], ['Here is some text '], [' '], [{'jjjjj': 'jjjjj'}]]\n_outputs...
350
446
coding
Solve the programming task below in a Python markdown code block. For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ i...
{"inputs": ["7\n1 0\n0 1\n0 3\n0 0\n1 0\n0 7\n1 0", "7\n1 0\n0 1\n1 2\n0 0\n1 0\n0 7\n1 0", "7\n0 0\n0 2\n0 3\n0 2\n0 4\n0 3\n1 4", "7\n1 0\n0 1\n0 2\n0 0\n1 0\n1 7\n1 0", "7\n0 2\n0 2\n0 1\n0 0\n1 4\n1 3\n0 0", "7\n0 0\n1 3\n1 0\n0 0\n0 4\n1 3\n1 9", "7\n1 0\n0 2\n1 2\n0 0\n1 0\n0 7\n1 0", "7\n0 0\n0 2\n0 1\n0 0\n0 0\...
286
382
coding
Solve the programming task below in a Python markdown code block. A number is simply made up of digits. The number 1256 is made up of the digits 1, 2, 5, and 6. For 1256 there are 24 distinct permutations of the digits: 1256, 1265, 1625, 1652, 1562, 1526, 2156, 2165, 2615, 2651, 2561, 2516, 5126, 5162, 5216, 5...
{"functional": "_inputs = [[2], [25], [737]]\n_outputs = [[2], [38], [629]]\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 ...
522
173
coding
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For a given number `num`, write a function to test if it's a numerical p...
{"functional": "_inputs = [[1221], [110011], [1456009006541], [123322], [1], [152], [9999], ['ACCDDCCA'], ['@14AbC'], ['1221'], [-450]]\n_outputs = [[True], [True], [True], [False], [True], [False], [True], ['Not valid'], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if i...
237
260
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will write a function `doubles` that will remove double string characters that are adjacent to each other. For example: `doubles('abbcccdddda') = 'aca'`, because, from left to right: ```Haskell a) There is only one 'a' on the left han...
{"functional": "_inputs = [['abbbzz'], ['zzzzykkkd'], ['abbcccdddda'], ['vvvvvoiiiiin'], ['rrrmooomqqqqj'], ['xxbnnnnnyaaaaam'], ['qqqqqqnpppgooooonpppppqmmmmmc'], ['qqqqqwwwx'], ['jjjfzzzzzzsddgrrrrru'], ['jjjjjfuuuutgggggqppdaaas'], ['iiiiibllllllyqqqqqbiiiiiituuf'], ['mmmmmmuzzqllllmqqqp']]\n_outputs = [['ab'], ['yk...
265
332
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string array words. Two strings are similar if they consist of the same characters. For example, "abca" and "cba" are similar since both consist of characters 'a', 'b', and 'c'. However, "ab...
{"functional": "def check(candidate):\n assert candidate(words = [\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]) == 2\n assert candidate(words = [\"aabb\",\"ab\",\"ba\"]) == 3\n assert candidate(words = [\"nba\",\"cba\",\"dba\"]) == 0\n\n\ncheck(Solution().similarPairs)"}
163
81
coding
Solve the programming task below in a Python markdown code block. Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task. Consider two infinite sets of numbers. The first set consists of odd positive...
{"inputs": ["1 3\n", "1 1\n", "1 1\n", "1 3\n", "5 14\n", "1 15\n", "1 15\n", "1 28\n"], "outputs": ["7", "1", "1\n", "7\n", "105", "135", "135\n", "434\n"]}
600
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix: 0 means the cell cannot be walked through. 1 represents an empty cell that can be wal...
{"functional": "def check(candidate):\n assert candidate(forest = [[1,2,3],[0,0,4],[7,6,5]]) == 6\n assert candidate(forest = [[1,2,3],[0,0,0],[7,6,5]]) == -1\n assert candidate(forest = [[2,3,4],[0,0,5],[8,7,6]]) == 6\n\n\ncheck(Solution().cutOffTree)"}
272
107
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Dobby loves playing games, especially games related to numbers. So, today Bhuvan gave him a new game. The description of the game goes as follows : Consider an array A...
{"inputs": ["3\n2 0 1"], "outputs": ["4"]}
479
18
coding
Solve the programming task below in a Python markdown code block. #Sorting on planet Twisted-3-7 There is a planet... in a galaxy far far away. It is exactly like our planet, but it has one difference: #The values of the digits 3 and 7 are twisted. Our 3 means 7 on the planet Twisted-3-7. And 7 means 3. Your task is ...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[12, 13, 14]], [[9, 2, 4, 7, 3]]]\n_outputs = [[[1, 2, 7, 4, 5, 6, 3, 8, 9]], [[12, 14, 13]], [[2, 7, 4, 3, 9]]]\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, ab...
305
259
coding
Solve the programming task below in a Python markdown code block. Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For exam...
{"inputs": ["a\n", "z\n", "a\n", "z\n", "ee\n", "iq\n", "iq\n", "ee\n"], "outputs": ["aa\n", "zz\n", "aa\n", "zz\n", "eee\n", "qiq\n", "qiq\n", "eee"]}
403
71
coding
Solve the programming task below in a Python markdown code block. Given N and M Dexter wants to know how many pairs a,b(1 ≤ a < b ≤N) are there such that (a+b) is divisible by M. For example when N=4 and M=3, there are 2 possible pairs the sum of which is divisible by M and they are (1,2) and (2,4). ------ Input ----...
{"inputs": ["3\n2 3\n4 3\n1 6"], "outputs": ["1\n2\n0"]}
205
28
coding
Solve the programming task below in a Python markdown code block. You're given an array $a$. You should repeat the following operation $k$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. -----I...
{"inputs": ["2 5\n2 3\n", "2 5\n2 3\n", "2 5\n4 3\n", "2 1\n4 3\n", "3 5\n1 2 3\n", "3 7\n1 2 3\n", "3 1\n6 1 7\n", "3 1\n6 6 7\n"], "outputs": ["2\n1\n0\n0\n0\n", "2\n1\n0\n0\n0\n", "3\n1\n0\n0\n0\n", "3\n", "1\n1\n1\n0\n0\n", "1\n1\n1\n0\n0\n0\n0\n", "1\n", "6\n"]}
407
170
coding
Solve the programming task below in a Python markdown code block. # Task let F(N) be the sum square of digits of N. So: `F(1) = 1, F(3) = 9, F(123) = 14` Choose a number A, the sequence {A0, A1, ...} is defined as followed: ``` A0 = A A1 = F(A0) A2 = F(A1) ... ``` if A = 123, we have: ``` 123 →...
{"functional": "_inputs = [[1], [85], [810], [812], [818], [833]]\n_outputs = [[1], [8], [8], [8], [1], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if le...
591
195
coding
Solve the programming task below in a Python markdown code block. Harvey Specter has agreed to take Mike Ross to a meeting filled with brilliant scientists at NSA Headquarters. But, as always, it's not going to be easy for Mike. He has to solve a puzzle given by Harvey. Harvey gives two numbers N and K and defines a ...
{"inputs": ["2\n10 4\n7 3\n"], "outputs": ["10\n7\n"]}
385
26
coding
Solve the programming task below in a Python markdown code block. Don Drumphet lives in a nice neighborhood, but one of his neighbors has started to let his house go. Don Drumphet wants to build a wall between his house and his neighbor’s, and is trying to get the neighborhood association to pay for it. He begins to ...
{"functional": "_inputs = [['Mexico'], ['Melania'], ['Melissa'], ['Me'], [''], ['I']]\n_outputs = [[['Mexico', 'Me']], [['Melania', 'Me']], [['Melissa', 'Me']], [['Me']], [['']], [['I']]]\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,...
216
200
coding
Solve the programming task below in a Python markdown code block. Problem Yamano Mifune Gakuen's 1st grade G group is a class where female students carrying misfortune gather. They face various challenges every day with the goal of being happy. In their class, they can take practical happiness courses as part of the ...
{"inputs": ["3 7 3\n0 1 1 1\n0 1 1 2\n1 1 3 4\n1 1 1 1\n1 2 1 2\n3 1 1 3\n2 2 2 1", "3 7 3\n0 1 1 1\n1 1 1 2\n1 1 3 4\n1 1 1 1\n1 2 1 2\n2 1 1 3\n2 2 2 1", "3 7 3\n0 1 0 1\n0 1 1 1\n1 1 3 0\n1 1 1 1\n1 3 1 2\n3 1 1 3\n2 2 2 1", "3 7 3\n0 1 2 1\n1 1 1 2\n1 1 3 4\n1 1 1 1\n1 2 1 2\n3 1 1 2\n2 2 2 1", "3 7 3\n0 1 2 1\n1 2...
564
542
coding
Solve the programming task below in a Python markdown code block. You have a stripe of checkered paper of length $n$. Each cell is either white or black. What is the minimum number of cells that must be recolored from white to black in order to have a segment of $k$ consecutive black cells on the stripe? If the input...
{"inputs": ["1\n20 2\nWWWBBBWBWBWBWBWBWBWB\n", "4\n5 3\nBBWBW\n5 5\nBBWBW\n5 1\nBBWBW\n1 1\nW\n"], "outputs": ["0\n", "1\n2\n0\n1\n"]}
489
74
coding
Solve the programming task below in a Python markdown code block. The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N p...
{"inputs": ["2\n1 5\n2 4\n2 6", "2\n2 5\n2 4\n2 6", "2\n0 5\n2 4\n2 6", "2\n0 5\n2 4\n2 5", "2\n0 5\n2 4\n2 3", "2\n1 5\n2 4\n3 6", "2\n0 10\n2 4\n2 3", "2\n0 12\n2 4\n2 3"], "outputs": ["2\n", "1\n", "2\n", "2\n", "1\n", "3", "1\n", "1\n"]}
477
159
coding
Solve the programming task below in a Python markdown code block. You are given a set of `n` segments on the axis `Ox`, each segment has integer endpoints between `0` and `m` inclusive.  Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers li and ri — coordinat...
{"functional": "_inputs = [[7, [[0, 7]]], [2, []], [0, []], [0, [[0, 0]]]]\n_outputs = [[[]], [[0, 1, 2]], [[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 isinstance(a, (list, tuple)):\n ...
284
195
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Ash is trying to get visa to Chefland. For the visa to be approved, he needs to satisfy the following three criteria: Solve at least $x_{1}$ problems on Codec...
{"inputs": ["4\n20 50 2100 1900 6 6\n50 20 1900 1900 5 5\n20 20 1900 1900 1 6\n27 27 1920 1920 3 3"], "outputs": ["NO\nNO\nNO\nYES"]}
562
98
coding
Solve the programming task below in a Python markdown code block. Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of n steps. On...
{"inputs": ["1\n0\n1\n", "1\n0\n1\n", "2\n0 5\n4 0\n1 2\n", "2\n0 5\n7 0\n1 2\n", "2\n0 4\n7 0\n1 2\n", "2\n0 9\n7 0\n1 2\n", "2\n0 1\n7 0\n1 2\n", "2\n0 5\n4 0\n1 2\n"], "outputs": ["0 ", "0 \n", "9 0 ", "12 0", "11 0", "16 0", "8 0", "9 0 \n"]}
510
161
coding
Solve the programming task below in a Python markdown code block. Two friends like to pool their money and go to the ice cream parlor. They always choose two distinct flavors and they spend all of their money. Given a list of prices for the flavors of ice cream, select the two that will cost all of the money they hav...
{"inputs": ["2\n4\n5\n1 4 5 3 2\n4 \n4\n2 2 4 3\n"], "outputs": ["1 4\n1 2\n"]}
668
47
coding
Solve the programming task below in a Python markdown code block. $Neha$ is given a number $N$. She always looks for special thing , this time she is looking for $Special$ $Number$ and $Partial$ $Special$ $Number$. A $Special$ $Number$ is a number whose product of its digits is equal to number itself i.e. $N $, and in...
{"inputs": ["3"], "outputs": ["1 20"]}
439
15
coding
Solve the programming task below in a Python markdown code block. Chef is shopping for masks. In the shop, he encounters 2 types of masks: Disposable Masks — cost X but last only 1 day. Cloth Masks — cost Y but last 10 days. Chef wants to buy masks to last him 100 days. He will buy the masks which cost him the least...
{"inputs": ["4\n10 100\n9 100\n88 99\n1 11\n"], "outputs": ["Cloth\nDisposable\nCloth\nDisposable\n"]}
590
46
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. Substrings that occur multipl...
{"functional": "def check(candidate):\n assert candidate(s = \"00110011\") == 6\n assert candidate(s = \"10101\") == 4\n\n\ncheck(Solution().countBinarySubstrings)"}
114
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. Teams $A$ and $B$ are having a penalty shoot-out to decide the winner of their football match. Each team gets to take a shot $N$ times, and the team...
{"inputs": ["2\n3\n101011\n3\n100001"], "outputs": ["4\n6"]}
767
32
coding
Solve the programming task below in a Python markdown code block. Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan...
{"inputs": ["2 3\n4 9\n2 4", "2 3\n4 9\n4 4", "2 6\n4 9\n4 4", "2 6\n3 9\n4 4", "2 6\n3 9\n2 4", "2 6\n3 9\n1 4", "2 3\n3 4\n1 6", "2 5\n3 4\n1 6"], "outputs": ["6\n", "12\n", "24\n", "18\n", "14\n", "10\n", "3\n", "5\n"]}
325
147
coding
Solve the programming task below in a Python markdown code block. You've purchased a ready-meal from the supermarket. The packaging says that you should microwave it for 4 minutes and 20 seconds, based on a 600W microwave. Oh no, your microwave is 800W! How long should you cook this for?! ___ # Input You'll be giv...
{"functional": "_inputs = [['600W', 4, 20, '800W'], ['800W', 3, 0, '1200W'], ['100W', 8, 45, '50W'], ['7500W', 0, 5, '600W'], ['450W', 3, 25, '950W'], ['21W', 64, 88, '25W'], ['83W', 61, 80, '26W'], ['38W', 95, 22, '12W']]\n_outputs = [['3 minutes 15 seconds'], ['2 minutes 0 seconds'], ['17 minutes 30 seconds'], ['1 mi...
277
362
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 have $C = 100,000$ cakes, numbered $1$ through $C$. Each cake has an integer height; initially, the height of each cake is $0$. There are $N$ op...
{"inputs": ["1\n3 2\n2 6\n4 9\n1 4"], "outputs": ["3"]}
723
28
coding
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard versions is the maximum value of $k$. You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first...
{"inputs": ["1\n9124\n", "1\n9124\n", "1\n3621\n", "1\n4320\n", "1\n2836\n", "1\n6961\n", "1\n3722\n", "1\n6297\n"], "outputs": ["4\n", "4\n", "1\n", "2\n", "7\n", "3\n", "5\n", "2\n"]}
587
110
coding
Solve the programming task below in a Python markdown code block. Problem statement AOR Ika got a cabbage with $ N $ leaves. The leaves of this cabbage are numbered $ 1, \ ldots, N $ in order from the outside, and the dirtiness of the $ i $ th leaf is $ D_i $. The larger this value is, the worse the degree of dirt is....
{"inputs": ["5 3 6 9\n9 1 5 3 1", "5 3 6 9\n9 1 6 3 1", "8 3 6 9\n9 1 6 3 1", "2 3 6 9\n9 7 5 3 1", "5 3 6 8\n9 1 5 3 1", "5 3 6 9\n9 7 5 3 1", "9 3 1 9\n22 2 6 2 0", "8 3 6 9\n15 1 6 3 1"], "outputs": ["1\n", "1\n", "1\n", "0\n", "1\n", "2", "4\n", "1\n"]}
707
191
coding
Solve the programming task below in a Python markdown code block. With the college fest approaching soon, Manasa is following a strict dieting regime . Today, she just cannot resist her temptation for having a pizza. An inner conflict ensues, and she decides that she will have a pizza, only if she comes up with a solut...
{"inputs": ["3\n1 2 3\n"], "outputs": ["40392\n"]}
496
24
coding
Solve the programming task below in a Python markdown code block. Initially, two non-touching spheres of radii R1 and R2 are lying in space at rest. Both of them are then given accelerations a1 and a2 respectively at time=0. Find whether they will ever come in contact. Their initial positions are represented as (x1,y1,...
{"inputs": ["2\n1 2\n0 0 0\n-1 0 0\n4 0 0\n1 0 0\n1 2\n0 0 0\n100 0 0\n4 0 0\n0 0 0\n"], "outputs": ["NO\nYES\n"]}
464
75
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, replace each element with its rank. The rank represents how large the element is. The rank has the following rules: Rank is an integer starting from 1. The larger the element, the larg...
{"functional": "def check(candidate):\n assert candidate(arr = [40,10,20,30]) == [4,1,2,3]\n assert candidate(arr = [100,100,100]) == [1,1,1]\n assert candidate(arr = [37,12,28,9,100,56,80,5,12]) == [5,3,4,2,8,6,7,1,3]\n\n\ncheck(Solution().arrayRankTransform)"}
121
129
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Chef's planet is called Javad. A year on Javad has $N$ months numbered $1$ through $N$. For each valid $i$, the $i$-th month has $a_{i}$ days numbered $1$ th...
{"inputs": ["4\n5\n1 2 3 4 5\n2 1 1\n3 5 1\n2\n3 3\n1 1 1\n2 2 2\n2\n1 1\n3 1 1\n3 2 1\n5\n1 4 3 4 6\n3 5 6\n10 1 1"], "outputs": ["26\n11\n2\n112"]}
699
107
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer permutations A and B of length n. A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A ...
{"functional": "def check(candidate):\n assert candidate(A = [1,3,2,4], B = [3,1,2,4]) == [0,2,3,4]\n assert candidate(A = [2,3,1], B = [3,1,2]) == [0,1,3]\n\n\ncheck(Solution().findThePrefixCommonArray)"}
147
88
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 of string words and two integers left and right. A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e...
{"functional": "def check(candidate):\n assert candidate(words = [\"are\",\"amy\",\"u\"], left = 0, right = 2) == 2\n assert candidate(words = [\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"], left = 1, right = 4) == 3\n\n\ncheck(Solution().vowelStrings)"}
136
82