task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. Chef has a natural number N. Cheffina challenges chef to check whether the given number is divisible by the sum of its digits or not. If the given number is divisible then print "Yes" else "No". -----Input:----- - First-line will contain $T$, the number...
{"inputs": ["2\n16\n27"], "outputs": ["No\nYes"]}
169
20
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s. The dis...
{"functional": "def check(candidate):\n assert candidate(s = \"loveleetcode\", c = \"e\") == [3,2,1,0,1,0,0,1,2,2,1,0]\n assert candidate(s = \"aaab\", c = \"b\") == [3,2,1,0]\n\n\ncheck(Solution().shortestToChar)"}
120
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times: Operation 1: If the number contains the substring "00", you can replace it with ...
{"functional": "def check(candidate):\n assert candidate(binary = \"000110\") == \"111011\"\n assert candidate(binary = \"01\") == \"01\"\n\n\ncheck(Solution().maximumBinaryString)"}
199
58
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef has a box full of infinite number of identical coins. One day while playing, he made N piles each containing equal number of coins. Chef suddenly remembered an important task and left the ...
{"inputs": ["1\n4\n1 2 3 4", "1\n4\n1 2 2 4", "1\n4\n1 2 2 2", "1\n4\n1 2 0 4", "1\n4\n1 1 1 1", "1\n4\n1 2 1 4", "1\n4\n1 0 2 2", "1\n4\n1 1 2 2"], "outputs": ["3", "2\n", "1\n", "3\n", "0\n", "2\n", "2\n", "2\n"]}
518
141
coding
Solve the programming task below in a Python markdown code block. Lets define G(x, {A_{1}, A_{2}, A_{3}, ..., A_{x}}) as a game played by 2 players in which we have x piles of stones with ith pile having A_{i} stones. Player 1 moves first. The players move alternatively. In a move a player can select a single non empty...
{"inputs": ["6\n1 1 2 3 3 2"], "outputs": ["1"]}
642
24
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef likes problems on geometry a lot. Please help him to solve one such problem. Find all possible triangles with integer sides which has the radius of inscribed circle (al...
{"inputs": ["2"], "outputs": ["5\n5 12 13\n6 8 10\n6 25 29\n7 15 20\n9 10 17"]}
393
51
coding
Solve the programming task below in a Python markdown code block. After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys...
{"inputs": ["3 1 3\n1\n2\n3\n", "4 0 4\n1\n2\n3\n4\n", "4 1 4\n1\n2\n3\n4\n", "5 2 5\n1\n2\n2\n4\n5\n", "5 2 5\n1\n2\n3\n1\n5\n", "5 2 5\n1\n3\n3\n1\n5\n", "5 2 5\n1\n3\n3\n2\n5\n", "5 2 5\n1\n2\n3\n4\n5\n"], "outputs": ["..X", "....", "...X", "...XX", "....X", "....X", "....X", "...XX"]}
725
170
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. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. Find the maximum value of the expression $|A_{x}-A_{y}| + |A_{y}-A_{z}| + |A_{z}-A_{x}|$ over...
{"inputs": ["3\n3\n2 7 5\n3\n3 3 3\n5\n2 2 2 2 5"], "outputs": ["10\n0\n6"]}
556
45
coding
Solve the programming task below in a Python markdown code block. This is the easy version of this problem. The difference between easy and hard versions is only the constraints on $a_i$ and on $n$. You can make hacks only if both versions of the problem are solved. Burenka is the crown princess of Buryatia, and soon ...
{"inputs": ["7\n4\n5 5 5 5\n3\n1 3 2\n2\n0 0\n3\n2 5 7\n6\n1 2 3 3 2 1\n10\n27 27 34 32 2 31 23 56 52 4\n5\n1822 1799 57 23 55\n"], "outputs": ["2\n2\n0\n2\n4\n7\n4\n"]}
736
124
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary tree root and an integer target, delete all the leaf nodes with value target. Note that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([1,2,3,2,None,2,4]), target = 2), tree_node([1,None,3,None,4]))\n assert is_same_tree(candidate(root = tree_node([1,3,3,3,2]), target = 3), tree_node([1,3,None,None,2]))\n assert is_same_tree(candidate(root = tree_node([1,2,...
168
195
coding
Solve the programming task below in a Python markdown code block. Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows, To decide the amount of beverage they plan to consume, say X. Then order for a random...
{"inputs": ["4\n4 3 25 5\n33", "4\n55 45 2 23\n58", "7\n2 5 4 9 7 33 6\n44", "6\n45 55 5 7 23 4\n107", "8\n4 8 9 7 45 6 3 27\n56", "8\n4 8 9 7 45 6 3 27\n156"], "outputs": ["True", "False", "True", "True", "True", "False"]}
370
148
coding
Solve the programming task below in a Python markdown code block. Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendsh...
{"inputs": ["3 3\n4 5\n0 17\n9 11\n", "1 1000000000\n15 1\n", "1 1000000000\n19 8\n", "1 1000000000\n15 12\n", "3 3\n4 15\n0 17\n9 11\n", "3 3\n4 15\n0 17\n9 11\n", "1 1000000000\n15 12\n", "3 3\n4 15\n0 17\n6 11\n"], "outputs": ["17\n", "1\n", "8\n", "12\n", "17\n", "17", "12", "26\n"]}
432
207
coding
Solve the programming task below in a Python markdown code block. You are given an integer array $a$ of length $n$. Does there exist an array $b$ consisting of $n+1$ positive integers such that $a_i=\gcd (b_i,b_{i+1})$ for all $i$ ($1 \leq i \leq n$)? Note that $\gcd(x, y)$ denotes the greatest common divisor (GCD) o...
{"inputs": ["1\n3\n6 3 2\n", "1\n3\n6 9 2\n", "1\n3\n12 4 3\n", "1\n3\n10 5 4\n", "1\n3\n35 7 5\n", "1\n3\n96 64 3\n", "1\n3\n22 11 18\n", "1\n3\n101 1 101\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
423
146
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string num, representing a large integer, and an integer k. We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful inte...
{"functional": "def check(candidate):\n assert candidate(num = \"5489355142\", k = 4) == 2\n assert candidate(num = \"11112\", k = 4) == 4\n assert candidate(num = \"00123\", k = 1) == 1\n\n\ncheck(Solution().getMinSwaps)"}
253
89
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Sereja is playing a game called Winner Eats Sandwich with his friends. There are N persons in total, including Sereja. Sereja is allotted the number 1, while his friends are allotted numbers fro...
{"inputs": ["2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n0.5000 0.5000 0.5000\n0.5000 0.5000 0.5000", "2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n0.5000 0.5000 0.5000\n0.5000 0.5000 0.5000 ", "2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n1.2649803683768097 0.5000 0.5000\n0.5000 0.5000 0.5000", "2\n2 2\n1.0000 1.7642945663...
565
896
coding
Solve the programming task below in a Python markdown code block. Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For examp...
{"inputs": ["3\n", "2\n", "8\n", "9\n", "6\n", "7\n", "5\n", "4\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "2\n"]}
334
70
coding
Solve the programming task below in a Python markdown code block. Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow) -----Input----- Input will start with an integer T the count of test cases, each case will hav...
{"inputs": ["1\n10"], "outputs": ["10"]}
160
16
coding
Solve the programming task below in a Python markdown code block. There are N people, conveniently numbered 1 through N. We want to divide them into some number of groups, under the following two conditions: - Every group contains between A and B people, inclusive. - Let F_i be the number of the groups containing exa...
{"inputs": ["7 3 4 2 5", "8 2 3 1 3", "7 1 3 1 3", "7 1 6 2 5", "0 3 8 2 7", "2 1 3 1 2", "8 2 5 1 3", "4 2 7 1 2"], "outputs": ["0\n", "280\n", "595\n", "105\n", "1\n", "2\n", "581\n", "4\n"]}
336
134
coding
Solve the programming task below in a Python markdown code block. Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day...
{"inputs": ["1 3\n5 3\n", "1 3\n5 3\n", "1 3\n1 3\n", "1 3\n1 6\n", "1 1\n2 4\n", "1 1\n3 4\n", "1 0\n3 4\n", "1 0\n3 2\n"], "outputs": ["3\n", "3\n", "3\n", "6\n", "2\n", "2\n", "0\n", "0\n"]}
486
118
coding
Solve the programming task below in a Python markdown code block. You have a rooted tree with $n$ vertices numbered from $\mbox{1}$ through $n$ where the root is vertex $\mbox{1}$. You are given $m$ triplets, the $j^{th}$ triplet is denoted by three integers $u_j,v_j,c_j$. The $j^{th}$ triplet represents a simple pat...
{"inputs": ["1\n8 8\n1 2 3\n1 3 1\n2 4 5\n2 5 1\n2 6 1\n3 7 2\n4 8 1\n1 2 3\n2 8 5\n1 8 7\n1 5 8\n1 6 10\n3 7 5\n1 7 6\n1 7 6\n"], "outputs": ["37\n"]}
670
110
coding
Solve the programming task below in a Python markdown code block. You are given array $a_1, a_2, \dots, a_n$. Find the subsegment $a_l, a_{l+1}, \dots, a_r$ ($1 \le l \le r \le n$) with maximum arithmetic mean $\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$ (in floating-point numbers, i.e. without any rounding). If th...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
266
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.   Please complete the following python code precisely: ```python # Definit...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,6,3,4,5,6]), val = 6), list_node([1,2,3,4,5]))\n assert is_same_list(candidate(head = list_node([]), val = 1), list_node([]))\n assert is_same_list(candidate(head = list_node([7,7,7,7]), val = 7), list_node([]))\n\n\nch...
128
117
coding
Solve the programming task below in a Python markdown code block. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars....
{"inputs": ["1\nsell 17\n", "1\nsell 31\n", "1\nwin 2000\n", "1\nsell 104\n", "1\nsell 2000\n", "2\nwin 2000\nsell 238\n", "2\nwin 2000\nsell 315\n", "2\nwin 2000\nsell 350\n"], "outputs": ["0\n", "0\n", "0", "0\n", "0", "0\n", "0\n", "0\n"]}
440
137
coding
Solve the programming task below in a Python markdown code block. This is the first step to understanding FizzBuzz. Your inputs: a positive integer, n, greater than or equal to one. n is provided, you have NO CONTROL over its value. Your expected output is an array of positive integers from 1 to n (inclusive). You...
{"functional": "_inputs = [[1], [2], [3], [4], [5]]\n_outputs = [[[1]], [[1, 2]], [[1, 2, 3]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tu...
109
209
coding
Solve the programming task below in a Python markdown code block. In a classic chase, Tom is running after Jerry as Jerry has eaten Tom's favourite food. Jerry is running at a speed of X metres per second while Tom is chasing him at a speed of Y metres per second. Determine whether Tom will be able to catch Jerry. No...
{"inputs": ["4\n2 3\n4 1\n1 1\n3 5\n"], "outputs": ["YES\nNO\nNO\nYES\n"]}
475
36
coding
Solve the programming task below in a Python markdown code block. Tieu owns a pizza restaurant and he manages it in his own way. While in a normal restaurant, a customer is served by following the first-come, first-served rule, Tieu simply minimizes the average waiting time of his customers. So he gets to decide who i...
{"inputs": ["3\n0 3\n1 9\n2 6\n", "3\n0 3\n1 9\n2 5\n"], "outputs": ["9\n", "8\n"]}
677
46
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Chef has bought a new robot, which will be used for delivering dishes to his customers. He started testing the robot by letting it move on a line. Initially...
{"inputs": ["2\n6 10\nRRLLLL\n2 0\nLL"], "outputs": ["5\n3"]}
497
28
coding
Solve the programming task below in a Python markdown code block. Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every tic...
{"inputs": ["1\n1731005\n", "1\n2340786\n", "1\n4533183\n", "1\n3050700\n", "1\n1474114\n", "1\n1456697\n", "1\n19938466\n", "1\n26757320\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
458
136
coding
Solve the programming task below in a Python markdown code block. Recently Vasya found a golden ticket — a sequence which consists of $n$ digits $a_1a_2\dots a_n$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $350178$ is lucky ...
{"inputs": ["2\n00\n", "2\n44\n", "2\n55\n", "2\n02\n", "2\n36\n", "2\n11\n", "2\n00\n", "2\n55\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
334
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid. The following rules define a valid string: Any left parenthesis '(' must have a corresponding right parenthesis...
{"functional": "def check(candidate):\n assert candidate(s = \"()\") == True\n assert candidate(s = \"(*)\") == True\n assert candidate(s = \"(*))\") == True\n\n\ncheck(Solution().checkValidString)"}
138
54
coding
Solve the programming task below in a Python markdown code block. You are given 2 numbers is `n` and `k`. You need to find the number of integers between 1 and n (inclusive) that contains exactly `k` non-zero digit. Example1 ` almost_everywhere_zero(100, 1) return 19` by following condition we have 19 numbers that ...
{"functional": "_inputs = [[100, 1], [11, 2], [20, 2], [101, 2], [10001, 2], [10001000, 2], [500309160, 2], [10000000000000000000000, 3], [10000000000000000000000, 21], [1203, 4]]\n_outputs = [[19], [1], [9], [82], [487], [1729], [2604], [1122660], [2407217760893271902598], [81]]\nimport math\ndef _deep_eq(a, b, tol=1e...
250
352
coding
Solve the programming task below in a Python markdown code block. There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoi...
{"inputs": ["5\nWWEEW", "5\nEWEWW", "5\nWWEWE", "5\nWEWEW", "5\nWEWWE", "5\nEWWWE", "5\nEWWEW", "5\nWWWEE"], "outputs": ["2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "2\n"]}
275
93
coding
Solve the programming task below in a Python markdown code block. Alice is playing a game with her good friend, Marisa. There are n boxes arranged in a line, numbered with integers from 1 to n from left to right. Marisa will hide a doll in one of the boxes. Then Alice will have m chances to guess where the doll is. If...
{"inputs": ["7 1\n3\n", "8 1\n8\n", "1 1\n1\n", "2 1\n2\n", "4 1\n1\n", "3 1\n2\n", "5 1\n1\n", "6 1\n5\n"], "outputs": ["27\n", "34\n", "0\n", "4\n", "14\n", "7\n", "19\n", "22\n"]}
648
107
coding
Solve the programming task below in a Python markdown code block. Given a word consisting of lowercase English letters, write a program to remove duplicates from the word. The characters in the output must preserve the same order, as their first appearance in the original word. Input Format The input consists of seve...
{"inputs": ["5\nbananasqr\naaaaa\nabcde\nayacazkeafagahbcbdbebfbg\nqweer\n"], "outputs": ["bansqr\na\nabcde\nayczkefghbd\nqwer\n"]}
168
59
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. You are given a tree of $n$ vertices numbered from $1$ to $n$, with edges numbered from $1$ to $n-1$. A tree is a connected undirected graph without cycles. You have to assign integer weights to each edge of the tree, such that the resultant graph is a p...
{"inputs": ["3\n2\n1 2\n4\n1 3\n4 3\n2 1\n7\n1 2\n1 3\n3 4\n3 5\n6 2\n7 2\n"], "outputs": ["2 \n3 2 2 \n-1\n"]}
690
71
coding
Solve the programming task below in a Python markdown code block. There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n2\n", "2 2\n100 9\n", "2 2\n100 99\n", "2 2\n100 99\n", "2 2\n100 27\n", "2 2\n100 100\n"], "outputs": ["YES\n1 \n", "YES\n1", "YES\n1 ", "YES\n1 2 ", "YES\n1 2 \n", "YES\n1 2", "YES\n1 2 ", "NO\n"]}
469
146
coding
Solve the programming task below in a Python markdown code block. Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one e...
{"inputs": ["1\n4\n", "1\n2\n", "1\n5\n", "1\n1\n", "1\n3\n", "1\n8\n", "2\n1 3\n", "2\n2 1\n"], "outputs": ["1 ", "1 ", "1 ", "2 ", "1\n", "1\n", "1 1 ", "1 1 "]}
319
89
coding
Solve the programming task below in a Python markdown code block. Ito joined the Kyudo club after entering high school. At first, I had a hard time because the arrow didn't reach the target, but in the fall of my first year of high school, I managed to improve to the point where the arrow reached the target. One day, ...
{"inputs": ["20\n4\n6\n2\n1\n3\n8\n2\n0\n0", "20\n4\n6\n2\n1\n0\n8\n2\n0\n0", "20\n4\n6\n2\n1\n1\n8\n2\n0\n0", "20\n4\n3\n4\n1\n3\n8\n2\n0\n0", "20\n4\n6\n2\n2\n3\n8\n2\n0\n0", "20\n4\n6\n2\n1\n0\n8\n2\n1\n0", "20\n4\n3\n0\n1\n3\n8\n2\n0\n0", "20\n8\n6\n2\n2\n3\n8\n2\n0\n0"], "outputs": ["16\n2\n", "13\n2\n", "14\n2\n"...
362
238
coding
Solve the programming task below in a Python markdown code block. zeros The zeros tool returns a new array with a given shape and type filled with $\mbox{o}$'s. import numpy print numpy.zeros((1,2)) #Default type is float #Output : [[ 0. 0.]] print numpy.zeros((1,2), dtype = numpy.int) #Type ch...
{"inputs": ["3 3 3\n"], "outputs": ["[[[0 0 0]\n [0 0 0]\n [0 0 0]]\n\n [[0 0 0]\n [0 0 0]\n [0 0 0]]\n\n [[0 0 0]\n [0 0 0]\n [0 0 0]]]\n[[[1 1 1]\n [1 1 1]\n [1 1 1]]\n\n [[1 1 1]\n [1 1 1]\n [1 1 1]]\n\n [[1 1 1]\n [1 1 1]\n [1 1 1]]]\n"]}
466
184
coding
Solve the programming task below in a Python markdown code block. Andrew likes meatballs very much. He has N plates of meatballs, here the i^{th} plate contains P_{i} meatballs. You need to find the minimal number of plates Andrew needs to take to his trip to Las Vegas, if he wants to eat there at least M meatballs. No...
{"inputs": ["1\n4 7\n1 2 3 4"], "outputs": ["2"]}
331
24
coding
Solve the programming task below in a Python markdown code block. For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The...
{"inputs": ["3\n0 0 3 0 1 1 2 0\n0 0 0 0 3 1 3 -1\n0 0 6 1 1 -2 5 0", "3\n0 0 3 0 1 1 2 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 3 -2 5 0", "3\n0 0 3 0 1 1 2 -1\n0 0 0 0 3 1 3 -1\n0 0 6 0 1 -2 5 0", "3\n1 0 3 0 1 1 0 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 2 -4 5 0", "3\n-1 -1 4 0 2 1 4 1\n2 1 0 0 0 0 3 0\n0 2 6 2 1 -2 5 0", "3\n0 0 3 0 1 ...
252
479
coding
Solve the programming task below in a Python markdown code block. Vasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits. But since EatForces takes care of the security of its users, user passwor...
{"inputs": ["1\nA00\n", "1\na00\n", "1\n825\n", "1\n000\n", "1\n0a0\n", "1\n0aa\n", "1\n00A\n", "1\n001\n"], "outputs": ["Aa0\n", "aA0\n", "aA5\n", "aA0\n", "Aa0\n", "0Aa\n", "a0A\n", "aA1\n"]}
644
117
coding
Solve the programming task below in a Python markdown code block. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n1\n", "1 4\n2 3 4 1\n", "1 4\n2 3 4 1\n", "2 3\n3 1 2\n1 2 3\n", "2 3\n3 1 2\n1 2 3\n", "2 4\n1 3 2 4\n1 3 4 2\n"], "outputs": ["YES\n", "YES\n", "YES", "NO\n", "NO", "YES\n", "YES", "YES\n"]}
478
145
coding
Solve the programming task below in a Python markdown code block. Given an array $a$, consisting of $n$ integers, find: $$\max\limits_{1 \le i < j \le n} LCM(a_i,a_j),$$ where $LCM(x, y)$ is the smallest positive integer that is divisible by both $x$ and $y$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, ...
{"inputs": ["2\n2 5\n", "2\n1 1\n", "2\n1 1\n", "2\n2 5\n", "2\n3 5\n", "3\n13 35 77\n", "4\n12 9 1 8\n", "4\n12 9 1 8\n"], "outputs": ["10", "1", "1\n", "10\n", "15\n", "1001", "72", "72\n"]}
282
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums of length n. You can perform the following operation as many times as you want: Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[...
{"functional": "def check(candidate):\n assert candidate(nums = [4,9,6,10]) == True\n assert candidate(nums = [6,8,11,12]) == True\n assert candidate(nums = [5,8,3]) == False\n\n\ncheck(Solution().primeSubOperation)"}
143
72
coding
Solve the programming task below in a Python markdown code block. You are batting at the pitch and all eyes are on you, the best player in all of IPL! The opposing team will relentlessly bowl at you an infinite number of balls! You notice that you only ever score a boundary on the M^{th} ball, if N mod M ≤ N/2, where ...
{"inputs": ["1\n3"], "outputs": ["3"]}
313
14
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multipl...
{"functional": "def check(candidate):\n assert candidate(s = \"leetcode\", wordDict = [\"leet\",\"code\"]) == True\n assert candidate(s = \"applepenapple\", wordDict = [\"apple\",\"pen\"]) == True\n assert candidate(s = \"catsandog\", wordDict = [\"cats\",\"dog\",\"sand\",\"and\",\"cat\"]) == False\n\n\ncheck(...
101
92
coding
Solve the programming task below in a Python markdown code block. You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same. Constraints * 1 \leq N,K \leq...
{"inputs": ["4 3", "3 2", "5 3", "56 6", "20 6", "25 4", "25 7", "74 1"], "outputs": ["1\n", "9", "1", "1458\n", "54\n", "432\n", "27\n", "405224\n"]}
211
93
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob take turns playing a game, with Alice starting first. There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and B...
{"functional": "def check(candidate):\n assert candidate(aliceValues = [1,3], bobValues = [2,1]) == 1\n assert candidate(aliceValues = [1,2], bobValues = [3,1]) == 0\n assert candidate(aliceValues = [2,4,3], bobValues = [1,6,7]) == -1\n\n\ncheck(Solution().stoneGameVI)"}
237
96
coding
Solve the programming task below in a Python markdown code block. Given an integer N, find the number of tuples (w, x, y, z) such that 1 ≤ w, x, y, z ≤ N and \frac{w}{x} + \frac{y}{z} is an integer. For example, if N = 2, the tuple (1,2,1,2) satisfies both conditions, i.e. \frac{1}{2} + \frac{1}{2} = 1 is an integer, ...
{"inputs": ["3\n2\n3\n7"], "outputs": ["10\n31\n355\n"]}
567
27
coding
Solve the programming task below in a Python markdown code block. Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1...
{"inputs": ["2\n2 3\n", "2\n2 3\n", "2\n4 3\n", "2\n1 3\n", "2\n4 1\n", "2\n1 6\n", "2\n7 1\n", "2\n1 1\n"], "outputs": ["5\n", "5\n", "7\n", "3\n", "3\n", "3\n", "3\n", "2\n"]}
538
102
coding
Solve the programming task below in a Python markdown code block. Chef has a sequence of $N$ integers, $A_1, A_2, ... , A_N$. He likes this sequence if it contains a subsequence of $M$ integers, $B_1, B_2, ... , B_M$ within it. A subsequence is a sequence that can be derived from another sequence by deleting some or n...
{"inputs": ["2\n6\n0 2 2 4 7 6\n3\n2 3 4\n6\n5 5 3 19 1 4\n2\n5 9", "2\n6\n0 2 2 4 7 6\n3\n2 3 4\n6\n5 5 0 19 1 4\n2\n5 9", "2\n6\n0 2 2 4 7 6\n3\n2 5 4\n6\n5 5 0 19 1 4\n2\n5 9", "2\n6\n0 2 3 4 7 6\n3\n2 3 4\n6\n22 5 6 19 1 4\n2\n4 3", "2\n6\n0 2 2 4 7 6\n3\n2 3 4\n6\n41 5 3 19 1 4\n2\n5 9", "2\n6\n1 1 3 4 7 6\n3\n2 3...
758
427
coding
Solve the programming task below in a Python markdown code block. My little sister came back home from school with the following task: given a squared sheet of paper she has to cut it in pieces which, when assembled, give squares the sides of which form an increasing sequence of numbers. At the beginning it was lot of ...
{"functional": "_inputs = [[12], [6], [50], [44], [625], [5], [7100], [123456], [1234567], [7654321], [4], [7654322]]\n_outputs = [[[1, 2, 3, 7, 9]], [None], [[1, 3, 5, 8, 49]], [[2, 3, 5, 7, 43]], [[2, 5, 8, 34, 624]], [[3, 4]], [[2, 3, 5, 119, 7099]], [[1, 2, 7, 29, 496, 123455]], [[2, 8, 32, 1571, 1234566]], [[6, 10...
580
418
coding
Solve the programming task below in a Python markdown code block. Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Polo loves walking aroun...
{"inputs": ["8 5\n", "9 8\n", "2 2\n", "2 1\n", "8 8\n", "1 1\n", "3 3\n", "8 1\n"], "outputs": ["16875\n", "2097152\n", "2\n", "1\n", "2097152\n", "1\n", "9\n", "823543\n"]}
418
107
coding
Solve the programming task below in a Python markdown code block. After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n. This sequence had the following property: if you write out the sums of all its...
{"inputs": ["1 1\n0\n", "1 1\n?\n", "1 1\n-1\n", "3 1\n4 ? 5\n", "3 2\n4 ? 5\n", "3 2\n? 1 2\n", "3 1\n-5 ? 0\n", "3 1\n-1 ? 1\n"], "outputs": ["0\n", "0\n", "-1 ", "Incorrect sequence\n", "4 0 5 ", "0 1 2\n", "-5 -1 0\n", "-1 0 1\n"]}
580
136
coding
Solve the programming task below in a Python markdown code block. Given a mathematical equation that has `*,+,-,/`, reverse it as follows: ```Haskell solve("100*b/y") = "y/b*100" solve("a+b-c/d*30") = "30*d/c-b+a" ``` More examples in test cases. Good luck! Please also try: [Simple time difference](https://www.co...
{"functional": "_inputs = [['100*b/y'], ['a+b-c/d*30'], ['a*b/c+50']]\n_outputs = [['y/b*100'], ['30*d/c-b+a'], ['50+c/b*a']]\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)...
181
195
coding
Solve the programming task below in a Python markdown code block. Animesh has $n$ empty candy jars, numbered from ${1}$ to $n$, with infinite capacity. He performs $m$ operations. Each operation is described by $3$ integers, ${a}$, ${b}$, and ${k}$. Here, ${a}$ and ${b}$ are indices of the jars, and ${k}$ is the number...
{"inputs": ["5 3\n1 2 100\n2 5 100\n3 4 100\n"], "outputs": ["160\n"]}
660
42
coding
Solve the programming task below in a Python markdown code block. Вася купил стол, у которого n ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2n частей возможно составить n ножек одинаковой длины. Пр...
{"inputs": ["1\n3 7\n", "1\n7 7\n", "3\n1 3 2 4 5 3\n", "3\n1 1 1 2 2 2\n", "10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15\n", "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15\n", "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153...
493
556
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 and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.   Please complete the follo...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), left = 2, right = 4), list_node([1,4,3,2,5]))\n assert is_same_list(candidate(head = list_node([5]), left = 1, right = 1), list_node([5]))\n\n\ncheck(Solution().reverseBetween)"}
137
95
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 tires where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds. For example, if fi = 3 and ri = 2, then the tire would...
{"functional": "def check(candidate):\n assert candidate(tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4) == 21\n assert candidate(tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5) == 25\n\n\ncheck(Solution().minimumFinishTime)"}
248
91
coding
Solve the programming task below in a Python markdown code block. problem A city in Canada where JOI lives is divided into a grid pattern by w roads that extend straight in the north-south direction and h roads that extend straight in the east-west direction. The w roads in the north-south direction are numbered 1, 2...
{"inputs": ["1 4\n7 16\n0 0", "1 6\n7 31\n0 0", "2 6\n7 31\n0 0", "2 4\n9 34\n0 0", "4 4\n8 40\n0 0", "4 2\n7 34\n0 0", "6 2\n7 65\n0 0", "2 7\n7 32\n0 0"], "outputs": ["1\n1102\n", "1\n6912\n", "2\n6912\n", "2\n96567\n", "8\n47890\n", "2\n8938\n", "2\n55345\n", "2\n7550\n"]}
440
193
coding
Solve the programming task below in a Python markdown code block. Chef loves bitwise operations. So, he creates the following problem but needs your help to solve it. Chef calls a sequence of integers A_{1}, A_{2}, \ldots, A_{N} tasty if it satisfies the following condition: parity(A_{i} \& A_{i+1}) \neq parity(A_{i} ...
{"inputs": ["2\n2\n0 0\n3\n6 16 69"], "outputs": ["-1\n1\n1 3"]}
692
35
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given two integers `n` and `k` and your task is to remove `k-digits` from `n` and return the lowest number possible, without changing the order of the digits in `n`. Return the result as a string. Let's take an example of `solv...
{"functional": "_inputs = [[123056, 1], [123056, 2], [123056, 3], [123056, 4], [1284569, 1], [1284569, 2], [1284569, 3], [1284569, 4]]\n_outputs = [['12056'], ['1056'], ['056'], ['05'], ['124569'], ['12456'], ['1245'], ['124']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl...
242
288
coding
Solve the programming task below in a Python markdown code block. When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a $2 \times n$ grid where each row is a permutation of the numbers $1,2,3,\ldots,n$. The...
{"inputs": ["2\n4\n1 4 2 3\n3 2 1 4\n8\n2 6 5 1 4 3 7 8\n3 8 7 5 1 2 4 6\n", "2\n4\n1 4 2 3\n3 2 1 4\n8\n2 6 5 1 4 3 7 8\n3 8 7 5 1 2 4 6\n"], "outputs": ["2\n8\n", "\n2\n8\n"]}
574
131
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi). Return true if all t...
{"functional": "def check(candidate):\n assert candidate(rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]) == True\n assert candidate(rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]) == False\n assert candidate(rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]) == False\n\n\ncheck(S...
116
154
coding
Solve the programming task below in a Python markdown code block. You are given two integers $a$ and $b$. You may perform any number of operations on them (possibly zero). During each operation you should choose any positive integer $x$ and set $a := a - x$, $b := b - 2x$ or $a := a - 2x$, $b := b - x$. Note that you ...
{"inputs": ["1\n29 2\n", "1\n24 2\n", "1\n24 1\n", "1\n21 2\n", "1\n16 0\n", "1\n20 0\n", "1\n31 0\n", "1\n35 0\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
438
110
coding
Solve the programming task below in a Python markdown code block. Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k...
{"inputs": ["1 2 2 1\n", "1 1 1 2\n", "4 6 2 1\n", "4 6 2 2\n", "6 4 2 2\n", "5 3 1 1\n", "6 5 4 3\n", "1 8 1 4\n"], "outputs": ["6\n", "31\n", "3\n", "122\n", "435\n", "8\n", "282051\n", "1\n"]}
525
128
coding
Solve the programming task below in a Python markdown code block. Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed dir...
{"inputs": ["1\n1\n0\n", "1\n1\n1\n", "1\n1\n0\n", "1\n1\n1\n", "2\n1 2\n0 0\n", "2\n2 1\n0 0\n", "2\n1 2\n0 1\n", "2\n2 1\n1 0\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "3\n", "1\n", "2\n", "0\n"]}
541
118
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of integers a_{1},a_{2},a_{3}.....a_{n}. You are free to replace any integer with any other positive integer. How many integers must be replaced to make the resulting sequence strictly increasing? Input Format The first line ...
{"inputs": ["3\n4 10 20\n", "5\n1 2 2 3 4 \n", "6\n1 7 10 2 20 22\n"], "outputs": ["0\n", "3\n", "1\n"]}
340
64
coding
Solve the programming task below in a Python markdown code block. One of Chef's friends offered him a deal: during $D$ days, they are going to exchange money. For each $i$ ($1 \le i \le D$), on the $i$-th day, Chef's friend would give Chef $A$ rupees, while Chef would give his friend $2^{i-1}$ rupees ($1$ rupee on day ...
{"inputs": ["4\n5\n8\n9\n1000000000"], "outputs": ["4 3\n5 3\n5 4\n35 30"]}
452
45
coding
Solve the programming task below in a Python markdown code block. Takahashi is a member of a programming competition site, ButCoder. Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating. The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or ...
{"inputs": ["0 6", "2 1", "3 1", "3 0", "1 0", "1 2", "2 2", "2 4"], "outputs": ["1006\n", "801\n", "701\n", "700\n", "900\n", "902\n", "802\n", "804\n"]}
286
95
coding
Solve the programming task below in a Python markdown code block. One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe to be a response from aliens! The scientists now want to ...
{"inputs": ["01\naaaaaa\n", "01\naabaaa\n", "01\naabbaa\n", "01\nbabbaa\n", "01\ncabbaa\n", "01\nbacbaa\n", "01\naacbaa\n", "01\naacaaa\n"], "outputs": ["4\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n"]}
552
108
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time. You are given a string keysPressed of length n, where keysPressed[i] was the ith key pressed in the testing sequence, and...
{"functional": "def check(candidate):\n assert candidate(releaseTimes = [9,29,49,50], keysPressed = \"cbcd\") == \"c\"\n assert candidate(releaseTimes = [12,23,36,46,62], keysPressed = \"spuda\") == \"a\"\n\n\ncheck(Solution().slowestKey)"}
281
86
coding
Solve the programming task below in a Python markdown code block. Vlad and Nastya live in a city consisting of $n$ houses and $n-1$ road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index $x$, and Nastya lives in a house with index $...
{"inputs": ["3\n\n3 1\n1 3\n2\n1 3\n1 2\n\n6 4\n3 5\n1 6 2 1\n1 3\n3 4\n3 5\n5 6\n5 2\n\n6 2\n3 2\n5 3\n1 3\n3 4\n3 5\n5 6\n5 2\n"], "outputs": ["3\n7\n2\n"]}
757
107
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 can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal. For example, if nums = [6,1,7,4,1]: Choosi...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,6,4]) == 1\n assert candidate(nums = [1,1,1]) == 3\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().waysToMakeFair)"}
205
71
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an array of strings words. You should add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in words. If two such substrings overlap, you should wrap them toge...
{"functional": "def check(candidate):\n assert candidate(s = \"abcxyz123\", words = [\"abc\",\"123\"]) == \"<b>abc</b>xyz<b>123</b>\"\n assert candidate(s = \"aaabbb\", words = [\"aa\",\"b\"]) == \"<b>aaabbb</b>\"\n\n\ncheck(Solution().addBoldTag)"}
139
95
coding
Solve the programming task below in a Python markdown code block. Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buses. You own a small bus service business and you have just received an order to replace $n$ tires. You know that the bus...
{"inputs": ["1\n25000\n", "4\n4\n7\n24\n998244353998244352\n"], "outputs": ["4167 6250\n", "1 1\n-1\n4 6\n166374058999707392 249561088499561088\n"]}
542
109
coding
Solve the programming task below in a Python markdown code block. There are $n$ trees in a park, numbered from $1$ to $n$. The initial height of the $i$-th tree is $h_i$. You want to water these trees, so they all grow to the same height. The watering process goes as follows. You start watering trees at day $1$. Duri...
{"inputs": ["1\n3\n14159 26535 89793\n", "3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4\n"], "outputs": ["92595\n", "4\n3\n16\n"]}
625
87
coding
Solve the programming task below in a Python markdown code block. Codex is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into sec...
{"inputs": ["19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19"], "outputs": ["4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916"]}
367
169
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.   Please complete the following python code precis...
{"functional": "def check(candidate):\n assert candidate(mat = [[0,1],[1,0]], target = [[1,0],[0,1]]) == True\n assert candidate(mat = [[0,1],[1,1]], target = [[1,0],[0,1]]) == False\n assert candidate(mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]) == True\n\n\ncheck(Solution().findRotati...
92
123
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor g[i], which is the minimum size of a cookie that the ch...
{"functional": "def check(candidate):\n assert candidate(g = [1,2,3], s = [1,1]) == 1\n assert candidate(g = [1,2], s = [1,2,3]) == 2\n\n\ncheck(Solution().findContentChildren)"}
162
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the number of longest increasing subsequences. Notice that the sequence has to be strictly increasing.   Please complete the following python code precisely: ```python class Solutio...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,4,7]) == 2\n assert candidate(nums = [2,2,2,2,2]) == 5\n\n\ncheck(Solution().findNumberOfLIS)"}
76
61
coding
Solve the programming task below in a Python markdown code block. In Snakeland, there are some snakes and mongooses. They are lined up in a row. The information about how exactly they are lined up it is provided to you by a string of length n. If the i-th character of this string is 's', then it means that there is a s...
{"inputs": ["4\nsm\nssm\nsms\nssmmmssss"], "outputs": ["mongooses\ntie\ntie\nsnakes"]}
647
34
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1. Function calls are stored in a call stack: when a function call starts, its ID is pushed onto the...
{"functional": "def check(candidate):\n assert candidate(n = 2, logs = [\"0:start:0\",\"1:start:2\",\"1:end:5\",\"0:end:6\"]) == [3,4]\n assert candidate(n = 1, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"0:start:6\",\"0:end:6\",\"0:end:7\"]) == [8]\n assert candidate(n = 2, logs = [\"0:start:0\",\"0:sta...
352
157
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string. You must solve the problem without using any built-in library for handling large integers (such as Big...
{"functional": "def check(candidate):\n assert candidate(num1 = \"11\", num2 = \"123\") == \"134\"\n assert candidate(num1 = \"456\", num2 = \"77\") == \"533\"\n assert candidate(num1 = \"0\", num2 = \"0\") == \"0\"\n\n\ncheck(Solution().addStrings)"}
112
89
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Bengali]. You are given N identical squares, each with side length A. All the squares have their sides parallel to the x-axis and y-axis. That is, the squares are not tilted. You have to take several (p...
{"inputs": ["5\n3 2\n5 3\n16 18\n11 8\n8 6\n"], "outputs": ["2\n6\n72\n24\n12\n"]}
364
48
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically...
{"functional": "def check(candidate):\n assert candidate(palindrome = \"abccba\") == \"aaccba\"\n assert candidate(palindrome = \"a\") == \"\"\n\n\ncheck(Solution().breakPalindrome)"}
196
52
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ of length $n$. A subsequence of this array is valid, if it satisfies these two conditions: - There shouldn't be any two even numbers within a distance of $K$, both which have been chosen in the subsequence. i.e. there shouldn't...
{"inputs": ["3\n1 1\n3\n2 1\n2 2\n5 2\n1 2 3 4 6"], "outputs": ["3\n2\n11"]}
490
45
coding
Solve the programming task below in a Python markdown code block. Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-...
{"inputs": ["4\n2 1 3 2\n3 2 1 2\n", "4\n2 2 3 1\n3 2 1 2\n", "4\n1 2 3 4\n3 2 1 4\n", "4\n2 2 3 2\n3 2 2 2\n", "4\n1 2 3 2\n3 2 1 2\n", "2\n1 100500\n1 100500\n", "1\n800950546\n800950546\n", "1\n873725529\n873725529\n"], "outputs": ["2\n1 2\n2 3\n", "3\n1 2\n3 4\n2 3\n", "3\n2 3\n1 2\n2 3\n", "2\n1 2\n2 3\n", "3\n2 3...
498
260
coding
Solve the programming task below in a Python markdown code block. You are given $n$ points with integer coordinates on a coordinate axis $OX$. The coordinate of the $i$-th point is $x_i$. All points' coordinates are distinct and given in strictly increasing order. For each point $i$, you can do the following operation...
{"inputs": ["1\n1\n29999\n", "5\n2\n1 4\n3\n1 2 3\n4\n1 2 3 7\n1\n1000000\n3\n2 5 6\n"], "outputs": ["YES\n", "YES\nYES\nNO\nYES\nYES\n"]}
584
80
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, y...
{"inputs": ["3\n2\n4\n8"], "outputs": ["1\n2\n3"]}
429
22
coding
Solve the programming task below in a Python markdown code block. n! = n × (n − 1) × (n − 2) × ... × 3 × 2 × 1 Is called the factorial of n. For example, the factorial of 12 12! = 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 479001600 And there are two consecutive 0s at the end. Write a program that inputs th...
{"inputs": ["2\n6\n11000\n0", "2\n6\n11100\n0", "2\n6\n10000\n0", "2\n3\n11100\n0", "2\n6\n10101\n0", "2\n1\n11110\n0", "2\n3\n10100\n0", "2\n0\n11110\n0"], "outputs": ["0\n1\n2748\n", "0\n1\n2772\n", "0\n1\n2499\n", "0\n0\n2772\n", "0\n1\n2523\n", "0\n0\n2774\n", "0\n0\n2523\n", "0\n"]}
276
191
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game on a binary string S of length N. Alice and Bob alternate turns, with Alice going first. On their turn, the current player must choose any index 1 ≤ i < |S| such that S_{i} \neq S_{i+1} and erase either S_{i} or S_{i+1} ...
{"inputs": ["3\n4\n1111\n3\n110\n4\n1010\n"], "outputs": ["Bob\nAlice\nBob"]}
466
37
coding
Solve the programming task below in a Python markdown code block. For encoding an even-length binary string into a sequence of A, T, C, and G, we iterate from left to right and replace the characters as follows: 00 is replaced with A 01 is replaced with T 10 is replaced with C 11 is replaced with G Given a binary stri...
{"inputs": ["4\n2\n00\n4\n0011\n6\n101010\n4\n1001\n"], "outputs": ["A\nAG\nCCC\nCT"]}
445
47
coding
Solve the programming task below in a Python markdown code block. Your job is to return the volume of a cup when given the diameter of the top, the diameter of the bottom and the height. You know that there is a steady gradient from the top to the bottom. You want to return the volume rounded to 2 decimal places. Ex...
{"functional": "_inputs = [[1, 1, 1], [10, 8, 10], [1000, 1000, 1000], [13.123, 123.12, 1], [5, 12, 31]]\n_outputs = [[0.79], [638.79], [785398163.4], [4436.57], [1858.51]]\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, a...
230
262
coding
Solve the programming task below in a Python markdown code block. Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a giv...
{"inputs": ["2\n74\n", "2\n33\n", "2\n24\n", "2\n46\n", "2\n15\n", "2\n16\n", "2\n22\n", "2\n71\n"], "outputs": ["74\n", "33\n", "24\n", "46\n", "15\n", "16\n", "22\n", "71\n"]}
224
102
coding
Solve the programming task below in a Python markdown code block. You are given a sequence $s$ consisting of $n$ digits from $1$ to $9$. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) ...
{"inputs": ["1\n3\n333\n", "1\n3\n333\n", "1\n3\n343\n", "1\n3\n218\n", "1\n3\n242\n", "1\n4\n3333\n", "1\n4\n5234\n", "1\n4\n9999\n"], "outputs": ["YES\n2\n3 33\n", "YES\n2\n3 33\n", "YES\n2\n3 43\n", "YES\n2\n2 18\n", "YES\n2\n2 42\n", "YES\n2\n3 333\n", "YES\n2\n5 234\n", "YES\n2\n9 999\n"]}
691
180
coding
Solve the programming task below in a Python markdown code block. You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points ...
{"inputs": ["1 1\n2 2\n", "1 1\n0 1\n", "1 1\n1 1\n", "1 1\n-1 1\n", "2 1\n0 2\n0 0\n", "2 1\n0 2\n-1 0\n", "2 2\n-3 1\n-4 -1\n", "3 2\n0 5\n-3 2\n1 8\n"], "outputs": ["1\n2 2\n", "1\n0 1\n", "1\n1 1\n", "1\n-1 1\n", "1\n0 2\n", "1\n-1 2\n", "1\n-3 -1\n", "1\n0 5\n"]}
267
178
coding
Solve the programming task below in a Python markdown code block. Chef has two integers X and Y. Chef wants to perform some operations to make X and Y equal. In one operation, Chef can either: set X := X + 1 or set Y := Y + 2 Find the minimum number of operations required to make X and Y equal. ------ Input Format -...
{"inputs": ["5\n3 4\n5 5\n7 3\n5 2\n7 12\n"], "outputs": ["1\n0\n2\n3\n5\n\n"]}
432
44