task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selectio...
{"inputs": ["3 8\n9 6 9", "3 8\n6 6 6", "3 8\n9 9 9", "3 8\n6 6 9", "3 8\n15 6 9", "3 8\n15 3 9", "3 8\n15 2 9", "1 11\n2 0 7"], "outputs": ["1\n", "0\n", "0\n", "0", "0\n", "0\n", "0\n", "0\n"]}
334
129
coding
Solve the programming task below in a Python markdown code block. The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it...
{"inputs": ["A\n", "B\n", "B\n", "A\n", "C\n", "@\n", "D\n", "?\n"], "outputs": ["<A>\n", "<B>\n", "<B>\n", "<A>\n", "<C>\n", "<@>\n", "<D>\n", "<?>\n"]}
714
78
coding
Solve the programming task below in a Python markdown code block. Chef loves arrays. But he really loves a specific kind of them - Rainbow Arrays. The array is a Rainbow Array if it has such a structure: - The first a1 elements equal to 1. - The next a2 elements equal to 2. - The next a3 elements equal to 3. - Th...
{"inputs": ["12", "25", "17", "32", "16", "42", "22", "20"], "outputs": ["0\n", "924\n", "28\n", "5005\n", "7\n", "38760\n", "210\n", "84\n"]}
488
83
coding
Solve the programming task below in a Python markdown code block. Thanks to the effects of El Nino this year my holiday snorkelling trip was akin to being in a washing machine... Not fun at all. Given a string made up of '~' and '\_' representing waves and calm respectively, your job is to check whether a person would...
{"functional": "_inputs = [['~'], ['_~~~~~~~_~__~______~~__~~_~~'], ['______~___~_'], ['____'], ['_~~_~____~~~~~~~__~_~']]\n_outputs = [['No Problem'], ['Throw Up'], ['Throw Up'], ['No Problem'], ['Throw Up']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ret...
165
215
coding
Solve the programming task below in a Python markdown code block. For every good kata idea there seem to be quite a few bad ones! In this kata you need to check the provided 2 dimensional array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than ...
{"functional": "_inputs = [[[['bad', 'bAd', 'bad'], ['bad', 'bAd', 'bad'], ['bad', 'bAd', 'bad']]], [[['gOOd', 'bad', 'BAD', 'bad', 'bad'], ['bad', 'bAd', 'bad'], ['GOOD', 'bad', 'bad', 'bAd']]], [[['gOOd', 'bAd', 'BAD', 'bad', 'bad', 'GOOD'], ['bad'], ['gOOd', 'BAD']]]]\n_outputs = [['Fail!'], ['Publish!'], ['I smell ...
161
271
coding
Solve the programming task below in a Python markdown code block. Given a sequence of $n$ numbers, $D=(d_1,d_2,\ldots,d_n)$, what's the maximum size of a subsequence of $\mbox{D}$ in which every pair is a nice pair? The pair $(a,b)$ is a nice pair iff at least one of the following condition holds. The parity of the...
{"inputs": ["4\n2 3 6 8\n"], "outputs": ["3\n"]}
491
22
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 representing a rotten orange. Every minute, any fresh orange that is 4-dire...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,1,1],[1,1,0],[0,1,1]]) == 4\n assert candidate(grid = [[2,1,1],[0,1,1],[1,0,1]]) == -1\n assert candidate(grid = [[0,2]]) == 0\n\n\ncheck(Solution().orangesRotting)"}
135
91
coding
Solve the programming task below in a Python markdown code block. Chef and his best friend Aleksa are into mathematical games these days. Today, they have some ( β‰₯ 0 ) black cells represented as B, and a white cell represented as W, lying randomly in a straight line. They have decided to play with these cells. In a mov...
{"inputs": ["3\nW\nBW\nBWBB"], "outputs": ["Chef\nAleksa\nAleksa"]}
556
27
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven ...
{"inputs": ["3\n2\n5\n4\n"], "outputs": ["1 3\n4 6 7 9 10\n2 3 5 6\n"]}
448
41
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Run has given you a list of statements of the form "A+B=C", where A, B and C consist only of decimal digits and small latin letters from 'a' to 'f'. Moreover, the first symbol of A, B, C is alw...
{"inputs": ["3\n2+2=10\n1+2=a\n3+5=8"], "outputs": ["2"]}
278
30
coding
Solve the programming task below in a Python markdown code block. To celebrate the start of the Rio Olympics (and the return of 'the Last Leg' on C4 tonight) this is an Olympic inspired kata. Given a string of random letters, you need to examine each. Some letters naturally have 'rings' in them. 'O' is an obvious exam...
{"functional": "_inputs = [['wHjMudLwtoPGocnJ'], ['eCEHWEPwwnvzMicyaRjk'], ['JKniLfLW'], ['EWlZlDFsEIBufsalqof'], ['IMBAWejlGRTDWetPS']]\n_outputs = [['Bronze!'], ['Bronze!'], ['Not even a medal!'], ['Silver!'], ['Gold!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):...
242
235
coding
Solve the programming task below in a Python markdown code block. One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, ju...
{"inputs": ["1 50\n50\n", "1 204\n50\n", "1 2994\n100\n", "2 93\n50 50\n", "2 24\n50 50\n", "2 24\n96 50\n", "2 50\n50 50\n", "2 153\n100 50\n"], "outputs": ["1\n1", "1\n1", "1\n1", "-1\n0\n", "-1\n0\n", "-1\n0\n", "-1\n0", "1\n1"]}
624
150
coding
Solve the programming task below in a Python markdown code block. You are given n integers a_1, a_2, …, a_n and an integer k. Find the maximum value of i β‹… j - k β‹… (a_i | a_j) over all pairs (i, j) of integers with 1 ≀ i < j ≀ n. Here, | is the [bitwise OR operator](https://en.wikipedia.org/wiki/Bitwise_operation#OR). ...
{"inputs": ["1\n2 1\n2 2\n", "1\n2 1\n2 0\n", "1\n2 1\n0 0\n", "1\n2 1\n2 1\n", "1\n2 2\n2 2\n", "1\n2 1\n1 0\n", "1\n2 2\n2 1\n", "1\n2 2\n0 0\n"], "outputs": ["0\n", "0\n", "2\n", "-1\n", "-2\n", "1\n", "-4\n", "2\n"]}
546
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... Β  Please complete the following python code ...
{"functional": "def check(candidate):\n assert candidate(columnNumber = 1) == \"A\"\n assert candidate(columnNumber = 28) == \"AB\"\n assert candidate(columnNumber = 701) == \"ZY\"\n assert candidate(columnNumber = 2147483647) == \"FXSHRXW\"\n\n\ncheck(Solution().convertToTitle)"}
106
91
coding
Solve the programming task below in a Python markdown code block. There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following proces...
{"inputs": ["1\nD\n85367\n", "1\nE\n85367\n", "1\nF\n85367\n", "1\nG\n85367\n", "1\nF\n59056\n", "1\nF\n80903\n", "1\nF\n42037\n", "1\nF\n18127\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]}
420
142
coding
Solve the programming task below in a Python markdown code block. Create a function ```python has_two_cube_sums(n) ``` which checks if a given number `n` can be written as the sum of two cubes in two different ways: `n = aΒ³+bΒ³ = cΒ³+dΒ³`. All the numbers `a`, `b`, `c` and `d` should be different and greater than `0`. ...
{"functional": "_inputs = [[1], [1729], [42], [4103], [4102], [4104], [4105], [4106], [0], [46163]]\n_outputs = [[False], [True], [False], [False], [False], [True], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math....
171
234
coding
Solve the programming task below in a Python markdown code block. Chef and Chefina are playing with dice. In one turn, both of them roll their dice at once. They consider a turn to be *good* if the sum of the numbers on their dice is greater than 6. Given that in a particular turn Chef and Chefina got X and Y on the...
{"inputs": ["4\n1 4\n3 4\n4 2\n2 6\n"], "outputs": ["NO\nYES\nNO\nYES\n"]}
410
36
coding
Solve the programming task below in a Python markdown code block. There are N numbers written on a blackboard. In one operation, Chef can: Choose any 3 integers A, B, and C written on the blackboard. Erase them from the blackboard. Write A \oplus B, B \oplus C, and C \oplus A on the blackboard. Here, \oplus denotes ...
{"inputs": ["1\n6\n0 1 2 3 2 0"], "outputs": ["2\n2 3 2\n1 1 1\n"]}
584
39
coding
Solve the programming task below in a Python markdown code block. Lia is fascinated by anything she considers to be a twin. She calls a pairs of positive integers, $\boldsymbol{i}$ and $j$, twins if: They are both prime. A prime number is an integer greater than $\mbox{1}$ that has no positive divisors other than $\mb...
{"inputs": ["3 13\n"], "outputs": ["3\n"]}
279
17
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
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting only of lowercase English letters. We call a substring special if it contains no character which has occurred at least twice (in other words, it does not contain a repeating charact...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\") == 10\n assert candidate(s = \"ooo\") == 3\n assert candidate(s = \"abab\") == 7\n\n\ncheck(Solution().numberOfSpecialSubstrings)"}
179
59
coding
Solve the programming task below in a Python markdown code block. Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: * 'U': go up, (x, y) β†’ (...
{"inputs": ["0 1\nD\n", "1 0\nD\n", "0 0\nD\n", "1 1\nLD\n", "0 -1\nU\n", "-1 0\nR\n", "-1 1\nR\n", "2 4\nRU\n"], "outputs": ["No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
466
102
coding
Solve the programming task below in a Python markdown code block. You've purchased a ready-meal from the supermarket. The packaging says that you should microwave it for 4 minutes and 20 seconds, based on a 600W microwave. Oh no, your microwave is 800W! How long should you cook this for?! ___ # Input You'll be giv...
{"functional": "_inputs = [['600W', 4, 20, '800W'], ['800W', 3, 0, '1200W'], ['100W', 8, 45, '50W'], ['7500W', 0, 5, '600W'], ['450W', 3, 25, '950W'], ['21W', 64, 88, '25W'], ['83W', 61, 80, '26W'], ['38W', 95, 22, '12W']]\n_outputs = [['3 minutes 15 seconds'], ['2 minutes 0 seconds'], ['17 minutes 30 seconds'], ['1 mi...
277
362
coding
Solve the programming task below in a Python markdown code block. There are N people (with different names) and K clubs. For each club you know the list of members (so you have K unordered lists). Each person can be a member of many clubs (and also 0 clubs) and two different clubs might have exactly the same members. T...
{"inputs": ["5", "9", "7", "8", "6", "2", "4", "3"], "outputs": ["4\n", "334\n", "336\n", "384\n", "1\n", "1", "7", "1"]}
628
65
coding
Solve the programming task below in a Python markdown code block. Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i. The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there h...
{"inputs": ["3\n1 3 6\n2 3 4", "3\n1 3 3\n2 3 20", "3\n1 3 6\n2 3 20", "3\n1 3 4\n2 3 20", "3\n1 3 4\n2 3 21", "3\n1 3 8\n2 3 20", "3\n1 3 4\n2 1 20", "3\n1 3 10\n2 3 20"], "outputs": ["10\n8\n10\n", "6\n23\n23\n", "12\n26\n26\n", "8\n24\n24\n", "8\n25\n25\n", "16\n28\n28\n", "24\n24\n8\n", "20\n30\n30\n"]}
738
217
coding
Solve the programming task below in a Python markdown code block. Vasya's older brother, Petya, attends an algorithm course in his school. Today he learned about matchings in graphs. Formally, a set of edges in a graph is called a matching if no pair of distinct edges in the set shares a common endpoint. Petya instantl...
{"inputs": ["3\n3 3\n1 2\n1 3\n2 3\n4 2\n1 2\n3 4\n5 0"], "outputs": ["3\n1\n0"]}
597
48
coding
Solve the programming task below in a Python markdown code block. Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10). Constraints * 2 ≀ N ≀ 10^5 * N is an integer. Input Inpu...
{"inputs": ["3", "5", "7", "4", "9", "8", "2", "6"], "outputs": ["3\n", "5\n", "7\n", "4\n", "9\n", "8\n", "2\n", "6\n"]}
152
62
coding
Solve the programming task below in a Python markdown code block. "What are your shoe sizes?" Suddenly, the doctor asked me when I met him for the first time. "It's 23.5" "Oh, that's a really nice number. It's 2 to the 4th power plus 2 to the 2nd power, 2 to the 1st power, 2 to the 0th power, and 2 to the 1st power."...
{"inputs": ["23.5\n158.1\n-1.0", "23.72975180461117\n158.1\n-1.0", "24.206542817215936\n158.1\n-1.0", "24.615346202775605\n158.1\n-1.0", "25.190547978615548\n158.1\n-1.0", "23.529780841564097\n158.1\n-1.0", "24.722659099067236\n158.1\n-1.0", "23.5\n158.1\n-0.5246083014985048"], "outputs": ["00010111.1000\nNA", "NA\nNA\...
488
311
coding
Solve the programming task below in a Python markdown code block. An array $[b_1, b_2, \ldots, b_m]$ is a palindrome, if $b_i = b_{m+1-i}$ for each $i$ from $1$ to $m$. Empty array is also a palindrome. An array is called kalindrome, if the following condition holds: It's possible to select some integer $x$ and delet...
{"inputs": ["4\n1\n1\n2\n1 2\n3\n1 2 3\n5\n1 4 4 1 4\n"], "outputs": ["YES\nYES\nNO\nYES\n"]}
659
50
coding
Solve the programming task below in a Python markdown code block. We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that i...
{"inputs": ["4 2 2", "4 2 1", "7 9 8", "2 5 8", "6 2 2", "1 5 8", "2 3 2", "2 1 8"], "outputs": ["Yes\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n"]}
251
94
coding
Solve the programming task below in a Python markdown code block. Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides with the pr...
{"inputs": ["101 2 5", "100 2 5", "111 2 5", "000 2 5", "010 2 8", "000 2 8", "101 2 8", "100 2 8"], "outputs": ["0\n", "3\n", "1\n", "4\n", "2\n", "7\n", "0\n", "3\n"]}
283
110
coding
Solve the programming task below in a Python markdown code block. The Collatz conjecture is one of the most famous one. Take any positive integer n, if it is even divide it by 2, if it is odd multiply it by 3 and add 1 and continue indefinitely.The conjecture is that whatever is n the sequence will reach 1. There is ma...
{"functional": "_inputs = [[0], [1], [4], [30], [1000], [1000000], ['a'], [-1], [['a']]]\n_outputs = [[[]], [[1, 1]], [[3, 8]], [[27, 112]], [[871, 179]], [[837799, 525]], [[]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
470
241
coding
Solve the programming task below in a Python markdown code block. "How did you get the deal,how did he agree?" "Its's simple Tom I just made him an offer he couldn't refuse" Ayush is the owner of a big construction company and a close aide of Don Vito The Godfather, recently with the help of the Godfather his company ...
{"inputs": ["2\n1\n2"], "outputs": ["2\n7"]}
296
18
coding
Solve the programming task below in a Python markdown code block. Champernown constant is an irrational number represented in decimal by "0." followed by concatenation of all positive integers in the increasing order. The first few digits of this constant are: 0.123456789101112... Your task is to write a program that ...
{"inputs": ["3 5\n6 7\n0 0", "4 5\n1 7\n0 0", "8 5\n6 7\n0 0", "3 5\n6 5\n0 0", "2 5\n1 0\n0 0", "2 5\n0 0\n0 0", "4 5\n0 0\n0 0", "4 1\n0 0\n0 0"], "outputs": ["34567\n6789101\n", "45678\n1234567\n", "89101\n6789101\n", "34567\n67891\n", "23456\n\n", "23456\n", "45678\n", "4\n"]}
206
201
coding
Solve the programming task below in a Python markdown code block. Consider a rooted binary tree with $n$ vertices containing numbers. Each vertex of the tree either has two sons (left son and right son), or no sons. We will call such a tree heap, if and only if for all vertices (except the root), the number assigned th...
{"inputs": ["5\n2 1 1 1 1\n"], "outputs": ["2\n"]}
646
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left o...
{"functional": "def check(candidate):\n assert candidate(start = \"_L__R__R_\", target = \"L______RR\") == True\n assert candidate(start = \"R_L_\", target = \"__LR\") == False\n assert candidate(start = \"_R\", target = \"R_\") == False\n\n\ncheck(Solution().canChange)"}
193
81
coding
Solve the programming task below in a Python markdown code block. problem Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class. In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exa...
{"inputs": ["10\n3\n111\n19\n8", "10\n52\n011\n3\n1", "10\n3\n010\n24\n9", "10\n3\n010\n19\n9", "10\n3\n011\n19\n9", "10\n3\n011\n19\n8", "10\n9\n100\n30\n95", "10\n9\n110\n30\n95"], "outputs": ["54\n", "42\n", "40\n", "40\n", "40\n", "40\n", "63\n", "65\n"]}
155
168
coding
Solve the programming task below in a Python markdown code block. The factorial of the integer $n$, written $n!$, is defined as: $n!=n\times(n-1)\times(n-2)\times\text{}\cdots\times3\times2\times1$ Calculate and print the factorial of a given integer. For example, if $n=30$, we calculate $30\times29\times28\tim...
{"inputs": ["25\n"], "outputs": ["15511210043330985984000000\n"]}
371
40
coding
Solve the programming task below in a Python markdown code block. There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N. On this sequence, Snuke can perform the following operation: * Choose K consecutive elements in the sequence. Then, replace the value of eac...
{"inputs": ["3 3\n2 2 3", "3 3\n2 2 2", "6 3\n2 2 2", "6 3\n0 2 2", "6 3\n0 3 2", "3 3\n1 2 4", "3 3\n2 2 0", "3 3\n2 2 1"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "1\n", "1\n", "1\n"]}
287
126
coding
Solve the programming task below in a Python markdown code block. There are two lists of different length. The first one consists of keys, the second one consists of values. Write a function ```createDict(keys, values)``` that returns a dictionary created from keys and values. If there are not enough values, the rest o...
{"functional": "_inputs = [[[], []], [[], [1]], [['a'], []], [['a', 'b', 'c'], [1, 2, 3]], [['a', 'b', 'c', 'd', 'e'], [1, 2]], [['a', 'b'], [1, 2, 3, 4]]]\n_outputs = [[{}], [{}], [{'a': None}], [{'a': 1, 'b': 2, 'c': 3}], [{'a': 1, 'b': 2, 'c': None, 'd': None, 'e': None}], [{'a': 1, 'b': 2}]]\nimport math\ndef _deep...
236
288
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings words (0-indexed). In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j]. Return ...
{"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"aabc\",\"bc\"]) == True\n assert candidate(words = [\"ab\",\"a\"]) == False\n\n\ncheck(Solution().makeEqual)"}
119
52
coding
Solve the programming task below in a Python markdown code block. There are N apple trees in a row. People say that one of them will bear golden apples. We want to deploy some number of inspectors so that each of these trees will be inspected. Each inspector will be deployed under one of the trees. For convenience, we ...
{"inputs": ["0 3", "6 4", "4 0", "9 0", "2 7", "1 3", "1 4", "1 7"], "outputs": ["0\n", "1\n", "4\n", "9\n", "1\n", "1\n", "1\n", "1\n"]}
240
78
coding
Solve the programming task below in a Python markdown code block. Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $1$. Each person is looking through the circle's center at the opposite person. ...
{"inputs": ["1\n1 2 3\n", "1\n2 3 4\n", "1\n1 2 3\n", "1\n2 3 4\n", "1\n1 3 4\n", "1\n1 7 4\n", "1\n9 10 1\n", "1\n9 10 1\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "2\n", "10\n", "-1\n", "-1\n"]}
605
122
coding
Solve the programming task below in a Python markdown code block. Alice, Bob, and Charlie have X, Y, and Z chocolates respectively. Find whether you can redistribute the chocolates such that: Each person has at least one chocolate; No two people have same number of chocolates; No chocolate is left after redistributio...
{"inputs": ["4\n1 2 3\n1 1 1\n2 2 2\n2 1 1\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
412
44
coding
Solve the programming task below in a Python markdown code block. Our Chef is very happy that his son was selected for training in one of the finest culinary schools of the world. So he and his wife decide to buy a gift for the kid as a token of appreciation. Unfortunately, the Chef hasn't been doing good business late...
{"inputs": ["2 2\n9 7\n10 8", "2 2\n9 7\n8 10", "2 2\n10 7\n3 0", "2 2\n9 7\n3 10", "2 2\n2 7\n10 8", "2 2\n9 7\n6 10", "2 2\n9 7\n6 16", "2 2\n11 4\n6 2"], "outputs": ["8\n", "GUESS\n", "7\n", "GUESS\n", "8\n", "GUESS\n", "GUESS\n", "4\n"]}
661
158
coding
Solve the programming task below in a Python markdown code block. Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, t...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n1 2\n", "2\n1 1\n", "3\n1 1 2\n", "3\n1 1 2\n", "3\n1 1 1\n"], "outputs": ["1\n1 ", "1\n1 ", "1\n2 ", "1\n2 ", "2\n1 1 ", "2\n1 2 ", "2\n1 2 ", "3\n1 1 1 "]}
469
123
coding
Solve the programming task below in a Python markdown code block. Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times: * Go one meter in the direction he is facing. Then...
{"inputs": ["2", "4", "3", "5", "8", "6", "1", "33"], "outputs": ["180\n", "90\n", "120\n", "72\n", "45\n", "60\n", "360", "120\n"]}
155
74
coding
Solve the programming task below in a Python markdown code block. ----- CHEF N TIMINGS ----- One day chef was working with some random numbers. Then he found something interesting. He observed that no 240, 567, 9999 and 122 and called these numbers nice as the digits in numbers are in increasing order. Also he called ...
{"inputs": ["1\n132"], "outputs": ["129"]}
244
18
coding
Solve the programming task below in a Python markdown code block. The aliens living in outer space are very advanced in technology, intelligence and everything, except one, and that is Cooking. Each year they spend millions of dollars in research, to crack famous recipes prepared by humans. Recently they came to kno...
{"inputs": ["4\n1 4\n3 10\n2 6\n5 8\n3\n1 5\n2 2 6\n3 1 10 9"], "outputs": ["3\n4\n2"]}
640
54
coding
Solve the programming task below in a Python markdown code block. You are given a set of `n` segments on the axis `Ox`, each segment has integer endpoints between `0` and `m` inclusive.  Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers li and ri β€” coordinat...
{"functional": "_inputs = [[7, [[0, 7]]], [2, []], [0, []], [0, [[0, 0]]]]\n_outputs = [[[]], [[0, 1, 2]], [[0]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
284
195
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer array nums. The element sum is the sum of all the elements in nums. The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums. Return the absolute dif...
{"functional": "def check(candidate):\n assert candidate(nums = [1,15,6,3]) == 9\n assert candidate(nums = [1,2,3,4]) == 0\n\n\ncheck(Solution().differenceOfSum)"}
124
57
coding
Solve the programming task below in a Python markdown code block. There are $n$ seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from $1$ to $n$ from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take b...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 0\n1\n", "1 0\n0\n", "1 2\n1\n", "5 314\n0 310 942 628 0\n", "5 314\n0 310 942 628 1\n", "5 314\n1 310 942 628 1\n"], "outputs": ["2 \n", "2 ", "1\n", "0\n", "3\n", "314 628 1256 942 1570 \n", "314 628 1256 942 1570\n", "315 629 1257 943 1571\n"]}
700
211
coding
Solve the programming task below in a Python markdown code block. We want to find the numbers higher or equal than 1000 that the sum of every four consecutives digits cannot be higher than a certain given value. If the number is ``` num = d1d2d3d4d5d6 ```, and the maximum sum of 4 contiguous digits is ```maxSum```, the...
{"functional": "_inputs = [[2000, 3], [2000, 4], [2000, 7], [3000, 7], [4000, 4], [5000, 2], [5000, 3], [5000, 4], [5000, 5], [5000, 6], [5000, 7], [5000, 8], [5000, 9]]\n_outputs = [[[11, 1110, 12555]], [[21, 1120, 23665]], [[85, 1200, 99986]], [[141, 1600, 220756]], [[35, 2000, 58331]], [[5, 1100, 6111]], [[15, 1200,...
754
496
coding
Solve the programming task below in a Python markdown code block. Mehta is a very rich guy. He has $N$ types of coins, and each type of coin is available in an unlimited supply. So Mehta goes to a supermarket to buy monthly groceries. There he sees that every item has a unique price, that is, no two items have the s...
{"inputs": ["4\n2\n3\n4\n5\n3\n1 10\n2 20\n3 7\n"], "outputs": ["8\n14\n4\n"]}
628
43
coding
Solve the programming task below in a Python markdown code block. Galileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tesse...
{"inputs": ["3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3"], "outputs": ["10\n90\n60\n30"]}
370
85
coding
Solve the programming task below in a Python markdown code block. Similar to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-ii/), but this time you need to operate with shuffled strings to identify if they are composed repeating a subpattern Since there is no deterministic way to tell ...
{"functional": "_inputs = [['a'], ['aaaa'], ['abcd'], ['babababababababa'], ['bbabbaaabbaaaabb'], ['123a123a123a'], ['123A123a123a'], ['12aa13a21233'], ['12aa13a21233A'], ['abcdabcaccd']]\n_outputs = [['a'], ['a'], ['abcd'], ['ab'], ['ab'], ['123a'], ['111222333Aaa'], ['123a'], ['111222333Aaaa'], ['aaabbccccdd']]\nimpo...
321
296
coding
Solve the programming task below in a Python markdown code block. The kingdom of Zion has cities connected by bidirectional roads. There is a unique path between any pair of cities. Morpheus has found out that the machines are planning to destroy the whole kingdom. If two machines can join forces, they will attack. ...
{"inputs": ["5 3\n2 1 8\n1 0 5\n2 4 5\n1 3 4\n2\n4\n0\n"], "outputs": ["10\n"]}
631
47
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the graph. Return tru...
{"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]) == True\n assert candidate(n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]]) == False\n\n\ncheck(Solution().validTree)"}
127
83
coding
Solve the programming task below in a Python markdown code block. This problem is a complicated version of D1, but it has significant differences, so read the whole statement. Polycarp has an array of $n$ ($n$ is even) integers $a_1, a_2, \dots, a_n$. Polycarp conceived of a positive integer $k$. After that, Polycarp ...
{"inputs": ["1\n6\n0 2 3 7 14 64\n", "1\n8\n0 0 0 1 1 1 2 2\n", "2\n4\n1 1 1 1\n4\n1 3 5 7\n", "1\n4\n-1000000 1000000 1 2\n", "1\n4\n-1000000 1000000 2 3\n", "1\n4\n1000000 -1000000 1 2\n", "1\n4\n2 3 -1000000 1000000\n", "1\n4\n-1000000 1 2 1000000\n"], "outputs": ["7\n", "2\n", "-1\n6\n", "2000000\n", "2000000\n", "...
474
269
coding
Solve the programming task below in a Python markdown code block. Your program fails again. This time it gets "Wrong answer on test 233" . This is the easier version of the problem. In this version 1 ≀ n ≀ 2000. You can hack this problem only if you solve and lock both problems. The problem is about a test containin...
{"inputs": ["1 1\n1\n", "1 0\n1\n", "3 3\n1 3 1\n", "5 5\n1 2 4 2 2\n", "5 5\n1 1 4 2 2\n", "6 2\n1 1 2 2 1 1\n", "6 2\n0 1 2 2 1 1\n", "6 2\n0 0 2 2 1 1\n"], "outputs": ["0\n", "0\n", "9\n", "1075\n", "1000\n", "16\n", "20\n", "32\n"]}
690
161
coding
Solve the programming task below in a Python markdown code block. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. I...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 0 1\n1\n", "1 0 1\n2\n", "2 1 2\n2 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
562
120
coding
Solve the programming task below in a Python markdown code block. Chef has invested his money at an interest rate of X percent per annum while the current inflation rate is Y percent per annum. An investment is called *good* if and only if the interest rate of the investment is at least twice of the inflation rate. ...
{"inputs": ["5\n7 4\n6 3\n2 4\n10 10\n20 1\n"], "outputs": ["NO\nYES\nNO\nNO\nYES\n"]}
453
45
coding
Solve the programming task below in a Python markdown code block. When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one th...
{"inputs": ["get_user_name L\ngetUserOame U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserName U\nGrtUseeName D\nEndOfInput X", "get_user_nbme L\ngetUserOame U\nGetUserName D\nEndOfInput X", "embn_resu_teg L\ngetUserOame U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserNamd U\nGetUserName D\nEndOfInp...
372
301
coding
Solve the programming task below in a Python markdown code block. Chef has an array consisting of N + K - 1 integers. The array contains only the first N positive odd numbers. Each number appears exactly once, except for one number which appears exactly K times. The sum of integers in Chef's array is equal to S. For e...
{"inputs": ["3\n3 2 14\n5 4 28\n2 3 10\n"], "outputs": ["5\n1\n3\n"]}
434
39
coding
Solve the programming task below in a Python markdown code block. Chef is very hungry. So, Chef goes to a shop selling burgers. The shop has 2 types of burgers: Normal burgers, which cost X rupees each Premium burgers, which cost Y rupees each (where Y > X) Chef has R rupees. Chef wants to buy exactly N burgers. He al...
{"inputs": ["4\n2 10 4 12\n4 8 10 50\n99 100 5 10\n9 10 10 200\n"], "outputs": ["4 0\n8 2\n-1\n0 10\n"]}
451
72
coding
Solve the programming task below in a Python markdown code block. This is an easy version of the problem. In this version, all cards have the same color. Alice has $n$ cards, each card is white, and the cards are stacked in a deck. Alice deals the cards to herself and to Bob, dealing at once several cards from the top...
{"inputs": ["5\n10\n6\n17\n8\n1000000\n"], "outputs": ["5 5\n1 5\n10 7\n3 5\n500202 499798\n"]}
396
61
coding
Solve the programming task below in a Python markdown code block. Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substr...
{"inputs": ["3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi\n\n"], "outputs": ["Tracy\nTracy\nTeddy"]}
367
55
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing One Card Poker. One Card Poker is a two-player game using playing cards. Each card in this game shows an integer between 1 and 13, inclusive. The strength of a card is determined by the number written on it, as follows: We...
{"inputs": ["8 7", "2 1", "0 0", "8 3", "3 1", "7 3", "4 1", "7 1"], "outputs": ["Alice\n", "Bob\n", "Draw\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Bob\n"]}
344
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2, of equal length n. In one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices. Find the mini...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5]) == 10\n assert candidate(nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3]) == 10\n assert candidate(nums1 = [1,2,2], nums2 = [1,2,2]) == -1\n\n\ncheck(Solution().minimumTotalCost)"}
176
119
coding
Solve the programming task below in a Python markdown code block. Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally... Lee has $n$ integers $a_1, a_2, \ldots, a_n$ in his backpack and he h...
{"inputs": ["3\n4 2\n1 13 7 0\n1 3\n6 2\n10 0 10 10 6 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 13 7 1\n1 3\n6 2\n7 10 11 0 11 19\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n0 18 12 1\n1 3\n6 2\n2 11 9 2 11 11\n3 3\n4 4\n1000000000 1000000000 1000...
747
966
coding
Solve the programming task below in a Python markdown code block. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k ...
{"inputs": ["1 1\n2\n0\n", "1 1\n2\n0\n", "1 1\n2\n1\n", "4 4\n1122\n2\n", "4 4\n1122\n2\n", "4 4\n1049\n2\n", "4 4\n1384\n2\n", "4 4\n2661\n2\n"], "outputs": ["4\n", "4\n", "5\n", "8\n", "8\n", "9\n", "7\n", "3\n"]}
656
133
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. You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the...
{"inputs": ["1\ne\n", "1\nA\n", "1\ne\n", "1\nA\n", "1\nf\n", "1\ng\n", "1\nd\n", "1\nc\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
217
86
coding
Solve the programming task below in a Python markdown code block. Unicode Transformation Format – 8-bit As the name suggests UTF-8 was designed to encode data in a stream of bytes. It works by splitting the bits up in multiples of eight. This is achieved by inserting headers to mark in how many bytes the bits were spl...
{"functional": "_inputs = [['\\x80'], ['\u07ff'], ['\u0800'], ['\\uffff']]\n_outputs = [['1100001010000000'], ['1101111110111111'], ['111000001010000010000000'], ['111011111011111110111111']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a...
632
264
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and you want to perform operations on x such that ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,4,12], start = 2, goal = 12) == 2\n assert candidate(nums = [3,5,7], start = 0, goal = -4) == 2\n assert candidate(nums = [2,8,16], start = 0, goal = 1) == -1\n\n\ncheck(Solution().minimumOperations)"}
252
100
coding
Solve the programming task below in a Python markdown code block. Write a function that returns the number of '2's in the factorization of a number. For example, ```python two_count(24) ``` should return 3, since the factorization of 24 is 2^3 x 3 ```python two_count(17280) ``` should return 7, since the factorizatio...
{"functional": "_inputs = [[24], [17280], [222222222222], [256], [1], [2], [482848428248882482], [7], [7777777777777777], [84934656]]\n_outputs = [[3], [7], [1], [8], [0], [1], [1], [0], [0], [20]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isc...
159
267
coding
Solve the programming task below in a Python markdown code block. Chef has planned that he will drink exactly X liters of tea daily. He has an empty jar having a capacity of Y liters. Chef can visit the tea shop to refill the jar. In each refill, the jar is completely filled to the brim and Chef is charged Z rupees. ...
{"inputs": ["4\n3 3 3\n6 3 3\n5 7 2\n9 4 5\n"], "outputs": ["3\n6\n2\n15\n"]}
485
45
coding
Solve the programming task below in a Python markdown code block. You are given $n$ elements numbered from $1$ to $n$, the element $i$ has value $a_i$ and color $c_i$, initially, $c_i = 0$ for all $i$. The following operation can be applied: Select three elements $i$, $j$ and $k$ ($1 \leq i < j < k \leq n$), such tha...
{"inputs": ["3\n1 1 2\n", "3\n1 1 1\n", "3\n1 2 1\n", "3\n1 2 2\n", "3\n1 2 3\n", "7\n1 2 1 2 7 4 7\n", "13\n1 2 3 2 1 3 3 4 5 5 5 4 7\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "2\n", "7\n"]}
386
133
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a string $S$ of lowercase English letters with length $N$. You are allowed to (but don't have to) choose one index in this string and change the letter at this ...
{"inputs": ["3\nabcd\ndbca\ndcba"], "outputs": ["6\n1\n0"]}
389
25
coding
Solve the programming task below in a Python markdown code block. Alice has recently learned in her economics class that the market is said to be in equilibrium when the supply is equal to the demand. Alice has market data for N time points in the form of two integer arrays S and D. Here, S_{i} denotes the supply at t...
{"inputs": ["2\n4\n1 2 3 4\n2 1 3 4\n4\n1 1 2 2\n1 2 1 1"], "outputs": ["2\n1"]}
438
50
coding
Solve the programming task below in a Python markdown code block. ByteLand is a large country with a tree-like road system. It has $N$ cities and $(N-1)$ unidirected roads. The capital of ByteLand is a city, numbered $\mbox{1}$, and all the roads go away from the capital. So people use these roads to reach any city fro...
{"inputs": ["5 2\n1 2 1 2 1\n1 2\n2 3\n3 4\n4 5\n2 4\n2 5\n"], "outputs": ["2\n3\n"]}
691
52
coding
Solve the programming task below in a Python markdown code block. Write a function that calculates the *least common multiple* of its arguments; each argument is assumed to be a non-negative integer. In the case that there are no arguments (or the provided array in compiled languages is empty), return `1`. ~~~if:objc ...
{"functional": "_inputs = [[2, 5], [2, 3, 4], [9], [0], [0, 1], [1, 1, 1], [5, 6, 7, 9, 6, 9, 18, 4, 5, 15, 15, 10, 17, 7], [17, 20, 4, 15, 4, 18, 12, 14, 20, 19, 2, 14, 13, 7], [11, 13, 4, 5, 17, 4, 10, 13, 16, 13, 13], [20, 1, 6, 10, 3, 7, 8, 4], [3, 9, 9, 19, 18, 14, 18, 9], [3, 9, 9, 19, 18, 14, 18, 0]]\n_outputs =...
138
464
coding
Solve the programming task below in a Python markdown code block. You have been recruited by an unknown organization for your cipher encrypting/decrypting skills. Being new to the organization they decide to test your skills. Your first test is to write an algorithm that encrypts the given string in the following s...
{"functional": "_inputs = [['amz'], ['welcome to the organization'], ['hello'], ['my name is'], ['goodbye']]\n_outputs = [['man'], ['qibkyai ty tfi yvgmzenmteyz'], ['fibby'], ['ao zmai eu'], ['gyyjloi']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
259
206
coding
Solve the programming task below in a Python markdown code block. In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\{h_1,h_2,h_3,......\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by ...
{"inputs": ["1\n7\n", "4\n1 4 2 1", "4\n1 8 2 1", "4\n1 2 2 2", "4\n1 2 2 1", "4\n1 2 2 1\n", "4\n1 12 2 1", "4\n1 12 0 2"], "outputs": ["7\n", "4\n", "8\n", "2\n", "2", "2\n", "12\n", "14\n"]}
302
125
coding
Solve the programming task below in a Python markdown code block. Aaron is struggling with trigonometric functions, so his teacher gave him extra homework. Given an integer, $n$, he must answer the following question: What is the maximum value of $sin(x)+sin(y)+sin(z)$, where $x}$, $y$, and $z$ are positive integers a...
{"inputs": ["3\n"], "outputs": ["2.524412954\n"]}
256
24
coding
Solve the programming task below in a Python markdown code block. Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not. Valid examples, should return true: should return false: Also feel free to reuse/extend the following starter code: ...
{"functional": "_inputs = [['s2324'], ['-234.4'], ['3 4'], ['3-4'], ['3 4 '], ['34.65'], ['-0'], ['0.0'], [''], [' ']]\n_outputs = [[False], [True], [False], [False], [False], [True], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
75
229
coding
Solve the programming task below in a Python markdown code block. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: - Place A blue balls at the end of the row of balls alread...
{"inputs": ["8 0 1", "8 3 7", "8 1 1", "8 1 7", "8 1 5", "6 1 0", "8 1 0", "6 2 3"], "outputs": ["0\n", "3\n", "4\n", "1\n", "2\n", "6\n", "8\n", "3\n"]}
266
94
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 with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree are cousins, or false otherwise. T...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4]), x = 4, y = 3) == False\n assert candidate(root = tree_node([1,2,3,None,4,None,5]), x = 5, y = 4) == True\n assert candidate(root = tree_node([1,2,3,None,4]), x = 2, y = 3) == False\n\n\ncheck(Solution().isCousins)"}
207
113
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly...
{"functional": "def check(candidate):\n assert candidate(nums = [1, 7, 3, 6, 5, 6]) == 3\n assert candidate(nums = [1, 2, 3]) == -1\n assert candidate(nums = [2, 1, -1]) == 0\n\n\ncheck(Solution().pivotIndex)"}
155
82
coding
Solve the programming task below in a Python markdown code block. Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said i...
{"inputs": ["6 1\n101011 2\n", "6 2\n000000 2\n010100 4\n", "7 2\n1011111 2\n1001111 1\n", "6 3\n000100 2\n010100 4\n111100 0\n", "6 3\n000000 2\n010100 4\n111100 2\n", "6 3\n000000 2\n010100 4\n111100 0\n", "8 3\n00111100 5\n10100111 2\n10110101 2\n", "6 4\n000110 2\n010001 2\n001111 2\n001100 2\n"], "outputs": ["15",...
387
277
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. In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to ...
{"inputs": ["1 2 0 2\nb\na\n1 a\n1 b\n", "1 1 1 1\na\nb: a 1\n1 a\n", "1 1 1 1\na\nc: a 1\n1 a\n", "1 1 1 1\na\nc: a 2\n1 a\n", "10 1 1 3\na\nb: a 2\n1 a\n1 a\n1 a\n", "20 1 1 3\na\nb: a 2\n1 a\n1 a\n1 a\n", "10 1 1 3\na\nc: a 2\n1 a\n1 a\n1 a\n", "20 1 1 3\na\nc: a 2\n1 a\n1 a\n1 a\n"], "outputs": ["2\na 1\nb 1\n", "1...
767
397
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that ...
{"functional": "def check(candidate):\n assert candidate(str1 = \"ABCABC\", str2 = \"ABC\") == \"ABC\"\n assert candidate(str1 = \"ABABAB\", str2 = \"ABAB\") == \"AB\"\n assert candidate(str1 = \"LEET\", str2 = \"CODE\") == \"\"\n\n\ncheck(Solution().gcdOfStrings)"}
124
84
coding
Solve the programming task below in a Python markdown code block. Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0. -----Input----- The first line of input contains T - number of test cases. Each of the n...
{"inputs": ["3\n1 2 0 3\n1 2 4 -1\n1 2 3 4"], "outputs": ["Yes\nYes\nNo"]}
237
40
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if it has no children The depth of the root of the tree is 0. if ...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([3,5,1,6,2,0,8,None,None,7,4])), tree_node([2,7,4]))\n assert is_same_tree(candidate(root = tree_node([1])), tree_node([1]))\n assert is_same_tree(candidate(root = tree_node([0,1,3,None,2])), tree_node([2]))\n\n\ncheck(Solut...
214
113
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of integers nums represents the numbers written on a chalkboard. Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes th...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2]) == False\n assert candidate(nums = [0,1]) == True\n assert candidate(nums = [1,2,3]) == True\n\n\ncheck(Solution().xorGame)"}
182
62
coding
Solve the programming task below in a Python markdown code block. In this simple exercise, you will build a program that takes a value, `integer `, and returns a list of its multiples up to another value, `limit `. If `limit` is a multiple of ```integer```, it should be included as well. There will only ever be positiv...
{"functional": "_inputs = [[5, 25], [1, 2], [5, 7], [4, 27], [11, 54]]\n_outputs = [[[5, 10, 15, 20, 25]], [[1, 2]], [[5]], [[4, 8, 12, 16, 20, 24]], [[11, 22, 33, 44]]]\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_...
181
249
coding
Solve the programming task below in a Python markdown code block. C: Canisal cryptography problem Ebi-chan was given the string C obtained by encrypting a non-negative integer D with "canisal cipher". This cipher replaces each number in decimal notation with a fixed number (not necessarily different from the original...
{"inputs": ["2\n8", "2\n5", "2\n0", "2\n38", "2\n44", "2\n40", "2\n10", "2\n30"], "outputs": ["2", "2", "2", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
564
80
coding
Solve the programming task below in a Python markdown code block. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences. Consider all integer sequences of length N whose elements are bet...
{"inputs": ["5 4 3 3", "5 4 2 3", "0 4 2 3", "8 5 7 5", "3 3 7 5", "7 4 2 3", "5 8 3 3", "8 4 2 3"], "outputs": ["460\n", "435\n", "0\n", "1761124\n", "1\n", "78735\n", "574\n", "962894\n"]}
404
131
coding
Solve the programming task below in a Python markdown code block. This is a follow-up from my previous Kata which can be found here: http://www.codewars.com/kata/5476f4ca03810c0fc0000098 This time, for any given linear sequence, calculate the function [f(x)] and return it as a function in Javascript or Lambda/Block in...
{"functional": "_inputs = [[[1, 2, 4, 7, 11]], [[0, 1, 2, 3, 100000]], [[0, 1, 2, 100000, 4]], [[0, 1, 100000, 3, 4]], [[0, 100000, 2, 3, 4]]]\n_outputs = [['Non-linear sequence'], ['Non-linear sequence'], ['Non-linear sequence'], ['Non-linear sequence'], ['Non-linear sequence']]\nimport math\ndef _deep_eq(a, b, tol=1e...
284
269