task_type
stringclasses
1 value
problem
stringlengths
261
3.34k
answer
stringlengths
35
6.15k
problem_tokens
int64
62
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. There are N stores called Store 1, Store 2, \cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores. It takes Takahashi one unit of time to travel from his house to one of the stores, or between any two store...
{"inputs": ["1 3\n0 0", "1 0\n1 0", "1 0\n1 1", "0 0\n1 1", "0 1\n1 1", "0 1\n2 1", "0 1\n4 1", "0 1\n4 2"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
439
110
coding
Solve the programming task below in a Python markdown code block. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one...
{"inputs": ["1 1 1\n4\n", "1 1 1\n4\n", "1 6 5\n9\n", "1 1 2\n4\n", "1 8 3\n10\n", "1 1 3\n10\n", "1 8 5\n10\n", "1 8 6\n10\n"], "outputs": ["1\n", "1\n", "5\n", "-1\n", "3\n", "-1\n", "5\n", "6\n"]}
648
122
coding
Solve the programming task below in a Python markdown code block. ## Fixed xor Write a function that takes two hex strings as input and XORs them against each other. If the strings are different lengths the output should be the length of the shortest string. Hint: The strings would first need to be converted to binar...
{"functional": "_inputs = [['1c0111001f010100061a024b53535009181c', '686974207468652062756c6c277320657965'], ['aadf', 'bce2'], ['ab3f', 'ac'], ['', ''], ['c611d9bdd9de38b9eb', '23a0745505d4d25494'], ['7d1e875da9d5e89b54c7eaf', '3541599be591709795cebd5'], ['785a6677b3e52f0e7', 'a8d97da7441'], ['6cbd75511e7f750c6827', '1...
385
505
coding
Solve the programming task below in a Python markdown code block. James found a love letter that his friend Harry has written to his girlfriend. James is a prankster, so he decides to meddle with the letter. He changes all the words in the letter into palindromes. To do this, he follows two rules: He can only re...
{"inputs": ["4\nabc\nabcba\nabcd\ncba\n"], "outputs": ["2\n0\n4\n2\n"]}
418
30
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 items of length n and an integer k. items[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the ith item respectively. Let's define the...
{"functional": "def check(candidate):\n assert candidate(items = [[3,2],[5,1],[10,1]], k = 2) == 17\n assert candidate(items = [[3,1],[3,1],[2,2],[5,3]], k = 3) == 19\n assert candidate(items = [[1,1],[2,1],[3,1]], k = 3) == 7\n\n\ncheck(Solution().findMaximumElegance)"}
229
110
coding
Solve the programming task below in a Python markdown code block. For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfies the condition: $1 \leq l \leq r \leq N$ and $a_l + a_{l+1} + ... + a...
{"inputs": ["6 5\n1 2 3 2 6 6\n6 9 5 21 15", "6 5\n1 2 4 2 6 6\n6 9 5 21 15", "6 5\n1 2 4 2 6 7\n6 9 5 21 15", "6 5\n1 4 0 2 7 6\n6 1 3 21 15", "6 5\n0 2 4 2 6 6\n6 9 5 21 15", "6 5\n1 2 3 4 7 6\n6 9 12 21 15", "6 5\n1 2 3 2 7 6\n6 9 12 21 15", "6 5\n1 2 3 5 5 6\n6 9 12 21 15"], "outputs": ["10\n13\n7\n21\n18\n", "9\n1...
296
366
coding
Solve the programming task below in a Python markdown code block. Tenten runs a weapon shop for ninjas. Today she is willing to sell $n$ shurikens which cost $1$, $2$, ..., $n$ ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is f...
{"inputs": ["1\n- 1\n+\n", "1\n+\n- 1\n", "1\n+\n- 1\n", "1\n- 1\n+\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "3\n+\n+\n+\n- 2\n- 1\n- 2\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "4\n+\n+\n- 2\n+\n- 3\n+\n- 1\n- 4\n"], "outputs": ["NO\n", "YES\n1 \n", "YES\n1\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n4 2 3 1 \n"]}
723
186
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ positive integers. You are allowed to perform this operation any number of times (possibly, zero): choose an index $i$ ($2 \le i \le n$), and change $a_i$ to $a_i - a_{i-1}$. Is it possible to make $a_i=0$ ...
{"inputs": ["1\n3\n3 9 96\n", "1\n4\n1 8 6 7\n", "1\n4\n3 21 9 6\n", "1\n5\n2 8 4 8 4\n", "1\n4\n5 10 5 10\n", "1\n4\n5 10 20 5\n", "1\n5\n2 4 4 10 10\n", "1\n8\n5 10 15 20 40 5 5 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
540
172
coding
Solve the programming task below in a Python markdown code block. You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. -----Input----- The first line co...
{"inputs": ["1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n"], "outputs": ["0 ", "0 ", "0 ", "0 ", "0 ", "0 0 ", "0 1 ", "1 0 "]}
290
91
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even. The digit sum of a positive integer is the sum of all its digits.   Please complete the followi...
{"functional": "def check(candidate):\n assert candidate(num = 4) == 2\n assert candidate(num = 30) == 14\n\n\ncheck(Solution().countEven)"}
86
45
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For t...
{"functional": "def check(candidate):\n assert candidate(n = 3) == 1 \n assert candidate(n = 0) == 0\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().bulbSwitch)"}
134
57
coding
Solve the programming task below in a Python markdown code block. Find out the maximum sub-array of non negative numbers from an array. The sub-array should be continuous. That is, a sub-array created by choosing the second and fourth element and skipping the third element is invalid. Maximum sub-array is defined in...
{"inputs": ["1\n6\n1 2 5 -7 2 3"], "outputs": ["1 2 5"]}
262
30
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. The *MEX* (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance: The MEX of [2, 2, 1] is 0, bec...
{"inputs": ["4\n0\n1\n2\n5\n"], "outputs": ["1\n2\n2\n4\n"]}
478
28
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the ith line of the source code. This represents the result of splitting the original source code strin...
{"functional": "def check(candidate):\n assert candidate(source = [\"/*Test program */\", \"int main()\", \"{ \", \" // variable declaration \", \"int a, b, c;\", \"/* This is a test\", \" multiline \", \" comment for \", \" testing */\", \"a = b + c;\", \"}\"]) == [\"int main()\",\"{ \",\" \",\"int a, b, c...
425
152
coding
Solve the programming task below in a Python markdown code block. Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he h...
{"inputs": ["2\n5 8", "2\n4 8", "2\n4 8\n", "2\n5 11", "2\n10 6", "2\n17 5", "2\n17 1", "2\n17 2"], "outputs": ["5\n", "8", "8\n", "18\n", "8\n", "72\n", "128\n", "113\n"]}
225
105
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Once upon a time chef decided to learn encodings. And, obviously, he started with the easiest one (well, actually the easiest after Caesar cypher) – substitution cypher. But very soon Chef got ...
{"inputs": ["3\nqwrtyuipasdfgjkzxcvbnmheol\ndummy!\nbfgjklmopqrstuwxzhvnicdyea\nabcd b efgd hbi!\nqwrtyuipasdfgjkzxcvbnmheol\nDummy!", "3\nqwrtyuipasdfgjkzxcvbnmheol\ndummy!\nbfgjklmopqrstuwxzhvnicdyea\nabcd b efgd hbi!\nqwrtyuipasdfgjkzxcvbnmheol\nDummy!"], "outputs": ["hello!\nhave a nice day!\nHello!", "hello!\nhave...
472
162
coding
Solve the programming task below in a Python markdown code block. # Task Your task is to find the sum for the range `0 ... m` for all powers from `0 ... n. # Example For `m = 2, n = 3`, the result should be `20` `0^0+1^0+2^0 + 0^1+1^1+2^1 + 0^2+1^2+2^2 + 0^3+1^3+2^3 = 20` Note, that no output ever exceeds 2e9....
{"functional": "_inputs = [[2, 3], [3, 5], [10, 9], [1, 1], [0, 0], [300, 2], [567, 2], [37, 4], [36, 4]]\n_outputs = [[20], [434], [1762344782], [3], [1], [9090501], [61083856], [15335280], [13409059]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return mat...
220
276
coding
Solve the programming task below in a Python markdown code block. You are given the array $a$ consisting of $n$ positive (greater than zero) integers. In one move, you can choose two indices $i$ and $j$ ($i \ne j$) such that the absolute difference between $a_i$ and $a_j$ is no more than one ($|a_i - a_j| \le 1$) and ...
{"inputs": ["1\n1\n23\n", "1\n1\n46\n", "1\n1\n114\n", "1\n1\n157\n", "1\n1\n305\n", "1\n1\n292\n", "1\n1\n430\n", "2\n3\n1 2 2\n4\n5 5 5 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\nYES\n"]}
544
130
coding
Solve the programming task below in a Python markdown code block. Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20). Output If...
{"inputs": ["4 5\n", "9 6\n", "5 6\n", "5 4\n", "8 2\n", "6 2\n", "2 5\n", "5 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "2 4\n", "2 3\n", "-1\n", "-1\n"]}
192
91
coding
Solve the programming task below in a Python markdown code block. A famous student of AESC MSU, as you know, comes from Kostomuksha. Kostomuksha has a popular game called Doka. The essence of Doka is as follows: You are given an array A and an integer X. You want to calculate how many subarrays of this array have a g...
{"inputs": ["3\n3 3\n3 3 3\n4 4\n1 2 3 4\n4 54\n36 81 54 54"], "outputs": ["6\n1\n6"]}
666
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that consists of lower case English letters and brackets. Reverse the strings in each pair of matching parentheses, starting from the innermost one. Your result should not contain any brackets...
{"functional": "def check(candidate):\n assert candidate(s = \"(abcd)\") == \"dcba\"\n assert candidate(s = \"(u(love)i)\") == \"iloveu\"\n assert candidate(s = \"(ed(et(oc))el)\") == \"leetcode\"\n assert candidate(s = \"a(bcdefghijkl(mno)p)q\") == \"apmnolkjihgfedcbq\"\n\n\ncheck(Solution().reverseParenth...
89
106
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path of length 4 or more in the grid that starts and ends at the same ce...
{"functional": "def check(candidate):\n assert candidate(grid = [[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]]) == True\n assert candidate(grid = [[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]]) ==...
232
150
coding
Solve the programming task below in a Python markdown code block. Watson likes to challenge Sherlock's math ability. He will provide a starting and ending value that describe a range of integers, inclusive of the endpoints. Sherlock must determine the number of square integers within that range. Note: A square integ...
{"inputs": ["2\n3 9\n17 24\n"], "outputs": ["2\n0\n"]}
365
26
coding
Solve the programming task below in a Python markdown code block. We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Ta...
{"inputs": ["3\nBBBGGGRRR", "3\nRRRBGGBGB", "3\nBRRGGGRBB", "3\nBGRGGRRBB", "3\nRGRBGRBGB", "3\nBBBGGRRGR", "3\nBBGBGRRRG", "3\nBBGBGGRRR"], "outputs": ["216", "36", "12", "24", "6", "72", "48", "144"]}
379
113
coding
Solve the programming task below in a Python markdown code block. Given two integer arrays where the second array is a shuffled duplicate of the first array with one element missing, find the missing element. Please note, there may be duplicates in the arrays, so checking if a numerical value exists in one and not the...
{"functional": "_inputs = [[[1, 2, 3], [1, 3]], [[6, 1, 3, 6, 8, 2], [3, 6, 6, 1, 2]], [[7], []], [[4, 3, 3, 61, 8, 8], [8, 61, 8, 3, 4]], [[0, 0, 0, 0, 0], [0, 0, 0, 0]]]\n_outputs = [[2], [8], [7], [3], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ret...
179
278
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 and two integers indexDiff and valueDiff. Find a pair of indices (i, j) such that: i != j, abs(i - j) <= indexDiff. abs(nums[i] - nums[j]) <= valueDiff, and Return true if such pa...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1], indexDiff = 3, valueDiff = 0) == True\n assert candidate(nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3) == False\n\n\ncheck(Solution().containsNearbyAlmostDuplicate)"}
127
84
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed binary matrix grid. In one operation, you can flip any 1 in grid to be 0. A binary matrix is well-isolated if there is no 1 in the matrix that is 4-directionally connected (i.e., horizontal a...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0],[0,1,1],[1,1,1]]) == 3\n assert candidate(grid = [[0,0,0],[0,0,0],[0,0,0]]) == 0\n assert candidate(grid = [[0,1],[1,0]]) == 0\n\n\ncheck(Solution().minimumOperations)"}
127
93
coding
Solve the programming task below in a Python markdown code block. This time around, Baby Ehab will play with permutations. He has $n$ cubes arranged in a row, with numbers from $1$ to $n$ written on them. He'll make exactly $j$ operations. In each operation, he'll pick up $2$ cubes and switch their positions. He's won...
{"inputs": ["2 3\n", "3 2\n", "4 2\n", "2 200\n", "3 200\n"], "outputs": ["1 1 1 \n", "3 3 \n", "6 12 \n", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
383
870
coding
Solve the programming task below in a Python markdown code block. You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S. Here, a ACGT string is a string that contains no characters other than A, C, G and T. -----Notes----- A su...
{"inputs": ["A\n", "Z\n", "CG\n", "ABC\n", "ATCPDER", "ATCPCER", "ATCPBER", "REBPCTA"], "outputs": ["1\n", "0\n", "2\n", "1\n", "3\n", "3\n", "3\n", "3\n"]}
234
76
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here Read problems statements in Russian here ------ Problem Statement ------ One day Chef is waiting his girlfriend on the bus station. The girlfriend said that she will be at time_{1}. Chef went to the ...
{"inputs": ["3\n10:00\n09:00\n6\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n54", "3\n10:01\n09:00\n7\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n8\n10:00\n08:00\n48\n10:00\n09:00\n60", "3\n10:01\n09:00\n...
564
655
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time. Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes m...
{"functional": "def check(candidate):\n assert candidate(satisfaction = [-1,-8,0,5,-9]) == 14\n assert candidate(satisfaction = [4,3,2]) == 20\n assert candidate(satisfaction = [-1,-4,-5]) == 0\n\n\ncheck(Solution().maxSatisfaction)"}
150
77
coding
Solve the programming task below in a Python markdown code block. Mr. Scrooge has a sum of money 'P' that he wants to invest. Before he does, he wants to know how many years 'Y' this sum 'P' has to be kept in the bank in order for it to amount to a desired sum of money 'D'. The sum is kept for 'Y' years in the bank wh...
{"functional": "_inputs = [[1000, 0.05, 0.18, 1100], [1000, 0.01625, 0.18, 1200], [1000, 0.05, 0.18, 1000]]\n_outputs = [[3], [14], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (l...
386
234
coding
Solve the programming task below in a Python markdown code block. A generalization of Bézier surfaces, called the S-patch, uses an interesting scheme for indexing its control points. In the case of an n-sided surface of degree d, each index has n non-negative integers that sum to d, and all possible configurations are...
{"functional": "_inputs = [[1, 0], [3, 0]]\n_outputs = [[[[0]]], [[[0, 0, 0]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\...
232
174
coding
Solve the programming task below in a Python markdown code block. Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a seque...
{"inputs": ["4\n<<<\n<><\n<=>\n<=<"], "outputs": ["4\n2\n2\n3"]}
452
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge be...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]]) == 23\n assert candidate(n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]]) == 1\n\n\ncheck(Solution().minimumTotalPrice)"}
266
108
coding
Solve the programming task below in a Python markdown code block. We have N integers. The i-th number is A_i. \{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N. \{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots...
{"inputs": ["3\n4 4 2", "3\n4 3 1", "3\n4 4 5", "3\n4 8 2", "3\n8 8 2", "3\n4 4 1", "3\n4 4 4", "3\n6 8 2"], "outputs": ["not coprime\n", "pairwise coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n"]}
318
137
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 array queries where queries[i] = [lefti, righti, ki]. We may rearrange the substring s[lefti...righti] for each query and then choose up to ki of them to replace with any lowercase English...
{"functional": "def check(candidate):\n assert candidate(s = \"abcda\", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]) == [True,False,False,True,True]\n\n\ncheck(Solution().canMakePaliQueries)"}
215
73
coding
Solve the programming task below in a Python markdown code block. # Introduction: Reversi is a game usually played by 2 people on a 8x8 board. Here we're only going to consider a single 8x1 row. Players take turns placing pieces, which are black on one side and white on the other, onto the board with their colour fac...
{"functional": "_inputs = [[[]], [[0]], [[0, 1]], [[0, 7, 4]], [[3]], [[3, 4]], [[3, 4, 5]], [[2, 1, 0]], [[0, 1, 4, 3, 2]], [[0, 1, 7, 2, 3]], [[3, 2, 7, 1, 0]], [[3, 4, 5, 6, 0, 2]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[7, 0, 1]], [[0, 7, 6]], [[1, 0, 2, 3, 4, 5, 6, 7]], [[5, 1, 3, 4, 6]], [[1, 7, 0, 5, 6, 4]]]\n_outputs = ...
360
456
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all the...
{"inputs": ["1 1 1\n7082632\n", "1 1 1\n1027282\n", "1 1 1\n1469884\n", "1 1 1\n99996055\n", "1 1 1\n41731973\n", "1 1 1\n74257449\n", "1 1 1\n69799202\n", "4 3 1\n1 100 1 1\n"], "outputs": ["7082632", "1027282\n", "1469884\n", "99996055", "41731973\n", "74257449\n", "69799202\n", "100\n"]}
499
218
coding
Solve the programming task below in a Python markdown code block. Vacations have arrived and Chef wants to go to his home in ChefLand. There are two types of routes he can take: Take a flight from his college to ChefArina which takes X minutes and then take a bus from ChefArina to ChefLand which takes Y minutes. Take...
{"inputs": ["3\n10 12 11\n3 5 15\n9 4 13\n"], "outputs": ["TRAIN\nPLANEBUS\nEQUAL\n"]}
474
43
coding
Solve the programming task below in a Python markdown code block. For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisible on $x$....
{"inputs": ["2\n1 1\n", "2\n4 6\n", "2\n3 3\n", "2\n3 3\n", "2\n4 6\n", "2\n3 5\n", "2\n1 2\n", "2\n1 1\n"], "outputs": ["1\n", "12\n", "3\n", "3\n", "12\n", "15\n", "2\n", "1\n"]}
565
105
coding
Solve the programming task below in a Python markdown code block. Sam has opened a new sushi train restaurant - a restaurant where sushi is served on plates that travel around the bar on a conveyor belt and customers take the plate that they like. Sam is using Glamazon's new visual recognition technology that allows a...
{"functional": "_inputs = [['rr'], ['rr rrr'], ['rr rrr rrr rr'], ['rrrrrrrrrrrrrrrrrr rr r'], ['']]\n_outputs = [[4], [8], [16], [34], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance...
352
197
coding
Solve the programming task below in a Python markdown code block. An n × n square matrix is special, if: it is binary, that is, each cell contains either a 0, or a 1; the number of ones in each row and column equals 2. You are given n and the first m rows of the matrix. Print the number of special n × n matrices, s...
{"inputs": ["5 0 13\n", "5 0 13\n", "2 0 1000\n", "2 0 1000\n", "2 0 1010\n", "4 0 1100\n", "99 0 757\n", "2 0 1100\n"], "outputs": ["12\n", "12\n", "1\n", "1\n", "1\n", "90\n", "613\n", "1\n"]}
347
127
coding
Solve the programming task below in a Python markdown code block. Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose release ye...
{"inputs": ["8\n1 6 5 4 3 2 7 8"], "outputs": ["2 6"]}
483
30
coding
Solve the programming task below in a Python markdown code block. Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a_1, a_2, ..., a_{n}. While Vasya wa...
{"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "3 1 2\n1 2 3\n3 1 2\n", "3 1 2\n1 2 5\n3 1 2\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n", "4 3 4\n1 2 3 4\n2 1 3 4\n", "4 2 2\n2 1 2 2\n1 2 2 2\n"], "outputs": ["TRUTH\n", "TRUTH\n", "LIE\n", "LIE\n", "LIE\n", "TRUTH\n", "LIE\n", "LIE\n"]}
709
202
coding
Solve the programming task below in a Python markdown code block. Given are N integers A_1,\ldots,A_N. We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive). -----Constrain...
{"inputs": ["4 2\n1 2 -3 0", "4 2\n1 2 -3 -1", "4 4\n1 2 -3 -4", "4 2\n1 2 -4 -1", "4 2\n1 2 -3 -4", "4 2\n1 2 -3 -4\n", "4 2\n0 -3 -2 -1", "4 3\n-1 -3 -3 -4"], "outputs": ["2\n", "3\n", "24\n", "4\n", "12", "12\n", "6\n", "999999998\n"]}
238
154
coding
Solve the programming task below in a Python markdown code block. Problem Given the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even. Constraints The input satisfies the following conditions. * 1 ≤ n ≤ 1018 Input The input is given in the fo...
{"inputs": ["4", "7", "6", "5", "0", "8", "9", "3"], "outputs": ["1\n", "8\n", "1\n", "2\n", "1\n", "1\n", "2\n", "4"]}
127
61
coding
Solve the programming task below in a Python markdown code block. Given $n$ strings, each of length $2$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $(i, j)$ such that $i < j$ and the $i$-th string and the $j$-th string differ in exactly one position. In other ...
{"inputs": ["2\n1\nab\n1\ncf\n", "4\n6\nab\ncb\ndb\naa\ncc\nef\n7\naa\nbb\ncc\nac\nca\nbb\naa\n4\nkk\nkk\nab\nab\n5\njf\njf\njk\njk\njk\n"], "outputs": ["0\n0\n", "5\n6\n0\n6\n"]}
650
94
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, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the great...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,6]) == True\n assert candidate(nums = [3,9,5]) == False\n assert candidate(nums = [4,3,12,8]) == True\n\n\ncheck(Solution().canTraverseAllPairs)"}
167
70
coding
Solve the programming task below in a Python markdown code block. In this problem you will write a simple generator of Brainfuck (https://en.wikipedia.org/wiki/Brainfuck) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brain...
{"inputs": ["7\n", "3\n", "6\n", "1\n", "2\n", "0\n", "2+3\n", "9-7\n"], "outputs": ["+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++....
382
103
coding
Solve the programming task below in a Python markdown code block. Johnny is a boy who likes to open and close lockers. He loves it so much that one day, when school was out, he snuck in just to play with the lockers. Each locker can either be open or closed. If a locker is closed when Johnny gets to it, he opens it, a...
{"functional": "_inputs = [[1], [5], [10], [20]]\n_outputs = [[[1]], [[1, 4]], [[1, 4, 9]], [[1, 4, 9, 16]]]\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 le...
357
194
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
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: 0 <= i <= s.length - 2 s[i] is a lower-case letter and s[i + 1] ...
{"functional": "def check(candidate):\n assert candidate(s = \"leEeetcode\") == \"leetcode\"\n assert candidate(s = \"abBAcC\") == \"\"\n assert candidate(s = \"s\") == \"s\"\n\n\ncheck(Solution().makeGood)"}
183
63
coding
Solve the programming task below in a Python markdown code block. -----Coal Company ----- The Tunisian Coal Mining company uses a train to ferry out coal blocks from its coal mines. The train has N containers numbered from 1 to N which need to be filled with blocks of coal. Assume there are infinite coal blocks. The ...
{"inputs": ["2\n3 2\n5 4 7\n5 1\n5 3 4 5 6"], "outputs": ["2\n1"]}
427
38
coding
Solve the programming task below in a Python markdown code block. A wildlife study involving ducks is taking place in North America. Researchers are visiting some wetlands in a certain area taking a survey of what they see. The researchers will submit reports that need to be processed by your function. ## Input The ...
{"functional": "_inputs = [[['Redhead 5', 'Labrador Duck 9', 'Blue-Winged Teal 25', \"Steller's Eider 200\"]], [['Canvasback 10', 'Mallard 150', 'American Wigeon 45', 'Baikal Teal 3', \"Barrow's Goldeneye 6\", 'Surf Scoter 12']], [['Redhead 3', 'Gadwall 1', 'Smew 4', 'Greater Scaup 10', 'Redhead 3', 'Gadwall 9',...
588
794
coding
Solve the programming task below in a Python markdown code block. Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms. If you want to know more http://en.wikipedia.org/wiki/DNA In DNA strings, symbols "A" and "T...
{"functional": "_inputs = [['AAAA'], ['ATTGC'], ['GTAT'], ['AAGG'], ['CGCG'], ['GTATCGATCGATCGATCGATTATATTTTCGACGAGATTTAAATATATATATATACGAGAGAATACAGATAGACAGATTA']]\n_outputs = [['TTTT'], ['TAACG'], ['CATA'], ['TTCC'], ['GCGC'], ['CATAGCTAGCTAGCTAGCTAATATAAAAGCTGCTCTAAATTTATATATATATATGCTCTCTTATGTCTATCTGTCTAAT']]\nimport ...
208
278
coding
Solve the programming task below in a Python markdown code block. There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or sev...
{"inputs": ["1 1 3 4\n7\n", "2 1 3 4\n7\n", "2 1 3 8\n7\n", "1 1 3 4\n7\n", "4 3 4 2\n7 9 11\n", "4 3 4 2\n3 9 11\n", "5 3 4 2\n7 9 11\n", "5 3 4 4\n7 9 11\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "4\n", "4\n", "5\n", "3\n"]}
554
154
coding
Solve the programming task below in a Python markdown code block. Let x be a string of length at least 1. We will call x a good string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x. For example, a, bbc and cdcdc are good strings, while aa, bbbb...
{"inputs": ["ddc", "aaa", "dec", "aa`", "eec", "aa_", "cee", "ba_"], "outputs": ["1\n1\n", "3\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n"]}
518
81
coding
Solve the programming task below in a Python markdown code block. The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2). You have developed two sequences of numbers. The first sequence that uses the bitwise XOR operation instead of the addition method is called the Xoronacci number. It is described as follows: X(...
{"inputs": ["1\n3 4 2"], "outputs": ["4"]}
383
18
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix". Chef has a matrix that consists of n rows, each...
{"inputs": ["4 4 6\n2 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 1", "4 4 6\n3 2\n3 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 6\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 2\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "3 6 2\n1 2\n3 0 \n6 2 \n4 3\n1 1\n5 3", "3 4 2\n1 2\n3 0 \n6 ...
661
349
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Russian. Chef has prepared a feast with N dishes for you. You like Chef's cooking, and so you want to eat all the dishes he has prepared for you. You are also given an array A of size N, where A_{i} represents the happiness ...
{"inputs": ["1\n3\n1 2 3", "1\n3\n-8 0 -2"], "outputs": ["18", "-10"]}
455
37
coding
Solve the programming task below in a Python markdown code block. This is the easy version of this problem. In this version, we do not have queries. Note that we have multiple test cases in this version. You can make hacks only if both versions of the problem are solved. An array $b$ of length $m$ is good if for all $...
{"inputs": ["3\n3\n1 2 3\n3\n1 1 1\n4\n2 1 4 3\n"], "outputs": ["6\n3\n7\n"]}
515
44
coding
Solve the programming task below in a Python markdown code block. Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th d...
{"inputs": ["1\n2\n", "1\n0\n", "1\n3\n", "1\n1\n", "2\n0 2\n", "2\n1 2\n", "2\n2 3\n", "2\n0 0\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "2\n"]}
686
94
coding
Solve the programming task below in a Python markdown code block. Write a function which reduces fractions to their simplest form! Fractions will be presented as an array/tuple (depending on the language), and the reduced fraction must be returned as an array/tuple: ``` input: [numerator, denominator] output: [newN...
{"functional": "_inputs = [[[60, 20]], [[80, 120]], [[4, 2]], [[45, 120]], [[1000, 1]], [[1, 1]], [[10956590, 13611876]], [[35884747, 5576447]], [[24622321, 24473455]], [[4255316, 11425973]]]\n_outputs = [[[3, 1]], [[2, 3]], [[2, 1]], [[3, 8]], [[1000, 1]], [[1, 1]], [[30605, 38022]], [[76841, 11941]], [[42673, 42415]]...
143
369
coding
Solve the programming task below in a Python markdown code block. Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level. Ivan decided that there should be exactly n_{i} vertices in the graph...
{"inputs": ["3\n3\n4\n6\n", "3\n1\n4\n6\n", "1\n15320\n", "1\n14179\n", "3\n3\n4\n6\n", "1\n164568\n", "1\n844906\n", "1\n8027497\n"], "outputs": ["2\n3\n6\n", "0\n3\n6\n", "30290\n", "28022\n", "2\n3\n6\n", "327988\n", "1687212\n", "16046980\n"]}
455
160
coding
Solve the programming task below in a Python markdown code block. In this Kata we focus on finding a sum S(n) which is the total number of divisors taken for all natural numbers less or equal to n. More formally, we investigate the sum of n components denoted by d(1) + d(2) + ... + d(n) in which for any i starting from...
{"functional": "_inputs = [[5], [10], [20], [59], [105], [785], [1001], [8009], [9999999999999], [9999999999998], [9999999999995], [9999999949950]]\n_outputs = [[10], [27], [66], [249], [510], [5364], [7077], [73241], [300880375389561], [300880375389537], [300880375389493], [300880373832097]]\nimport math\ndef _deep_eq...
466
355
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums with the following properties: nums.length == 2 * n. nums contains n + 1 unique elements. Exactly one element of nums is repeated n times. Return the element that is repeated n ti...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,3]) == 3\n assert candidate(nums = [2,1,2,5,3,2]) == 2\n assert candidate(nums = [5,1,5,2,5,3,5,4]) == 5\n\n\ncheck(Solution().repeatedNTimes)"}
97
87
coding
Solve the programming task below in a Python markdown code block. You are given a tree consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is equal to $a_i$. Recall that a simple path is a path that visits each vertex at most once. Let the weight of the path be the bitwise XOR of t...
{"inputs": ["1\n25\n", "4\n2 1 1 1\n1 2\n1 3\n1 4\n", "5\n2 2 2 2 2\n1 2\n2 3\n3 4\n4 5\n", "6\n3 2 1 3 2 1\n4 5\n3 4\n1 4\n2 1\n6 1\n", "10\n7 4 6 7 6 6 7 5 7 5\n8 7\n4 5\n9 6\n2 5\n4 8\n9 10\n4 3\n9 4\n1 8\n", "20\n4 1 3 4 7 3 8 7 7 3 1 1 7 1 9 5 1 10 6 3\n6 15\n12 11\n18 1\n9 17\n8 1\n1 20\n13 7\n10 15\n20 19\n10 16...
472
330
coding
Solve the programming task below in a Python markdown code block. Baby is getting his frst tooth. This means more sleepless nights, but with the fun of feeling round his gums and trying to guess which will be first out! Probably best have a sweepstake with your friends - because you have the best chance of knowing. Y...
{"functional": "_inputs = [[[1, 2, 3, 4]], [[1, 2, 6, 4]], [[1, 2, 5, 7, 1, 0, 9]], [[9, 2, 8, 1]], [[1, 1, 1, 1]], [[20, 9, 16, 19]], [[15]]]\n_outputs = [[3], [2], [6], [2], [-1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a...
270
258
coding
Solve the programming task below in a Python markdown code block. The solution of $ x ^ 3 = q $ is to calculate the recurrence formula $ x_ {n + 1} = x_n-\ frac {x_ {n} ^ 3 --q} {3x_ {n} ^ 2} $ It can be calculated approximately with. Put a positive number $ \ frac {q} {2} $ in $ x_1 $ $ x_2 = x_1-\ frac {x_ {1} ^ 3 ...
{"inputs": ["15\n8\n-1", "15\n3\n-1", "15\n1\n-1", "15\n5\n-1", "15\n9\n-1", "15\n2\n-1", "15\n6\n-1", "15\n4\n-1"], "outputs": ["2.466212\n2.000000\n", "2.466212\n1.442253\n", "2.466212\n1.000002\n", "2.466212\n1.709976\n", "2.466212\n2.080084\n", "2.466212\n1.259921\n", "2.466212\n1.817124\n", "2.466212\n1.587401\n"]...
401
238
coding
Solve the programming task below in a Python markdown code block. Given is a number sequence A of length N. Find the number of integers i \left(1 \leq i \leq N\right) with the following property: - For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i. -----Constraints----- - ...
{"inputs": ["4\n6 8 5 5", "4\n5 8 5 5", "4\n6 8 2 5", "4\n7 8 5 5", "4\n8 8 5 5", "4\n3 8 2 5", "4\n7 9 5 5", "4\n7 9 8 5"], "outputs": ["2\n", "1\n", "2\n", "2\n", "0\n", "3\n", "2\n", "4\n"]}
209
126
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence $A_1, A_2, \ldots, A_N$. For any pair of integers $(l, r)$ such that $1 \le l \le r \le N$, let's define $\mathrm{OR}(l, r)$ as $A_l \lor A_{l+1} \lor \ldots \lor A_r$. Here, $\lor$ is the bitwise OR operator. In total, ...
{"inputs": ["4\n3\n1 2 7\n2\n1 2\n3\n6 5 8\n5\n12 32 45 23 47"], "outputs": ["NO\nYES\nYES\nNO"]}
564
57
coding
Solve the programming task below in a Python markdown code block. The number `1035` is the smallest integer that exhibits a non frequent property: one its multiples, `3105 = 1035 * 3`, has its same digits but in different order, in other words, `3105`, is one of the permutations of `1035`. The number `125874` is the f...
{"functional": "_inputs = [[10000, 7], [5000, 7], [10000, 4], [8000, 4], [5000, 3], [10000, 3]]\n_outputs = [[1], [0], [2], [1], [1], [2]]\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, ...
489
224
coding
Solve the programming task below in a Python markdown code block. Let us define the FizzBuzz sequence a_1,a_2,... as follows: - If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. - If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. - If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. - If none of t...
{"inputs": ["3", "4", "8", "1", "7", "0", "1\n", "16"], "outputs": ["3\n", "7\n", "22\n", "1\n", "14\n", "0\n", "1\n", "76\n"]}
299
67
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums. The next greater number of a number x is the first greater nu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1]) == [2,-1,2]\n assert candidate(nums = [1,2,3,4,3]) == [2,3,4,-1,4]\n\n\ncheck(Solution().nextGreaterElements)"}
138
70
coding
Solve the programming task below in a Python markdown code block. Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the ...
{"inputs": ["1\nw\n", "1\nw\n", "1\nv\n", "1\nu\n", "1\nt\n", "1\ns\n", "2\nno\n", "2\ncb\n"], "outputs": ["w\n", "w\n", "v\n", "u\n", "t\n", "s\n", "no\n", "cb\n"]}
527
87
coding
Solve the programming task below in a Python markdown code block. The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: Operation ++ increases the value of variable x...
{"inputs": ["1\n++X\n", "1\nX--\n", "1\nX--\n", "1\n--X\n", "1\nX++\n", "1\n++X\n", "2\nX++\n--X\n", "2\n--X\n--X\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "0\n", "-2\n"]}
323
104
coding
Solve the programming task below in a Python markdown code block. You are given a string containing characters $\mbox{A}$ and $\mbox{B}$ only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string. You...
{"inputs": ["5\nAAAA\nBBBBB\nABABABAB\nBABABA\nAAABBB\n"], "outputs": ["3\n4\n0\n0\n4\n"]}
356
39
coding
Solve the programming task below in a Python markdown code block. Everyone knows what a square looks like. Mathematically, a square is a regular quadrilateral. This means that it has four equal sides and four equal angles (90 degree angles). One beautiful day, Johnny eagerly examined the interesting properties of squar...
{"inputs": ["1\n7\n0 0\n0 1\n1 0\n1 1\n1 2\n2 1\n2 2"], "outputs": ["3"]}
362
42
coding
Solve the programming task below in a Python markdown code block. For every string, after every occurrence of `'and'` and `'but'`, insert the substring `'apparently'` directly after the occurrence. If input does not contain 'and' or 'but', return the original string. If a blank string, return `''`. If substring `'app...
{"functional": "_inputs = [['A fast-food resteraunt down the street was grumbling my tummy but I could not go.'], ['apparently'], ['and'], ['but'], ['but apparently'], ['and apparently'], ['but but but and and and'], [''], ['but and apparently apparently apparently apparently'], ['and apparentlybutactuallynot voilewtfm...
303
354
coding
Solve the programming task below in a Python markdown code block. One suggestion to build a satisfactory password is to start with a memorable phrase or sentence and make a password by extracting the first letter of each word. Even better is to replace some of those letters with numbers (e.g., the letter `O` can be r...
{"functional": "_inputs = [['Give me liberty or give me death'], ['Keep Calm and Carry On']]\n_outputs = [['Gml0gmd'], ['KCaC0']]\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...
199
178
coding
Solve the programming task below in a Python markdown code block. Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum...
{"inputs": ["2\n", "1\n", "3\n", "1\n", "3\n", "2\n", "1+1\n", "1+2\n"], "outputs": ["2\n", "1\n", "3\n", "1\n", "3\n", "2\n", "1+1\n", "1+2\n"]}
306
78
coding
Solve the programming task below in a Python markdown code block. The educational program (AHK Education) of the Aiz Broadcasting Corporation broadcasts a program called "Play with Tsukuro" for children. Today is the time to make a box with drawing paper, but I would like to see if the rectangular drawing paper I prepa...
{"inputs": ["2 2\n2 3\n2 3\n2 3\n2 2\n5 2", "2 2\n2 3\n2 2\n2 3\n2 2\n2 2", "2 2\n2 3\n2 3\n2 2\n2 2\n5 2", "2 2\n2 3\n2 2\n2 3\n2 2\n2 3", "2 2\n2 3\n4 2\n2 3\n2 2\n2 3", "2 2\n2 3\n4 4\n2 3\n2 2\n2 3", "2 2\n2 3\n4 4\n2 3\n1 2\n2 3", "2 2\n2 3\n4 4\n2 3\n1 1\n2 3"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n",...
317
238
coding
Solve the programming task below in a Python markdown code block. CQXYM found a rectangle A of size n × m. There are n rows and m columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation. A...
{"inputs": ["1\n5 4\n1000\n0000\n0110\n0001\n0001\n", "1\n5 4\n1000\n0000\n1110\n0001\n0000\n", "1\n5 4\n1011\n0000\n1010\n0000\n1000\n", "1\n5 4\n1000\n0010\n0110\n0001\n0001\n", "1\n5 4\n1011\n0000\n1010\n0001\n1000\n", "1\n5 4\n1000\n0100\n0110\n0101\n0000\n", "1\n5 4\n1011\n0000\n1010\n1001\n1000\n", "1\n5 4\n0011\...
639
306
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. In one move, you can choose one element of nums and change it to any value. Return the minimum difference between the largest and smallest value of nums after performing at most th...
{"functional": "def check(candidate):\n assert candidate(nums = [5,3,2,4]) == 0\n assert candidate(nums = [1,5,0,10,14]) == 1\n assert candidate(nums = [3,100,20]) == 0\n\n\ncheck(Solution().minDifference)"}
93
78
coding
Solve the programming task below in a Python markdown code block. In this Kata, we are going to determine if the count of each of the characters in a string can be equal if we remove a single character from that string. For example: ``` solve('abba') = false -- if we remove any character, the count of each character w...
{"functional": "_inputs = [['aaaa'], ['abba'], ['abbba'], ['aabbcc'], ['aaaabb'], ['aabbccddd'], ['aabcde'], ['abcde'], ['aaabcde'], ['abbccc']]\n_outputs = [[True], [False], [True], [False], [False], [True], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
176
222
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese , Russian and Vietnamese Churu is taking the course called “Introduction to Data Structures”. Yesterday, he learned how to use a stack to check is a given parentheses expression is balanced or not. He finds...
{"inputs": ["2\n4 1\n0 3\n4 2\n0 3\n1 2", "2\n4 1\n0 3\n4 1\n0 3\n1 2", "2\n4 1\n1 2\n4 2\n0 3\n2 1", "2\n4 1\n0 3\n4 2\n0 3\n2 2", "2\n4 1\n0 3\n4 2\n0 3\n2 0", "2\n4 1\n0 3\n4 1\n0 3\n1 0", "2\n4 1\n0 3\n4 1\n0 3\n1 1", "2\n4 1\n0 3\n4 1\n0 3\n2 0"], "outputs": ["()()\n(())", "()()\n()()\n", "(())\n()()\n", "()()\n()...
479
247
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth $A$ billion dollars and have no liabilities. He aims t...
{"inputs": ["3\n100 200 10\n111 199 11\n190 200 10"], "outputs": ["10\n8\n1"]}
552
50
coding
Solve the programming task below in a Python markdown code block. Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (`HH:MM:SS`) * `HH` = hours, padded to 2 digits, range: 00 - 99 * `MM` = minutes, padded to 2 digits, range: 00 - 59 * `SS` = seconds...
{"functional": "_inputs = [[0], [59], [60], [3599], [3600], [86399], [86400], [359999]]\n_outputs = [['00:00:00'], ['00:00:59'], ['00:01:00'], ['00:59:59'], ['01:00:00'], ['23:59:59'], ['24:00:00'], ['99:59:59']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
168
273
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game with a binary string S of length N and an empty string T. They both take turns and Alice plays first. In Alice's turn, she picks the first character of string S, appends the character to either the front or back of str...
{"inputs": ["4\n2\n10\n4\n0001\n6\n010111\n10\n1110000010"], "outputs": ["10\n0100\n101101\n0011011000"]}
583
71
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. It is a sweltering summer day, and a boy wants to buy some ice cream bars. At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in co...
{"functional": "def check(candidate):\n assert candidate(costs = [1,3,2,4,1], coins = 7) == 4\n assert candidate(costs = [10,6,8,7,7,8], coins = 5) == 0\n assert candidate(costs = [1,6,3,1,2,5], coins = 20) == 6\n\n\ncheck(Solution().maxIceCream)"}
172
104
coding
Solve the programming task below in a Python markdown code block. Chef has a binary string S of length N. Chef can perform the following operation on the string: Choose any substring of S; Remove the chosen substring from S; Concatenate the remaining parts of the string S, obtained after removing the substring. Find ...
{"inputs": ["3\n4\n1010\n6\n011011\n11\n01011011101\n"], "outputs": ["2\n2\n3\n"]}
645
49
coding
Solve the programming task below in a Python markdown code block. You work in the best consumer electronics corporation, and your boss wants to find out which three products generate the most revenue. Given 3 lists of the same length like these: * products: `["Computer", "Cell Phones", "Vacuum Cleaner"]` * amounts: `[...
{"functional": "_inputs = [[['Computer', 'Cell Phones', 'Vacuum Cleaner'], [3, 24, 8], [199, 299, 399]], [['Cell Phones', 'Vacuum Cleaner', 'Computer', 'Autos', 'Gold', 'Fishing Rods', 'Lego', ' Speakers'], [5, 25, 2, 7, 10, 3, 2, 24], [51, 225, 22, 47, 510, 83, 82, 124]], [['Cell Phones', 'Vacuum Cleaner', 'Computer',...
162
475
coding
Solve the programming task below in a Python markdown code block. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way ot...
{"inputs": ["9 3\n8 3\n4 4\n2 1", "9 3\n8 3\n4 4\n4 1", "9 3\n2 3\n4 4\n1 1", "9 3\n8 3\n4 2\n2 1", "9 3\n8 3\n4 2\n2 1\n", "10000 1\n1 10000\n", "9999 2\n2 9999\n2 10000\n", "10000 2\n1 9999\n1 10000\n"], "outputs": ["4\n", "3\n", "9\n", "4", "4\n", "100000000\n", "49995000\n", "99990000\n"]}
350
212
coding
Solve the programming task below in a Python markdown code block. One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first. There are $n$ books standing in a row on the shelf, the $i$-th book has color $a_i$. Y...
{"inputs": ["5\n1 2 2 1 3\n", "5\n1 2 2 1 1\n", "5\n1 2 4 1 3\n", "5\n1 2 1 1 1\n", "5\n2 2 2 1 3\n", "5\n1 2 1 2 1\n", "5\n1 2 1 1 2\n", "5\n2 1 2 1 3\n"], "outputs": ["2\n", "1\n", "2\n", "1\n", "0\n", "2\n", "1\n", "2\n"]}
419
150
coding
Solve the programming task below in a Python markdown code block. You are given a sequence a_1, a_2, ..., a_n, consisting of integers. You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning, or to the end of a. Note that you have to move a...
{"inputs": ["3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 4 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 5 8 8\n7\n4 2 5 2 6 4...
711
502
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s consisting of only lowercase English letters, and an integer count. A substring of s is said to be an equal count substring if, for each unique letter in the substring, it appears ex...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabcbbcc\", count = 3) == 3\n assert candidate(s = \"abcd\", count = 2) == 0\n assert candidate(s = \"a\", count = 5) == 0\n\n\ncheck(Solution().equalCountSubstrings)"}
131
75
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, and two integers num1 and num2. num1 and num2 are coprime numbers. A ratio substring is a substring of s where the ratio between the number of 0's and the number of 1's in the substrin...
{"functional": "def check(candidate):\n assert candidate(s = \"0110011\", num1 = 1, num2 = 2) == 4\n assert candidate(s = \"10101\", num1 = 3, num2 = 1) == 0\n\n\ncheck(Solution().fixedRatio)"}
235
77
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Return the single element that appears only once. Your solution mu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,3,3,4,4,8,8]) == 2\n assert candidate(nums = [3,3,7,7,10,11,11]) == 10\n\n\ncheck(Solution().singleNonDuplicate)"}
101
76
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition o...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,4]) == [2,3]\n assert candidate(nums = [1,1]) == [1,2]\n\n\ncheck(Solution().findErrorNums)"}
146
59