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. You are given an array of positive integers $a_1, a_2, \ldots, a_n$. Make the product of all the numbers in the array (that is, $a_1 \cdot a_2 \cdot \ldots \cdot a_n$) divisible by $2^n$. You can perform the following operation as many times as you lik...
{"inputs": ["6\n1\n2\n2\n3 2\n3\n10 6 11\n4\n13 17 1 1\n5\n1 1 12 1 1\n6\n20 7 14 18 3 5\n"], "outputs": ["0\n1\n1\n-1\n2\n1\n"]}
699
87
coding
Solve the programming task below in a Python markdown code block. The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d_1 is the distance between the 1-st and the 2-nd station; d_2 is the distance between the 2-nd and the 3-rd station; ... d_{n...
{"inputs": ["3\n1 1 1\n3 1\n", "3\n1 1 1\n2 1\n", "3\n1 1 1\n3 1\n", "4\n2 3 4 9\n1 3\n", "3\n4 37 33\n3 3\n", "4\n1 1 1 1\n2 4\n", "4\n1 1 2 1\n2 4\n", "3\n4 37 33\n3 3\n"], "outputs": ["1\n", "1\n", "1\n", "5\n", "0\n", "2\n", "2\n", "0\n"]}
500
160
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs. A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high. Β  Please com...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4,2,7], low = 2, high = 6) == 6\n assert candidate(nums = [9,8,4,2,1], low = 5, high = 14) == 8\n\n\ncheck(Solution().countPairs)"}
115
78
coding
Solve the programming task below in a Python markdown code block. Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend worki...
{"inputs": ["1 1\n86399\n", "1 1\n86399\n", "2 2\n86400 86398\n", "2 86400\n0 86400\n", "2 86400\n1 86399\n", "2 86400\n1 86399\n", "2 86400\n0 86399\n", "2 86400\n0 48332\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "1\n", "1\n"]}
294
170
coding
Solve the programming task below in a Python markdown code block. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is t...
{"inputs": ["2 4\n0 1\n", "2 2\n0 1\n", "2 4\n0 0\n", "2 1\n0 0\n", "2 2\n0 0\n", "2 4\n1 0\n", "2 4\n-1 1\n", "2 4\n-1 0\n"], "outputs": ["4\n", "2\n", "5\n", "2\n", "3\n", "4\n", "4\n", "4\n"]}
545
120
coding
Solve the programming task below in a Python markdown code block. The NumPy (Numeric Python) package helps us manipulate large arrays and matrices of numeric data. To use the NumPy module, we need to import it using: import numpy Arrays A NumPy array is a grid of values. They are similar to lists, except that ev...
{"inputs": ["1 2 3 4 -8 -10\n"], "outputs": ["[-10. -8. 4. 3. 2. 1.]\n"]}
272
49
coding
Solve the programming task below in a Python markdown code block. Problem Let $ f (x) $ be the sum of each digit when the non-negative integer $ x $ is expressed in binary. Given a positive integer $ N $, output the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $. Example of calculating the function $ f (5) $: When ...
{"inputs": ["6", "1", "5", "4", "3", "8", "7", "2"], "outputs": ["2\n", "1\n", "2\n", "2\n", "2\n", "3\n", "3\n", "1"]}
245
61
coding
Solve the programming task below in a Python markdown code block. Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and all of mathematics. It states: Every even integer greater than 2 can be expressed as the sum of two primes. For example: `6 = 3 + 3` `8 = 3 + 5` `10 = 3 +...
{"functional": "_inputs = [[2], [4], [6], [8], [10], [52], [54], [56], [58], [100], [200], [1000], [5000]]\n_outputs = [[[]], [[[2, 2]]], [[[3, 3]]], [[[3, 5]]], [[[3, 7], [5, 5]]], [[[5, 47], [11, 41], [23, 29]]], [[[7, 47], [11, 43], [13, 41], [17, 37], [23, 31]]], [[[3, 53], [13, 43], [19, 37]]], [[[5, 53], [11, 47]...
319
1,625
coding
Solve the programming task below in a Python markdown code block. There is a square matrix n Γ— n, consisting of non-negative integer numbers. You should find such a way on it that * starts in the upper left cell of the matrix; * each following cell is to the right or down from the current cell; * the way ends...
{"inputs": ["2\n7 6\n3 8\n", "2\n4 6\n3 8\n", "2\n4 4\n3 8\n", "2\n4 7\n3 8\n", "2\n4 7\n6 8\n", "2\n4 7\n9 8\n", "2\n4 7\n10 8\n", "2\n4 2\n10 8\n"], "outputs": ["0\nDR", "0\nDR\n", "0\nDR\n", "0\nDR\n", "0\nDR\n", "0\nDR\n", "0\nRD\n", "0\nRD\n"]}
221
151
coding
Solve the programming task below in a Python markdown code block. Your job is to build a function which determines whether or not there are double characters in a string (including whitespace characters). For example ```aa```, ``!!`` or ``` ```. You want the function to return true if the string contains double cha...
{"functional": "_inputs = [['abca'], ['aabc'], ['a 11 c d'], ['AabBcC'], ['a b c'], ['a b c d e f g h i h k'], ['2020'], [\"a!@\u20ac\u00a3#$%^&*()_-+=}]{[|':;?/>.<,~\"]]\n_outputs = [[False], [True], [True], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, f...
260
253
coding
Solve the programming task below in a Python markdown code block. You are given two integers $a$ and $b$. You may perform any number of operations on them (possibly zero). During each operation you should choose any positive integer $x$ and set $a := a - x$, $b := b - 2x$ or $a := a - 2x$, $b := b - x$. Note that you ...
{"inputs": ["1\n29 2\n", "1\n24 2\n", "1\n24 1\n", "1\n21 2\n", "1\n16 0\n", "1\n20 0\n", "1\n31 0\n", "1\n35 0\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
438
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d). For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16. Given an integer array nums, choos...
{"functional": "def check(candidate):\n assert candidate(nums = [5,6,2,7,4]) == 34\n assert candidate(nums = [4,2,5,9,7,4,8]) == 64\n\n\ncheck(Solution().maxProductDifference)"}
170
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Β  Please complete the following python code precisely: ```python class Solution: def generateMatrix(self, n: ...
{"functional": "def check(candidate):\n assert candidate(n = 3) == [[1,2,3],[8,9,4],[7,6,5]]\n assert candidate(n = 1) == [[1]]\n\n\ncheck(Solution().generateMatrix)"}
74
63
coding
Solve the programming task below in a Python markdown code block. Get excited, folks, because it is time for the final match of Codechef Premier League (CPL)! Mike and Tracy also want to watch the grand finale, but unfortunately, they could not get tickets to the match. However, Mike is not someone who gives up so easi...
{"inputs": ["2\n8 38\n7 8 19 7 8 7 10 20\n4 5\n2 10 4 9"], "outputs": ["7\n2"]}
668
51
coding
Solve the programming task below in a Python markdown code block. Kulyash believes in equality. Given an integer N, output a binary string of length N such that: The count of 01 [subsequences] in the string is equal to the count of 10 subsequences; The string has at least one occurrence of 0 as well as 1. If multip...
{"inputs": ["2\n4\n3\n"], "outputs": ["1001\n010\n"]}
316
25
coding
Solve the programming task below in a Python markdown code block. This question is similar to the $"Operation$ $on$ $a$ $Tuple"$ problem in this month's Long Challenge but with a slight variation. Consider the following operations on a triple of integers. In one operation, you should: - Choose a positive integer $d>0...
{"inputs": ["1\n2 2 1\n3 3 2"], "outputs": ["3"]}
379
24
coding
Solve the programming task below in a Python markdown code block. Trigrams are a special case of the n-gram, where n is 3. One trigram is a continious sequence of 3 chars in phrase. [Wikipedia](https://en.wikipedia.org/wiki/Trigram) - return all trigrams for the given phrase - replace spaces with \_ - return an e...
{"functional": "_inputs = [['the quick red'], ['Hi']]\n_outputs = [['the he_ e_q _qu qui uic ick ck_ k_r _re red'], ['']]\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...
146
179
coding
Solve the programming task below in a Python markdown code block. Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B. The territory of Country B is represented by a two-dimensional grid. The first place you occupy is a square on ...
{"inputs": ["2\n3\n5", "2\n3\n6", "2\n3\n4", "2\n6\n4", "2\n6\n5", "2\n6\n6", "2\n9\n6", "2\n0\n6"], "outputs": ["9\n", "10\n", "8\n", "11\n", "12\n", "13\n", "16\n", "7\n"]}
340
99
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two s...
{"functional": "def check(candidate):\n assert candidate(a = \"x\", b = \"y\") == True\n assert candidate(a = \"abdef\", b = \"fecab\") == True\n assert candidate(a = \"ulacfd\", b = \"jizalu\") == True\n\n\ncheck(Solution().checkPalindromeFormation)"}
232
74
coding
Solve the programming task below in a Python markdown code block. You are standing at the point $0$ on a coordinate line. Your goal is to reach the point $n$. In one minute, you can move by $2$ or by $3$ to the left or to the right (i. e., if your current coordinate is $x$, it can become $x-3$, $x-2$, $x+2$ or $x+3$). ...
{"inputs": ["1\n56\n", "1\n6942\n", "1\n10241\n", "1\n22812\n", "1\n99999\n", "1\n507348\n", "1\n123451\n", "4\n1\n3\n4\n12\n"], "outputs": ["19\n", "2314\n", "3414\n", "7604\n", "33333\n", "169116\n", "41151\n", "2\n1\n2\n4\n"]}
301
148
coding
Solve the programming task below in a Python markdown code block. Let us begin with an example: A man has a rather old car being worth $2000. He saw a secondhand car being worth $8000. He wants to keep his old car until he can buy the secondhand one. He thinks he can save $1000 each month but the prices of his old ...
{"functional": "_inputs = [[2000, 8000, 1000, 1.5], [8000, 12000, 500, 1], [18000, 32000, 1500, 1.25], [7500, 32000, 300, 1.55]]\n_outputs = [[[6, 766]], [[8, 597]], [[8, 332]], [[25, 122]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a,...
725
275
coding
Solve the programming task below in a Python markdown code block. You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (x_{i}, y_{i}). We know that no two bombs are at the same point and that no bomb is at point w...
{"inputs": ["2\n1 0\n1 0\n", "2\n1 1\n1 0\n", "2\n2 1\n0 -1\n", "2\n2 1\n1 -1\n", "2\n2 2\n1 -1\n", "2\n2 0\n1 -1\n", "2\n3 0\n1 -1\n", "2\n1 0\n1 -1\n"], "outputs": ["8\n1 1 R\n2\n1 1 L\n3\n1 1 R\n2\n1 1 L\n3\n", "10\n1 1 R\n2\n1 1 L\n3\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n", "10\n1 1 D\n2\n1 1 U\n3\n1 2 R\n1 1 U\n2\n1 ...
745
455
coding
Solve the programming task below in a Python markdown code block. It is an interesting exercise to write a program to print out all permutations of $1, 2, …, n$. However, since there are $6227020800$ permutations of $1, 2, …, 13$, it is unlikely that we would ever run this program on an input of size more than $10$. Ho...
{"inputs": ["3 2\n3 1 2\n2 3 1\n"], "outputs": ["3 2 1\n3 1 2 "]}
483
38
coding
Solve the programming task below in a Python markdown code block. A bracket sequence is a string that is one of the following: - An empty string; - The concatenation of (, A, and ) in this order, for some bracket sequence A ; - The concatenation of A and B in this order, for some non-empty bracket sequences A and B ...
{"inputs": ["2\n)\n()(", "2\n)(\n)(", "2\n((\n)(", "2\n((\n()", "2\n)\n(((", "2\n)(\n))", "2\n)\n())", "2\n(\n((("], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
230
98
coding
Solve the programming task below in a Python markdown code block. In this kata you must take an input string, reverse the order of the words, and reverse the order of the letters within the words. But, as a bonus, every test input will end with a punctuation mark (! ? .) and the output should be returned with the mark...
{"functional": "_inputs = [['an Easy one?'], ['a small lOan OF 1,000,000 $!'], ['<?> &!.\".'], ['b3tTer p4ss thIS 0ne.'], ['']]\n_outputs = [['eno ysaE na?'], ['$ 000,000,1 FO naOl llams a!'], ['\".!& >?<.'], ['en0 SIht ss4p reTt3b.'], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or is...
185
251
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers. All gar...
{"functional": "def check(candidate):\n assert candidate(n = 3, paths = [[1,2],[2,3],[3,1]]) == [1,2,3]\n assert candidate(n = 4, paths = [[1,2],[3,4]]) == [1,2,1,2]\n assert candidate(n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]) == [1,2,3,4]\n\n\ncheck(Solution().gardenNoAdj)"}
209
129
coding
Solve the programming task below in a Python markdown code block. Did you know you can download more RAM? There is a shop with $n$ different pieces of software that increase your RAM. The $i$-th RAM increasing software takes $a_i$ GB of memory to run (temporarily, once the program is done running, you get the RAM back)...
{"inputs": ["1\n1 1000\n1000\n1000\n", "4\n3 10\n20 30 10\n9 100 10\n5 1\n1 1 5 1 1\n1 1 1 1 1\n5 1\n2 2 2 2 2\n100 100 100 100 100\n5 8\n128 64 32 16 8\n128 64 32 16 8\n"], "outputs": ["2000\n", "29\n6\n1\n256\n"]}
608
166
coding
Solve the programming task below in a Python markdown code block. A new TV streaming service was recently started in Chefland called the Chef-TV. A group of N friends in Chefland want to buy Chef-TV subscriptions. We know that 6 people can share one Chef-TV subscription. Also, the cost of one Chef-TV subscription is X...
{"inputs": ["3\n1 100\n12 250\n16 135\n"], "outputs": ["100\n500\n405\n"]}
398
44
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the ...
{"inputs": ["1\n4\ngrace graceful disgraceful gracefully", "1\n4\necarg graceful disgraceful gracefully", "1\n4\necarg grbceful lufecargsid gracefully", "1\n4\ngeacr graceful disgraceful gracefully", "1\n4\necarg grbceful lufecargsid gradefulmy", "1\n4\nfcgra grbcdful disgraceeul gracefvlmy", "1\n4\ngrace gracefuk disg...
262
160
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. It's a lockdown. You’re bored in your house and are playing golf in the hallway. The hallway has $N + 2$ tiles numbered from $0$ to $N+1$ from left to right...
{"inputs": ["3\n5 4 2\n5 3 2\n5 5 2"], "outputs": ["YES\nNO\nNO"]}
646
34
coding
Solve the programming task below in a Python markdown code block. There are $n$ pairs of hard disk drives (HDDs) in a cluster. Each HDD is located at an integer coordinate on an infinite straight line, and each pair consists of one primary HDD and one backup HDD. Next, you want to place $\boldsymbol{\mbox{k}}$ compute...
{"inputs": ["5 2\n6 7\n-1 1\n0 1\n5 2\n7 3\n"], "outputs": ["13\n"]}
721
38
coding
Solve the programming task below in a Python markdown code block. The ugliness of a sequence of size N is defined as the number of pairs of neighboring elements which are not equal to each other. Formally, the ugliness of a sequence increase by 1 if for a value of i, 2 ≀ i ≀ N, the following condition holds true: A_{i}...
{"inputs": ["2\n8 2\n1 2 1 2 2 2 1 2\n8 3\n1 2 2 1 1 1 2 3"], "outputs": ["0 0\n1 1 3\n"]}
700
61
coding
Solve the programming task below in a Python markdown code block. DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value w_{c}. For each special string s = s_1s_2... s_{|}s| (|s| is the length of the string) he represents its value with a function f(s)...
{"inputs": ["a\n0\n5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "a\n0\n5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "a\n0\n5 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "a\n1\n5 1 1 1 1 1 1 0 2 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1\n", "a\n0\n5 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1...
370
503
coding
Solve the programming task below in a Python markdown code block. There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise. Constra...
{"inputs": ["8 2 4", "3 3 1", "3 8 7", "1 2 4", "4 3 1", "6 8 7", "1 0 4", "4 2 1"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n", "No\n", "No\n"]}
219
94
coding
Solve the programming task below in a Python markdown code block. We just discovered a new data structure in our research group: a suffix three! It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in. It's super ...
{"inputs": ["8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_okama_kenpo\nang_halaman_doon_ay_sarisari_singkamasu\nsi_roy_mustang_ay_namamasu\n", "8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_o...
541
995
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game. The board is a 3 x 3 array that consists of char...
{"functional": "def check(candidate):\n assert candidate(board = [\"O \",\" \",\" \"]) == False\n assert candidate(board = [\"XOX\",\" X \",\" \"]) == False\n assert candidate(board = [\"XOX\",\"O O\",\"XOX\"]) == True\n\n\ncheck(Solution().validTicTacToe)"}
233
84
coding
Solve the programming task below in a Python markdown code block. Problem Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules. 1. First of all, select one of your favorite strings from the list and exclude that string from the list. 2. Next, s...
{"inputs": ["5\nuoy\nate\nmy\nhum\ntoast", "5\nuoy\nate\nmy\nhum\ntoasu", "5\nuoy\natf\nmy\nhum\ntoasu", "5\nuyp\natf\nmy\nhum\ntoasu", "5\npyu\nauf\nmy\nhum\ntoasu", "5\npyu\nauf\nmy\nmuh\ntoasu", "5\npyu\nfua\nmy\nmuh\ntoasu", "5\npyu\nfua\nmy\nmui\ntoasu"], "outputs": ["e\nt\ny\n", "e\ny\n", "f\ny\n", "f\np\ny\n", "...
377
206
coding
Solve the programming task below in a Python markdown code block. ## Nova polynomial add This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140...
{"functional": "_inputs = [[[1], [1]], [[1, 2], [1]], [[1, 2, 3, 4], [4, 3, 2, 1]], [[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]]\n_outputs = [[[2]], [[2, 2]], [[5, 5, 5, 5]], [[]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or is...
297
290
coding
Solve the programming task below in a Python markdown code block. There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not pri...
{"inputs": ["2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0", "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.0 5.0 7.0 9.0", "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.541356008746918 5.0 7.0 9.0", "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680...
364
971
coding
Solve the programming task below in a Python markdown code block. Chef's professor is planning to give his class a group assignment. There are 2N students in the class, with distinct roll numbers ranging from 1 to 2N. Chef's roll number is X. The professor decided to create N groups of 2 students each. The groups were...
{"inputs": ["3\n2 2\n3 1\n3 4\n"], "outputs": ["3\n6\n3"]}
456
29
coding
Solve the programming task below in a Python markdown code block. Jzzhu has invented a kind of sequences, they meet the following property:$f_{1} = x ; f_{2} = y ; \forall i(i \geq 2), f_{i} = f_{i - 1} + f_{i + 1}$ You are given x and y, please calculate f_{n} modulo 1000000007 (10^9 + 7). -----Input----- The firs...
{"inputs": ["2 3\n3\n", "2 3\n6\n", "1 3\n6\n", "3 4\n6\n", "1 2\n6\n", "5 9\n6\n", "1 2\n6\n", "2 3\n6\n"], "outputs": ["1\n", "1000000006\n", "1000000005\n", "1000000006\n", "1000000006\n", "1000000003\n", "1000000006\n", "1000000006\n"]}
300
165
coding
Solve the programming task below in a Python markdown code block. Implement a function that normalizes out of range sequence indexes (converts them to 'in range' indexes) by making them repeatedly 'loop' around the array. The function should then return the value at that index. Indexes that are not out of range should ...
{"functional": "_inputs = [[[], 10]]\n_outputs = [[None]]\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(_d...
292
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a binary string s. In one second, all occurrences of "01" are simultaneously replaced with "10". This process repeats until no occurrences of "01" exist. Return the number of seconds needed to complete t...
{"functional": "def check(candidate):\n assert candidate(s = \"0110101\") == 4\n assert candidate(s = \"11100\") == 0\n\n\ncheck(Solution().secondsToRemoveOccurrences)"}
99
54
coding
Solve the programming task below in a Python markdown code block. Chef has an array of N natural numbers most of them are repeated. Cheffina challenges chef to find all numbers(in ascending order) whose frequency is strictly more than K. -----Input:----- - First-line will contain $T$, the number of test cases. Then th...
{"inputs": ["1\n5 1\n5 2 1 2 5"], "outputs": ["2 5"]}
196
28
coding
Solve the programming task below in a Python markdown code block. # Task Given a string `str`, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome. # Example For `str = "abcdc"`, the output should be `"abcdcba"`. # Input/Output - `[in...
{"functional": "_inputs = [['abcdc'], ['ababab']]\n_outputs = [['abcdcba'], ['abababa']]\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): retu...
134
167
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7. Β  Please complete the following python c...
{"functional": "def check(candidate):\n assert candidate(arr = [3,1,2,4]) == 17\n assert candidate(arr = [11,81,94,43,3]) == 444\n\n\ncheck(Solution().sumSubarrayMins)"}
98
67
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. A subarray is a contiguous subsequence of the array. Β  Please complete the following python code precisely: ```pytho...
{"functional": "def check(candidate):\n assert candidate(arr = [1,4,2,5,3]) == 58\n assert candidate(arr = [1,2]) == 3\n assert candidate(arr = [10,11,12]) == 66\n\n\ncheck(Solution().sumOddLengthSubarrays)"}
84
77
coding
Solve the programming task below in a Python markdown code block. Chef recently took a course in linear algebra and learned about linear combinations of vectors. Therefore, in order to test his intelligence, Raj gave him a "fuzzy" problem to solve. A sequence of integers $B_1, B_2, \ldots, B_M$ generates an integer $K$...
{"inputs": ["2\n2 4\n3\n1\n2\n8"], "outputs": ["0\n2\n3"]}
614
28
coding
Solve the programming task below in a Python markdown code block. Vova is playing a computer game. There are in total $n$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $k$. During each turn Vova can choose what to...
{"inputs": ["1\n1000000000 499999999 3 2\n", "1\n1000000000 999999999 2 1\n", "1\n1000000000 499999999 3 2\n", "1\n1000000000 999999999 2 1\n", "1\n1001000000 499999999 3 2\n", "1\n1000010000 999999999 2 1\n", "1\n1001000000 316833107 3 2\n", "1\n1000000000 499999999 3 1\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "10...
689
296
coding
Solve the programming task below in a Python markdown code block. Bob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions: There will be 4 different kinds of queries:- - Alice gives an integer $i$ and Bob has to repor...
{"inputs": ["1\n2 2\n2\n1\n1\n1"], "outputs": ["ON"]}
551
24
coding
Solve the programming task below in a Python markdown code block. Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest AB...
{"inputs": ["15", "10", "426", "101", "638", "268", "457", "000"], "outputs": ["111\n", "111\n", "444\n", "111\n", "666\n", "333\n", "555\n", "0\n"]}
191
90
coding
Solve the programming task below in a Python markdown code block. You are given a set of strings S. Each string consists of lowercase Latin letters. For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string an...
{"inputs": ["1\n0 z\n1\n1\n", "8\n0 a\n1 b\n2 a\n2 b\n4 a\n4 b\n5 d\n6 d\n5\n2 3 4 7 8\n", "8\n0 a\n1 b\n2 a\n2 b\n4 a\n4 b\n2 c\n6 d\n5\n2 3 4 7 8\n", "8\n0 a\n1 b\n2 a\n2 b\n4 a\n4 b\n5 d\n6 e\n5\n2 3 4 7 8\n", "8\n0 a\n1 b\n2 a\n2 b\n4 a\n4 b\n5 c\n6 d\n5\n2 3 4 7 8\n", "10\n0 i\n1 q\n2 g\n0 k\n1 e\n5 r\n4 m\n5 h\n3...
666
407
coding
Solve the programming task below in a Python markdown code block. You are given the sequence of Nucleotides of one strand of DNA through a string S of length N. S contains the character A, T, C, and G only. Chef knows that: A is complementary to T. T is complementary to A. C is complementary to G. G is complementary t...
{"inputs": ["4\n4\nATCG\n4\nGTCC\n5\nAAAAA\n3\nTAC\n"], "outputs": ["TAGC\nCAGG\nTTTTT\nATG\n"]}
440
46
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. In Olympics, the countries are ranked by the total number of medals won. You are given six integers G_{1}, S_{1}, B_{1}, and G_{2}, S_{2}, B_{2}, the number o...
{"inputs": ["3\n10 20 30 0 29 30\n0 0 0 0 0 1\n1 1 1 0 0 0\n"], "outputs": ["1\n2\n1"]}
484
58
coding
Solve the programming task below in a Python markdown code block. You are given N binary strings S_{1}, S_{2}, \dots, S_{N}, each of length M. You want to concatenate all the N strings in some order to form a single large string of length N \cdot M. Find the minimum possible number of inversions the resulting string ca...
{"inputs": ["4\n2 1\n0\n1\n3 2\n10\n00\n01\n2 4\n0010\n1011\n3 4\n1011\n1101\n0101\n"], "outputs": ["0\n2\n3\n11"]}
694
74
coding
Solve the programming task below in a Python markdown code block. You are given an array A of length N. You have to partition the elements of the array into some [subsequences] such that: Each element A_{i} (1 ≀ i ≀ N) belongs to exactly one subsequence. The [mean] of the mean of subsequences is maximised. Formally, ...
{"inputs": ["3\n2\n10 20\n3\n1 2 3\n5\n50 50 50 50 50\n"], "outputs": ["15\n2.25\n50\n"]}
656
56
coding
Solve the programming task below in a Python markdown code block. # Task John was in math class and got bored, so he decided to fold some origami from a rectangular `a Γ— b` sheet of paper (`a > b`). His first step is to make a square piece of paper from the initial rectangular piece of paper by folding the sheet along ...
{"functional": "_inputs = [[2, 1], [10, 7], [3, 1], [4, 1], [3, 2], [4, 2], [1000, 700], [1000, 999]]\n_outputs = [[2], [6], [3], [4], [3], [2], [6], [1000]]\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 ...
397
234
coding
Solve the programming task below in a Python markdown code block. A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his...
{"inputs": ["1\nq\n", "1\na\n", "1\na\n", "1\nq\n", "1\nb\n", "1\np\n", "1\no\n", "1\nn\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
375
86
coding
Solve the programming task below in a Python markdown code block. You are parking at a parking lot. You can choose from the following two fee plans: - Plan 1: The fee will be AΓ—T yen (the currency of Japan) when you park for T hours. - Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee wh...
{"inputs": ["7 17 120\n", "5 20 100\n", "6 18 100\n"], "outputs": ["119\n", "100\n", "100\n"]}
234
57
coding
Solve the programming task below in a Python markdown code block. Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can sele...
{"inputs": ["2\n0 0\n", "2\n1 0\n", "2\n0 1\n", "2\n0 2\n", "2\n2 0\n", "2\n2 0\n", "2\n0 2\n", "2\n0 0\n"], "outputs": ["2\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "2\n"]}
499
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1. Return the maximum product of nums after at most k operations. Since...
{"functional": "def check(candidate):\n assert candidate(nums = [0,4], k = 5) == 20\n assert candidate(nums = [6,3,3,2], k = 2) == 216\n\n\ncheck(Solution().maximumProduct)"}
129
64
coding
Solve the programming task below in a Python markdown code block. A conglomerate consists of $n$ companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and continu...
{"inputs": ["1\n4 2 2 3 2\n", "1\n4 2 2 3 2\n", "1\n4 2 2 3 0\n", "1\n4 3 2 3 0\n", "1\n4 3 2 4 0\n", "1\n4 1 2 4 0\n", "1\n4 2 2 2 2\n", "1\n1 2 2 3 0\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
508
149
coding
Solve the programming task below in a Python markdown code block. Luntik came out for a morning stroll and found an array $a$ of length $n$. He calculated the sum $s$ of the elements of the array ($s= \sum_{i=1}^{n} a_i$). Luntik calls a subsequence of the array $a$ nearly full if the sum of the numbers in that subsequ...
{"inputs": ["5\n5\n1 2 3 4 5\n2\n1000 1000\n2\n1 0\n5\n3 0 2 1 1\n5\n2 1 0 3 0\n", "5\n5\n1 2 3 4 5\n2\n1000 1000\n2\n1 0\n5\n3 0 2 1 0\n5\n2 1 0 3 0\n", "5\n5\n1 4 3 4 5\n2\n1000 1000\n2\n1 0\n5\n3 0 4 1 0\n5\n0 1 0 3 0\n", "5\n5\n1 2 3 4 1\n2\n1000 1000\n2\n1 0\n5\n3 0 2 1 1\n5\n2 1 0 3 0\n", "5\n5\n1 2 3 4 5\n2\n100...
532
566
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums consisting of positive integers. Starting with score = 0, apply the following algorithm: Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,3,4,5,2]) == 7\n assert candidate(nums = [2,3,5,1,3,2]) == 5\n\n\ncheck(Solution().findScore)"}
140
63
coding
Solve the programming task below in a Python markdown code block. Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendsh...
{"inputs": ["3 3\n4 5\n0 17\n9 11\n", "1 1000000000\n15 1\n", "1 1000000000\n19 8\n", "1 1000000000\n15 12\n", "3 3\n4 15\n0 17\n9 11\n", "3 3\n4 15\n0 17\n9 11\n", "1 1000000000\n15 12\n", "3 3\n4 15\n0 17\n6 11\n"], "outputs": ["17\n", "1\n", "8\n", "12\n", "17\n", "17", "12", "26\n"]}
432
207
coding
Solve the programming task below in a Python markdown code block. Chef has a garden with $N$ plants arranged in a line in decreasing order of height. Initially the height of the plants are $A_1, A_2, ..., A_N$. The plants are growing, after each hour the height of the $i$-th plant increases by $i$ millimeters. Find the...
{"inputs": ["1\n3\n8 4 2"], "outputs": ["2"]}
373
20
coding
Solve the programming task below in a Python markdown code block. A group of $n$ friends living in an $m$-dimensional hyperspace want to meet up at some central location. The hyperspace is in the form of an $m$-dimensional grid, and each person can only move along grid lines. For example, to go from $(0,0)\rightarrow(1...
{"inputs": ["3 2\n1 1\n2 2\n3 3\n"], "outputs": ["2 2\n"]}
630
30
coding
Solve the programming task below in a Python markdown code block. Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i. Silver Fox can use bombs to attack the monsters. ...
{"inputs": ["3 3 2\n1 4\n5 4\n9 2", "2 3 1\n1 1\n5 6\n9 2", "2 0 1\n1 1\n5 6\n9 2", "2 0 2\n1 1\n5 6\n9 2", "1 0 2\n1 1\n5 6\n9 2", "0 2 1\n1 1\n5 6\n4 3", "3 3 2\n1 2\n1 4\n9 0", "3 3 2\n1 4\n5 5\n9 2"], "outputs": ["3\n", "6\n", "7\n", "4\n", "1\n", "0\n", "2\n", "3\n"]}
394
190
coding
Solve the programming task below in a Python markdown code block. Jack really likes his number five: the trick here is that you have to multiply each number by 5 raised to the number of digits of each numbers, so, for example: ```python multiply(3)==15 multiply(10)==250 multiply(200)==25000 multiply(0)==0 multiply(-3)=...
{"functional": "_inputs = [[10], [5], [200], [0], [-2]]\n_outputs = [[250], [25], [25000], [0], [-10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) !...
116
189
coding
Solve the programming task below in a Python markdown code block. Problem Den, the phone number of Ukunikia Co., Ltd., enters a very long phone number into the phone every day. One day, too tired, Den came up with a surprising idea. "Isn't it even a little easier if you rearrange the arrangement of the buttons on the ...
{"inputs": ["10\n1598114589", "10\n2555486547", "10\n2722382398", "10\n2713182985", "10\n4333783596", "10\n1859787539", "10\n1888971773", "10\n6843843631"], "outputs": ["142\n853\n967\n", "123\n659\n847\n", "139\n428\n576\n", "317\n482\n659\n", "124\n783\n695\n", "124\n853\n796\n", "173\n892\n456\n", "125\n347\n689\n"]...
478
238
coding
Solve the programming task below in a Python markdown code block. Gru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him away from the limelight, he has built a transmogrifier β€” a machine which mutates mi...
{"inputs": ["1\n5 2\n0 4 1 3 1", "1\n5 0\n0 4 0 7 1", "1\n5 0\n1 0 0 0 0", "1\n5 3\n2 4 1 3 1", "1\n5 3\n2 4 0 3 1", "1\n5 3\n0 4 0 3 1", "1\n5 3\n0 4 1 3 1", "1\n5 2\n0 4 1 5 1"], "outputs": ["0\n", "3\n", "4\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
396
174
coding
Solve the programming task below in a Python markdown code block. Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For...
{"inputs": ["1\na\n", "1\nf\n", "1\na\n", "1\nf\n", "1\nb\n", "1\ng\n", "1\nc\n", "1\nh\n"], "outputs": ["1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n", "1\n\n"]}
300
94
coding
Solve the programming task below in a Python markdown code block. You are given a length of string and two thumbtacks. On thumbtack goes into the focus point *Fβ‚€* with coordinates *xβ‚€* and *yβ‚€*, and the other does into point *F₁* with points *x₁* and *y₁*. The string is then tied at the ends to the thumbtacks and has l...
{"functional": "_inputs = [[{'x': 0, 'y': 0}, {'x': 0, 'y': 0}, 2, {'x': 0, 'y': 0}], [{'x': 0, 'y': 0}, {'x': 0, 'y': 0}, 2, {'x': 1, 'y': 1}]]\n_outputs = [[True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol,...
267
236
coding
Solve the programming task below in a Python markdown code block. You have a given integer $n$. Find the number of ways to fill all $3 \times n$ tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap. $\square$ This picture describes when $n = 4$. The left ...
{"inputs": ["4\n", "1\n", "2\n", "8\n", "5\n", "7\n", "3\n", "6\n"], "outputs": ["4", "0", "2", "16", "0", "0", "0", "8"]}
188
63
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On day 1, one person discovers a secret. You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are a...
{"functional": "def check(candidate):\n assert candidate(n = 6, delay = 2, forget = 4) == 5\n assert candidate(n = 4, delay = 1, forget = 3) == 6\n\n\ncheck(Solution().peopleAwareOfSecret)"}
183
65
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor. The doctor advised Alice to only eat n / 2 of the candies she has (n is always ...
{"functional": "def check(candidate):\n assert candidate(candyType = [1,1,2,2,3,3]) == 3\n assert candidate(candyType = [1,1,2,3]) == 2\n assert candidate(candyType = [6,6,6,6]) == 1\n\n\ncheck(Solution().distributeCandies)"}
165
86
coding
Solve the programming task below in a Python markdown code block. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it int...
{"inputs": ["1 4\n1\nu\nu\nu\nu\n", "1 4\n2\nu\nu\nu\nu\n", "3 1\n6 26 22\naga\n", "3 1\n6 26 42\naga\n", "3 1\n6 26 39\naga\n", "3 1\n14 26 22\naag\n", "3 1\n25 26 22\naag\n", "3 1\n25 26 22\naga\n"], "outputs": ["4 4\n", "8 8\n", "6 26\n", "6 42\n", "6 39\n", "14 26\n", "22 26\n", "22 26\n"]}
468
196
coding
Solve the programming task below in a Python markdown code block. B-Mansion and courier Problem Statement Taro lives alone in a mansion. Taro, who loves studying, intends to study in his study in the house today. Taro can't concentrate outside the study, so he always studies in the study. However, on this day, $ N $...
{"inputs": ["1 1 5\n6", "1 2 9\n9", "1 1 5\n5", "1 1 5\n1", "1 1 2\n3", "1 2 4\n3", "1 1 0\n1", "1 1 5\n3"], "outputs": ["5\n", "7\n", "4\n", "3\n", "2\n", "1\n", "0\n", "3"]}
535
109
coding
Solve the programming task below in a Python markdown code block. Anna Hazare is a well known social activist in India. On 5th April, 2011 he started "Lokpal Bill movement". Chef is very excited about this movement. He is thinking of contributing to it. He gathers his cook-herd and starts thinking about how our commu...
{"inputs": ["1\n6\n3\n5\n1 4\n3 5 6\n2 4 6\n4 5"], "outputs": ["4 1.166667"]}
715
47
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string array features where features[i] is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which features ...
{"functional": "def check(candidate):\n assert candidate(features = [\"cooler\",\"lock\",\"touch\"], responses = [\"i like cooler cooler\",\"lock touch cool\",\"locker like touch\"]) == [\"touch\",\"cooler\",\"lock\"]\n assert candidate(features = [\"a\",\"aa\",\"b\",\"c\"], responses = [\"a\",\"a aa\",\"a a a a ...
198
112
coding
Solve the programming task below in a Python markdown code block. You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it...
{"inputs": ["4 1 5 1\n-\n", "4 1 6 1\n-\n", "4 2 6 1\n-\n", "4 1 5 1\n-\n", "1 1 4 2\n-+\n", "1 1 4 2\n-+\n", "2 2 3 3\n+-+\n", "2 2 3 3\n+-+\n"], "outputs": ["999999228\n", "999998454\n", "999998073\n", "999999228\n", "3\n", "3\n", "7\n", "7\n"]}
584
170
coding
Solve the programming task below in a Python markdown code block. Kawashiro Nitori is a girl who loves competitive programming. One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem. Given a string $s$ and a parameter $k$, you need to check if there exist $k+1$ non...
{"inputs": ["7\n5 1\nqwqwq\n2 1\nc`\n3 1\nioi\n4 2\niqcc\n22 0\ndokidokiliteratureclub\n9 8\nimteamshanghaialice\n6 3\naaaaaa\n", "7\n5 1\nqwqwq\n2 1\nab\n3 1\nioi\n4 2\nicpc\n22 0\ndokidokiliteratureclub\n19 8\nimteamshanghaialice\n6 3\naaaaaa\n", "7\n5 1\nqwqwq\n2 1\nab\n3 1\nioi\n4 2\nipcc\n22 0\ndokidokiliteraturec...
553
672
coding
Solve the programming task below in a Python markdown code block. In this kata, you've to count lowercase letters in a given string and return the letter count in a hash with 'letter' as key and count as 'value'. The key must be 'symbol' instead of string in Ruby and 'char' instead of string in Crystal. Example: ```...
{"functional": "_inputs = [['codewars'], ['activity'], ['arithmetics'], ['traveller'], ['daydreamer']]\n_outputs = [[{'a': 1, 'c': 1, 'd': 1, 'e': 1, 'o': 1, 'r': 1, 's': 1, 'w': 1}], [{'a': 1, 'c': 1, 'i': 2, 't': 2, 'v': 1, 'y': 1}], [{'a': 1, 'c': 1, 'e': 1, 'h': 1, 'i': 2, 'm': 1, 'r': 1, 's': 1, 't': 2}], [{'a': 1...
159
382
coding
Solve the programming task below in a Python markdown code block. Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers $n$ and $k$, count the number of arrays of length $n$ such that: all its elements are integers between $0$ and $2^k-1$ (inclusive); the bit...
{"inputs": ["1\n2 3\n", "1\n2 3\n", "1\n2 2\n", "1\n0 2\n", "1\n1 3\n", "1\n2 4\n", "1\n5 20\n", "1\n9 20\n"], "outputs": ["8\n", "8\n", "4\n", "0\n", "1\n", "16\n", "430973056\n", "953271190\n"]}
321
121
coding
Solve the programming task below in a Python markdown code block. A chess tournament will be held soon, where $n$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players. ...
{"inputs": ["3\n3\n111\n1\n1\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n", "3\n3\n111\n2\n12\n4\n2122\n", "3\n3\n111\n2\n11\n4\n2122\n", "3\n3\n111\n2\n22\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n"], "outputs": ["YES\nX==\n=X=\n==X\nYES\nX\nYES\nX=+-\n=X==\n-=X+\n+=-X\n", "YES\nX==\n=X=\n==...
500
411
coding
Solve the programming task below in a Python markdown code block. You are the judge at a competitive eating competition and you need to choose a winner! There are three foods at the competition and each type of food is worth a different amount of points. Points are as follows: - Chickenwings: 5 points - Hamburgers...
{"functional": "_inputs = [[[{'name': 'Billy The Beast', 'chickenwings': 17, 'hamburgers': 7, 'hotdogs': 8}, {'name': 'Habanero Hillary', 'chickenwings': 5, 'hamburgers': 17, 'hotdogs': 11}, {'name': 'Joey Jaws', 'chickenwings': 8, 'hamburgers': 8, 'hotdogs': 15}, {'name': 'Big Bob', 'chickenwings': 20, 'hamburgers': 4...
265
604
coding
Solve the programming task below in a Python markdown code block. β€” Hey folks, how do you like this problem? β€” That'll do it. BThero is a powerful magician. He has got $n$ piles of candies, the $i$-th pile initially contains $a_i$ candies. BThero can cast a copy-paste spell as follows: He chooses two piles $(i, j)...
{"inputs": ["3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\n", "3\n2 2\n2 1\n3 5\n1 2 3\n3 7\n3 2 2\n", "3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n4 2 2\n", "3\n2 2\n2 1\n3 5\n1 3 3\n3 7\n3 2 2\n", "3\n2 4\n1 1\n3 5\n1 2 3\n3 7\n4 2 2\n", "3\n2 2\n2 1\n3 5\n1 3 3\n3 7\n4 2 2\n", "3\n2 2\n2 1\n3 5\n1 4 3\n3 7\n4 2 2\n", "3\n2 2\n1 1\n3 5\n1 ...
478
326
coding
Solve the programming task below in a Python markdown code block. There is a train going from Station A to Station B that costs X yen (the currency of Japan). Also, there is a bus going from Station B to Station C that costs Y yen. Joisino got a special ticket. With this ticket, she can take the bus for half the fare i...
{"inputs": ["5 0", "1 2", "1 2\n", "3 54", "3 34", "5 34", "5 -1", "51 1"], "outputs": ["5\n", "2\n", "2\n", "30\n", "20\n", "22\n", "4\n", "51\n"]}
256
87
coding
Solve the programming task below in a Python markdown code block. Mr. X has come up with a new string compression algorithm. Consider a string of length N which contains up to K distinct characters. The compression algorithm works as follows: Replace each maximal contiguous substring containing only one distinct charac...
{"inputs": ["2\n3 1\n3 2\n"], "outputs": ["2.0\n4.0"]}
615
27
coding
Solve the programming task below in a Python markdown code block. A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given price lists for keyboards and USB drives and a budget, find the cost to buy them. If it is not possible to buy both items, ret...
{"inputs": ["5 1 1\n4\n5\n", "10 2 3\n3 1\n5 2 8\n"], "outputs": ["-1\n", "9\n"]}
514
46
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, check whether it is a mirror of itself (i.e., symmetric around its center). Β  Please complete the following python code precisely: ```python # Definition for a binary tree node. # clas...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,2,3,4,4,3])) == True\n assert candidate(root = tree_node([1,2,2,None,3,None,3])) == False\n\n\ncheck(Solution().isSymmetric)"}
126
68
coding
Solve the programming task below in a Python markdown code block. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in t...
{"inputs": ["1 1 1\n1\n", "1 1 1\n0\n", "1 1 1\n0\n", "1 1 1\n1\n", "2 2 1\n0 1\n1 0\n", "2 2 1\n0 1\n1 0\n", "2 2 2\n0 1\n1 0\n", "2 2 2\n0 1\n0 0\n"], "outputs": ["1 0\n", "0 0\n", "0 0", "1 0", "2 0\n", "2 0", "2 0\n", "1 0\n"]}
445
155
coding
Solve the programming task below in a Python markdown code block. Write a program to obtain a number $N$ and increment its value by 1 if the number is divisible by 4 $otherwise$ decrement its value by 1. -----Input:----- - First line will contain a number $N$. -----Output:----- Output a single line, the new value of ...
{"inputs": ["5"], "outputs": ["4"]}
137
12
coding
Solve the programming task below in a Python markdown code block. # Task **_Given_** a **_Divisor and a Bound_** , *Find the largest integer N* , Such That , # Conditions : * **_N_** is *divisible by divisor* * **_N_** is *less than or equal to bound* * **_N_** is *greater than 0*. ___ # Notes * The **_par...
{"functional": "_inputs = [[2, 7], [3, 10], [7, 17], [10, 50], [37, 200], [7, 100]]\n_outputs = [[6], [9], [14], [50], [185], [98]]\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, ...
574
216
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 two integers x and y. You can perform two types of operations any number of times. Remove substring "ab" and gain x points. For example, when removing "ab" from "cabxbae" it becomes "c...
{"functional": "def check(candidate):\n assert candidate(s = \"cdbcbbaaabab\", x = 4, y = 5) == 19\n assert candidate(s = \"aabbaaxybbaabb\", x = 5, y = 4) == 20\n\n\ncheck(Solution().maximumGain)"}
159
74
coding
Solve the programming task below in a Python markdown code block. Chef has started developing interest in playing chess, and was learning how the [Queen] moves. Chef has an empty N \times N chessboard. He places a Queen at (X, Y) and wonders - What are the number of cells that are under attack by the Queen? Notes: ...
{"inputs": ["5\n1 1 1\n3 2 2\n3 2 1\n2 2 2\n150 62 41\n"], "outputs": ["0\n8\n6\n3\n527\n"]}
529
58
coding
Solve the programming task below in a Python markdown code block. Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L'Β β€” instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a...
{"inputs": ["1\nR\n", "1\nR\n", "2\nDU\n", "2\nDU\n", "2\nUD\n", "4\nDLUU\n", "4\nRRDR\n", "4\nRRDR\n"], "outputs": ["0\n", "0", "1\n", "1", "1\n", "0\n", "0\n", "0"]}
293
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1]. The safe has a peculiar way of checking the password. When you enter in a sequence, it c...
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 2) == \"10\"\n assert candidate(n = 2, k = 2) == \"01100\"\n\n\ncheck(Solution().crackSafe)"}
289
61
coding
Solve the programming task below in a Python markdown code block. Integer sequence $\boldsymbol{a}$ having length $2n+2$ is defined as follows: $a_{0}=0$ $a_{1}=C$ $a_{i+2}=(a_{i+1}+a_i)\ \text{\% M}$, where $0\leq i<2n$ Write a function generator, $gen$, to generate the remaining values for $a_2$ through $a_{2n+1}$....
{"inputs": ["4 5 3\n"], "outputs": ["2\n"]}
720
18
coding
Solve the programming task below in a Python markdown code block. # Task Mobius function - an important function in number theory. For each given n, it only has 3 values: ``` 0 -- if n divisible by square of a prime. Such as: 4, 8, 9 1 -- if n not divisible by any square of a prime and have even number of p...
{"functional": "_inputs = [[10], [9], [8], [100000000001], [7], [5]]\n_outputs = [[1], [0], [0], [0], [-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 ...
191
197