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. Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i. He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditio...
{"inputs": ["3\n4 2 3\n", "4\n5 4 2 1", "4\n5 2 2 1", "4\n8 2 2 1", "4\n8 2 1 1", "4\n6 4 2 1", "4\n5 4 3 1", "4\n6 2 2 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n"]}
252
125
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given two strings `a` and `b` and your task will be to return the characters that are not common in the two strings. For example: ```Haskell solve("xyab","xzca") = "ybzc" --The first string has 'yb' which is not in the second...
{"functional": "_inputs = [['xyab', 'xzca'], ['xyabb', 'xzca'], ['abcd', 'xyz'], ['xxx', 'xzca']]\n_outputs = [['ybzc'], ['ybbzc'], ['abcdxyz'], ['zca']]\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...
198
194
coding
Solve the programming task below in a Python markdown code block. You are given <var>Q</var> tuples of integers <var>(L_i, A_i, B_i, M_i)</var>. For each tuple, answer the following question. There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}. The initial term is A, and the common difference...
{"inputs": ["5 5 4 10007", "2 5 4 10007", "2 1 4 10007", "5 3 4 10007", "5 3 4 10007\n", "6 8 1 1000000", "4 8 1 1001000", "3 8 1 1001000"], "outputs": ["358\n", "59\n", "15\n", "5563", "5563\n", "111213\n", "891011\n", "8910\n"]}
354
171
coding
Solve the programming task below in a Python markdown code block. Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security sy...
{"inputs": ["1\n0\n", "1\n0\n", "2\n0 1\n", "2\n0 1\n", "3\n0 2 0\n", "3\n0 2 1\n", "3\n0 2 1\n", "3\n0 2 0\n"], "outputs": ["0\n", "0", "0\n", "0", "1\n", "1\n", "1", "1"]}
576
102
coding
Solve the programming task below in a Python markdown code block. Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] f...
{"inputs": ["10\n8 5 9 2 6 3 7 0 10 4", "10\n8 5 9 2 6 3 7 0 10 3", "10\n8 5 9 2 6 3 7 1 10 4", "10\n8 5 9 2 6 4 11 0 10 3", "10\n8 5 9 2 6 4 11 0 10 5", "10\n8 5 9 2 6 4 11 1 10 5", "10\n10 5 9 2 6 4 11 1 10 5", "10\n10 5 9 2 6 4 19 1 10 5"], "outputs": ["0 2 3 4 5 6 7 8 9 10\n34\n", "0 2 3 3 5 6 7 8 9 10\n34\n", "1 2...
391
427
coding
Solve the programming task below in a Python markdown code block. A sequence of integers is called a wonderful sequence if all the integers in it are positive and it is a strictly increasing sequence. Given a sequence of integers, you have to make it a wonderful sequence. For that you can change any element you want, ...
{"inputs": ["3\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8", "4\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8\n4\n2 2 2 2"], "outputs": ["0\n2\n1", "0\n2\n1\n3"]}
300
92
coding
Solve the programming task below in a Python markdown code block. This is simple version of harder [Square Sums](/kata/square-sums). # Square sums Write function `square_sums_row` (or `squareSumsRow`/`SquareSumsRow` depending on language rules) that, given integer number `N` (in range `2..43`), returns array of integ...
{"functional": "_inputs = [[5], [24]]\n_outputs = [[False], [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) != len(b): return False\n re...
622
163
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A set of real numbers can be represented as the union of several disjoint intervals, where each interval is in the form [a, b). A real number x is in the set if one of its intervals [a, b) contains x (i.e. a <= x < b)...
{"functional": "def check(candidate):\n assert candidate(intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]) == [[0,1],[6,7]]\n assert candidate(intervals = [[0,5]], toBeRemoved = [2,3]) == [[0,2],[3,5]]\n assert candidate(intervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4]) == [[-5,-4],[-3...
221
149
coding
Solve the programming task below in a Python markdown code block. You have $n$ barrels lined up in a row, numbered from left to right from one. Initially, the $i$-th barrel contains $a_i$ liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $x$ and...
{"inputs": ["2\n4 1\n5 5 5 5\n3 2\n0 0 0\n", "2\n4 2\n5 5 5 5\n3 2\n0 0 0\n", "2\n4 2\n5 5 5 5\n3 2\n0 0 1\n", "2\n4 3\n5 5 2 5\n3 2\n0 1 0\n", "2\n4 3\n5 5 2 1\n3 2\n0 1 0\n", "2\n4 3\n5 1 2 1\n3 2\n0 1 0\n", "2\n4 2\n2 5 5 0\n3 2\n0 0 0\n", "2\n4 3\n5 1 2 2\n3 2\n0 1 0\n"], "outputs": ["10\n0\n", "15\n0\n", "15\n1\n"...
525
269
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that consists of lower case English letters and brackets. Reverse the strings in each pair of matching parentheses, starting from the innermost one. Your result should not contain any brackets...
{"functional": "def check(candidate):\n assert candidate(s = \"(abcd)\") == \"dcba\"\n assert candidate(s = \"(u(love)i)\") == \"iloveu\"\n assert candidate(s = \"(ed(et(oc))el)\") == \"leetcode\"\n assert candidate(s = \"a(bcdefghijkl(mno)p)q\") == \"apmnolkjihgfedcbq\"\n\n\ncheck(Solution().reverseParenth...
89
106
coding
Solve the programming task below in a Python markdown code block. You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers. You can choose any non-negative integer $D$ (i.e. $D \ge 0$), and for each $a_i$ you can: add $D$ (only once), i. e. perform $a_i := a_i + D$, or subtract $D$ (only once), i...
{"inputs": ["2\n2 8\n", "1\n100\n", "2\n1 1\n", "2\n2 7\n", "2\n5 8\n", "2\n3 1\n", "2\n2 5\n", "2\n3 8\n"], "outputs": ["3\n", "0\n", "0\n", "5\n", "3\n", "1\n", "3\n", "5\n"]}
556
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a binary string s consisting only of zeroes and ones. A substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. N...
{"functional": "def check(candidate):\n assert candidate(s = \"01000111\") == 6\n assert candidate(s = \"00111\") == 4\n assert candidate(s = \"111\") == 0\n\n\ncheck(Solution().findTheLongestBalancedSubstring)"}
129
73
coding
Solve the programming task below in a Python markdown code block. Summer is at its peak in Chefland. Chef is planning to purchase a water cooler to keep his room cool. He has two options available: Rent a cooler at the cost of X coins per month. Purchase a cooler for Y coins. Given that the summer season will last fo...
{"inputs": ["3\n5 10 1\n5 10 2\n5 10 3"], "outputs": ["YES\nNO\nNO"]}
549
37
coding
Solve the programming task below in a Python markdown code block. Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th specta...
{"inputs": ["5 3 5\n", "3 2 4\n", "6 1 4\n", "2 2 3\n", "5 4 6\n", "2 1 2\n", "2 2 2\n", "5 5 6\n"], "outputs": ["3\n", "1\n", "1\n", "1\n", "3\n", "1\n", "2\n", "4\n"]}
666
102
coding
Solve the programming task below in a Python markdown code block. # Introduction The Condi (Consecutive Digraphs) cipher was introduced by G4EGG (Wilfred Higginson) in 2011. The cipher preserves word divisions, and is simple to describe and encode, but it's surprisingly difficult to crack. # Encoding Algorithm The ...
{"functional": "_inputs = [['on', 'cryptogram', 10]]\n_outputs = [['jx']]\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 ...
690
163
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has a number D containing only digits 0's and 1's. He wants to make the number to have all the digits same. For that, he will change exactly one digit, i.e. from 0 to 1 ...
{"inputs": ["2\n101\n11"], "outputs": ["Yes\nNo"]}
351
21
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator. Please complete the following python code precisely: ```python class Solution: def maximum(self, a...
{"functional": "def check(candidate):\n assert candidate(a = 1, b = 2) == 2\n\n\ncheck(Solution().maximum)"}
73
35
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string "abcdefghijklmnopqrstuvwxyz". For example, "abc" is an alphabetical c...
{"functional": "def check(candidate):\n assert candidate(s = \"abacaba\") == 2\n assert candidate(s = \"abcde\") == 5\n\n\ncheck(Solution().longestContinuousSubstring)"}
120
48
coding
Solve the programming task below in a Python markdown code block. You are given a rectangular grid with $n$ rows and $m$ columns. The cell located on the $i$-th row from the top and the $j$-th column from the left has a value $a_{ij}$ written in it. You can perform the following operation any number of times (possibly...
{"inputs": ["1\n3 3\n-3 -2 -1\n0 -2 0\n-3 -2 -1\n", "1\n3 3\n0 -1 -2\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-1 0 -1\n", "1\n3 3\n-3 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-1 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-4 -4 -1\n-3 -4 -2\n-3 -2 0\n", "1\n3 3\n-6 -4 -1\n-3 -4 ...
468
272
coding
Solve the programming task below in a Python markdown code block. Given an array of one's and zero's that represents a positive binary number convert the number to two's complement value. Two's complement is the way most computers represent positive or negative integers. The most significant bit is negative. Example...
{"functional": "_inputs = [[[0, 0, 0, 0]], [[0, 0, 1, 0]], [[0, 0, 1, 1]], [[0, 1, 0, 0]]]\n_outputs = [[[0, 0, 0, 0]], [[1, 1, 1, 0]], [[1, 1, 0, 1]], [[1, 1, 0, 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_to...
234
246
coding
Solve the programming task below in a Python markdown code block. Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$. Polycarp considers the price on the day $i$ to be bad if later (that is, a d...
{"inputs": ["5\n6\n3 9 2 6 7 5\n1\n1000000\n2\n2 1\n10\n31 5 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 5 4 6 7 4\n1\n1000000\n2\n2 0\n10\n2 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 9 2 6 7 5\n1\n1000000\n2\n2 1\n10\n31 5 59 26 53 58 97 93 23 84\n7\n3 2 1 2 4 4 5\n", "5\n6\n3 9 4 6 7 5\n1\n...
523
763
coding
Solve the programming task below in a Python markdown code block. You are given an integer $x$ and an array of integers $a_1, a_2, \ldots, a_n$. You have to determine if the number $a_1! + a_2! + \ldots + a_n!$ is divisible by $x!$. Here $k!$ is a factorial of $k$ — the product of all positive integers less than or eq...
{"inputs": ["1 1\n1\n", "1 2\n2\n", "1 5\n3\n", "2 3\n2 1\n", "2 10\n1 1\n", "1 500000\n1\n", "5 2\n2 1 1 1 1\n", "6 4\n3 2 2 2 3 3\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n"]}
606
130
coding
Solve the programming task below in a Python markdown code block. Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and r...
{"inputs": ["1\n5\n4\n", "1\n5\n4\n", "1\n8\n4\n", "1\n8\n1\n", "1\n7\n1\n", "1\n5\n1\n", "1\n5\n2\n", "1\n8\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
446
102
coding
Solve the programming task below in a Python markdown code block. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be...
{"inputs": ["3\n1 2\n1 3", "3\n1 3\n2 3", "3\n1 3\n2 1", "3\n1 2\n2 3", "3\n1 2\n2 3\n", "4\n1 2\n2 3\n2 4", "4\n1 2\n2 3\n1 4", "4\n1 2\n1 3\n2 4"], "outputs": ["125000001\n", "125000001\n", "125000001\n", "125000001", "125000001\n", "250000002\n", "375000003\n", "375000003\n"]}
503
202
coding
Solve the programming task below in a Python markdown code block. A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices. A subtree of a tree T is a tree with both vertices a...
{"inputs": ["3\n1 2\n1 3\n2 0 1\n", "3\n1 2\n1 3\n1 -1 1\n", "3\n1 2\n1 3\n1 -1 2\n", "3\n1 2\n1 3\n2 -1 1\n", "3\n1 2\n1 3\n1 -1 3\n", "3\n1 2\n1 3\n2 -1 3\n", "3\n1 2\n1 3\n1 -1 1\n", "5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3\n"], "outputs": ["2\n", "3\n", "3\n", "4\n", "5\n", "4\n", "3\n", "8\n"]}
417
194
coding
Solve the programming task below in a Python markdown code block. You invited $n$ guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. Your guests happen to be a little bit shy, so the $i$-th guest...
{"inputs": ["1\n5 6\n", "1\n0 0\n", "1\n0 0\n", "1\n5 8\n", "1\n0 8\n", "1\n0 9\n", "1\n5 6\n", "2\n6 6\n3 3\n"], "outputs": ["7\n", "1\n", "1\n", "9\n", "9\n", "10\n", "7\n", "11\n"]}
468
108
coding
Solve the programming task below in a Python markdown code block. You will be given an array that contains two strings. Your job is to create a function that will take those two strings and transpose them, so that the strings go from top to bottom instead of left to right. A few things to note: 1. There should be one ...
{"functional": "_inputs = [[['Hello', 'World']], [['joey', 'louise']], [['a', 'cat']], [['cat', '']], [['!a!a!', '?b?b']]]\n_outputs = [['H W\\ne o\\nl r\\nl l\\no d'], ['j l\\no o\\ne u\\ny i\\n s\\n e'], ['a c\\n a\\n t'], ['c \\na \\nt '], ['! ?\\na b\\n! ?\\na b\\n! ']]\nimport math\ndef _deep_eq(a, b, tol=...
142
268
coding
Solve the programming task below in a Python markdown code block. Make a function that will return a greeting statement that uses an input; your program should return, `"Hello, how are you doing today?"`. SQL: return results in a column named ```greeting``` *[Make sure you type the exact thing I wrote or the program...
{"functional": "_inputs = [['Ryan'], ['Shingles']]\n_outputs = [['Hello, Ryan how are you doing today?'], ['Hello, Shingles how are you doing today?']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i...
95
178
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data. You are given an m x n matrix mat and two integers r and c re...
{"functional": "def check(candidate):\n assert candidate(mat = [[1,2],[3,4]], r = 1, c = 4) == [[1,2,3,4]]\n assert candidate(mat = [[1,2],[3,4]], r = 2, c = 4) == [[1,2],[3,4]]\n\n\ncheck(Solution().matrixReshape)"}
179
92
coding
Solve the programming task below in a Python markdown code block. A great king of a certain country suddenly decided to visit the land of a friendly country. The country is famous for trains, and the king visits various stations. There are 52 train stations, each with a single uppercase or lowercase alphabetic name (n...
{"inputs": ["2\n1 2\nbdd\n3\n3 2 1\nDDDA\n5\n3 1 4 5 2\ndcdkIlkP\n0", "2\n1 2\nbdd\n3\n3 2 2\nDDDA\n5\n3 1 4 5 2\ndcdkIlkP\n0", "2\n1 2\nbdd\n3\n5 2 2\nDDDA\n5\n3 1 4 5 2\ndcdkIlkP\n0", "2\n1 2\nddb\n3\n3 2 1\nDDDA\n5\n3 1 4 5 3\ndcdkIlkP\n0", "2\n1 2\nbcd\n3\n3 2 1\nDDDA\n5\n3 1 4 5 2\ndcdkIlkP\n0", "2\n1 2\nadd\n3\n3...
753
451
coding
Solve the programming task below in a Python markdown code block. You have a given picture with size $w \times h$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells i...
{"inputs": ["1 1\n*\n", "1 1\n*\n", "2 2\n..\n..\n", "2 2\n..\n..\n", "3 3\n*.*\n***\n*.*\n", "3 3\n...\n...\n...\n", "3 3\n...\n..*\n.**\n", "3 3\n.*.\n***\n.*.\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]}
467
133
coding
Solve the programming task below in a Python markdown code block. *Mario has reached Bowser's Castle and is inches away from rescuing Princess Peach. He has to answer the following problem at the gate to be allowed to enter. Can you help him?* Let S(M) denote the set of all [prime] [factors] of M. Given two positive...
{"inputs": ["3\n21 63\n72 72\n25 20"], "outputs": ["YES\nYES\nNO"]}
451
34
coding
Solve the programming task below in a Python markdown code block. Count the number of divisors of a positive integer `n`. Random tests go up to `n = 500000`. ## Examples ```python divisors(4) == 3 # 1, 2, 4 divisors(5) == 2 # 1, 5 divisors(12) == 6 # 1, 2, 3, 4, 6, 12 divisors(30) == 8 # 1, 2, 3, 5, 6, 10, 15, ...
{"functional": "_inputs = [[1], [4], [5], [12], [25], [30], [4096]]\n_outputs = [[1], [3], [2], [6], [3], [8], [13]]\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 ...
176
197
coding
Solve the programming task below in a Python markdown code block. # Bubblesort Algorithm ## Overview The Bubblesort Algorithm is one of many algorithms used to sort a list of similar items (e.g. all numbers or all letters) into either ascending order or descending order. Given a list (e.g.): ```python [9, 7, 5, 3, ...
{"functional": "_inputs = [[[9, 7, 5, 3, 1, 2, 4, 6, 8]], [[1, 2]], [[2, 1]], [[1, 3]], [[3, 1]], [[24, 57]], [[89, 36]], [[1, 2, 3]], [[2, 4, 1]], [[17, 5, 11]], [[25, 16, 9]], [[103, 87, 113]], [[1032, 3192, 2864]], [[1, 2, 3, 4]], [[2, 3, 4, 1]], [[3, 4, 1, 2]], [[4, 1, 2, 3]], [[7, 5, 3, 1]], [[5, 3, 7, 7]], [[3, 1...
387
796
coding
Solve the programming task below in a Python markdown code block. Your are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array. Print $1$ if the string contains characters from the given array only els...
{"inputs": ["3\nabcd\n4\na b c d\naabbbcccdddd\n4\na b c d\nacd\n3\na b d"], "outputs": ["1\n1\n0"]}
250
45
coding
Solve the programming task below in a Python markdown code block. ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of ...
{"inputs": ["1 1\n1\n1\n1\n", "1 20\n1\n1\n200000000\n", "2 2\n1 2\n1\n200000000\n", "2 5\n1 2\n1\n200000000\n", "1 1\n42\n5\n1\n41\n42\n43\n84\n", "1 1\n42\n5\n1\n39\n42\n43\n84\n", "1 1\n1000000\n1\n200000000\n", "1 1\n1000000\n1\n179035188\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n-1\n1\n-1\n-1\n", "-1\n-...
632
239
coding
Solve the programming task below in a Python markdown code block. You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times): choose two indexes, i and j (1 ≤ i < j ≤ n; ...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n2 1\n", "2\n1 2\n", "3\n3 2 1\n", "3\n1 2 3\n"], "outputs": ["0\n", "0\n", "0\n", "1\n1 2\n", "1\n1 2\n", "0\n", "1\n1 3\n", "0\n"]}
356
114
coding
Solve the programming task below in a Python markdown code block. Your friend gave you a dequeue D as a birthday present. D is a horizontal cylinder that contains a row of N jewels. The values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values. In the beginning, you have n...
{"inputs": ["1 1\n1\n", "2 40\n770493 0\n", "1 100\n4847850\n", "6 2\n0 9 0 -1 3 2", "6 4\n-10 8 2 0 2 6", "6 4\n-10 3 2 0 2 6", "6 4\n-10 3 4 0 2 6", "6 2\n-10 3 6 0 2 6"], "outputs": ["1\n", "770493\n", "4847850\n", "9\n", "14\n", "10\n", "12\n", "8\n"]}
504
185
coding
Solve the programming task below in a Python markdown code block. I'm new to coding and now I want to get the sum of two arrays...actually the sum of all their elements. I'll appreciate for your help. P.S. Each array includes only integer numbers. Output is a number too. Also feel free to reuse/extend the following st...
{"functional": "_inputs = [[[1, 2, 3], [4, 5, 6]], [[-1, -2, -3], [-4, -5, -6]], [[0, 0, 0], [4, 5, 6]], [[100, 200, 300], [400, 500, 600]]]\n_outputs = [[21], [-21], [15], [2100]]\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_to...
86
252
coding
Solve the programming task below in a Python markdown code block. Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make...
{"inputs": ["1 1 2\n", "2 2 1\n", "2 1 1\n", "2 1 2\n", "4 2 5\n", "1 2 1\n", "9 5 1\n", "1 1 1\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
586
102
coding
Solve the programming task below in a Python markdown code block. How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl'f fubrf. I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it? According to Wikipedia, ROT13 (http://en.wiki...
{"functional": "_inputs = [['EBG13 rknzcyr.'], [\"How can you tell an extrovert from an\\nintrovert at NSA? Va gur ryringbef,\\ngur rkgebireg ybbxf ng gur BGURE thl'f fubrf.\"], ['123'], ['Guvf vf npghnyyl gur svefg xngn V rire znqr. Gunaxf sbe svavfuvat vg! :)'], ['@[`{']]\n_outputs = [['ROT13 example.'], [\"Ubj pna l...
215
341
coding
Solve the programming task below in a Python markdown code block. The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it. In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different ...
{"inputs": ["4\nrgbBRG\nRgbrBG\nbBrRgG\nrgRGBb\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
482
39
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are currently designing a dynamic array. You are given a 0-indexed integer array nums, where nums[i] is the number of elements that will be in the array at time i. In addition, you are given an integer k, the maxi...
{"functional": "def check(candidate):\n assert candidate(nums = [10,20], k = 0) == 10\n assert candidate(nums = [10,20,30], k = 1) == 10\n assert candidate(nums = [10,20,15,30,20], k = 2) == 15\n\n\ncheck(Solution().minSpaceWastedKResizing)"}
236
102
coding
Solve the programming task below in a Python markdown code block. There is a $n \times m$ grid. You are standing at cell $(1, 1)$ and your goal is to finish at cell $(n, m)$. You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell $(x, y)$. You can: move right to t...
{"inputs": ["6\n1 1 0\n2 2 2\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\n", "6\n1 1 0\n2 2 4\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\n", "6\n1 1 0\n2 2 4\n2 2 3\n2 2 4\n1 4 2\n100 100 10000\n", "6\n1 1 0\n2 2 4\n3 2 3\n2 2 4\n1 4 3\n100 100 10000\n", "6\n1 1 0\n2 2 4\n2 2 2\n2 2 4\n1 4 2\n100 100 10000\n", "6\n1 1 1\n2 2 4\n2 2 2...
548
502
coding
Solve the programming task below in a Python markdown code block. Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post offic...
{"inputs": ["1\n1\n1\n", "1\n0\n0\n", "1\n2\n2\n", "1\n3\n3\n", "1\n4\n4\n", "3\n3 3 3\n3 2 4\n", "4\n0 7 2 3\n8 1 0 3\n", "4\n1 7 2 3\n9 1 0 3\n"], "outputs": ["1\n1 \n", "1\n1 ", "1\n1 ", "1\n1 ", "1\n1 ", "3\n1 2 3 \n", "2\n2 4 ", "2\n2 4 "]}
738
155
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A substring is a contiguous (non-empty) sequence of characters within a string. A vowel substring is a substring that only consists of vowels ('a', 'e', 'i', 'o', and 'u') and has all five vowels present in it. Given ...
{"functional": "def check(candidate):\n assert candidate(word = \"aeiouu\") == 2\n assert candidate(word = \"unicornarihan\") == 0\n assert candidate(word = \"cuaieuouac\") == 7\n assert candidate(word = \"bbaeixoubb\") == 0\n\n\ncheck(Solution().countVowelSubstrings)"}
117
83
coding
Solve the programming task below in a Python markdown code block. Given a string, return the minimal number of parenthesis reversals needed to make balanced parenthesis. For example: ```Javascript solve(")(") = 2 Because we need to reverse ")" to "(" and "(" to ")". These are 2 reversals. solve("(((())") = 1 We need...
{"functional": "_inputs = [[')()('], ['((()'], ['((('], ['())((('], ['())()))))()()(']]\n_outputs = [[2], [1], [-1], [3], [4]]\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...
152
189
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 32-bit integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used. All the letters in the answer string should be lowercase characters, and...
{"functional": "def check(candidate):\n assert candidate(num = 26) == \"1a\"\n assert candidate(num = -1) == \"ffffffff\"\n\n\ncheck(Solution().toHex)"}
124
47
coding
Solve the programming task below in a Python markdown code block. Each pizza consists of 4 slices. There are N friends and each friend needs exactly X slices. Find the minimum number of pizzas they should order to satisfy their appetite. ------ Input Format ------ - The first line of input will contain a single in...
{"inputs": ["4\n1 5\n2 6\n4 3\n3 5\n"], "outputs": ["2\n3\n3\n4\n"]}
383
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size...
{"functional": "def check(candidate):\n assert candidate(packages = [2,3,5], boxes = [[4,8],[2,8]]) == 6\n assert candidate(packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]) == -1\n assert candidate(packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]) == 9\n\n\ncheck(Solution().minWastedSpace)"}
371
126
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of integers $a_1, a_2, ..., a_N$. An element ak is said to be an average element if there are indices $i, j$ (with $i \neq j$) such that $a_k = \frac{a_i + a_j}{2}$. In the sequence 371022171537102217153 \quad 7 \quad 10 \quad 2...
{"inputs": ["5\n3\n7\n10\n3\n18", "5\n3\n8\n11\n17\n30", "6\n3\n7\n10\n17\n22\n15"], "outputs": ["2", "0", "1"]}
688
65
coding
Solve the programming task below in a Python markdown code block. Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions ...
{"inputs": ["1 1 2\n1\n2\n", "1 1 1\n1\n1\n", "2 2 1\n1 2\n1 2\n", "2 2 1\n1 2\n2 1\n", "2 2 1\n1 2\n4 1\n", "2 2 1\n1 1\n4 1\n", "2 2 1\n2 1\n4 1\n", "2 2 1\n2 1\n4 2\n"], "outputs": ["0\n", "1\n1 ", "1\n1 ", "1\n1 ", "0\n", "0\n", "0\n", "0\n"]}
341
161
coding
Solve the programming task below in a Python markdown code block. Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good. Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three condit...
{"inputs": ["1\n1\n", "1\n4\n", "1\n2\n", "1\n8\n", "1\n3\n", "1\n7\n", "1\n9\n", "1\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
378
86
coding
Solve the programming task below in a Python markdown code block. Takahashi has a string S of length N consisting of digits from 0 through 9. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integ...
{"inputs": ["4 3\n2919", "4 1\n2020", "4 3\n1541", "4 3\n3041", "4 2\n3041", "4 6\n1793", "4 4\n3041", "4 2\n1173"], "outputs": ["4\n", "10\n", "2\n", "3\n", "5\n", "1\n", "6\n", "0\n"]}
400
119
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted array of integers, write a method to find a magic index, if one exists, in array A. If not, return -1. If there are mor...
{"functional": "def check(candidate):\n assert candidate(nums = [0, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 1, 1]) == 1\n\n\ncheck(Solution().findMagicIndex)"}
123
62
coding
Solve the programming task below in a Python markdown code block. Finding your seat on a plane is never fun, particularly for a long haul flight... You arrive, realise again just how little leg room you get, and sort of climb into the seat covered in a pile of your own stuff. To help confuse matters (although they cla...
{"functional": "_inputs = [['2B'], ['20B'], ['58I'], ['60D'], ['17K']]\n_outputs = [['Front-Left'], ['Front-Left'], ['No Seat!!'], ['Back-Middle'], ['Front-Right']]\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=t...
255
197
coding
Solve the programming task below in a Python markdown code block. Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than durin...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "5 6 3\n5 4 3 2 1\n", "5 6 3\n5 5 5 5 5\n", "5 6 3\n1 2 1 1 1\n", "5 6 3\n1 2 2 1 1\n", "5 6 3\n5 4 6 2 1\n"], "outputs": ["1\n", "1\n", "1\n", "5\n", "10\n", "2\n", "3\n", "6\n"]}
641
159
coding
Solve the programming task below in a Python markdown code block. Archith was a making noise in digital logic class.Sir was very frustrated by the behaviour of Archith. Sir asked archith to meet him in staff room. As archith reached staff room sir gave a smile and asked to complete this assignment in one day if not he ...
{"inputs": ["20\n212245523\n546843625\n456431356\n546463364\n584651321\n352145896\n53\n2\n32\n32\n32692\n32646\n41354\n4351\n312\n524\n54365\n58421\n54213\n23452"], "outputs": ["odd\nodd\nodd\nodd\nodd\neven\neven\nodd\nodd\nodd\nodd\neven\neven\nodd\neven\nodd\nodd\neven\nodd\nodd"]}
213
183
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. Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '$\rightarrow$', and the arguments an...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n1 1\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n"], "outputs": ["YES\n0\n", "NO\n", "NO", "YES\n0", "NO\n", "NO\n", "NO\n", "YES\n1->0\n"]}
724
100
coding
Solve the programming task below in a Python markdown code block. A core idea of several left-wing ideologies is that the wealthiest should *support* the poorest, no matter what and that is exactly what you are called to do using this kata (which, on a side note, was born out of the necessity to redistribute the width ...
{"functional": "_inputs = [[[2, 3, 5, 15, 75], 5], [[2, 3, 5, 15, 75], 20], [[2, 3, 5, 45, 45], 5], [[2, 3, 5, 45, 45], 30], [[24, 48, 22, 19, 37], 30]]\n_outputs = [[[5, 5, 5, 15, 70]], [[20, 20, 20, 20, 20]], [[5, 5, 5, 42, 43]], [[]], [[30, 30, 30, 30, 30]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinst...
669
332
coding
Solve the programming task below in a Python markdown code block. Sereja has two integers — A and B — in 7-ary system. He wants to calculate the number C, such that B * C = A. It is guaranteed that B is a divisor of A. Please, help Sereja calculate the number C modulo 7L. -----Input----- First line of input contains...
{"inputs": ["3\n21\n5\n10\n202\n13\n1\n202\n13\n2"], "outputs": ["3\n3\n13"]}
320
43
coding
Solve the programming task below in a Python markdown code block. William has a favorite bracket sequence. Since his favorite sequence is quite big he provided it to you as a sequence of positive integers $c_1, c_2, \dots, c_n$ where $c_i$ is the number of consecutive brackets "(" if $i$ is an odd number or the number ...
{"inputs": ["1\n6\n", "1\n6\n", "1\n7\n", "2\n49 1\n", "2\n49 1\n", "2\n15 1\n", "3\n1 2 39\n", "3\n1 2 39\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
544
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: "../" : Move to the parent folder of the current folder. (If you are already in the mai...
{"functional": "def check(candidate):\n assert candidate(logs = [\"d1/\",\"d2/\",\"../\",\"d21/\",\"./\"]) == 2\n assert candidate(logs = [\"d1/\",\"d2/\",\"./\",\"d3/\",\"../\",\"d31/\"]) == 3\n assert candidate(logs = [\"d1/\",\"../\",\"../\",\"../\"]) == 0\n\n\ncheck(Solution().minOperations)"}
191
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other inters...
{"functional": "def check(candidate):\n assert candidate(n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]) == 4\n assert candidate(n = 2, roads = [[1,0,10]]) == 1\n\n\ncheck(Solution().countPaths)"}
219
116
coding
Solve the programming task below in a Python markdown code block. Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of...
{"inputs": ["1 1 1\n.\n", "1 1 1\n*\n", "1 1 1\n.\n", "1 1 1\n*\n", "1 2 2\n..\n", "1 2 1\n..\n", "1 2 3\n..\n", "1 2 2\n..\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "2\n", "0\n", "1\n"]}
421
118
coding
Solve the programming task below in a Python markdown code block. You are given a length of string and two thumbtacks. On thumbtack goes into the focus point *F₀* with coordinates *x₀* and *y₀*, and the other does into point *F₁* with points *x₁* and *y₁*. The string is then tied at the ends to the thumbtacks and has l...
{"functional": "_inputs = [[{'x': 0, 'y': 0}, {'x': 0, 'y': 0}, 2, {'x': 0, 'y': 0}], [{'x': 0, 'y': 0}, {'x': 0, 'y': 0}, 2, {'x': 1, 'y': 1}]]\n_outputs = [[True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol,...
267
236
coding
Solve the programming task below in a Python markdown code block. Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set ...
{"inputs": ["9 1 31\n2 3 3\n3 3 19\n16 10 3\n20 3 45\n20 8 19\n20 20 155\n3 6 6\n3 3 15\n0 0 0", "9 3 31\n2 3 3\n10 3 28\n16 6 87\n20 3 102\n20 8 19\n20 20 155\n3 6 6\n3 3 15\n0 0 0", "9 3 5\n9 1 22\n10 3 28\n16 10 107\n26 1 102\n20 10 21\n20 10 2\n3 4 3\n4 2 6\n0 0 0", "9 6 23\n2 3 3\n8 3 41\n16 10 87\n20 3 102\n20 2 ...
458
786
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string array words. Two strings are similar if they consist of the same characters. For example, "abca" and "cba" are similar since both consist of characters 'a', 'b', and 'c'. However, "ab...
{"functional": "def check(candidate):\n assert candidate(words = [\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]) == 2\n assert candidate(words = [\"aabb\",\"ab\",\"ba\"]) == 3\n assert candidate(words = [\"nba\",\"cba\",\"dba\"]) == 0\n\n\ncheck(Solution().similarPairs)"}
163
81
coding
Solve the programming task below in a Python markdown code block. Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees. There are $n$ t...
{"inputs": ["4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5\n"], "outputs": ["2\n13\n36\n33\n"]}
619
63
coding
Solve the programming task below in a Python markdown code block. You have a digit sequence S of length 4. You are wondering which of the following formats S is in: - YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order - MMYY...
{"inputs": ["3367", "2206", "1291", "1211", "2352", "2340", "2265", "2454"], "outputs": ["NA\n", "YYMM\n", "MMYY\n", "AMBIGUOUS\n", "NA\n", "NA\n", "NA\n", "NA\n"]}
248
91
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"]. Given two sentences sentence1 and sentence2 each ...
{"functional": "def check(candidate):\n assert candidate(sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"good\"],[\"fine\",\"good\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]) == True\n assert candidate(sentence1 = [\"I\",\"love\",\"le...
253
209
coding
Solve the programming task below in a Python markdown code block. Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer. We all know that programs often store sets of integers. For example, if we have a problem about a wei...
{"inputs": ["1\nint\n", "2\nint int\n", "1\npair iot\n", "1\npair ins\n", "1\npair int\n", "2\npair int int\n", "2\nint pair int\n", "1\nint pair pair\n"], "outputs": ["int\n", "Error occurred\n", "Error occurred\n", "Error occurred\n", "Error occurred\n", "pair<int,int>\n", "Error occurred\n", "Error occurred\n"]}
632
106
coding
Solve the programming task below in a Python markdown code block. Complete the solution. It should try to retrieve the value of the array at the index provided. If the index is out of the array's max bounds then it should return the default value instead. Example: ```Haskell solution [1..3] 1 1000 `shouldBe` 2 soluti...
{"functional": "_inputs = [[[None, None], 0, 'a']]\n_outputs = [[None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
338
161
coding
Solve the programming task below in a Python markdown code block. Casimir has a string $s$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions: he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the s...
{"inputs": ["6\nABACAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCBCBCBC\n", "6\nABACAB\nABBA\nAC\nABC\nCABCBB\nCBCBCBCBCBCBCBCB\n", "6\nABACAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCACBCBC\n", "6\nABACAB\nABBA\nBC\nABB\nCABCBB\nCBCBCBCBCBCBCBCB\n", "6\nABBCAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCACBCBC\n", "6\nABACAC\nABBA\nAC\nACB\nC...
489
342
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has three spells. Their powers are A, B, and C respectively. Initially, Chef has 0 hit points, and if he uses a spell with power P, then his number of hit points...
{"inputs": ["2\n4 2 8\n10 14 18"], "outputs": ["12\n32"]}
413
31
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has obtained the results of a past Cook-Off. He wants to estimate the skill level of each contestant. The contestants can be classified with high probability (w.h.p.) ba...
{"inputs": ["7\n0 0 0 0 0\n0 1 0 1 0\n0 0 1 0 0\n1 1 1 1 1\n0 1 1 1 0\n0 1 1 1 1\n1 1 1 1 0"], "outputs": ["Beginner\nMiddle Developer\nJunior Developer\nJeff Dean\nSenior Developer\nHacker\nHacker"]}
571
101
coding
Solve the programming task below in a Python markdown code block. Given a sequence A of length N, the weight of this sequence is defined as \text{weight}(A) = \sum_{i = 1}^{N} i\cdot A_{i} Given an integer N, we pick a permutation A of [1, 2 \dots N] uniformly at random. What is the expected weight of this permutatio...
{"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n499122181\n12\n"]}
634
33
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums with the following properties: nums.length == 2 * n. nums contains n + 1 unique elements. Exactly one element of nums is repeated n times. Return the element that is repeated n ti...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,3]) == 3\n assert candidate(nums = [2,1,2,5,3,2]) == 2\n assert candidate(nums = [5,1,5,2,5,3,5,4]) == 5\n\n\ncheck(Solution().repeatedNTimes)"}
97
87
coding
Solve the programming task below in a Python markdown code block. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print -1 instead. -----Constraints----- - 2 \leq N \leq 10^5 - 0 \leq A_i \leq 10^{18} - All values in input are integers. -----Input----- Inp...
{"inputs": ["3\n011 1 315218201", "3\n001 188 468791915", "3\n011 188 468791915", "3\n011 291 468791915", "3\n011 133 468791915", "3\n011 133 735631313", "3\n011 133 315218201", "3\n101 2947 468791915"], "outputs": ["3467400211\n", "88132880020\n", "969461680220\n", "1500602919915\n", "685842571645\n", "1076228610919\n...
257
295
coding
Solve the programming task below in a Python markdown code block. There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough carrots to ...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 4\n6\n", "1 4\n19\n", "1 8\n19\n", "1 4\n19\n", "1 15\n19\n", "3 6\n5 3 1\n"], "outputs": ["1\n", "1\n", "10\n", "91\n", "47\n", "91\n", "27\n", "15\n"]}
440
117
coding
Solve the programming task below in a Python markdown code block. You are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \le Z \le N$ and $(X \oplus Z) < (Y \oplus Z)$, where $\oplus$ denotes the bitwise XOR operation. -----Input----- - The first line of the input cont...
{"inputs": ["3\n1 2 10\n2 1 10\n0 0 7"], "outputs": ["6\n5\n0"]}
281
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(l...
{"functional": "def check(candidate):\n assert candidate(nums = [5,7,7,8,8,10], target = 8) == [3,4]\n assert candidate(nums = [5,7,7,8,8,10], target = 6) == [-1,-1]\n assert candidate(nums = [], target = 0) == [-1,-1]\n\n\ncheck(Solution().searchRange)"}
109
99
coding
Solve the programming task below in a Python markdown code block. You are given a pair of integers $(a, b)$ and an integer $x$. You can change the pair in two different ways: set (assign) $a := |a - b|$; set (assign) $b := |a - b|$, where $|a - b|$ is the absolute difference between $a$ and $b$. The pair $(a, b)$ ...
{"inputs": ["1\n4398046511104 4398050705408 8388608\n", "8\n6 9 3\n15 38 7\n18 8 8\n30 30 30\n40 50 90\n24 28 20\n365 216 52\n537037812705867558 338887693834423551 3199921013340\n"], "outputs": ["YES\n", "YES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n"]}
466
183
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef likes problems involving arrays. Unfortunately, the last one he tried to solve didn't quite get solved. Chef has an array A of N positive numbers. He wants to find the ...
{"inputs": ["3\n3\n1 3 2\n4\n4 1 2 1\n6\n1 2 2 2 2 1", "3\n3\n1 3 2\n4\n4 1 3 1\n6\n1 2 2 2 2 1", "3\n3\n1 3 2\n4\n4 1 3 1\n6\n1 2 2 0 2 1", "3\n3\n1 3 2\n4\n4 1 3 1\n6\n1 1 2 0 2 1", "3\n3\n1 3 2\n4\n4 2 3 1\n6\n1 2 2 2 2 1", "3\n3\n1 5 2\n4\n4 2 3 1\n6\n1 2 2 2 2 1", "3\n3\n1 3 3\n4\n4 1 3 1\n6\n1 0 2 0 2 1", "3\n3\n...
362
349
coding
Solve the programming task below in a Python markdown code block. Master Shifu is training Po to become The Dragon Warrior and as a final assignment he must obtain maximum deliciousness from dumplings. There are $N$ plates of dumplings in front of him with deliciousness $A_1, A_2, \ldots, A_N$, Po can choose any numbe...
{"inputs": ["2\n4\n1 2 3 4\n5\n3 2 0 3 0"], "outputs": ["4\n4"]}
313
36
coding
Solve the programming task below in a Python markdown code block. Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls ar...
{"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "3 2\n2 1 2\n1 3\n", "3 2\n1 2\n2 1 3\n", "3 2\n1 2\n2 1 3\n", "3 2\n2 1 2\n1 3\n", "5 3\n1 4\n3 1 2 3\n1 5\n", "5 3\n1 4\n3 1 2 3\n1 5\n"], "outputs": ["0\n", "0", "1\n", "3\n", "3", "1", "2\n", "2"]}
742
162
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Dobby loves playing games, especially games related to numbers. So, today Bhuvan gave him a new game. The description of the game goes as follows : Consider an array A...
{"inputs": ["3\n2 0 1"], "outputs": ["4"]}
479
18
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are very good friends and they always distribute all the eatables equally among themselves. Alice has A chocolates and Bob has B chocolates. Determine whether Alice and Bob can distribute all the chocolates equally among themselves. Note ...
{"inputs": ["4\n1 1\n1 3\n1 2\n1 4\n"], "outputs": ["YES\nYES\nNO\nNO\n"]}
433
36
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. In Chefland, each person has their own non-empty personal string. When two people with personal strings $T_{1}$ and $T_{2}$ (possibly identical) bec...
{"inputs": ["3\nabcd\naaaa\nababcdccdc"], "outputs": ["0\n1\n1"]}
501
25
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931"]}
231
73
coding
Solve the programming task below in a Python markdown code block. You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts. Suppose you decided to sell packs with $a$ cans in a pack with a discount and some cu...
{"inputs": ["3\n3 4\n1 2\n120 150\n", "3\n3 4\n1 2\n120 150\n", "1\n000000101 821042\n", "1\n000000101 321987\n", "1\n000001101 321987\n", "1\n10485760 20971520\n", "1\n20971520 41943040\n", "1\n10485760 20971520\n"], "outputs": ["YES\nNO\nYES\n", "YES\nNO\nYES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
612
215
coding
Solve the programming task below in a Python markdown code block. You are given a set S of strings consisting of `0` and `1`, and an integer K. Find the longest string that is a subsequence of K or more different strings in S. If there are multiple strings that satisfy this condition, find the lexicographically smalle...
{"inputs": ["2 5\n0\n11\n1111", "3 0\n1\n3\n1111\n01000110", "3 2\n1\n2\n1011\n01001110", "3 2\n1\n2\n1011\n01000110", "3 2\n1\n2\n1111\n01000110", "3 2\n1\n3\n1111\n01000110", "3 0\n1\n3\n1111\n00000110", "3 2\n1\n2\n1111\n01001110"], "outputs": ["", "000\n", "00\n", "00\n", "00\n", "00\n", "000\n", "00\n"]}
531
221
coding
Solve the programming task below in a Python markdown code block. Chef considers a permutation P of \{1, 2, 3, \dots, N\} End Sorted if and only if P_{1} = 1 and P_{N} = N. Chef is given a permutation P. In one operation Chef can choose any index i \ (1 ≤ i ≤ N-1) and swap P_{i} and P_{i+1}. Determine the minimum num...
{"inputs": ["4\n4\n1 3 2 4\n3\n3 2 1\n2\n2 1\n3\n2 1 3\n"], "outputs": ["0\n3\n1\n1\n"]}
587
52
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row ...
{"functional": "def check(candidate):\n assert candidate(wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]) == 2\n assert candidate(wall = [[1],[1],[1]]) == 3\n\n\ncheck(Solution().leastBricks)"}
197
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed strings word1 and word2. A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j]. Return true if it is ...
{"functional": "def check(candidate):\n assert candidate(word1 = \"ac\", word2 = \"b\") == False\n assert candidate(word1 = \"abcc\", word2 = \"aab\") == True\n assert candidate(word1 = \"abcde\", word2 = \"fghij\") == True\n\n\ncheck(Solution().isItPossible)"}
140
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative. Initially every stu...
{"functional": "def check(candidate):\n assert candidate(positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is studious\",\"the student is smart\"], student_id = [1,2], k = 2) == [1,2]\n assert candidate(positive_feedback = [\"smart\",\"brilliant\",...
240
146
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign....
{"functional": "def check(candidate):\n assert candidate(sentence = \"there are $1 $2 and 5$ candies in the shop\", discount = 50) == \"there are $0.50 $1.00 and 5$ candies in the shop\"\n assert candidate(sentence = \"1 2 $3 4 $5 $6 7 8$ $9 $10$\", discount = 100) == \"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$\"\n...
201
144
coding
Solve the programming task below in a Python markdown code block. Takahashi is standing on a multiplication table with infinitely many rows and columns. The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1). In one move, he can move from (i,j) to either (i+1,j) or (i,j+1). Given an...
{"inputs": ["5", "1", "2", "3", "6", "2\n", "83", "19"], "outputs": ["4\n", "0\n", "1\n", "2\n", "3\n", "1\n", "82\n", "18\n"]}
206
67
coding
Solve the programming task below in a Python markdown code block. ## Story > "You have serious coding skillz? You wannabe a [scener](https://en.wikipedia.org/wiki/Demoscene)? Complete this mission and u can get in teh crew!" You have read a similar message on your favourite [diskmag](https://en.wikipedia.org/wiki/Dis...
{"functional": "_inputs = [['Hello World!', 3, 10], [\"I'm a Codewars warrior lately...\", 5, 18]]\n_outputs = [[' H\\n e\\n l\\n l\\n o\\n \\n W\\no\\nr\\n l\\n d\\n !'], [\" I\\n '\\n m\\n \\n a\\n \\n C\\n o\\n d\\n e\...
498
336