task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the sq...
{"inputs": ["3\n7\n15", "3\n7\n45", "3\n7\n76", "3\n7\n54", "3\n0\n76", "3\n2\n43", "3\n2\n59", "3\n1\n34"], "outputs": ["3\n", "7\n", "11\n", "8\n", "26\n", "15\n", "20\n", "12\n"]}
266
107
coding
Solve the programming task below in a Python markdown code block. Bohan loves milk tea so much and he drinks one cup of milk tea every day. The local shop sells milk tea in two sizes: a Medium cup for $3 and a Large cup for $4. For every cup of milk tea purchased Bohan receives a promotional stamp. Bohan may redeem 6 s...
{"inputs": ["3\nMLM\nMMLLMMLL\nMMMMMMML"], "outputs": ["10\n24\n22"]}
355
32
coding
Solve the programming task below in a Python markdown code block. Chef is here with another matrix A having N rows and M columns, such that A_{(i,j)} = (i-1)\cdot M+j. Chef decided to make this matrix interesting. He performed K operations on the matrix. In each operation, he will choose either a row or column and ...
{"inputs": ["2\n2 2 2\n1 2 0\n0 1 2\n1 3 1\n1 2 6"], "outputs": ["5\n16\n"]}
712
46
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 You'll be given 2 numbers as arguments: ```(num,s)```. Write a function whi...
{"functional": "_inputs = [[6, 4], [75, 1], [19, 3], [101, 2], ['ACCDDCCA', 3], [773, '1551'], [-4505, 15]]\n_outputs = [[[11, 22, 33, 44]], [[77]], [[22, 33, 44]], [[101, 111]], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float)...
370
260
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le ...
{"inputs": ["4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 4 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 6 5 8 9 8 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 ...
755
878
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty. Alice starts, then they alternate m...
{"inputs": ["2\nforces\nabba\n"], "outputs": ["Alice\nDraw\n"]}
597
21
coding
Solve the programming task below in a Python markdown code block. Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations: * add(i, x): add x to ai. * getSum(s, t): print the sum of as, as+1,...,at. Note that the initial values of ai (i = 1, 2, . . . , n) are 0. Constrai...
{"inputs": ["4 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "4 5\n0 1 0\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 4\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 4 4\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 2\n0 3 9\n1 1 2\n0 2 2", "4 5\n0 1 0\n0 2 2\n0 1 5\n1 1 0\n1 2 3", "4 5\n0 1 1\n0...
322
332
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k. The store sells baskets of k distinct candies. The tastiness of a candy basket is the small...
{"functional": "def check(candidate):\n assert candidate(price = [13,5,1,8,21,2], k = 3) == 8\n assert candidate(price = [1,3,1], k = 2) == 2\n assert candidate(price = [7,7,7,7], k = 2) == 0\n\n\ncheck(Solution().maximumTastiness)"}
122
94
coding
Solve the programming task below in a Python markdown code block. Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret! A password is an array $a$ of $n$ positive integers. You apply the following operation to the array: pick any t...
{"inputs": ["1\n1\n1\n", "1\n1\n1\n", "1\n3\n3 4 7\n", "1\n3\n3 1 2\n", "1\n3\n1 2 3\n", "1\n3\n1 3 4\n", "1\n3\n3 2 1\n", "1\n3\n4 3 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
581
126
coding
Solve the programming task below in a Python markdown code block. Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29. Input The input is a sequence of datasets. The end of the i...
{"inputs": ["2 2\n2 8\n0 0", "4 1\n2 7\n0 0", "6 2\n7 8\n0 0", "3 3\n2 1\n0 0", "5 1\n2 7\n0 0", "4 4\n6 4\n0 0", "4 1\n3 8\n0 0", "5 1\n1 7\n0 0"], "outputs": ["Monday\nSunday\n", "Thursday\nSaturday\n", "Wednesday\nThursday\n", "Wednesday\nSunday\n", "Saturday\nSaturday\n", "Sunday\nFriday\n", "Thursday\nMonday\n", "...
212
158
coding
Solve the programming task below in a Python markdown code block. Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied...
{"inputs": ["3\n0 1\n0 10\n0 100\n", "4\n2 1\n0 0\n1 5\n1 3\n", "4\n2 0\n0 0\n1 5\n2 3\n", "4\n2 1\n0 0\n1 5\n2 3\n", "4\n2 1\n0 0\n1 5\n4 3\n", "4\n2 1\n1 0\n1 5\n4 3\n", "4\n2 1\n1 0\n1 5\n2 3\n", "4\n2 0\n1 0\n1 5\n2 3\n"], "outputs": ["111", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "0\n"]}
293
198
coding
Solve the programming task below in a Python markdown code block. Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences. -----Input----- Same as the easy version, but the limits have changed: 1...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "4 1\n1 2 2 1\n", "4 2\n1 2 3 1\n", "4 2\n1 2 3 2\n", "4 2\n1 2 3 2\n", "4 3\n1 1 1 1\n", "4 2\n2 2 3 1\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "3\n", "1\n", "3\n"]}
146
138
coding
Solve the programming task below in a Python markdown code block. Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such th...
{"inputs": ["2 1 1\n1 2 1\n", "2 1 1\n1 2 1\n", "2 1 2\n1 2 1\n", "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n", "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n", "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n"], "outputs": ["2\n1 2 \n", "2\n1 2 ", "2\n1 2\n", "3\n1 2 4 \n", "3\n1 2...
665
276
coding
Solve the programming task below in a Python markdown code block. A company has N members, who are assigned ID numbers 1, ..., N. Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number. When a person X is the immediate boss of a person Y, the person Y is said to be an immedi...
{"inputs": ["5\n1 1 2 3", "5\n1 2 2 3", "5\n1 2 2 2", "5\n1 1 2 5", "5\n1 2 4 3", "5\n1 2 4 2", "5\n2 1 2 5", "5\n1 2 4 5"], "outputs": ["2\n1\n1\n0\n0\n", "1\n2\n1\n0\n0\n", "1\n3\n0\n0\n0\n", "2\n1\n0\n0\n1\n", "1\n1\n1\n1\n0\n", "1\n2\n0\n1\n0\n", "1\n2\n0\n0\n1\n", "1\n1\n0\n1\n1\n"]}
290
190
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and b...
{"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]) == 4\n assert candidate(n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]) == 3\n\n\ncheck(Solution().reachableNodes)"}
168
113
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Convert a non-negative integer num to its English words representation.   Please complete the following python code precisely: ```python class Solution: def numberToWords(self, num: int) -> str: ```
{"functional": "def check(candidate):\n assert candidate(num = 123) == \"One Hundred Twenty Three\"\n assert candidate(num = 12345) == \"Twelve Thousand Three Hundred Forty Five\"\n assert candidate(num = 1234567) == \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n\n\ncheck(Solution(...
60
91
coding
Solve the programming task below in a Python markdown code block. Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole per...
{"inputs": ["1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 1 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 2 7 8 9 -7 -3 4 -...
615
397
coding
Solve the programming task below in a Python markdown code block. Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ......
{"inputs": ["6 2 4\n1 2 1 1 0 3\n1 6\n3 5\n", "6 2 3\n1 4 1 1 0 3\n1 6\n3 5\n", "6 2 4\n1 2 1 1 1 5\n1 6\n3 5\n", "6 2 3\n1 2 0 1 0 3\n1 6\n3 5\n", "6 2 3\n1 4 1 2 0 3\n1 6\n2 5\n", "6 2 7\n1 2 1 1 1 5\n1 6\n3 5\n", "6 2 1\n1 2 0 1 0 3\n1 6\n3 5\n", "6 2 3\n1 4 1 2 0 3\n1 4\n2 5\n"], "outputs": ["0\n0\n", "3\n0\n", "2\...
397
278
coding
Solve the programming task below in a Python markdown code block. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational...
{"inputs": ["1\n1 1 1 1\n", "1\n7 7 1 1\n", "1\n2 2 1 1\n", "1\n0 5 0 1\n", "1\n2 2 1 1\n", "1\n1 1 1 1\n", "1\n0 5 0 1\n", "1\n7 7 1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
458
134
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct pos...
{"inputs": ["2\n3\n1 2 3\n5\n2 4 1 3 5"], "outputs": ["YES\nNO"]}
294
34
coding
Solve the programming task below in a Python markdown code block. Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the be...
{"inputs": ["6\n", "4\n", "2\n", "11\n", "11\n", "58\n", "30\n", "26\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO", "NO\n", "NO\n", "NO\n", "NO\n"]}
415
74
coding
Solve the programming task below in a Python markdown code block. Mid semesters are nearly here. In order to pass the time waiting for the question paper malfunctions, the students have organized a betting pool on students that will pass the semester and the students that will fail. Students place their bets on the s...
{"inputs": ["100\n387 384\n416 278\n336 294\n493 387\n422 150\n28 363\n60 191\n427 264\n427 41\n237 173\n369 212\n430 68\n31 283\n124 363\n136 68\n303 430\n59 23\n168 70\n457 394\n43 12\n374 230\n420 422\n38 285\n325 199\n371 316\n27 414\n481 92\n374 457\n171 363\n282 497\n426 306\n328 85\n6 337\n230 347\n358 314\n396 ...
245
1,187
coding
Solve the programming task below in a Python markdown code block. Many cats live on the campus of a school. Natsume's daily routine is to pet those cats. However, the cats may be capricious and go for a walk off campus. The campus site is a rectangle with each side parallel to the x-axis or y-axis and is surrounded by...
{"inputs": ["2\n1 3 11 11\n4\n13 13\n2 15\n10 9\n5 10\n1 3 20 18\n4\n6 13\n2 15\n1 10\n25 4", "2\n1 3 20 16\n4\n13 13\n2 15\n10 10\n5 10\n0 3 20 0\n4\n1 8\n1 15\n10 10\n25 4", "2\n1 1 11 11\n4\n13 25\n2 15\n10 9\n5 14\n1 3 20 18\n4\n6 13\n2 15\n1 10\n25 4", "2\n1 3 6 10\n4\n21 13\n1 7\n10 10\n8 10\n1 0 20 10\n4\n21 6\n...
510
602
coding
Solve the programming task below in a Python markdown code block. Chef has to attend an exam that starts in X minutes, but of course, watching shows takes priority. Every episode of the show that Chef is watching, is 24 minutes long. If he starts watching a new episode now, will he finish watching it strictly before...
{"inputs": ["4\n30\n23\n60\n24\n"], "outputs": ["Yes\nNo\nYes\nNo\n"]}
420
32
coding
Solve the programming task below in a Python markdown code block. Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The p...
{"inputs": ["3\n", "8\n", "2\n", "1\n", "8\n", "1\n", "2\n", "7\n"], "outputs": ["3\n", "8\n", "2\n", "1\n", "8\n", "1\n", "2\n", "7\n"]}
239
70
coding
Solve the programming task below in a Python markdown code block. Given is a md5 hash of a five digits long PIN. It is given as string. Md5 is a function to hash your password: "password123" ===> "482c811da5d5b4bc6d497ffa98491e38" Why is this useful? Hash functions like md5 can create a hash from string in a short tim...
{"functional": "_inputs = [['827ccb0eea8a706c4c34a16891f84e7b'], ['86aa400b65433b608a9db30070ec60cd']]\n_outputs = [['12345'], ['00078']]\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, (...
425
222
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Roma gave Chef an array of intergers. Chef wants to make all integers in the array equal to 1. In a single operation, he can select a prime number p and a subset of the integers, and then div...
{"inputs": ["1\n3\n1 2 4"], "outputs": ["2"]}
380
20
coding
Solve the programming task below in a Python markdown code block. You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org...
{"inputs": ["1\n1\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n8\n", "1\n11\n", "1\n10\n", "2\n1 1\n"], "outputs": ["0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n"]}
397
90
coding
Solve the programming task below in a Python markdown code block. Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n ...
{"inputs": ["3\n3 2 1\n", "3\n2 1 3\n", "3\n1 2 3\n", "3\n3 1 2\n", "5\n4 2 1 3 5\n", "5\n3 2 1 4 5\n", "5\n4 1 2 3 5\n", "10\n1 9 8 10 2 3 4 6 5 7\n"], "outputs": ["1\n", "2\n", "3\n", "2\n", "3\n", "3\n", "4\n", "6\n"]}
487
146
coding
Solve the programming task below in a Python markdown code block. Igor is in 11th grade. Tomorrow he will have to write an informatics test by the strictest teacher in the school, Pavel Denisovich. Igor knows how the test will be conducted: first of all, the teacher will give each student two positive integers $a$ and...
{"inputs": ["1\n99999 1000000\n", "1\n999999 1000000\n", "5\n1 3\n5 8\n2 5\n3 19\n56678 164422\n", "3\n186850 373693\n1 4\n313129 626299\n", "6\n1 4\n1 4\n4 5\n631059 999974\n1 2\n1 2\n", "4\n2 3\n183887 367789\n3 4\n316073 632198\n", "5\n2 3\n39710 210498\n394744 789486\n1 5\n2 4\n", "6\n1 4\n11286 22574\n488702 97740...
462
404
coding
Solve the programming task below in a Python markdown code block. Mr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path. To cut the distance short, one day he decides to construct a skywalk from his place to his friend’s place. Help him to f...
{"inputs": ["1\n2 L 2 R 2 L 1"], "outputs": ["5.0NW"]}
308
26
coding
Solve the programming task below in a Python markdown code block. It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n peo...
{"inputs": ["5 2 3\n", "5 5 6\n", "2 4 3\n", "2 1 1\n", "5 6 7\n", "5 2 8\n", "3 2 3\n", "5 7 8\n"], "outputs": ["1\n", "2\n", "3\n", "1\n", "2\n", "2\n", "1\n", "2\n"]}
419
102
coding
Solve the programming task below in a Python markdown code block. Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones. Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions: - For each ...
{"inputs": ["2\n0 0", "2\n0 1", "2\n1 1", "2\n1 1", "2\n0 1", "2\n0 0", "2\n1 0", "2\n1 0\n"], "outputs": ["0 0\n", "0 1\n", "1 0\n", "1 0\n", "0 1\n", "0 0\n", "1 1", "1 1\n"]}
380
110
coding
Solve the programming task below in a Python markdown code block. Teddy and Freddy are two friends. Teddy has a pile of strings of size $N$. Each string $Si$ in the pile has length less or equal to $100$ ($len(Si) \leq 100$). Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size $M$. Tedd...
{"inputs": ["4\na\naa\naaa\naaaa\n5\naaaaa", "4\na\nabc\nabcd\nabcde\n5\naaaaa"], "outputs": ["4", "1"]}
412
45
coding
Solve the programming task below in a Python markdown code block. You are given an unweighted, undirected graph. Write a program to check if it's a tree topology. -----Input----- The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M...
{"inputs": ["3 2\n1 2\n2 3"], "outputs": ["YES"]}
163
22
coding
Solve the programming task below in a Python markdown code block. We have the following sequence: ```python f(0) = 0 f(1) = 1 f(2) = 1 f(3) = 2 f(4) = 4; f(n) = f(n-1) + f(n-2) + f(n-3) + f(n-4) + f(n-5); ``` Your task is to give the number of total values for the odd terms of the sequence up to the n-th term (includ...
{"functional": "_inputs = [[0], [1], [2]]\n_outputs = [[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 if len(a) != len(b): return False\n r...
369
170
coding
Solve the programming task below in a Python markdown code block. Given are integer sequences A and B of length 3N. Each of these two sequences contains three copies of each of 1, 2, \dots, N. In other words, A and B are both arrangements of (1, 1, 1, 2, 2, 2, \dots, N, N, N). Tak can perform the following operation t...
{"inputs": ["3\n2 3 3 1 2 1 2 1 3\n3 2 2 1 1 1 3 3 2", "3\n1 1 1 2 2 2 3 3 3\n2 1 1 1 2 2 3 3 3", "3\n1 1 1 2 2 2 3 3 3\n1 1 1 2 3 2 3 3 2", "3\n2 3 3 1 2 1 2 1 3\n3 2 1 2 1 1 3 3 2", "3\n2 3 1 1 3 2 2 1 3\n1 2 1 3 1 2 3 2 3", "3\n3 3 1 1 3 2 2 1 2\n1 1 2 3 2 2 3 1 3", "3\n2 3 3 1 1 1 3 2 2\n3 2 2 1 1 1 3 3 2", "3\n1 1...
538
351
coding
Solve the programming task below in a Python markdown code block. William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of cryptocurrencies. The conference has $n$ participants, ...
{"inputs": ["2 1\n1 2\n", "3 1\n2 3\n", "4 1\n2 4\n", "3 2\n1 3\n3 1\n", "4 2\n2 4\n3 4\n", "4 3\n2 1\n4 1\n1 2\n", "7 6\n1 2\n3 4\n2 4\n7 6\n6 5\n1 7\n", "10 8\n1 2\n2 3\n3 4\n1 4\n6 7\n8 9\n8 10\n1 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n2\n", "1\n2\n", "1\n2\n3\n", "1\n1\n3\n3\n3\n6\n", "1\n2\n3\n4\n5\n5\n6\n8\n...
645
216
coding
Solve the programming task below in a Python markdown code block. You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest....
{"inputs": ["1 2 4\nST\n", "1 2 1\nST\n", "2 1 4\nS\nT\n", "1 3 3\nSaT\n", "2 1 1\nS\nT\n", "1 3 3\nTyS\n", "1 4 1\nSxyT\n", "3 3 1\naaa\naaa\nTSa\n"], "outputs": ["\n", "\n", "\n", "a\n", "\n", "y\n", "-1\n", "\n"]}
592
127
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also gi...
{"functional": "def check(candidate):\n assert candidate(chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25) == 3\n assert candidate(chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19) == 0\n\n\ncheck(Solution().maximumRobots)"}
197
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We call a positive integer special if all of its digits are distinct. Given a positive integer n, return the number of special integers that belong to the interval [1, n].   Please complete the following python code p...
{"functional": "def check(candidate):\n assert candidate(n = 20) == 19\n assert candidate(n = 5) == 5\n assert candidate(n = 135) == 110\n\n\ncheck(Solution().countSpecialNumbers)"}
84
62
coding
Solve the programming task below in a Python markdown code block. Polycarp has a string $s[1 \dots n]$ of length $n$ consisting of decimal digits. Polycarp performs the following operation with the string $s$ no more than once (i.e. he can perform operation $0$ or $1$ time): Polycarp selects two numbers $i$ and $j$ ($...
{"inputs": ["1\n4\n2021\n", "1\n4\n2029\n", "1\n4\n2030\n", "1\n4\n2040\n", "1\n4\n2050\n", "1\n4\n2090\n", "1\n4\n2080\n", "1\n4\n2070\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
730
126
coding
Solve the programming task below in a Python markdown code block. We will define the median of a sequence b of length M, as follows: - Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down...
{"inputs": ["1\n4", "1\n2", "1\n7", "1\n3", "1\n6", "1\n1", "1\n5", "1\n8"], "outputs": ["4\n", "2\n", "7\n", "3\n", "6\n", "1\n", "5\n", "8\n"]}
508
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a non-negative integer array nums. In one operation, you must: Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums. Subtract x from every positive elem...
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,0,3,5]) == 3\n assert candidate(nums = [0]) == 0\n\n\ncheck(Solution().minimumOperations)"}
114
51
coding
Solve the programming task below in a Python markdown code block. D: Sunburn-Suntan- story Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. Cute like an angel. Aizu Nyan is planning to participate in this summer festival, so I...
{"inputs": ["20\n1\n0 7", "20\n1\n3 7", "20\n1\n2 7", "20\n1\n0 3", "20\n1\n4 6", "20\n1\n6 7", "20\n1\n0 4", "20\n1\n1 4"], "outputs": ["7\n", "4\n", "5\n", "3\n", "2\n", "1\n", "4\n", "3\n"]}
679
118
coding
Solve the programming task below in a Python markdown code block. There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all col...
{"inputs": ["2 1\n2 2", "2 1\n1 2", "2 1\n1 2\n", "6 5\n3 3\n1 2\n5 6\n3 4\n4 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 4", "6 5\n3 3\n1 2\n5 6\n3 4\n2 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 1", "6 5\n2 3\n1 2\n5 6\n3 4\n4 3"], "outputs": ["1\n", "1", "1\n", "8\n9\n12\n14\n15\n", "3\n3\n5\n5\n6\n", "8\n11\n13\n14\n15\n", "3\n5\n6\n6\n6...
411
242
coding
Solve the programming task below in a Python markdown code block. Every number may be factored in prime factors. For example, the number 18 may be factored by its prime factors ``` 2 ``` and ```3``` ``` 18 = 2 . 3 . 3 = 2 . 3² ``` The sum of the prime factors of 18 is ```2 + 3 + 3 = 8``` But some numbers like 70 are...
{"functional": "_inputs = [[10, 100], [80, 150], [90, 200]]\n_outputs = [[[16, 27, 30, 60, 70, 72, 84]], [[84, 105, 150]], [[105, 150, 180]]]\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(...
399
235
coding
Solve the programming task below in a Python markdown code block. Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love. Write a function...
{"functional": "_inputs = [[1, 4], [2, 2], [0, 1], [0, 0]]\n_outputs = [[True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a...
122
185
coding
Solve the programming task below in a Python markdown code block. Complete the function that accepts a string parameter, and reverses each word in the string. **All** spaces in the string should be retained. ## Examples ``` "This is an example!" ==> "sihT si na !elpmaxe" "double spaces" ==> "elbuod secaps" ``` ...
{"functional": "_inputs = [['The quick brown fox jumps over the lazy dog.'], ['apple'], ['a b c d'], ['double spaced words'], ['stressed desserts'], ['hello hello']]\n_outputs = [['ehT kciuq nworb xof spmuj revo eht yzal .god'], ['elppa'], ['a b c d'], ['elbuod decaps sdrow'], ['desserts stressed'], ['olleh olleh']...
102
242
coding
Solve the programming task below in a Python markdown code block. A person is said to be sleep deprived if he slept strictly less than 7 hours in a day. Chef was only able to sleep X hours yesterday. Determine if he is sleep deprived or not. ------ Input Format ------ - The first line contains a single integer T — ...
{"inputs": ["3\n4\n7\n10\n"], "outputs": ["YES\nNO\nNO\n"]}
265
25
coding
Solve the programming task below in a Python markdown code block. Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formal...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n6\n", "1\n51\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
517
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A happy string is a string that: consists only of letters of the set ['a', 'b', 'c']. s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed). For example, strings "abc", "ac", "b" and "abc...
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 3) == \"c\"\n assert candidate(n = 1, k = 4) == \"\"\n assert candidate(n = 3, k = 9) == \"cab\"\n assert candidate(n = 2, k = 7) == \"\"\n assert candidate(n = 10, k = 100) == \"abacbabacb\"\n\n\ncheck(Solution().getHappyString)"}
204
114
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid. A string is called valid if ...
{"functional": "def check(candidate):\n assert candidate(word = \"b\") == 2\n assert candidate(word = \"aaa\") == 6\n assert candidate(word = \"abc\") == 0\n\n\ncheck(Solution().addMinimum)"}
111
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s. Reorder the string using the following algorithm: Remove the smallest character from s and append it to the result. Remove the smallest character from s that is greater than the last appende...
{"functional": "def check(candidate):\n assert candidate(s = \"aaaabbbbcccc\") == \"abccbaabccba\"\n assert candidate(s = \"rat\") == \"art\"\n assert candidate(s = \"leetcode\") == \"cdelotee\"\n assert candidate(s = \"ggggggg\") == \"ggggggg\"\n assert candidate(s = \"spo\") == \"ops\"\n\n\ncheck(Solut...
207
101
coding
Solve the programming task below in a Python markdown code block. Alex is transitioning from website design to coding and wants to sharpen his skills with CodeWars. He can do ten kata in an hour, but when he makes a mistake, he must do pushups. These pushups really tire poor Alex out, so every time he does them they ...
{"functional": "_inputs = [[10, 120], [11, 120], [3, 45], [8, 120], [6, 60], [9, 180], [20, 120], [20, 125], [20, 130], [20, 135]]\n_outputs = [[3], [3], [2], [3], [2], [4], [0], [1], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose...
164
265
coding
Solve the programming task below in a Python markdown code block. Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read. He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a...
{"inputs": ["act\n2\ncat\ndog"], "outputs": ["Yes\nNo"]}
373
22
coding
Solve the programming task below in a Python markdown code block. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s i...
{"inputs": ["1 3\nf\n", "1 3\nf\n", "1 3\ne\n", "1 6\ne\n", "2 3\nba\n", "2 3\ngi\n", "2 3\ngi\n", "2 3\nhi\n"], "outputs": ["fff\n", "fff\n", "eee\n", "eeeeee\n", "baa\n", "gig\n", "gig\n", "hih\n"]}
447
109
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. There are three distinct points - A, B, C in the X-Y plane. Initially, you are located at point A. You want to reach the point C satisfying the following cond...
{"inputs": ["4\n1 1\n1 3\n3 3\n0 0\n2 2\n3 4\n5 2\n3 2\n1 2\n1 1\n-1 1\n10000 10000\n"], "outputs": ["YES\nNO\nYES\nNO"]}
746
76
coding
Solve the programming task below in a Python markdown code block. A family of kookaburras are in my backyard. I can't see them all, but I can hear them! # How many kookaburras are there? ## Hint The trick to counting kookaburras is to listen carefully * The males go ```HaHaHa```... * The females go ```hahaha`...
{"functional": "_inputs = [[''], ['hahahahaha'], ['hahahahahaHaHaHa'], ['HaHaHahahaHaHa'], ['hahahahahahahaHaHa']]\n_outputs = [[0], [1], [2], [3], [2]]\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 ...
139
200
coding
Solve the programming task below in a Python markdown code block. Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character. -----Constraints----- - S and...
{"inputs": ["apple\nelppa", "abcdd\nbcdea", "elppa\nelppa", "elppa\nelppb", "elpap\nelppb", "ddc`a\nbbcfa", "ddcba\nbcdea", "cdcba\nbcdea"], "outputs": ["4\n", "5\n", "0\n", "1\n", "2\n", "3\n", "4\n", "4\n"]}
203
101
coding
Solve the programming task below in a Python markdown code block. Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate ...
{"inputs": ["1 0\n3 3\n3", "1 3\n3 2\n3", "1 2\n3 0\n3", "1 0\n3 6\n3", "0 3\n3 2\n3", "1 2\n5 0\n3", "1 0\n3 8\n3", "0 2\n5 0\n3"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
287
126
coding
Solve the programming task below in a Python markdown code block. The Ackermann function is a famous function that played a big role in computability theory as the first example of a total computable function that is not primitive recursive. Since then the function has been a bit simplified but is still of good use. D...
{"functional": "_inputs = [[1, 1], [4, 0], [3, 3]]\n_outputs = [[3], [13], [61]]\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...
255
178
coding
Solve the programming task below in a Python markdown code block. **This Kata is intended as a small challenge for my students** All Star Code Challenge #18 Create a function called that accepts 2 string arguments and returns an integer of the count of occurrences the 2nd argument is found in the first one. If no oc...
{"functional": "_inputs = [['hello', 'l'], ['hello', 'e'], ['codewars', 'c'], ['ggggg', 'g'], ['hello world', 'o']]\n_outputs = [[2], [1], [1], [5], [2]]\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...
130
198
coding
Solve the programming task below in a Python markdown code block. Patlu has recently got a new problem based on Pallindromes. A Pallindrome is a number that is same from front and back, example $121$ is pallindrome but $123$ is not . He wants to calculate sum of all $N$ digit number which are Pallindromic in nature and...
{"inputs": ["2\n1\n2"], "outputs": ["9\n99"]}
238
19
coding
Solve the programming task below in a Python markdown code block. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are m_{i} tasks assigned to the i-th server. In order to balance the load for eac...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n6\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
519
86
coding
Solve the programming task below in a Python markdown code block. An array $b$ is good if the sum of elements of $b$ is even. You are given an array $a$ consisting of $n$ positive integers. In one operation, you can select an index $i$ and change $a_i := \lfloor \frac{a_i}{2} \rfloor$. $^\dagger$ Find the minimum num...
{"inputs": ["1\n1\n524287\n", "4\n4\n1 1 1 1\n2\n7 4\n3\n1 2 4\n1\n15\n"], "outputs": ["19\n", "0\n2\n1\n4\n"]}
616
67
coding
Solve the programming task below in a Python markdown code block. ## Task Given a string, add the fewest number of characters possible from the front or back to make it a palindrome. ## Example For the input `cdcab`, the output should be `bacdcab` ## Input/Output Input is a string consisting of lowercase latin let...
{"functional": "_inputs = [['abcdc'], ['ababa']]\n_outputs = [['abcdcba'], ['ababa']]\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 ...
135
165
coding
Solve the programming task below in a Python markdown code block. Chef has a binary string S of length N. Chef can perform the following operation on S: Insert any character (0 or 1) at any position in S. Find the minimum number of operations Chef needs to perform so that no two consecutive characters are same in S. ...
{"inputs": ["3\n2\n11\n4\n0101\n5\n00100\n"], "outputs": ["1\n0\n2\n"]}
339
38
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of N integer numbers A. Calculate the sum of A_{i} AND A_{j} for all the pairs (i, j) where i < j. The AND operation is the Bitwise AND operation, defined as in here. ------ Input ------ The first line of input consists of t...
{"inputs": ["5\n1 2 3 4 5", "5\n2 2 3 4 5", "5\n2 2 6 4 5", "5\n0 2 6 4 5", "5\n1 2 5 4 6", "5\n0 2 3 4 5", "5\n2 2 6 6 5", "5\n1 2 8 4 6"], "outputs": ["9", "11\n", "18\n", "14\n", "15\n", "7\n", "24\n", "6\n"]}
256
146
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$. Find a sequence of $n$ integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$a_1 \oplus a_2 \oplus \dots \oplus a_n = \frac{a_1 + a_2 + \dots + a_n}{n},$$ where $\oplus$ represents the bitwise XO...
{"inputs": ["3\n1\n4\n3\n"], "outputs": ["2 \n1 3 2 2 \n2 2 2 \n"]}
391
37
coding
Solve the programming task below in a Python markdown code block. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elepha...
{"inputs": ["1\n1 2\n", "1\n1 1\n", "1\n1 4\n", "1\n2 1\n", "2\n1 1\n1 1\n", "2\n1 2\n2 3\n", "2\n1 2\n2 1\n", "2\n1 1\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
421
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Let's define a function countUniqueChars(s) that returns the number of unique characters in s. For example, calling countUniqueChars(s) if s = "LEETCODE" then "L", "T", "C", "O", "D" are the unique characters since t...
{"functional": "def check(candidate):\n assert candidate(s = \"LEETCODE\") == 92\n\n\ncheck(Solution().uniqueLetterString)"}
185
35
coding
Solve the programming task below in a Python markdown code block. You have managed to intercept an important message and you are trying to read it. You realise that the message has been encoded and can be decoded by switching each letter with a corresponding letter. You also notice that each letter is paired with the...
{"functional": "_inputs = [['sr'], ['svool'], ['r slkv mlylwb wvxlwvh gsrh nvhhztv'], ['qzezxirkg rh z srts ovevo wbmznrx fmgbkvw zmw rmgvikivgvw kiltiznnrmt ozmtfztv rg szh yvvm hgzmwziwravw rm gsv vxnzxirkg ozmtfztv hkvxrurxzgrlm zolmthrwv sgno zmw xhh rg rh lmv lu gsv gsivv vhhvmgrzo gvxsmloltrvh lu dliow drwv dvy x...
203
614
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 strings nums, where each string is of equal length and consists of only digits. You are also given a 0-indexed 2D integer array queries where queries[i] = [ki, trimi]. For each queri...
{"functional": "def check(candidate):\n assert candidate(nums = [\"102\",\"473\",\"251\",\"814\"], queries = [[1,1],[2,3],[4,2],[1,2]]) == [2,2,1,0]\n assert candidate(nums = [\"24\",\"37\",\"96\",\"04\"], queries = [[2,1],[2,2]]) == [3,0]\n\n\ncheck(Solution().smallestTrimmedNumbers)"}
230
114
coding
Solve the programming task below in a Python markdown code block. Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M. Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N): - There exists a non-negative integer...
{"inputs": ["2 46\n6 10", "2 85\n6 10", "2 50\n4 10", "2 62\n6 10", "2 50\n6 10", "2 50\n6 10\n", "2 46\n10 10", "2 12\n10 10"], "outputs": ["2\n", "3\n", "0\n", "2\n", "2", "2\n", "5\n", "1\n"]}
354
128
coding
Solve the programming task below in a Python markdown code block. You are given an array A of N integers . You want to convert the array A into a permutation of N integers. To do this, you can apply the following operation on array A exactly once . Pick an integer X, where 1 ≤ X ≤ 2\cdot 10^{7}. For each i , 1 ≤ i ≤ N...
{"inputs": ["2\n3\n2 7 1\n2\n2 2"], "outputs": ["YES 4\nNO"]}
528
30
coding
Solve the programming task below in a Python markdown code block. You are given a certain integer, ```n, n > 0```. You have to search the partition or partitions, of n, with maximum product value. Let'see the case for ```n = 8```. ``` Partition Product [8] 8 [7, 1] ...
{"functional": "_inputs = [[8], [10]]\n_outputs = [[[[3, 3, 2], 18]], [[[4, 3, 3], [3, 3, 2, 2], 36]]]\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) !...
630
196
coding
Solve the programming task below in a Python markdown code block. Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. ...
{"inputs": ["3\n-1 2 -3\n3\n1 -2 3 \n"], "outputs": ["5\n7\n6\n"]}
612
34
coding
Solve the programming task below in a Python markdown code block. It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are...
{"inputs": ["1 1\n", "6 2\n", "6 3\n", "6 4\n", "6 5\n", "6 6\n", "2 2\n", "6 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]}
363
86
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of non-negative integers $A_1, A_2, \ldots, A_N$. At most once, you may choose a non-negative integer $X$ and for each valid $i$, change $A_i$ to $A_i \oplus X$ ($\oplus$ denotes bitwise XOR). Find the minimum possible value of t...
{"inputs": ["3\n5\n2 3 4 5 6\n4\n7 7 7 7\n3\n1 1 3"], "outputs": ["14\n0\n2"]}
473
47
coding
Solve the programming task below in a Python markdown code block. We have N points numbered 1 to N arranged in a line in this order. Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The...
{"inputs": ["4 2\n1 2 2\n3 4 2", "4 2\n1 2 1\n1 4 2", "3 1\n1 3 4\n6 0 0", "4 2\n1 4 1\n3 4 2", "1 2\n2 2 2\n3 3 2", "4 2\n1 2 2\n3 4 0", "3 2\n1 2 2\n3 4 0", "3 2\n1 2 2\n6 4 0"], "outputs": ["-1\n", "2\n", "4\n", "1\n", "0\n", "-1\n", "-1\n", "-1\n"]}
456
175
coding
Solve the programming task below in a Python markdown code block. __Definition:__ According to Wikipedia, a [complete binary tree](https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees) is a binary tree _"where every level, except possibly the last, is completely filled, and all nodes in the last level are as...
{"functional": "_inputs = [[[1]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]\n_outputs = [[[1]], [[4, 2, 6, 1, 3, 5]], [[7, 4, 9, 2, 6, 8, 10, 1, 3, 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_to...
571
254
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will count the number of times the first string occurs in the second. ```Haskell solve("zaz","zazapulz") = 4 because they are ZAZapulz, ZAzapulZ, ZazApulZ, zaZApulZ ``` More examples in test cases. Good luck! Please also try [Simp...
{"functional": "_inputs = [['zaz', 'zazapulz'], ['rat', 'ratatoulie'], ['kata', 'katakatak'], ['code', 'codeodecode'], ['kata', 'kataxxxxkatak'], ['code', 'cozzdezodeczzode'], ['zaaz', 'zazaapulz'], ['defg', 'dsedsfsgsg'], ['defg', 'dvsxvevdvsvfvsvgvsvgg']]\n_outputs = [[4], [3], [7], [11], [7], [11], [4], [2], [3]]\ni...
152
277
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is n...
{"functional": "def check(candidate):\n assert candidate(s = \"YazaAay\") == \"aAa\"\n assert candidate(s = \"Bb\") == \"Bb\"\n assert candidate(s = \"c\") == \"\"\n assert candidate(s = \"dDzeE\") == \"dD\"\n\n\ncheck(Solution().longestNiceSubstring)"}
161
83
coding
Solve the programming task below in a Python markdown code block. Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1...
{"inputs": ["10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 170267273\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1...
450
960
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = ...
{"functional": "def check(candidate):\n assert candidate(celsius = 36.50) == [309.65000,97.70000]\n assert candidate(celsius = 122.11) == [395.26000,251.79800]\n\n\ncheck(Solution().convertTemperature)"}
150
91
coding
Solve the programming task below in a Python markdown code block. Welcome young Jedi! In this Kata you must create a function that takes an amount of US currency in `cents`, and returns a dictionary/hash which shows the least amount of coins used to make up that amount. The only coin denominations considered in this ex...
{"functional": "_inputs = [[56], [0], [100], [-3], [7.9]]\n_outputs = [[{'Nickels': 1, 'Pennies': 1, 'Dimes': 0, 'Quarters': 2}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 4}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}], [{'Nickels': ...
315
311
coding
Solve the programming task below in a Python markdown code block. Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by $i \operatorname{mod} j$. A Modular Equation, as Hamed's teacher described, ...
{"inputs": ["1 0\n", "0 0\n", "5 2\n", "2 0\n", "2 0\n", "5 2\n", "1 0\n", "0 0\n"], "outputs": ["1\n", "infinity\n", "1\n", "2\n", "2", "1", "1", "infinity"]}
407
82
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, and three integers a, b and c. You need to find the number of good triplets. A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true: 0 <= i < j < k < arr.lengt...
{"functional": "def check(candidate):\n assert candidate(arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3) == 4\n assert candidate(arr = [1,1,2,2,3], a = 0, b = 0, c = 1) == 0\n\n\ncheck(Solution().countGoodTriplets)"}
179
93
coding
Solve the programming task below in a Python markdown code block. John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed. There are $n$ students, ea...
{"inputs": ["1\n0 0 0 0\n", "1\n0 0 0 0\n", "1\n0 1 0 0\n", "1\n0 0 0 1\n", "1\n0 0 0 2\n", "1\n0 2 3 1\n", "1\n0 2 1 1\n", "1\n1 2 1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
630
134
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 brother Chefu is a competitive programmer. Every day, he practices for ICPC (International Chefs' Programming Contest) by solving problems. Today, Che...
{"inputs": ["2\n8 3\n1 2 2 1 3 3 2 1\n5 3\n1 1 2 2 3"], "outputs": ["3\n-1"]}
541
49
coding
Solve the programming task below in a Python markdown code block. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the en...
{"inputs": ["4\n", "5\n", "3\n", "2\n", "8\n", "6\n", "1\n", "24\n"], "outputs": ["Rajesh", "Howard", "Penny", "Leonard", "Leonard\n", "Sheldon", "Sheldon", "Penny"]}
362
72
coding
Solve the programming task below in a Python markdown code block. Natasha's favourite numbers are $n$ and $1$, and Sasha's favourite numbers are $m$ and $-1$. One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ elements ar...
{"inputs": ["0 2\n", "2 0\n", "2 2\n", "0 0\n", "1 4\n", "0 0\n", "1 4\n", "6 2\n"], "outputs": ["0\n", "2\n", "5\n", "0\n", "1\n", "0\n", "1\n", "121\n"]}
610
88
coding
Solve the programming task below in a Python markdown code block. Peter can see a clock in the mirror from the place he sits in the office. When he saw the clock shows 12:22 1 2 3 4 5 6 7 8 9 10 11 12 He knows that the time is 11:38 1 2 3 4 5 6 7 8 9 10 11 12 in the same manner: 05:25 --> 06:35 01:50 --...
{"functional": "_inputs = [['06:35'], ['11:59'], ['12:02'], ['04:00'], ['06:00'], ['12:00']]\n_outputs = [['05:25'], ['12:01'], ['11:58'], ['08:00'], ['06:00'], ['12:00']]\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...
289
235
coding
Solve the programming task below in a Python markdown code block. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be c...
{"inputs": ["5\n", "1\n", "2\n", "0\n", "8\n", "3\n", "34\n", "55\n"], "outputs": ["0 0 5\n", "0 0 1\n", "0 0 2\n", "0 0 0\n", "0 0 8\n", "0 0 3\n", "0 0 34\n", "0 0 55\n"]}
286
106
coding
Solve the programming task below in a Python markdown code block. ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and de...
{"inputs": ["3 2\n", "1 3\n", "4 3\n", "2 4\n", "2 4\n", "1 3\n", "4 3\n", "3 2\n"], "outputs": ["1 8", "1 1", "23 128", "29 32", "29 32", "1 1", "23 128", "1 8\n"]}
551
105
coding
Solve the programming task below in a Python markdown code block. Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers fr...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n-3\n", "1\n-4\n", "1\n-1\n", "2\n0 0\n", "2\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
255
93
coding
Solve the programming task below in a Python markdown code block. This is an easier version of the next problem. The difference is only in constraints. You are given a rectangular $n \times m$ matrix $a$. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation...
{"inputs": ["1\n4 2\n1 1\n2 1\n1 2\n2 2\n", "1\n4 2\n1 1\n2 1\n1 2\n2 2\n", "1\n4 2\n1 2\n2 1\n1 2\n2 2\n", "1\n4 2\n1 1\n2 1\n1 2\n2 1\n", "1\n4 2\n1 2\n2 1\n1 3\n2 2\n", "1\n4 2\n1 2\n2 1\n1 5\n2 2\n", "1\n4 2\n1 2\n3 1\n1 5\n2 2\n", "1\n3 2\n1 1\n2 1\n1 2\n2 1\n"], "outputs": ["7\n", "7\n", "8\n", "7\n", "9\n", "11\...
453
232
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given an integer array nums, return the sum of Hamming distances between all the pairs of the integer...
{"functional": "def check(candidate):\n assert candidate(nums = [4,14,2]) == 6\n assert candidate(nums = [4,14,4]) == 4\n\n\ncheck(Solution().totalHammingDistance)"}
93
55
coding
Solve the programming task below in a Python markdown code block. You are given a grid with n rows and m columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number k > 0 written on it, then exactly k of its neighboring ce...
{"inputs": ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n5 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\...
758
1,478