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 the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules: In the beginning, you have the permutation P=[1,2,3,...
{"functional": "def check(candidate):\n assert candidate(queries = [3,1,2,1], m = 5) == [2,1,2,1] \n assert candidate(queries = [4,1,2,2], m = 4) == [3,1,2,0]\n assert candidate(queries = [7,5,5,8,3], m = 8) == [6,5,0,7,5]\n\n\ncheck(Solution().processQueries)"}
175
117
coding
Solve the programming task below in a Python markdown code block. F: Tea Party Yun decided to hold a tea party at the company. The shop sells $ N $ sets of bread, each containing $ A_1, A_2, A_3, \ dots, A_N $. Yun decided to make a sandwich by combining two breads into a pair. Yun-san is very careful, so I want to...
{"inputs": ["5\n4 3 5 6 7", "5\n2 3 3 6 7", "5\n6 2 5 0 3", "5\n9 2 2 0 6", "5\n0 0 7 6 0", "5\n0 0 7 1 0", "5\n0 9 2 0 2", "5\n0 0 7 0 0"], "outputs": ["11\n", "9\n", "8\n", "5\n", "3\n", "4\n", "2\n", "0\n"]}
359
143
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.   Please complete the following python code precisely: ```pyth...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,None,5,None,4])) == [1,3,4]\n assert candidate(root = tree_node([1,None,3])) == [1,3]\n assert candidate(root = tree_node([])) == []\n\n\ncheck(Solution().rightSideView)"}
135
82
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.   Please complete the following python code precisely: ```python # Defin...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5])), list_node([3,4,5]))\n assert is_same_list(candidate(head = list_node([1,2,3,4,5,6])), list_node([4,5,6]))\n\n\ncheck(Solution().middleNode)"}
122
85
coding
Solve the programming task below in a Python markdown code block. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: - If Takahashi has one or more cookies, eat one of his cookies. - Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. - If they both ha...
{"inputs": ["2 3 1", "2 3 2", "2 3 0", "2 6 0", "4 6 0", "8 6 0", "0 6 0", "0 9 0"], "outputs": ["1 3\n", "0 3\n", "2 3\n", "2 6\n", "4 6\n", "8 6\n", "0 6\n", "0 9\n"]}
302
110
coding
Solve the programming task below in a Python markdown code block. Chef has learned a new technique for comparing two recipes. A recipe contains a list of ingredients in increasing order of the times they will be processed. An ingredient is represented by a letter 'a'-'z'. The i-th letter in a recipe denotes the i-th in...
{"inputs": ["3\nalex axle\nparadise diapers\nalice bob", "3\nalex axle\nesidarap diapers\nalice bob", "3\nelax axle\nesidarap djapers\nalice bob", "3\nelax axle\nesidarap diapers\nalice bob", "3\nelax ayle\nesidarap djapers\nalice bob", "3\nelax ayle\nesidarap srepajd\nalice bob", "3\nelax ayle\netidarap srepajd\nalice...
571
202
coding
Solve the programming task below in a Python markdown code block. There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consis...
{"inputs": ["1\n0 0 0 0\n", "1\n0 0 0 0\n", "1\n0 0 1 0\n", "1\n0 0 2 0\n", "1\n4 0 0 0\n", "1\n1 0 0 0\n", "1\n2 0 0 0\n", "1\n1 0 1 0\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "4\n", "1\n", "2\n", "1\n"]}
750
134
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 convex polygon with N vertices. You have to find any ⌊N/10⌋ distinct points with integer coordinates that lie strictly inside the polygon, or determine that ...
{"inputs": ["1\n11\n0 0\n1 1\n2 3\n2 5\n0 10\n-2 10\n-5 9\n-8 7\n-8 4\n-6 1\n-2 0"], "outputs": ["0 1"]}
635
69
coding
Solve the programming task below in a Python markdown code block. You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: All cells in a set have the same color. Every two cells in a set share row or column. -----Input----- The first lin...
{"inputs": ["1 1\n0\n", "1 1\n0\n", "2 2\n1 1\n1 1\n", "2 2\n1 1\n1 1\n", "2 2\n1 0\n1 1\n", "2 3\n1 0 1\n0 1 0\n", "2 3\n1 0 1\n1 1 0\n", "2 3\n1 1 1\n0 1 0\n"], "outputs": ["1\n", "1\n", "8\n", "8\n", "6\n", "8\n", "9\n", "12\n"]}
277
151
coding
Solve the programming task below in a Python markdown code block. Given the string S and m queries. The i-th query is given by the two strings xi and yi. For each query, answer the longest substring of the string S, starting with xi and ending with yi. For the string S, | S | represents the length of S. Also, the fac...
{"inputs": ["abracadabsa\n5\nab a\na a\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na b\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na c\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na c\na c\nac ca\nz z", "abracadabsa\n5\nba a\na c\na c\nac ca\nz y", "abracadabsa\n5\nba a\na c\nb c\nac ca\nz y", "abracadabsa\n2\nba a\na c\nb c\...
491
288
coding
Solve the programming task below in a Python markdown code block. A mischievous notice has arrived from the primitive slow-life organization "Akaruda". Akaruda is famous for mischief such as throwing a pie at the face of a VIP, but recently it has become more radical, such as using gunpowder to sprinkle rat fireworks a...
{"inputs": ["4\n02:15\n05:01\n11:55\n10:40", "4\n02:15\n05:01\n11:54\n10:40", "4\n12:15\n05:01\n11:54\n10:40", "4\n02:15\n05:01\n11:55\n11:40", "4\n12:05\n05:01\n11:44\n00:41", "4\n02:15\n10:50\n11:54\n10:40", "4\n03:05\n06:11\n11:55\n10:41", "4\n03:15\n11:60\n11:55\n00:40"], "outputs": ["alert\nsafe\nalert\nwarning\n"...
403
302
coding
Solve the programming task below in a Python markdown code block. Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interes...
{"inputs": ["2 0\n1 1\n", "2 0\n0 0\n", "2 1\n0 1\n", "2 1\n0 2\n", "2 1\n0 1\n", "2 0\n1 1\n", "2 1\n0 2\n", "2 0\n0 0\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
473
118
coding
Solve the programming task below in a Python markdown code block. A hypergraph is a generalization of a graph, where an edge can connect any number of vertices. A k-uniform hypergraph is a hypergraph such that all its hyperedges have size k. For more information, see Wikipedia. Let's call a particular hypergraph a hyp...
{"inputs": ["4\n3\n4\n5\n8\n\n"], "outputs": ["1\n6\n25\n93268"]}
492
33
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Trans bought a calculator at creatnx's store. Unfortunately, it is fake. It has many bugs. One of them is adding two numbers without carrying. Example expression: 12 + 9 will...
{"inputs": ["2\n12 9\n25 25"], "outputs": ["11\n40"]}
241
27
coding
Solve the programming task below in a Python markdown code block. You are given an array a_1, a_2, ..., a_n and an array b_1, b_2, ..., b_n. For one operation you can sort in non-decreasing order any subarray a[l ... r] of the array a. For example, if a = [4, 2, 2, 1, 3, 1] and you choose subbarray a[2 ... 5], then t...
{"inputs": ["1\n2\n2 1\n1 1\n", "1\n2\n2 1\n2 2\n", "1\n2\n1 2\n1 1\n", "1\n3\n3 1 2\n2 1 3\n", "1\n3\n2 1 3\n1 3 2\n", "1\n3\n1 3 2\n2 1 3\n", "1\n3\n2 2 2\n1 1 1\n", "1\n3\n3 2 1\n1 3 2\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]}
480
170
coding
Solve the programming task below in a Python markdown code block. From an array A containing N integers, you construct a binary string S of length (N - 1) as follows. For all 1 ≤ i < N: If A_{i} < A_{i+1}, then S_{i} = 0. If A_{i} > A_{i+1}, then S_{i} = 1. Given the string S, determine the count of indices i (1 ≤ i ≤...
{"inputs": ["3\n2\n0\n7\n000111\n6\n11100\n"], "outputs": ["1\n1\n2\n"]}
554
39
coding
Solve the programming task below in a Python markdown code block. There is a square grid with N rows and M columns. Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}. Among the 2^{N+M} possible pairs of a subset A of the rows and a subset...
{"inputs": ["2 2\n1 1\n1 0", "2 2\n1 0\n1 0", "2 2\n1 0\n2 0", "1 2\n1 0\n2 0", "2 2\n2 1\n1 0", "2 2\n2 0\n1 0", "1 2\n2 0\n2 0", "2 2\n0 1\n1 0"], "outputs": ["6\n", "4\n", "4\n", "2\n", "6\n", "4\n", "2\n", "6"]}
321
141
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values. We translate one image however we choose by sliding all the 1 bits left, rig...
{"functional": "def check(candidate):\n assert candidate(img1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]) == 3\n assert candidate(img1 = [[1]], img2 = [[1]]) == 1\n assert candidate(img1 = [[0]], img2 = [[0]]) == 0\n\n\ncheck(Solution().largestOverlap)"}
190
109
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. You are allowed to perform two types of operations on the string in any sequence: Type-1: Remove the character at the start of the string s and append it to the end of the string. Typ...
{"functional": "def check(candidate):\n assert candidate(s = \"111000\") == 2\n assert candidate(s = \"010\") == 0\n assert candidate(s = \"1110\") == 1\n\n\ncheck(Solution().minFlips)"}
194
66
coding
Solve the programming task below in a Python markdown code block. Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use them. Let’...
{"inputs": ["2 10 3\n100 3\n99 1\n", "2 100 2\n100 2\n100 2\n", "2 1000 1\n100 1\n100 1\n", "2 1000 1\n100 1\n100 2\n", "2 1001 0\n101 1\n100 2\n", "2 1000 1\n101 1\n100 2\n", "2 1001 1\n101 1\n100 2\n", "2 100 10\n100 11\n90 9\n"], "outputs": ["NO\n", "YES\n51 2\n0 1\n1 2\n", "YES\n1001 2\n0 1\n1 2\n", "YES\n501 2\n0 ...
628
316
coding
Solve the programming task below in a Python markdown code block. You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = a·10^{b}, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" ...
{"inputs": ["1\n", "1\n", "2\n", "3\n", "4\n", "16\n", ".1\n", "1.\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "4\n", "1.6E1\n", "1E-1\n", "1\n"]}
247
79
coding
Solve the programming task below in a Python markdown code block. We have a string S of length N consisting of uppercase English letters. How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)? -----Constraints----- - 3 \leq N \leq 50 - S consists of uppercase English letters. ...
{"inputs": ["3\nABC\n", "3\nDEF\n", "10\nQCBABDCBAZ", "10\nZABCDB@BCQ", "10\nZABCCB@BDQ", "10\nZABCCB@CDQ", "10\nQDB@BCCBAZ", "10\nZABCCQ@BDB"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "0\n", "1\n"]}
157
120
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 1-indexed integer array nums of length n. An element nums[i] of nums is called special if i divides n, i.e. n % i == 0. Return the sum of the squares of all special elements of nums.   Please complete ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == 21\n assert candidate(nums = [2,7,1,19,18,3]) == 63\n\n\ncheck(Solution().sumOfSquares)"}
103
65
coding
Solve the programming task below in a Python markdown code block. Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria. 1. first by $x$-coordinate 2. in case of a tie, by $y$-coordinate Constraints * $1 \leq n \leq 100,000$ * $-1,000,000,000 \leq x_i, y_i \l...
{"inputs": ["5\n4 7\n5 5\n2 3\n5 8\n2 1", "5\n4 7\n5 5\n2 6\n5 8\n2 1", "5\n4 7\n5 5\n2 3\n6 8\n2 1", "5\n4 7\n5 5\n2 12\n5 8\n2 1", "5\n0 7\n5 5\n2 12\n5 8\n2 1", "5\n0 6\n8 9\n3 1\n6 16\n0 0", "5\n0 7\n5 5\n2 12\n5 16\n2 1", "5\n0 7\n5 5\n3 12\n5 16\n2 1"], "outputs": ["2 1\n2 3\n4 7\n5 5\n5 8\n", "2 1\n2 6\n4 7\n5 5...
262
379
coding
Solve the programming task below in a Python markdown code block. Consider having a cow that gives a child every year from her fourth year of life on and all her subsequent children do the same. After n years how many cows will you have? Return null if n is not an integer. Note: Assume all the cows are alive after n ...
{"functional": "_inputs = [[1], [3], [5]]\n_outputs = [[1], [2], [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)):\n if len(a) != len(b): return False\n r...
92
167
coding
Solve the programming task below in a Python markdown code block. You are given an array with $N$ integers: $A[1], A[2], \ldots, A[N]$ (where $N$ is even). You are allowed to permute the elements however you want. Say, after permuting the elements, you end up with the array $A'[1], A'[2], \ldots, A'[N]$. Your goal is t...
{"inputs": ["1\n4\n1 -3 2 -3"], "outputs": ["9"]}
583
22
coding
Solve the programming task below in a Python markdown code block. Auction square1001 You were watching a certain auction. An auction is a transaction in which when there are a large number of buyers and the number of items is limited, the one with the highest price is given the right to buy. (From the 7th edition of ...
{"inputs": ["5\n8 6 9 1 0", "5\n0 6 9 1 0", "5\n1 1 1 1 0", "5\n0 1 1 2 4", "5\n0 6 6 1 0", "5\n0 5 6 1 0", "5\n0 5 6 2 0", "5\n0 5 6 3 0"], "outputs": ["4\n5\n", "3\n5\n", "5\n5\n", "2\n5\n", "4\n5\n", "3\n5\n", "3\n5\n", "3\n5\n"]}
577
158
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef will have N guests in his house today. He wants to serve at least one dish to each of the N guests. Chef can make two types of dishes. He needs one fruit and one...
{"inputs": ["4\n2 1 2 1\n3 2 2 2\n4 2 6 3\n3 1 3 1\n"], "outputs": ["YES\nNO\nYES\nNO"]}
412
51
coding
Solve the programming task below in a Python markdown code block. Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color x_{i} and the kit for away games of this team has color y_{i} (x_{i} ≠ y_{i})...
{"inputs": ["2\n1 2\n2 1\n", "2\n1 2\n1 2\n", "2\n1 2\n3 4\n", "2\n1 2\n1 2\n", "2\n1 2\n3 4\n", "2\n1 2\n1 0\n", "2\n1 4\n2 1\n", "2\n1 2\n3 0\n"], "outputs": ["2 0\n2 0\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n2 0\n", "1 1\n1 1\n"]}
400
182
coding
Solve the programming task below in a Python markdown code block. # Convert number to reversed array of digits Given a random non-negative number, you have to return the digits of this number within an array in reverse order. ## Example: ``` 348597 => [7,9,5,8,4,3] ``` Also feel free to reuse/extend the following st...
{"functional": "_inputs = [[35231], [23582357], [984764738], [45762893920], [548702838394]]\n_outputs = [[[1, 3, 2, 5, 3]], [[7, 5, 3, 2, 8, 5, 3, 2]], [[8, 3, 7, 4, 6, 7, 4, 8, 9]], [[0, 2, 9, 3, 9, 8, 2, 6, 7, 5, 4]], [[4, 9, 3, 8, 3, 8, 2, 0, 7, 8, 4, 5]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstan...
93
339
coding
Solve the programming task below in a Python markdown code block. C: Only one subsequence --Unique Subsequence- problem One day Ebi-chan noticed that a text string T of length n and a pattern string P (m \ leq n) of length m were placed on the desk. Ebi-chan loves the "only one subsequence" that appears in strings, s...
{"inputs": ["aizucamp\nuza", "aziucamp\nazu", "azjucamp\nazu", "azjucamp\nazt", "azjucamp\nzat", "pmacujza\nzat", "pmacuiza\nzat", "pmicuaza\nzat"], "outputs": ["no\n", "yes\n", "yes\n", "no\n", "no\n", "no\n", "no\n", "no\n"]}
433
107
coding
Solve the programming task below in a Python markdown code block. A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP de...
{"inputs": ["1 1 1\n1 1 1\n1 1 1\n", "1 0 1\n1 1 1\n1 1 1\n", "1 0 2\n1 1 1\n1 1 1\n", "1 100 1\n1 1 1\n1 1 1\n", "79 1 1\n1 1 10\n1 1 100\n", "79 1 1\n2 1 10\n1 1 100\n", "79 1 0\n2 1 10\n1 1 100\n", "1 10 29\n1 1 43\n1 1 100\n"], "outputs": ["1", "2\n", "2\n", "0", "10", "10\n", "10\n", "34"]}
456
217
coding
Solve the programming task below in a Python markdown code block. In this Kata, two players, Alice and Bob, are playing a palindrome game. Alice starts with `string1`, Bob starts with `string2`, and the board starts out as an empty string. Alice and Bob take turns; during a turn, a player selects a letter from his or h...
{"functional": "_inputs = [['abc', 'xyz'], ['abc', 'axy'], ['abc', 'bax'], ['btzgd', 'svjyb'], ['eyfjy', 'ooigv'], ['mctimp', 'eyqbnh'], ['qtkxttl', 'utvohqk']]\n_outputs = [[2], [2], [2], [2], [1], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retu...
472
233
coding
Solve the programming task below in a Python markdown code block. You are given an array consisting of $n$ integers $a_1$, $a_2$, ..., $a_n$. Initially $a_x = 1$, all other elements are equal to $0$. You have to perform $m$ operations. During the $i$-th operation, you choose two indices $c$ and $d$ such that $l_i \le ...
{"inputs": ["1\n16 771 1\n2 146\n", "1\n152 771 0\n3 282\n", "1\n65 1380 0\n3 282\n", "1\n13 1380 0\n3 282\n", "1\n152 771 1\n2 146\n", "1\n152 771 0\n13 15\n", "1\n239 771 0\n3 282\n", "1\n65 2224 0\n3 282\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
556
197
coding
Solve the programming task below in a Python markdown code block. You are standing on the $\mathit{OX}$-axis at point $0$ and you want to move to an integer point $x > 0$. You can make several jumps. Suppose you're currently at point $y$ ($y$ may be negative) and jump for the $k$-th time. You can: either jump to the ...
{"inputs": ["1\n8\n", "1\n6\n", "1\n3\n", "1\n1\n", "1\n4\n", "1\n7\n", "1\n10\n", "1\n10\n"], "outputs": ["4\n", "3\n", "2\n", "1\n", "3\n", "4\n", "4\n", "4\n"]}
672
88
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7. -----Constraints----- - 1≤N≤10^3 -----Input----- The input is given from Standard Input in the following format: N -----Output----- Print the number of the pos...
{"inputs": ["8", "0", "2", "4", "9", "5", "7", "6"], "outputs": ["96\n", "1\n", "2\n", "8\n", "160\n", "16\n", "60\n", "30"]}
139
67
coding
Solve the programming task below in a Python markdown code block. You are given a permutation p_1, p_2, ... , p_n (an array where each integer from 1 to n appears exactly once). The weight of the i-th element of this permutation is a_i. At first, you separate your permutation into two non-empty sets — prefix and suffi...
{"inputs": ["2\n2 1\n9 5\n", "2\n1 2\n9 9\n", "2\n2 1\n14 5\n", "2\n2 1\n14 7\n", "2\n2 1\n14 3\n", "2\n2 1\n26 7\n", "2\n2 1\n28 7\n", "2\n1 2\n17 9\n"], "outputs": ["5\n", "0\n", "5\n", "7\n", "3\n", "7\n", "7\n", "0\n"]}
599
140
coding
Solve the programming task below in a Python markdown code block. JJ gives you a number N and challenges you to construct a permutation P of length N such that: |P_{i + 1} - P_{i}| ≥ 2 for all 1 ≤ i ≤ N - 1 (Here |x| denotes the absolute value of x) Can you complete JJ's challenge? As a reminder, a permutation of len...
{"inputs": ["2\n2\n6\n"], "outputs": ["-1\n1 4 2 5 3 6\n"]}
393
31
coding
Solve the programming task below in a Python markdown code block. You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side. Unfortunately, the ground beneath the fence is not flat. For simplic...
{"inputs": ["1\n2 2\n2 8\n", "1\n2 2\n4 8\n", "1\n2 2\n3 9\n", "1\n2 4\n1 6\n", "1\n2 3\n0 9\n", "1\n2 5\n2 9\n", "1\n2 2\n2 9\n", "1\n2 3\n0 8\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
659
134
coding
Solve the programming task below in a Python markdown code block. There are n villages in a Chefland. Some of the villages have electricity facilities, other doesn't. You can consider the villages arranged in line in the order 1 to n from left to right. i-th of village can be considered at xi coordinates. Chef decided...
{"inputs": ["2\n2\n01\n1 2\n3\n100\n1 5 6"], "outputs": ["1\n5"]}
491
35
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef and his little brother are playing with sticks. Initially, Chef has $N$ sticks with lengths $A_{1}, A_{2}, \dots, A_{N}$. He should give his little brother at least $K$ ...
{"inputs": ["2\n7 6\n1 2 3 1 2 2 1\n5 4\n1 2 1 2 3"], "outputs": ["2\n-1"]}
605
47
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. Constraints * 1 \leq K \leq N\leq 10 * S is...
{"inputs": ["5\norrer\n2", "5\nrorre\n2", "5\norrer\n1", "5\nrerro\n1", "5\nrerro\n2", "5\nerror\n4", "5\norrer\n4", "5\nserro\n1"], "outputs": ["*rr*r\n", "*o***\n", "o****\n", "r*rr*\n", "*e***\n", "***o*\n", "***e*\n", "s****\n"]}
188
116
coding
Solve the programming task below in a Python markdown code block. Four players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals of the t...
{"inputs": ["1\n8 6 2 7\n", "1\n8 6 2 7\n", "1\n8 6 0 7\n", "1\n9 4 0 7\n", "1\n2 4 0 1\n", "1\n1 6 2 7\n", "1\n9 6 0 7\n", "1\n9 4 0 6\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
494
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values: 0 represents an empty cell, 1 represents an obstacle that may be removed. You can move up, down, left, or right from an...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1],[1,1,0],[1,1,0]]) == 2\n assert candidate(grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]) == 0\n\n\ncheck(Solution().minimumObstacles)"}
150
88
coding
Solve the programming task below in a Python markdown code block. You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right. To cyclica...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "3 1\n1\n1\n0\n", "3 1\n0\n0\n0\n", "3 1\n1\n2\n0\n", "2 3\n111\n010\n", "2 3\n110\n010\n", "2 3\n111\n000\n"], "outputs": ["-1", "0", "-1", "-1", "-1\n", "0\n", "0\n", "-1"]}
508
128
coding
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For a given number ```num```, return its closest numerical palindrome which c...
{"functional": "_inputs = [[8], [281], [1029], [1221], ['BGHHGB'], ['11029'], [-1029]]\n_outputs = [[11], [282], [1001], [1221], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ...
344
220
coding
Solve the programming task below in a Python markdown code block. Complete the function that accepts a valid string and returns an integer. Wait, that would be too easy! Every character of the string should be converted to the hex value of its ascii code, then the result should be the sum of the numbers in the hex str...
{"functional": "_inputs = [['kcxnjsklsHskjHDkl7878hHJk'], [''], ['ThisIsATest!'], ['dhsajkbfyewquilb4y83q903ybr8q9apf7\\\\9ph79qw0-eq230br[wq87r0=18-[#20r370B 7Q0RFP23B79037902RF79WQ0[]]]']]\n_outputs = [[218], [0], [120], [802]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
146
279
coding
Solve the programming task below in a Python markdown code block. Chef has an array of N natural numbers. Cheffina challenges the chef to choose the two numbers from the array and following the condition as the area of the rectangle formed from the two numbers is maximum. Cheffina also asks the chef to choose two numbe...
{"inputs": ["1\n5\n4 2 1 5 3"], "outputs": ["20 2"]}
228
27
coding
Solve the programming task below in a Python markdown code block. AtCoDeer the deer has N square tiles. The tiles are numbered 1 through N, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the 1000 colors, which are represented by the integers 0 b...
{"inputs": ["6\n0 1 2 3\n0 4 6 1\n1 6 9 2\n2 7 5 3\n6 4 5 7\n4 0 3 5", "6\n0 0 0 0\n0 0 1 0\n0 0 0 0\n0 0 0 0\n0 0 0 1\n0 1 0 0", "6\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n1 0 0 0", "6\n0 1 2 3\n0 4 6 1\n1 6 9 2\n3 7 5 3\n6 4 5 7\n4 0 3 5", "6\n0 1 2 3\n0 4 6 1\n1 6 9 2\n3 7 5 3\n6 4 6 7\n4 0 3 5", "6\n0 1 2 3\n...
568
447
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given an array of strings and your task is to remove all consecutive duplicate letters from each string in the array. For example: * `dup(["abracadabra","allottee","assessee"]) = ["abracadabra","alote","asese"]`. * `d...
{"functional": "_inputs = [[['ccooddddddewwwaaaaarrrrsssss', 'piccaninny', 'hubbubbubboo']], [['abracadabra', 'allottee', 'assessee']], [['kelless', 'keenness']], [['Woolloomooloo', 'flooddoorroommoonlighters', 'chuchchi']], [['adanac', 'soonness', 'toolless', 'ppellee']], [['callalloo', 'feelless', 'heelless']], [['pu...
257
387
coding
Solve the programming task below in a Python markdown code block. Write a function that will check whether the permutation of an input string is a palindrome. Bonus points for a solution that is efficient and/or that uses _only_ built-in language functions. Deem yourself **brilliant** if you can come up with a version ...
{"functional": "_inputs = [['a'], ['aa'], ['baa'], ['aab'], ['baabcd'], ['racecars'], ['abcdefghba'], ['']]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [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,...
172
203
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ of length $n$ consisting only of the characters 0 and 1. You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the remainin...
{"inputs": ["3\n3 2 0\n000\n5 -2 5\n11001\n6 1 0\n100111\n", "3\n3 2 0\n000\n5 -1 5\n11001\n6 1 0\n100111\n", "3\n3 2 1\n000\n5 -2 5\n11001\n6 1 0\n110111\n", "3\n3 2 1\n010\n5 -2 4\n11000\n6 2 0\n100111\n", "3\n3 2 0\n000\n5 -2 5\n11001\n6 1 -4\n100111\n", "3\n3 2 0\n000\n5 -2 5\n11001\n6 1 -4\n110111\n", "3\n3 2 0\n0...
542
394
coding
Solve the programming task below in a Python markdown code block. Sum all the numbers of the array (in F# and Haskell you get a list) except the highest and the lowest element (the value, not the index!). (The highest/lowest element is respectively only one element at each edge, even if there are more than one with the...
{"functional": "_inputs = [[None], [[]], [[3]], [[-3]], [[3, 5]], [[-3, -5]], [[6, 2, 1, 8, 10]], [[6, 0, 1, 10, 10]], [[-6, -20, -1, -10, -12]], [[-6, 20, -1, 10, -12]]]\n_outputs = [[0], [0], [0], [0], [0], [0], [16], [17], [-28], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst...
221
277
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. The *greatest common divisor* (GCD) of a sequence is the greatest positive integer which divides each element of this sequence. You are given a sequence $A$ of positive inte...
{"inputs": ["2\n2\n2 3\n2\n2 4"], "outputs": ["0\n-1"]}
445
27
coding
Solve the programming task below in a Python markdown code block. There are a total of W x H squares, with H rows vertically and W columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and outputs the maximum rectangular area consisting of only the unmarked squares. ...
{"inputs": ["10 7\n...*....**\n..........\n**....**..\n........*.\n..*.......\n**........\n.*........\n..........\n....*..***\n...*....*.\n10 4\n..*....*..\n.*.*...*..\n..*..*****\n*...*..*..\n..*..*...*\n..........\n.***.*..**\n..*..*...*\n..*..*...*\n****...***\n2 2\n...\n...\n0 0", "10 6\n...*....**\n..........\n**....
504
1,102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. With respect to a given puzzle string, a word is valid if both the following conditions are satisfied: word contains the first letter of puzzle. For each letter in word, that letter is in puzzle. For example, if th...
{"functional": "def check(candidate):\n assert candidate(\nwords = [\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"], \npuzzles = [\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]) == [1,1,3,2,4,0]\n\n\ncheck(Solution().findNumOfValidWords)"}
190
95
coding
Solve the programming task below in a Python markdown code block. Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in other words, a string s of length n, consisting of characters "(" and ")". Sereja needs to answer m queries, each of them is described by two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). The a...
{"inputs": ["(\n1\n1 1\n", ")\n1\n1 1\n", "(\n1\n1 1\n", ")\n1\n1 1\n", "()\n1\n1 2\n", ")(\n1\n1 2\n", ")(\n1\n1 2\n", "()\n1\n1 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "2\n", "0\n", "0\n", "2\n"]}
556
120
coding
Solve the programming task below in a Python markdown code block. Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photo...
{"inputs": ["1\n0 0 0 0\n", "1\n0 0 -1 0\n", "1\n0 10 0 19\n", "1\n0 10 1 11\n", "1\n0 -1 -1 0\n", "1\n0 10 0 11\n", "1\n0 -1 -1 1\n", "1\n0 10 0 10\n"], "outputs": ["0", "0\n", "-10\n", "-9\n", "0\n", "-10\n", "0\n", "-10"]}
452
143
coding
Solve the programming task below in a Python markdown code block. Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is t...
{"inputs": ["2 2\n", "3 2\n", "1 8\n", "100000 100000\n"], "outputs": ["8\n", "12\n", "0\n", "530123477\n"]}
265
65
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal. A subarray is a contiguous part of the array.   Please complete the following python code precisely: ```python c...
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,1,0,1], goal = 2) == 4\n assert candidate(nums = [0,0,0,0,0], goal = 0) == 15\n\n\ncheck(Solution().numSubarraysWithSum)"}
89
73
coding
Solve the programming task below in a Python markdown code block. A positive integer is called a 2-3-integer, if it is equal to 2^{x}·3^{y} for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 10...
{"inputs": ["1 1\n", "2 2\n", "2 2\n", "1 1\n", "1 2\n", "1 10\n", "2 10\n", "1 10\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "7\n", "6\n", "7\n"]}
337
89
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree are cousins, or false otherwise. T...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4]), x = 4, y = 3) == False\n assert candidate(root = tree_node([1,2,3,None,4,None,5]), x = 5, y = 4) == True\n assert candidate(root = tree_node([1,2,3,None,4]), x = 2, y = 3) == False\n\n\ncheck(Solution().isCousins)"}
207
113
coding
Solve the programming task below in a Python markdown code block. Create a function that takes in the sum and age difference of two people, calculates their individual ages, and returns a pair of values (oldest age first) if those exist or `null/None` if: * `sum < 0` * `difference < 0` * Either of the calculated ages ...
{"functional": "_inputs = [[24, 4], [30, 6], [70, 10], [18, 4], [63, 14], [80, 80], [63, -14], [-22, 15]]\n_outputs = [[[14, 10]], [[18, 12]], [[40, 30]], [[11, 7]], [[38.5, 24.5]], [[80, 0]], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retu...
106
266
coding
Solve the programming task below in a Python markdown code block. A binary string is a string that consists of characters $0$ and $1$. Let $\operatorname{MEX}$ of a binary string be the smallest digit among $0$, $1$, or $2$ that does not occur in the string. For example, $\operatorname{MEX}$ of $001011$ is $2$, becaus...
{"inputs": ["6\n1\n1001\n01100\n111\n0000\n01010\n", "6\n1\n1001\n01100\n101\n0000\n01010\n", "6\n1\n1111\n01100\n101\n1000\n11010\n", "6\n1\n1010\n11100\n100\n0000\n01010\n", "6\n0\n1011\n01100\n010\n0000\n01010\n", "6\n0\n1001\n01100\n110\n0010\n01010\n", "6\n0\n1001\n01100\n111\n0010\n01010\n", "6\n1\n0010\n01100\n1...
552
374
coding
Solve the programming task below in a Python markdown code block. Given two non-negative decimal integers $a$ and $b$, calculate their AND (logical conjunction), OR (logical disjunction) and XOR (exclusive disjunction) and print them in binary representation of 32 bits. Constraints * $0 \leq a, b \leq 2^{32} - 1$ In...
{"inputs": ["1 1", "2 1", "2 0", "1 0", "0 0", "1 3", "2 3", "4 0"], "outputs": ["00000000000000000000000000000001\n00000000000000000000000000000001\n00000000000000000000000000000000\n", "00000000000000000000000000000000\n00000000000000000000000000000011\n00000000000000000000000000000011\n", "00000000000000000000000000...
223
854
coding
Solve the programming task below in a Python markdown code block. You will be given a string and you task is to check if it is possible to convert that string into a palindrome by removing a single character. If the string is already a palindrome, return `"OK"`. If it is not, and we can convert it to a palindrome by re...
{"functional": "_inputs = [['abba'], ['abbaa'], ['abbaab'], ['madmam'], ['raydarm'], ['hannah'], ['baba'], ['babab'], ['bababa'], ['abcbad'], ['abcdba'], ['dabcba'], ['abededba'], ['abdcdeba'], ['abcdedba'], ['abbcdedba']]\n_outputs = [['OK'], ['remove one'], ['not possible'], ['remove one'], ['not possible'], ['OK'], ...
237
285
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right]. The tes...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,4,3], left = 2, right = 3) == 3\n assert candidate(nums = [2,9,2,5,6], left = 2, right = 8) == 7\n\n\ncheck(Solution().numSubarrayBoundedMax)"}
122
81
coding
Solve the programming task below in a Python markdown code block. Kuznecov likes art, poetry, and music. And strings consisting of lowercase English letters. Recently, Kuznecov has found two strings, $a$ and $b$, of lengths $n$ and $m$ respectively. They consist of lowercase English letters and no character is contain...
{"inputs": ["1\n5 1 5\naaaaa\nx\n", "3\n6 4 2\naaaaaa\nbbbb\n5 9 3\ncaaca\nbedededeb\n7 7 1\nnoskill\nwxhtzdy\n"], "outputs": ["aaaaa\n", "aabaabaa\naaabbcc\ndihktlwlxnyoz\n"]}
681
88
coding
Solve the programming task below in a Python markdown code block. We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, y_1),...
{"inputs": ["4 2 2", "4 5 7", "2 3 2", "4 6 7", "2 3 3", "2 4 3", "1 4 3", "1 4 4"], "outputs": ["56\n", "4883760\n", "25\n", "24227280\n", "100\n", "336\n", "20\n", "10\n"]}
510
115
coding
Solve the programming task below in a Python markdown code block. # Scenario *You're saying good-bye your best friend* , **_See you next happy year_** . **_Happy Year_** *is the year with only distinct digits* , (e.g) **_2018_** ___ # Task **_Given_** a year, **_Find_** **_The next happy year_** or **_The closest...
{"functional": "_inputs = [[1001], [1123], [2001], [2334], [3331], [1987], [5555], [7712], [8088], [8999]]\n_outputs = [[1023], [1203], [2013], [2340], [3401], [2013], [5601], [7801], [8091], [9012]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i...
519
270
coding
Solve the programming task below in a Python markdown code block. There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want. To play d...
{"inputs": ["H\nQD KD\n", "D\n9S 8S\n", "H\nTH 8H\n", "D\nAC KS\n", "H\nAH KH\n", "H\nAD KD\n", "D\n8S 6C\n", "H\nAC QC\n"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
443
103
coding
Solve the programming task below in a Python markdown code block. Given a string containing a list of integers separated by commas, write the function string_to_int_list(s) that takes said string and returns a new list containing all integers present in the string, preserving the order. For example, give the string "-...
{"functional": "_inputs = [['1,2,3,4,5'], ['21,12,23,34,45'], ['-1,-2,3,-4,-5'], ['1,2,3,,,4,,5,,,'], [',,,,,1,2,3,,,4,,5,,,'], [''], [',,,,,,,,']]\n_outputs = [[[1, 2, 3, 4, 5]], [[21, 12, 23, 34, 45]], [[-1, -2, 3, -4, -5]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):...
148
306
coding
Solve the programming task below in a Python markdown code block. You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like. Constraints * 2 \leq N \leq 10^5 * 1 \leq A_i \leq...
{"inputs": ["3\n5\n6\n1", "3\n5\n3\n1", "3\n0\n3\n1", "3\n0\n0\n1", "3\n0\n0\n0", "3\n5\n5\n1", "3\n-1\n0\n1", "3\n-1\n1\n1"], "outputs": ["9\n", "6\n", "5\n", "2\n", "0\n", "8", "3\n", "4\n"]}
204
111
coding
Solve the programming task below in a Python markdown code block. Your task is to write a function named `do_math` that receives a single argument. This argument is a string that contains multiple whitespace delimited numbers. Each number has a single alphabet letter somewhere within it. ``` Example : "24z6 1x23 y369 ...
{"functional": "_inputs = [['24z6 1z23 y369 89z 900b'], ['24z6 1x23 y369 89a 900b'], ['10a 90x 14b 78u 45a 7b 34y'], ['111a 222c 444y 777u 999a 888p'], ['1z 2t 3q 5x 6u 8a 7b']]\n_outputs = [[1414], [1299], [60], [1459], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, floa...
499
302
coding
Solve the programming task below in a Python markdown code block. **DESCRIPTION:** Your strict math teacher is teaching you about right triangles, and the Pythagorean Theorem --> a^2 + b^2 = c^2 whereas a and b are the legs of the right triangle and c is the hypotenuse of the right triangle. On the test however, the...
{"functional": "_inputs = [[1, 1], [3, 4], [4, 6], [5, 12], [8, 10]]\n_outputs = [[[1]], [[2, 3, 4, 6]], [[3, 4, 5, 6, 7, 8, 9]], [[8, 9, 10, 11, 12, 14, 15, 16]], [[3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
397
296
coding
Solve the programming task below in a Python markdown code block. You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 thr...
{"inputs": ["6\n2 3 6 1 3 1", "6\n5 2 2 2 8 8", "6\n2 5 3 1 3 1", "6\n3 6 3 1 6 1", "6\n2 6 6 1 3 1", "6\n2 5 3 2 3 1", "6\n2 6 3 1 3 1", "6\n2 5 3 2 3 2"], "outputs": ["3\n", "0\n", "2\n", "1\n", "2\n", "0\n", "2\n", "0\n"]}
383
158
coding
Solve the programming task below in a Python markdown code block. Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on. Kyota Ootori has just ...
{"inputs": ["1 1\n", "5 8\n", "5 1\n", "2 2\n", "3 3\n", "9 1\n", "4 2\n", "2 1\n"], "outputs": ["1 ", "2 1 4 3 5 ", "1 2 3 4 5 ", "2 1 ", "2 1 3 ", "1 2 3 4 5 6 7 8 9 ", "1 2 4 3 ", "1 2\n"]}
647
125
coding
Solve the programming task below in a Python markdown code block. The only difference between this problem and D2 is that you don't have to provide the way to construct the answer in this problem, but you have to do it in D2. There's a table of $n \times m$ cells ($n$ rows and $m$ columns). The value of $n \cdot m$ is...
{"inputs": ["1\n6 1 0\n", "1\n1 2 1\n", "1\n2 1 0\n", "1\n6 3 8\n", "1\n4 1 0\n", "1\n1 4 2\n", "1\n7 4 2\n", "1\n8 1 0\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
446
118
coding
Solve the programming task below in a Python markdown code block. Given an array, return the reversed version of the array (a different kind of reverse though), you reverse portions of the array, you'll be given a length argument which represents the length of each portion you are to reverse. E.g if after reversi...
{"functional": "_inputs = [[[2, 4, 6, 8, 10, 12, 14, 16], 3], [[2, 4, 6, 8, 10, 12, 14, 16], 2], [[1, 2, 3, 4, 5, 6], 2], [[1, 2, 3, 4, 5, 6], 0], [[1, 2, 3, 4, 5, 6], 10]]\n_outputs = [[[6, 4, 2, 12, 10, 8, 16, 14]], [[4, 2, 8, 6, 12, 10, 16, 14]], [[2, 1, 4, 3, 6, 5]], [[1, 2, 3, 4, 5, 6]], [[6, 5, 4, 3, 2, 1]]]\nimp...
168
384
coding
Solve the programming task below in a Python markdown code block. In recreational mathematics, a [Keith number](https://en.wikipedia.org/wiki/Keith_number) or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence: `14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208, ...
{"functional": "_inputs = [[14], [10], [4], [28], [23], [0], [19], [47], [34], [61], [58], [75], [197], [742], [1104], [1537], [2208], [2697], [7385], [31331], [120284], [1084051], [44121607], [251133297], [96189170155], [11812665388886672], [855191324330802397989], [18354972585225358067718266], [4179620576514742697470...
465
493
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part. Note that the partition is done so that after concatenating all the parts in or...
{"functional": "def check(candidate):\n assert candidate(s = \"ababcbacadefegdehijhklij\") == [9,7,8]\n assert candidate(s = \"eccbbbbdec\") == [10]\n\n\ncheck(Solution().partitionLabels)"}
114
62
coding
Solve the programming task below in a Python markdown code block. Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a_0 + a_1x^1 + ... + a_{n}x^{n}. Numbers a_{i} are called coefficients of a polynomial, non-negative integer n is ...
{"inputs": ["2 2 2\n", "2 3 3\n", "1 1 1\n", "7 8 9\n", "3 3 3\n", "1 5 5\n", "1 2 2\n", "1 2 5\n"], "outputs": ["2\n", "1\n", "inf\n", "1\n", "2\n", "1\n", "1\n", "1\n"]}
286
102
coding
Solve the programming task below in a Python markdown code block. A group of $n$ dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them — a bla...
{"inputs": ["1 100 1\n0\n", "1 1 100\n2\n", "1 100 1\n2\n", "2 9 6\n2 2\n", "1 1 100\n1\n", "1 100 1\n1\n", "1 1 100\n0\n", "2 1 1\n2 2\n"], "outputs": ["0\n", "1\n", "1\n", "12\n", "0\n", "0\n", "0\n", "2\n"]}
637
135
coding
Solve the programming task below in a Python markdown code block. There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn o...
{"inputs": ["3 100000007\n", "4 100000007\n", "5 999999937\n", "6 100000007\n", "7 100000007\n", "6 100000007\n", "5 999999937\n", "7 100000007\n"], "outputs": ["6\n", "20\n", "78\n", "344\n", "1680\n", "344\n", "78\n", "1680\n"]}
472
163
coding
Solve the programming task below in a Python markdown code block. Sophia has discovered several alien languages. Suprisingly, all of these languages have an alphabet, and each of them may contain thousands of characters! Also, all the words in a language have the same number of characters in it. However, the aliens li...
{"inputs": ["3\n1 3\n2 3\n3 2\n"], "outputs": ["1\n3\n6\n"]}
675
30
coding
Solve the programming task below in a Python markdown code block. You are given a positive integer $N$. Print a numerical triangle of height $N-1$ like the one below: 1 22 333 4444 55555 ...... Can you do it using only arithmetic operations, a single for loop and print statement? Use no more than two lines. The ...
{"inputs": ["5\n"], "outputs": ["1\n22\n333\n4444\n"]}
191
26
coding
Solve the programming task below in a Python markdown code block. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The comput...
{"inputs": ["3 0 3\n0\n", "1 1 1\n0\n", "1 1 1\n0\n", "3 0 3\n0\n", "1 2 1\n0\n", "2 0 3\n0\n", "1 2 0\n0\n", "2 1 3\n0\n"], "outputs": ["0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n"]}
519
134
coding
Solve the programming task below in a Python markdown code block. Write a function that accepts two square (`NxN`) matrices (two dimensional arrays), and returns the product of the two. Only square matrices will be given. How to multiply two square matrices: We are given two matrices, A and B, of size 2x2 (note: tes...
{"functional": "_inputs = [[[[1, 2], [3, 2]], [[3, 2], [1, 1]]], [[[9, 7], [0, 1]], [[1, 1], [4, 12]]], [[[1, 2, 3], [3, 2, 1], [2, 1, 3]], [[4, 5, 6], [6, 5, 4], [4, 6, 5]]]]\n_outputs = [[[[5, 4], [11, 8]]], [[[37, 93], [4, 12]]], [[[28, 33, 29], [28, 31, 31], [26, 33, 31]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5...
610
323
coding
Solve the programming task below in a Python markdown code block. Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the s...
{"inputs": ["1 10 9 5\n1 2 3 4 5 6 7 8 9 1\n1 1 9 2 3\n", "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 4 5 6 7 8 9 1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 3 5 6 7 8 9 1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 3 5 6 7 6 9 1\n1 1 9 2 3\n", "10 1 9 5\n1\n...
694
366
coding
Solve the programming task below in a Python markdown code block. # Task A range-collapse representation of an array of integers looks like this: `"1,3-6,8"`, where `3-6` denotes the range from `3-6`, i.e. `[3,4,5,6]`. Hence `"1,3-6,8"` = `[1,3,4,5,6,8]`. Some other range-collapse representations of `[1,3,4,5,6,8]...
{"functional": "_inputs = [[[1, 3, 4, 5, 6, 8]], [[1, 2, 3]], [[11, 43, 66, 123]], [[3, 4, 5, 8, 9, 10, 11, 23, 43, 66, 67]]]\n_outputs = [[8], [4], [1], [64]]\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...
390
244
coding
Solve the programming task below in a Python markdown code block. A permutation of length N is an array of N integers A = [A_{1}, A_{2}, \dots, A_{N}] such that every integer from 1 to N appears in it exactly once. We define a function over a permutation as follows: F(A) = (A_{1} * A_{2}) + (A_{2} * A_{3}) + \cdots + ...
{"inputs": ["2\n2\n3"], "outputs": ["2\n333333343\n"]}
600
27
coding
Solve the programming task below in a Python markdown code block. Write a function that returns a sequence (index begins with 1) of all the even characters from a string. If the string is smaller than two characters or longer than 100 characters, the function should return "invalid string". For example: ````` "abcdef...
{"functional": "_inputs = [['a'], ['abcdefghijklm'], ['aBc_e9g*i-k$m'], [''], ['ab'], ['aiqbuwbjqwbckjdwbwkqbefhglqhfjbwqejbcadn.bcaw.jbhwefjbwqkvbweevkj.bwvwbhvjk.dsvbajdv.hwuvghwuvfhgw.vjhwncv.wecnaw.ecnvw.kejvhnw.evjkhweqv.kjhwqeev.kjbhdjk.vbaewkjva']]\n_outputs = [['invalid string'], [['b', 'd', 'f', 'h', 'j', 'l']...
123
309
coding
Solve the programming task below in a Python markdown code block. Find the number of palindromic numbers among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward. -----Constraints-...
{"inputs": ["7055 945", "7055 699", "5344 1543", "7055 1543", "10323 699", "10323 293", "10426 293", "15714 1543"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
197
125
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings of the same length words. In one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i]. Two strings words[i] and words[j] are speci...
{"functional": "def check(candidate):\n assert candidate(words = [\"abcd\",\"cdab\",\"cbad\",\"xyzz\",\"zzxy\",\"zzyx\"]) == 3\n assert candidate(words = [\"abc\",\"acb\",\"bac\",\"bca\",\"cab\",\"cba\"]) == 3\n\n\ncheck(Solution().numSpecialEquivGroups)"}
243
77
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false. An integer m is a divisor of n if there exists an integer k such that n = k * m.   Please complete the following pytho...
{"functional": "def check(candidate):\n assert candidate(n = 2) == False\n assert candidate(n = 4) == True\n\n\ncheck(Solution().isThree)"}
90
41
coding
Solve the programming task below in a Python markdown code block. God's Blessing on This PermutationForces! A Random Pebble You are given a permutation $p_1,p_2,\ldots,p_n$ of length $n$ and a positive integer $k \le n$. In one operation you can choose two indices $i$ and $j$ ($1 \le i < j \le n$) and swap $p_i$ wit...
{"inputs": ["4\n3 1\n2 3 1\n3 3\n1 2 3\n4 2\n3 4 1 2\n1 1\n1\n"], "outputs": ["1\n0\n2\n0\n"]}
550
58
coding
Solve the programming task below in a Python markdown code block. Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n se...
{"inputs": ["1 0 0\n1\n", "1 0 0\n0\n", "1 1 0\n0\n", "1 1 10\n23\n", "2 0 1\n1 1\n", "1 1 10\n20\n", "2 0 1\n1 0\n", "2 0 100\n98 2\n"], "outputs": ["1\n", "0\n", "0", "33\n", "1\n", "30", "1", "100\n"]}
470
132
coding
Solve the programming task below in a Python markdown code block. Make a function that receives a value, ```val``` and outputs the smallest higher number than the given value, and this number belong to a set of positive integers that have the following properties: - their digits occur only once - they are odd - they...
{"functional": "_inputs = [[12], [13], [99], [999999], [9999999999]]\n_outputs = [[15], [15], [105], [1023459], ['There is no possible number that fulfills those requirements']]\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=t...
187
215
coding
Solve the programming task below in a Python markdown code block. Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = $2$, b = $3$ changes the v...
{"inputs": ["2\n1 2 3\n5 4 100\n", "2\n1 2 3\n7 4 100\n", "2\n1 1 3\n5 4 100\n", "2\n1 1 3\n5 4 101\n", "2\n1 1 3\n5 4 111\n", "2\n1 2 3\n5 4 100\n", "16\n1 1 1\n3 4 7\n4 5 13\n456 123 7890123\n1 1 1000000000\n45 12 782595420\n1 1000000000 1000000000\n1 999999999 1000000000\n1 99999 676497416\n5 6 930234861\n8 9 881919...
364
836
coding
Solve the programming task below in a Python markdown code block. Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time t_{i} needed to serve him. A person will be disappointed if the time he waits is more than the t...
{"inputs": ["5\n15 2 1 5 3\n", "1\n1000000000\n", "1\n1000000000\n", "5\n15 2 2 5 3\n", "5\n15 2 1 8 3\n", "5\n15 2 2 4 3\n", "5\n15 2 1 5 3\n", "10\n13 2 5 55 21 34 1 8 1 3\n"], "outputs": ["4\n", "1\n", "1\n", "4\n", "5\n", "4\n", "4\n", "6\n"]}
289
172