task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n binary matrix mat, return the number of submatrices that have all ones.   Please complete the following python code precisely: ```python class Solution: def numSubmat(self, mat: List[List[int]]) -> ...
{"functional": "def check(candidate):\n assert candidate(mat = [[1,0,1],[1,1,0],[1,1,0]]) == 13\n assert candidate(mat = [[0,1,1,0],[0,1,1,1],[1,1,1,0]]) == 24\n\n\ncheck(Solution().numSubmat)"}
71
84
coding
Solve the programming task below in a Python markdown code block. Rahul is assigned a task by his fellow mates.He has to take a string from somewhere and first of all he has to calculate the weight of that string.The weight of string is calculated by adding the ASCII values of each characters in that string and then di...
{"inputs": ["Hello", "Worldd", "Hello World"], "outputs": ["olleH", "d", "l"]}
237
27
coding
Solve the programming task below in a Python markdown code block. Two words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other. The output can be in anyorder. -----Input----- First line c...
{"inputs": ["3\n3\nnope qwerty hope\n5\nbrain drain request grain nest\n4\nthese words dont rhyme"], "outputs": ["Case : 1\nhope nope\nqwerty\nCase : 2\nbrain drain grain\nnest request\nCase : 3\nthese\ndont\nwords\nrhyme"]}
326
72
coding
Solve the programming task below in a Python markdown code block. Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is o...
{"inputs": ["0\n", "9\n", "8\n", "4\n", "7\n", "6\n", "5\n", "2\n"], "outputs": ["1\n", "48\n", "44\n", "20\n", "36\n", "32\n", "28\n", "8\n"]}
267
76
coding
Solve the programming task below in a Python markdown code block. LiLand is a country, consisting of n cities. The cities are numbered from 1 to n. The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel between the cities, but the fl...
{"inputs": ["3 3\n1 2\n2 3\n1 3\n", "4 3\n1 2\n2 3\n3 4\n1 4\n", "4 4\n1 2\n2 3\n3 4\n1 3\n", "4 2\n1 2\n2 4\n3 4\n1 4\n", "4 3\n1 2\n2 3\n3 4\n1 3\n", "4 3\n1 2\n2 3\n3 4\n2 3\n", "4 3\n1 2\n2 3\n3 4\n1 5\n", "4 3\n1 2\n2 3\n3 4\n0 3\n"], "outputs": ["Yes\n1\n1\n2\n", "Yes\n2\n2\n2\n", "Yes\n1\n1\n2\n2\n", "Yes\n2\n2\...
514
258
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. Consider the string `"1 2 36 4 8"`. Lets take pairs of these numbers, concatenate each pair and determine how many of them of divisible by `k`. ```Pearl If k = 3, we get following numbers ['12', '18', '21', '24', '42', '48', '81', '84'], all divisible...
{"functional": "_inputs = [['1 2 36 4 8', 2], ['1 2 36 4 8', 3], ['1 2 36 4 8', 4], ['1 2 36 4 8', 8]]\n_outputs = [[16], [8], [11], [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, (...
342
222
coding
Solve the programming task below in a Python markdown code block. Chef is good at making pancakes. Generally he gets requests to serve N pancakes at once. He serves them in the form of a stack. A pancake can be treated as a circular disk with some radius. Chef needs to take care that when he places a pancake on the to...
{"inputs": ["2\n1\n2", "2\n0\n2", "2\n0\n4", "2\n0\n5", "2\n0\n6", "2\n0\n8", "2\n1\n8", "2\n2\n8"], "outputs": ["1\n2", "0\n2\n", "0\n15\n", "0\n52\n", "0\n203\n", "0\n4140\n", "1\n4140\n", "2\n4140\n"]}
272
122
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 of length n. Assume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow: F(k) = 0 * arrk[0] + 1 * arrk[1] +...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,6]) == 26\n assert candidate(nums = [100]) == 0\n\n\ncheck(Solution().maxRotateFunction)"}
164
53
coding
Solve the programming task below in a Python markdown code block. William has array of $n$ numbers $a_1, a_2, \dots, a_n$. He can perform the following sequence of operations any number of times: Pick any two items from array $a_i$ and $a_j$, where $a_i$ must be a multiple of $2$ $a_i = \frac{a_i}{2}$ $a_j = a_j \cd...
{"inputs": ["5\n3\n6 4 2\n5\n1 2 3 4 5\n1\n10\n3\n2 3 4\n15\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"], "outputs": ["50\n46\n10\n26\n35184372088846\n"]}
632
105
coding
Solve the programming task below in a Python markdown code block. This kata is part of the collection [Mary's Puzzle Books](https://www.codewars.com/collections/marys-puzzle-books). Mary brought home a "spot the differences" book. The book is full of a bunch of problems, and each problem consists of two strings that a...
{"functional": "_inputs = [['abcdefg', 'abcqetg'], ['Hello World!', 'hello world.'], ['FixedGrey', 'FixedGrey'], ['HACKER', 'H4CK3R'], ['This is a really long sentence.', 'That is a_really long sentence,'], ['', ''], ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba'], ['YOLO lol', 'ROLO mom'], ['www.youtube.c...
319
472
coding
Solve the programming task below in a Python markdown code block. A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously. He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from t...
{"inputs": ["2\n8\n2", "2\n8\n4", "2\n4\n4", "2\n8\n6", "2\n4\n1", "2\n4\n0", "2\n10\n4", "2\n10\n6"], "outputs": ["0\n", "0\n", "0\n", "2\n", "0\n", "1\n", "1\n", "4\n"]}
305
96
coding
Solve the programming task below in a Python markdown code block. Stephanie just learned about a game called Nim in which there are two players and $n$ piles of stones. During each turn, a player must choose any non-empty pile and take as many stones as they want. The first player who cannot complete their turn (i.e., ...
{"inputs": ["2 2\n"], "outputs": ["6\n"]}
393
16
coding
Solve the programming task below in a Python markdown code block. The internet is a very confounding place for some adults. Tom has just joined an online forum and is trying to fit in with all the teens and tweens. It seems like they're speaking in another language! Help Tom fit in by translating his well-formatted Eng...
{"functional": "_inputs = [['Hi, how are you today?'], ['I think it would be nice if we could all get along.'], [\"Let's eat, Grandma!\"], ['Woot woot woot woot woot woot!'], ['Hi, I can have cheeseburger?'], ['Sometimes I use ? in the middle of a sentence; is that ok?!'], ['Unto us a child is born.'], ['What happened ...
713
708
coding
Solve the programming task below in a Python markdown code block. Given $n$ two-dimensional points in space, determine whether they lie on some vertical or horizontal line. If yes, print YES; otherwise, print NO. Input Format The first line contains a single positive integer, $n$, denoting the number of points. Eac...
{"inputs": ["5\n0 1\n0 2\n0 3\n0 4\n0 5\n", "5\n0 1\n0 2\n1 3\n0 4\n0 5\n"], "outputs": ["YES\n", "NO\n"]}
268
62
coding
Solve the programming task below in a Python markdown code block. You are given positive integers A and B. Find the K-th largest positive integer that divides both A and B. The input guarantees that there exists such a number. -----Constraints----- - All values in input are integers. - 1 \leq A, B \leq 100 - The K-...
{"inputs": ["2 1 1", "4 8 1", "1 1 1", "1 1 1\n", "12 3 2", "8 12 3", "6 12 2", "16 1 1"], "outputs": ["1\n", "4\n", "1", "1\n", "1\n", "1\n", "3\n", "1\n"]}
180
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone. A stone can be removed if it shares either the same row or the same column as another stone that ha...
{"functional": "def check(candidate):\n assert candidate(stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]) == 5\n assert candidate(stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]) == 3\n assert candidate(stones = [[0,0]]) == 0\n\n\ncheck(Solution().removeStones)"}
139
101
coding
Solve the programming task below in a Python markdown code block. There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only p levels of the game. And Little Y can pass only q levels o...
{"inputs": ["1\n0\n0\n", "1\n0\n0\n", "1\n0\n1 1\n", "1\n1 1\n0\n", "100\n0\n0\n", "1\n0\n1 1\n", "1\n1 1\n0\n", "100\n0\n0\n"], "outputs": ["Oh, my keyboard!\n", "Oh, my keyboard!\n", "I become the guy.\n", "I become the guy.\n", "Oh, my keyboard!\n", "I become the guy.\n", "I become the guy.\n", "Oh, my keyboard!\n"]...
363
146
coding
Solve the programming task below in a Python markdown code block. Your task is to define a function that understands basic mathematical expressions and solves them. For example: ```python calculate("1 + 1") # => 2 calculate("18 + 4*6") # => 42 calculate("245 - 826") # => -581 calculate("09 + 000482") # ...
{"functional": "_inputs = [['1 + 1'], ['9 - 4'], ['1 - 4'], ['3 * 4'], ['9 / 3'], ['26 + 73'], ['524 + 277'], ['1 / 2'], ['2 / 5'], ['1 + 2 + 3 + 4 + 5 + 6'], ['123 - 3 - 20 - 100'], ['123 * 987 * 135 * 246'], ['200 / 2 / 10 / 5'], ['1+2-3+4-5+6-7+8-9+10'], ['5*2/3*9/10*123/8'], ['1*2*3/1/2/3+1+2+3-1-2-3'], ['1+2 * 4']...
334
528
coding
Solve the programming task below in a Python markdown code block. Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages. Recent actions shows a list of n differen...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 2 3\n", "3\n2 1 3\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
540
102
coding
Solve the programming task below in a Python markdown code block. This is the hard version of this problem. The only difference between the easy and hard versions is the constraints on $k$ and $m$. In this version of the problem, you need to output the answer by modulo $10^9+7$. You are given a sequence $a$ of length ...
{"inputs": ["3\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n", "4\n4 3 2\n1 2 4 3\n4 2 1\n1 1 1 1\n1 1 1\n1\n10 4 3\n5 6 1 3 2 9 8 1 2 4\n", "4\n4 3 2\n1 2 4 3\n4 3 2\n1 1 1 1\n1 3 1\n1\n10 3 2\n5 6 1 3 2 9 8 1 2 4\n"], "outputs": ["1\n1\n1\n", "2\n6\n1\n20\n", "2\n4\n0\n15\n"]}
702
198
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.   Please complete the following python code precisely: ```python class Solution...
{"functional": "def check(candidate):\n assert candidate(nums = [-4,-1,0,3,10]) == [0,1,9,16,100]\n assert candidate(nums = [-7,-3,2,3,11]) == [4,9,9,49,121]\n\n\ncheck(Solution().sortedSquares)"}
78
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix mat and an integer target. Choose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized. Return ...
{"functional": "def check(candidate):\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]], target = 13) == 0\n assert candidate(mat = [[1],[2],[3]], target = 100) == 94\n assert candidate(mat = [[1,2,9,8,7]], target = 6) == 1\n\n\ncheck(Solution().minimizeTheDifference)"}
119
104
coding
Solve the programming task below in a Python markdown code block. "You must lift the dam. With a lever. I will give it to you. You must block the canal. With a rock. I will not give the rock to you." Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them....
{"inputs": ["1\n1\n1000000000\n", "1\n1\n1000000000\n", "1\n1\n1000000001\n", "1\n1\n1000001001\n", "1\n1\n1000011001\n", "1\n1\n1000111001\n", "1\n1\n1000101001\n", "1\n1\n1000101101\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
508
174
coding
Solve the programming task below in a Python markdown code block. An ordered sequence of numbers from 1 to N is given. One number might have deleted from it, then the remaining numbers were mixed. Find the number that was deleted. Example: - The starting array sequence is `[1,2,3,4,5,6,7,8,9]` - The mixed array wit...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 7, 9, 4, 8, 1, 2, 3]], [[1, 2, 3, 4, 5, 6, 7], [2, 3, 6, 1, 5, 4, 7]], [[1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 7, 6, 9, 4, 8, 1, 2, 3]], [[1], []], [[], []]]\n_outputs = [[6], [0], [0], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, flo...
186
320
coding
Solve the programming task below in a Python markdown code block. You have an n × m rectangle table, its cells are not initially painted. Your task is to paint all cells of the table. The resulting picture should be a tiling of the table with squares. More formally: each cell must be painted some color (the colors are...
{"inputs": ["1 3\n", "2 2\n", "3 4\n", "4 3\n", "1 1\n", "2 3\n", "3 2\n", "1 2\n"], "outputs": ["ABA\n", "AA\nAA\n", "AAAB\nAAAC\nAAAB\n", "AAA\nAAA\nAAA\nBCB\n", "A\n", "AAB\nAAC\n", "AA\nAA\nBC\n", "AB\n"]}
331
109
coding
Solve the programming task below in a Python markdown code block. Minion Chef likes to eat bananas a lot. There are N piles of bananas in front of Chef; for each i (1 ≤ i ≤ N), the i-th pile contains Ai bananas. Chef's mother wants her to eat the bananas and be healthy. She has gone to the office right now and will com...
{"inputs": ["3\n3 3\n1 2 3\n3 4\n1 2 3\n4 5\n4 3 2 7"], "outputs": ["3\n2\n4"]}
552
48
coding
Solve the programming task below in a Python markdown code block. Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e...
{"inputs": ["1 1\ne\ne\ne\ne\n", "1 1\na\na\na\na\n", "1 1\ne\na\na\na\n", "1 1\ne\na\ne\na\n", "1 1\na\na\na\ne\n", "1 1\ne\na\ne\ne\n", "1 1\ne\na\na\ne\n", "1 1\na\ne\na\ni\n"], "outputs": ["aaaa\n", "aaaa\n", "NO\n", "abab\n", "NO\n", "NO\n", "abba\n", "NO\n"]}
688
152
coding
Solve the programming task below in a Python markdown code block. In this Kata, we define an arithmetic progression as a series of integers in which the differences between adjacent numbers are the same. You will be given an array of ints of `length > 2` and your task will be to convert it into an arithmetic progressio...
{"functional": "_inputs = [[[1, 1, 3, 5, 6, 5]], [[2, 1, 2]], [[1, 2, 3]], [[1, 1, 10]], [[24, 21, 14, 10]], [[3, 2, 1, 1, 1]], [[1, 3, 6, 9, 12]], [[0, 0, 0, 0, 0]], [[5, 4, 3, 2, 1, 1]], [[1, 2, 1]], [[1, 2, 3, 1, 1]], [[1, 3, 6, 8, 10]], [[5, 6, 5, 3, 1, 1]]]\n_outputs = [[4], [1], [0], [-1], [3], [4], [1], [0], [1]...
327
371
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointin...
{"functional": "def check(candidate):\n assert candidate(word = \"abc\") == 5\n assert candidate(word = \"bza\") == 7\n assert candidate(word = \"zjpc\") == 34\n\n\ncheck(Solution().minTimeToType)"}
152
61
coding
Solve the programming task below in a Python markdown code block. You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`. Constraints * 1 \leq K \leq 5 * All values in input are integers. Input Input is given from...
{"inputs": ["4", "6", "5", "8", "7", "9", "2", "1"], "outputs": ["ACLACLACLACL\n", "ACLACLACLACLACLACL\n", "ACLACLACLACLACL\n", "ACLACLACLACLACLACLACLACL\n", "ACLACLACLACLACLACLACL\n", "ACLACLACLACLACLACLACLACLACL\n", "ACLACL\n", "ACL\n"]}
122
96
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 matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi. Count and return the num...
{"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, ops = [[2,2],[3,3]]) == 4\n assert candidate(m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]) == 4\n assert candidate(m = 3, n = 3, ops = []) == 9\n\n\ncheck(Solution().maxCount)"}
133
135
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has an integer $N$ and he wants to generate a matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). He...
{"inputs": ["1\n2"], "outputs": ["1 2\n4 3"]}
601
20
coding
Solve the programming task below in a Python markdown code block. We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}. Print the number of elements p_i (1 < i < n) that satisfy the following condition: - p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}. -----C...
{"inputs": ["3\n1 2 3\n", "3\n1 3 2\n", "3\n2 1 3\n", "5\n2 3 5 4 2", "5\n2 1 5 4 2", "5\n2 6 4 8 3", "5\n2 1 5 4 3", "5\n2 1 2 4 3"], "outputs": ["1\n", "0\n", "0\n", "2\n", "1\n", "0\n", "1\n", "1\n"]}
284
133
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a contai...
{"functional": "def check(candidate):\n assert candidate([1,8,6,2,5,4,8,3,7]) == 49 \n assert candidate(height = [1,1]) == 1\n\n\ncheck(Solution().maxArea)"}
131
61
coding
Solve the programming task below in a Python markdown code block. You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix. Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring cell to th...
{"inputs": ["1 0\nz\n", "1 1\ng\n", "1 0\na\n", "1 1\nz\n", "1 0\ng\n", "1 0\ny\n", "1 1\nf\n", "1 2\nf\n"], "outputs": ["z\n", "a\n", "a\n", "a\n", "g\n", "y", "a", "a"]}
458
99
coding
Solve the programming task below in a Python markdown code block. There are N points in a D-dimensional space. The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}). The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... ...
{"inputs": ["1 1\n1\n2\n3\n4\n5", "5 1\n0\n2\n3\n4\n5", "0 1\n1\n2\n3\n4\n5", "1 0\n1\n2\n3\n4\n5", "1 0\n1\n2\n3\n4\n4", "1 0\n1\n2\n3\n7\n4", "1 0\n1\n3\n3\n7\n4", "0 0\n1\n3\n3\n7\n4"], "outputs": ["0\n", "10\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
514
159
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two points on the X-Y plane is the Eucli...
{"functional": "def check(candidate):\n assert candidate(points = [[1,3],[-2,2]], k = 1) == [[-2,2]]\n assert candidate(points = [[3,3],[5,-1],[-2,4]], k = 2) == [[3,3],[-2,4]]\n\n\ncheck(Solution().kClosest)"}
163
83
coding
Solve the programming task below in a Python markdown code block. You work as a system administrator in a dormitory, which has $n$ rooms one after another along a straight hallway. Rooms are numbered from $1$ to $n$. You have to connect all $n$ rooms to the Internet. You can connect each room to the Internet directly...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "1 0\n1\n", "1 0\n0\n", "4 1\n0011\n", "4 2\n0011\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "4\n", "3\n"]}
673
108
coding
Solve the programming task below in a Python markdown code block. A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck. Your ta...
{"inputs": ["3 1\n4 4\n0 0", "3 1\n6 4\n0 0", "3 4\n4 1\n0 0", "3 1\n4 2\n0 0", "3 2\n6 4\n0 0", "3 7\n4 1\n0 0", "4 4\n4 1\n0 0", "4 1\n4 2\n0 0"], "outputs": ["0\n2\n", "0\n3\n", "4\n1\n", "0\n4\n", "3\n3\n", "0\n1\n", "2\n1\n", "1\n4\n"]}
249
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. You can return the answer in any order.   Please complete the following p...
{"functional": "def check(candidate):\n assert candidate(n = 2) == [\"1/2\"]\n assert candidate(n = 3) == [\"1/2\",\"1/3\",\"2/3\"]\n assert candidate(n = 4) == [\"1/2\",\"1/3\",\"1/4\",\"2/3\",\"3/4\"]\n assert candidate(n = 1) == []\n\n\ncheck(Solution().simplifiedFractions)"}
92
108
coding
Solve the programming task below in a Python markdown code block. Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order. -----Constraints----- - C is a lowercase English letter that is not z. -----Input----- Input is given from Standard Input in the following form...
{"inputs": ["z", "b", "x", "`", "w", "_", "{", "^"], "outputs": ["{\n", "c\n", "y\n", "a\n", "x\n", "`\n", "|\n", "_\n"]}
97
58
coding
Solve the programming task below in a Python markdown code block. Polycarp doesn't like integers that are divisible by $3$ or end with the digit $3$ in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too. Polycarp starts to write out the positive (greater than $0$) integers w...
{"inputs": ["1\n5\n", "1\n5\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n1\n", "1\n4\n", "1\n8\n"], "outputs": ["7\n", "7\n", "2\n", "4\n", "8\n", "1\n", "5\n", "11\n"]}
302
87
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 multi-set S of N integers, and an integer K. You want to find the maximum value of minimal excluded non-negative integer (MEX) of the multi-set given that you...
{"inputs": ["4\n3 0\n1 0 2\n3 1\n1 0 2\n4 3\n2 5 4 9\n2 0\n3 4"], "outputs": ["3\n4\n6\n0"]}
573
58
coding
Solve the programming task below in a Python markdown code block. Goal Given a list of elements [a1, a2, ..., an], with each ai being a string, write a function **majority** that returns the value that appears the most in the list. If there's no winner, the function should return None, NULL, nil, etc, based on the pr...
{"functional": "_inputs = [[['A', 'B', 'A']], [['A', 'B', 'C']], [['A', 'B', 'B', 'A']], [['A', 'A', 'A', 'A']], [['A']], [['A', 'A', 'A', 'BBBBBBBB']], [['A', 'B', 'C', 'C']], [[]], [['B', 'C', '', '']]]\n_outputs = [['A'], [None], [None], ['A'], ['A'], ['A'], ['C'], [None], ['']]\nimport math\ndef _deep_eq(a, b, tol=...
135
258
coding
Solve the programming task below in a Python markdown code block. Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided tha...
{"inputs": ["z\na\n", "a\nb\n", "a\na\n", "b\nb\n", "b\na\n", "ac\na\n", "z\nww\n", "ab\nb\n"], "outputs": ["z\n", "-1\n", "-1\n", "-1", "b", "ac\n", "z\n", "ba\n"]}
547
84
coding
Solve the programming task below in a Python markdown code block. Chef loves squares! You are given N points with integers coordinates, Chef asks you to find out how many points he should add to these set of N points, so that one could create at least one square having its vertices from the points of the resulting set....
{"inputs": ["3\n0 0\n2 2\n3 3", "3\n0 0\n2 2\n3 3", "5\n0 0\n100 100\n200 200\n100 0\n0 100", "5\n0 0\n100 100\n200 200\n100 0\n0 100"], "outputs": ["2", "2", "0", "0"]}
320
118
coding
Solve the programming task below in a Python markdown code block. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions x_{i}, y_{i} (x_{i} < y_{i}) in the permuted array a. Let's define the value d_{i} = y_{i} - x_{i} — the distance bet...
{"inputs": ["2\n", "1\n", "3\n", "4\n", "4\n", "3\n", "8\n", "6\n"], "outputs": ["1 1 2 2\n", "1 1\n", "1 3 1 2 2 3\n", "1 3 3 1 2 4 2 4\n", "1 3 3 1 2 4 2 4 ", "1 3 1 2 2 3 ", "1 3 5 7 7 5 3 1 2 4 6 8 6 4 2 8 \n", "1 3 5 5 3 1 2 4 6 4 2 6 \n"]}
216
178
coding
Solve the programming task below in a Python markdown code block. Given is an integer sequence of length N: A_1, A_2, \cdots, A_N. An integer sequence X, which is also of length N, will be chosen randomly by independently choosing X_i from a uniform distribution on the integers 1, 2, \ldots, A_i for each i (1 \leq i \l...
{"inputs": ["3\n1 2 3\n", "3\n2 1 2\n", "1\n78261382\n", "5\n9 7 4 4 1\n", "5\n4 5 7 10 9\n", "6\n7 4 4 2 6 1\n", "6\n6 3 4 5 5 5\n", "6\n1 1 1 1 1 1\n"], "outputs": ["2\n", "500000005\n", "1\n", "825396833\n", "966269851\n", "420386910\n", "880111120\n", "1\n"]}
595
188
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. Chef lives in a huge apartment building with $N$ floors, numbered $0$ (ground floor) through $N$ (terrace). Unfortunately, it has only one lift. We ...
{"inputs": ["1\n2 3\n1 2\n0 1\n1 0"], "outputs": ["6"]}
621
28
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N (i.e. every character of S is either 0 or 1). You can perform the following operation on S: select any two indices i, j of the same parity, i.e. either both i, j are odd or both i, j are even swap S_{i} and S_...
{"inputs": ["3\n5\n00100\n5\n01010\n5\n10001"], "outputs": ["1\n2\n2"]}
666
40
coding
Solve the programming task below in a Python markdown code block. The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". This time I will make a box with sticks, but I would like to see if I can make a rectangular parallelepiped usi...
{"inputs": ["1 1 2 2 3 1 1 3 3 3 1 2", "1 1 3 4 8 9 7 3 3 5 5 5", "1 0 2 2 3 1 1 3 3 3 1 2", "1 1 3 7 8 9 7 3 3 5 5 5", "0 0 2 2 3 1 1 3 3 3 1 2", "1 1 2 2 5 1 2 3 3 3 1 2", "1 1 3 4 8 9 3 3 4 5 5 5", "1 1 2 2 3 1 2 3 2 3 1 2"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]}
283
238
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ of length $n$ consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. ...
{"inputs": ["1\nx\n", "1\nx\n", "1\nx\n", "5\nabaca\n", "5\nabaca\n", "8\nabcddcba\n", "8\nabcddcba\n", "500\nbbababaabaabaabbbbbbaabbabbabbaabababababbbbabaaabbbbaaabbbbbbbabababaaaaabbbbabaababbababbaaaaaabbaaabbaabaaababbbbbabbaabaabaabbbaaabaabbaaabbaabababbaaabaaabaaaaabbbababaabbbbabbbbbababbbaabaabbabaabbabbabab...
204
301
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. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal. For example, 2373 is made up of three distinct digits: 2, 3, a...
{"functional": "def check(candidate):\n assert candidate(nums = [51,71,17,24,42]) == 88\n assert candidate(nums = [1,2,3,4]) == -1\n\n\ncheck(Solution().maxSum)"}
129
63
coding
Solve the programming task below in a Python markdown code block. Problem statement There is an unsigned $ 2 $ decimal integer $ X $ with $ N $ in digits including Leading-zeros. Output the largest non-negative integer that can be expressed in $ 2 $ base in $ N $ digits where the Hamming distance from $ X $ is $ D $. ...
{"inputs": ["5\n00001\n4", "5\n00000\n3", "5\n00001\n1", "5\n10001\n1", "5\n10001\n2", "5\n10001\n4", "5\n10000\n1", "5\n00010\n1"], "outputs": ["11111\n", "11100\n", "10001\n", "11001\n", "11101\n", "11110\n", "11000\n", "10010\n"]}
357
158
coding
Solve the programming task below in a Python markdown code block. A football league of N teams is taking place, where each team plays other teams once in [single round robin] fashion. A team gets 3 points for winning a game and 0 for losing (assume that no games end in a draw/tie). What is the maximum possible differen...
{"inputs": ["4\n2\n3\n4\n9"], "outputs": ["3\n3\n6\n12"]}
435
27
coding
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Given a board of N rows and M columns, place the minimum number of knights such that every cell either contains a knight or is attacked by at least one knight. Like in stand...
{"inputs": ["1\n2 4"], "outputs": ["4"]}
362
16
coding
Solve the programming task below in a Python markdown code block. Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in ...
{"inputs": ["x\n", "y\n", "x\n", "xxx\n", "xxx\n", "yxx\n", "yxyxy\n", "xxyxx\n"], "outputs": ["x\n", "y\n", "x", "xxx\n", "xxx", "x\n", "y\n", "xxx\n"]}
587
73
coding
Solve the programming task below in a Python markdown code block. Write a function named `first_non_repeating_letter` that takes a string input, and returns the first character that is not repeated anywhere in the string. For example, if given the input `'stress'`, the function should return `'t'`, since the letter *t...
{"functional": "_inputs = [['a'], ['stress'], ['moonmen'], [''], ['abba'], ['aa'], ['~><#~><'], ['hello world, eh?'], ['sTreSS'], [\"Go hang a salami, I'm a lasagna hog!\"]]\n_outputs = [['a'], ['t'], ['e'], [''], [''], [''], ['#'], ['w'], ['T'], [',']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, ...
182
231
coding
Solve the programming task below in a Python markdown code block. Today Chef wants to evaluate the dishes of his $N$ students. He asks each one to cook a dish and present it to him. Chef loves his secret ingredient, and only likes dishes with at least $X$ grams of it. Given $N$, $X$ and the amount of secret ingredient ...
{"inputs": ["3\n5 100\n11 22 33 44 55\n5 50\n10 20 30 40 50\n5 45\n12 24 36 48 60"], "outputs": ["NO\nYES\nYES"]}
373
77
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. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence...
{"inputs": ["1\n4\n-5 4 1 2"], "outputs": ["7 7 4 5"]}
703
29
coding
Solve the programming task below in a Python markdown code block. In this kata, you'll be given an integer of range `0 <= x <= 99` and have to return that number spelt out in English. A few examples: ```python name_that_number(4) # returns "four" name_that_number(19) # returns "nineteen" name_that_number(99) # ret...
{"functional": "_inputs = [[1], [52], [21], [99], [0], [53], [23], [76]]\n_outputs = [['one'], ['fifty two'], ['twenty one'], ['ninety nine'], ['zero'], ['fifty three'], ['twenty three'], ['seventy six']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return m...
168
214
coding
Solve the programming task below in a Python markdown code block. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix $M$ of size $n \times n$ contains only 'X' and '.' (without quotes). The element in the $i$-th row and the $j$-th column $(i, j)$ is defined as $M(i, j)$, where $...
{"inputs": ["1\nX\n", "1\n.\n", "1\n.\n", "1\nX\n", "1\n/\n", "1\nY\n", "1\n0\n", "1\nZ\n"], "outputs": ["0\n", "0\n", "0", "0", "0\n", "0\n", "0\n", "0\n"]}
558
84
coding
Solve the programming task below in a Python markdown code block. The medians of a triangle are the segments that unit the vertices with the midpoint of their opposite sides. The three medians of a triangle intersect at the same point, called the barycenter or the centroid. Given a triangle, defined by the cartesian co...
{"functional": "_inputs = [[[4, 6], [12, 4], [10, 10]], [[4, 2], [12, 2], [6, 10]], [[4, 8], [8, 2], [16, 6]]]\n_outputs = [[[8.6667, 6.6667]], [[7.3333, 4.6667]], [[9.3333, 5.3333]]]\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...
355
257
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Find all valid combinations of k numbers that sum up to n such that the following conditions are true: Only numbers 1 through 9 are used. Each number is used at most once. Return a list of all possible valid combina...
{"functional": "def check(candidate):\n assert candidate(k = 3, n = 7) == [[1,2,4]]\n assert candidate(k = 3, n = 9) == [[1,2,6],[1,3,5],[2,3,4]]\n assert candidate(k = 4, n = 1) == []\n\n\ncheck(Solution().combinationSum3)"}
121
95
coding
Solve the programming task below in a Python markdown code block. Alice, Bob, and Charlie are contributing to buy a Netflix subscription. However, Netfix allows only two users to share a subscription. Given that Alice, Bob, and Charlie have A, B, and C rupees respectively and a Netflix subscription costs X rupees, fin...
{"inputs": ["4\n1 1 1 3\n2 3 1 5\n4 2 3 4\n2 1 4 7\n"], "outputs": ["NO\nYES\nYES\nNO\n"]}
487
52
coding
Solve the programming task below in a Python markdown code block. In this Kata you need to write the method SharedBits that returns true if 2 integers share at least two '1' bits. For simplicity assume that all numbers are positive For example int seven = 7; //0111 int ten = 10; //1010 int fifteen = 15; //1111 ...
{"functional": "_inputs = [[1, 2], [16, 8], [1, 1], [2, 3], [7, 10], [43, 77], [7, 15], [23, 7]]\n_outputs = [[False], [False], [False], [False], [False], [True], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=...
224
226
coding
Solve the programming task below in a Python markdown code block. Chef's phone shows a Battery Low notification if the battery level is 15 \% or less. Given that the battery level of Chef's phone is X \%, determine whether it would show a Battery low notification. ------ Input Format ------ - First line will conta...
{"inputs": ["3\n15\n3\n65"], "outputs": ["Yes\nYes\nNo"]}
359
24
coding
Solve the programming task below in a Python markdown code block. Jimmy loves playing with strings. He thinks string $\mbox{A}$ is similar to string $\mbox{B}$ if the following conditions are satisfied: Both strings have the same length (i.e., $A=a_{0}a_{1}\ldots a_{n-1}$ and $B=b_0b_1\ldots b_{n-1}$). For each valid...
{"inputs": ["8 4\ngiggabaj\n1 1\n1 2\n1 3\n2 4\n"], "outputs": ["8\n6\n2\n1\n"]}
651
42
coding
Solve the programming task below in a Python markdown code block. Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in ...
{"inputs": ["1 1\n5\n", "3 1\n1 1 1\n", "2 2\n97 197\n", "2 1\n97 197\n", "2 2\n193 193\n", "4 2\n0 2 1 2\n", "4 2\n0 2 2 2\n", "4 2\n1 2 1 2\n"], "outputs": [" 1\n", " 6\n", " ...
616
150
coding
Solve the programming task below in a Python markdown code block. You are given an array A consisting of N positive integers and a positive integer K. Find whether there exists a *subset* S of the elements of A such that the product of all elements of S is divisible by K. Note that a *subset* is obtained by deleting ...
{"inputs": ["3\n2 2\n7 8\n5 3\n1 1 2 1 1\n3 6\n7 2 3\n"], "outputs": ["YES\nNO\nYES"]}
449
49
coding
Solve the programming task below in a Python markdown code block. Akash loves going to school, but not on weekends. A week consists of 7 days (Monday to Sunday). Akash takes a leave every Saturday. If a month consists of N days and the first-day of the month is Monday, find the number of days Akash would take a lea...
{"inputs": ["4\n5\n6\n8\n22"], "outputs": ["0\n1\n1\n3"]}
410
27
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.   Please complete the following python code precisely: ```pyth...
{"functional": "def check(candidate):\n assert candidate(arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4) == 3\n assert candidate(arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5) == 6\n\n\ncheck(Solution().numOfSubarrays)"}
89
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,2,1,3]) == [3,3,2,2,1]\n assert candidate(nums = [1,2]) == [2,1]\n\n\ncheck(Solution().smallestSubarrays)"}
229
67
coding
Solve the programming task below in a Python markdown code block. Chef has a binary string S of size N. Chef can perform the following operation on the string: Select any substring of size 3 and reverse it. Find the minimum *distance* between any two 1s Chef can achieve, by applying the above operation any (possibly z...
{"inputs": ["3\n2\n11\n3\n101\n7\n0100101\n"], "outputs": ["1\n2\n1"]}
560
38
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diam...
{"functional": "def check(candidate):\n assert candidate(points = [[10,16],[2,8],[1,6],[7,12]]) == 2\n assert candidate(points = [[1,2],[3,4],[5,6],[7,8]]) == 4\n assert candidate(points = [[1,2],[2,3],[3,4],[4,5]]) == 2\n\n\ncheck(Solution().findMinArrowShots)"}
216
103
coding
Solve the programming task below in a Python markdown code block. Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there were also ...
{"inputs": ["3 7 0\n", "2 0 1\n", "1 1 0\n", "0 0 1\n", "1 0 1\n", "5 7 1\n", "1 1 1\n", "0 0 0\n"], "outputs": ["-", "+", "0", "?", "?", "-", "?", "0"]}
501
87
coding
Solve the programming task below in a Python markdown code block. You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer. -----Constraints----- - a and b are integers. - 1 \leq a, b \leq 100 -----Input----- Input is given from Standard Input in the fo...
{"inputs": ["1 3\n", "7 4\n", "5 5\n"], "outputs": ["2\n", "6\n", "5\n"]}
140
36
coding
Solve the programming task below in a Python markdown code block. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboar...
{"inputs": ["5 1\n0\n", "1 1\n0\n", "5 2\n0\n", "2 1\n0\n", "3 1\n0\n", "2 2\n0\n", "15 5\n0\n", "20 1\n0\n"], "outputs": ["5\n", "1\n", "2\n", "2\n", "3\n", "1\n", "3\n", "20\n"]}
400
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the nth ugly number.   Please complete the following python code precisely: ```python class Solution: ...
{"functional": "def check(candidate):\n assert candidate(n = 10) == 12\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().nthUglyNumber)"}
83
47
coding
Solve the programming task below in a Python markdown code block. Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. Fo...
{"inputs": ["2\n2\n0", "2\n7\n0", "2\n0\n0", "2\n5\n0", "2\n1\n0", "2\n3\n0", "2\n8\n0", "2\n6\n0"], "outputs": ["5\n5\n", "5\n58\n", "5\n", "5\n28\n", "5\n2\n", "5\n10\n", "5\n77\n", "5\n41\n"]}
231
113
coding
Solve the programming task below in a Python markdown code block. $n$ students attended the first meeting of the Berland SU programming course ($n$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wedn...
{"inputs": ["2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 1 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 1\n", "2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 1 1\n0 0 0 ...
657
598
coding
Solve the programming task below in a Python markdown code block. Write a function `take_umbrella()` that takes two arguments: a string representing the current weather and a float representing the chance of rain today. Your function should return `True` or `False` based on the following criteria. * You should take a...
{"functional": "_inputs = [['sunny', 0.4], ['rainy', 0.0], ['cloudy', 0.2]]\n_outputs = [[False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
202
187
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Limak is a little polar bear, who loves eating cookies and drinking milk. For this reason he often visits Chef's kitchen. Limak is going to spend N minutes in the kitchen. E...
{"inputs": ["4\n7\ncookie milk milk cookie milk cookie milk\n5\ncookie cookie milk milk milk\n4\nmilk milk milk milk\n1\ncookie"], "outputs": ["YES\nNO\nYES\nNO"]}
611
48
coding
Solve the programming task below in a Python markdown code block. # Definition **_Extra perfect number_** *is the number that* **_first_** and **_last_** *bits* are **_set bits_**. ____ # Task **_Given_** *a positive integer* `N` , **_Return_** the **_extra perfect numbers_** *in range from* `1` to `N` . ___...
{"functional": "_inputs = [[3], [5], [7], [28], [39]]\n_outputs = [[[1, 3]], [[1, 3, 5]], [[1, 3, 5, 7]], [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27]], [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin...
480
319
coding
Solve the programming task below in a Python markdown code block. You will be given an array of non-negative integers and positive integer bin width. Your task is to create the Histogram method that will return histogram data corresponding to the input array. The histogram data is an array that stores under index i t...
{"functional": "_inputs = [[[1, 1, 0, 1, 3, 2, 6], 1], [[1, 1, 0, 1, 3, 2, 6], 2], [[], 1], [[8], 1]]\n_outputs = [[[1, 3, 1, 1, 0, 0, 1]], [[4, 2, 0, 1]], [[]], [[0, 0, 0, 0, 0, 0, 0, 0, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(...
248
269
coding
Solve the programming task below in a Python markdown code block. You are given a sequence whose $n^{\text{th}}$ term is $T_{n}=n^{K}$ You have to evaluate the series $S_n=T_1+T_2+T_3+\cdots+T_n$ Find $S_n\:\text{mod}\:(10^9+7)$. Input Format The first line of input contains $\mathbf{T}$, the number of test cases...
{"inputs": ["3\n5 3\n4 2\n4 1\n"], "outputs": ["225\n30\n10\n"]}
314
34
coding
Solve the programming task below in a Python markdown code block. Chef's son wants to go on a roller coaster ride. The height of Chef's son is X inches while the minimum height required to go on the ride is H inches. Determine whether he can go on the ride or not. ------ Input Format ------ - The first line contains...
{"inputs": ["4\n15 20\n50 48\n32 32\n38 39\n"], "outputs": ["NO\nYES\nYES\nNO"]}
357
43
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a forest with an unknown number of rabbits. We asked n rabbits "How many rabbits have the same color as you?" and collected the answers in an integer array answers where answers[i] is the answer of the ith ra...
{"functional": "def check(candidate):\n assert candidate(answers = [1,1,2]) == 5\n assert candidate(answers = [10,10,10]) == 11\n\n\ncheck(Solution().numRabbits)"}
115
59
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of unique integers preorder, return true if it is the correct preorder traversal sequence of a binary search tree.   Please complete the following python code precisely: ```python class Solution: de...
{"functional": "def check(candidate):\n assert candidate(preorder = [5,2,1,3,6]) == True\n assert candidate(preorder = [5,2,6,1,3]) == False\n\n\ncheck(Solution().verifyPreorder)"}
73
60
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. Our lazy white falcon finally decided to learn heavy-light decomposition. Her teacher gave an assignment for her to practice this new technique. Please help her by solving this problem. You are given a tree with $N$ nodes and each node's value is initi...
{"inputs": ["3 3\n0 1\n1 2\n1 0 1\n1 1 2\n2 0 2\n"], "outputs": ["2\n"]}
358
42
coding
Solve the programming task below in a Python markdown code block. Today was a sad day. Having bought a new beard trimmer, I set it to the max setting and shaved away at my joyous beard. Stupidly, I hadnt checked just how long the max setting was, and now I look like Ive just started growing it! Your task, given a bear...
{"functional": "_inputs = [[[['J', '|'], ['J', '|'], ['...', '|']]], [[['J', '|', 'J'], ['J', '|', '|'], ['...', '|', 'J']]], [[['J', '|', 'J', 'J'], ['J', '|', '|', 'J'], ['...', '|', 'J', '|']]]]\n_outputs = [[[['|', '|'], ['|', '|'], ['...', '...']]], [[['|', '|', '|'], ['|', '|', '|'], ['...', '...', '...']]], [[['...
198
288
coding
Solve the programming task below in a Python markdown code block. Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each secon...
{"inputs": ["3 1\n0.1\n", "3 1\n9.9\n", "3 1\n0.9\n", "3 1\n9.5\n", "3 3\n9.9\n", "3 3\n9.9\n", "3 1\n0.1\n", "3 1\n9.9\n"], "outputs": ["0.1\n", "10\n", "1\n", "10\n", "10\n", "10\n", "0.1\n", "10\n"]}
628
127
coding
Solve the programming task below in a Python markdown code block. Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his s...
{"inputs": ["1 2\nab\n", "1 3\nab\n", "1 3\nab\n", "1 0\nab\n", "0 2\nab\n", "1 1\nab\n", "1 1\naa\n", "1 2\nab\n"], "outputs": ["Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n"]}
341
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a squ...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,2],[1,3]]) == 3\n assert candidate(grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]) == 16\n\n\ncheck(Solution().swimInWater)"}
189
115
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A cell (r, c) of an excel sheet is represented as a string "<col><row>" where: <col> denotes the column number c of the cell. It is represented by alphabetical letters. For example, the 1st column is denoted by 'A...
{"functional": "def check(candidate):\n assert candidate(s = \"K1:L2\") == [\"K1\",\"K2\",\"L1\",\"L2\"]\n assert candidate(s = \"A1:F1\") == [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"]\n\n\ncheck(Solution().cellsInRange)"}
287
81
coding
Solve the programming task below in a Python markdown code block. Little C loves number «3» very much. He loves all things about it. Now he is playing a game on a chessboard of size $n \times m$. The cell in the $x$-th row and in the $y$-th column is called $(x,y)$. Initially, The chessboard is empty. Each time, he pl...
{"inputs": ["2 2\n", "3 3\n", "1 4\n", "1 6\n", "7 1\n", "7 2\n", "2 3\n", "2 5\n"], "outputs": ["0", "8", "2", "6", "6", "12", "4", "10"]}
339
80
coding
Solve the programming task below in a Python markdown code block. Fennec is fighting with N monsters. The health of the i-th monster is H_i. Fennec can do the following two actions: - Attack: Fennec chooses one monster. That monster's health will decrease by 1. - Special Move: Fennec chooses one monster. That monster...
{"inputs": ["3 1\n0 1 5", "3 0\n0 1 5", "3 1\n4 1 6", "3 1\n4 1 5", "3 1\n4 1 5\n", "8 8\n7 9 3 2 3 8 4 6", "8 0\n4 9 5 2 3 6 5 6", "8 1\n4 9 5 2 3 6 5 6"], "outputs": ["1\n", "6\n", "5\n", "5", "5\n", "0\n", "40\n", "31\n"]}
320
158
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Let's call a positive integer $M$ a *beautiful number* if the following conditions are satisfied: The decimal representation of $M$ (without leading ...
{"inputs": ["2\n1\n2"], "outputs": ["1\n34"]}
453
19