problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string cons...
{"inputs": ["1\na\n", "1\na\n", "1\nb\n", "12\ntoosmallword\n", "12\ntoosmallworc\n", "12\ntoosmallword\n", "25\nnxYTzLFwzNolAumjgcAboyxAj\n", "25\nabcdefghijklmnopqrstuvwxy\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
210
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard version is the constraint on $n$. You are given an undirected complete graph on $n$ vertices. A complete graph is a graph where each pair of vertices is connected by an edge. You have to paint the edges ...
{"inputs": ["3\n", "4\n", "42\n", "13\n", "69\n", "100\n", "500\n", "1337\n"], "outputs": ["6\n", "50\n", "934067958\n", "456092424\n", "242481789\n", "878752271\n", "39656147\n", "520628749\n"]}
coding
448
Solve the programming task below in a Python markdown code block. A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that th...
{"inputs": ["4\n7\n44\n7\n4747477", "4\n7\n7\n477\n4747477", "4\n7\n7\n447\n4747477", "4\n7\n47\n477\n4747477", "4\n4\n47\n477\n4747477", "4\n7\n44\n477\n4747477", "4\n47\n4\n477\n4747477", "4\n47\n7\n477\n4747477"], "outputs": ["0\n3\n0\n23\n", "0\n0\n3\n23\n", "0\n0\n5\n23\n", "0\n2\n3\n23\n", "1\n2\n3\n23\n", "0\n3\...
coding
618
Solve the programming task below in a Python markdown code block. In this task you have to code process planner. You will be given initial thing, target thing and a set of processes to turn one thing into another (in the form of _[process\_name, start\_thing, end\_thing]_). You must return names of shortest sequence ...
{"functional": "_inputs = [['a', 'c', [['1', 'a', 'c'], ['2', 'a', 'b'], ['3', 'b', 'c']]], ['a', 'd', [['1', 'a', 'b'], ['2', 'b', 'c'], ['3', 'c', 'b']]], ['a', 'd', [['1', 'a', 'b'], ['2', 'b', 'c'], ['3', 'c', 'b'], ['4', 'c', 'd']]]]\n_outputs = [[['1']], [[]], [['1', '2', '4']]]\nimport math\ndef _deep_eq(a, b, t...
coding
241
Solve the programming task below in a Python markdown code block. There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the ...
{"inputs": ["5\n1\n4\n1\n2\n2", "5\n1\n2\n1\n2\n3", "5\n1\n2\n1\n2\n1", "5\n1\n2\n1\n3\n2", "5\n1\n2\n1\n5\n2", "5\n1\n2\n1\n1\n2", "5\n1\n3\n1\n1\n2", "5\n2\n3\n1\n1\n2"], "outputs": ["2\n", "3\n", "5\n", "3\n", "3\n", "3\n", "2\n", "2\n"]}
coding
267
Solve the programming task below in a Python markdown code block. The sequence of n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n. For example, (24, 25, 26, 27, 28) between 23 and 29 is...
{"inputs": ["10\n11\n75\n2\n1883\n0", "10\n11\n70\n2\n1883\n0", "10\n8\n55\n2\n48870\n0", "10\n8\n55\n2\n87472\n0", "10\n11\n53\n2\n7780\n0", "10\n4\n55\n2\n87472\n0", "10\n11\n53\n2\n6070\n0", "10\n3\n55\n2\n87472\n0"], "outputs": ["4\n0\n6\n0\n10\n", "4\n0\n4\n0\n10\n", "4\n4\n6\n0\n2\n", "4\n4\n6\n0\n30\n", "4\n0\n0...
coding
305
Solve the programming task below in a Python markdown code block. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $...
{"inputs": ["a\n", "z\n", "z\n", "a\n", "b\n", "c\n", "cc\n", "zy\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]}
coding
628
Solve the programming task below in a Python markdown code block. Chef likes strings a lot but he likes palindromic strings more. Today, Chef has two strings A and B, each consisting of lower case alphabets. Chef is eager to know whether it is possible to choose some non empty strings s1 and s2 where s1 is a substring...
{"inputs": ["3\nabc\nabc\na\nb\nabba\nbaab", "3\nabc\nabc\nb\nb\nabba\nbaab", "3\nbaa\n`cc\nb\nb\n`bab\nbaac", "3\naab\n_dc\na\nb\nba`b\ncbaa", "3\nabc\nacc\na\nb\nabba\nbaab", "3\nbaa\ndc^\n`\nb\n`b`b\naaac", "3\n_ba\ndb`\nb\na\ndb`b\nc_ac", "3\ncbb\n`ab\nb\nb\n`bc`\na_aa"], "outputs": ["Yes\nNo\nYes", "Yes\nYes\nYes\...
coding
435
Solve the programming task below in a Python markdown code block. You probably know that the "mode" of a set of data is the data point that appears most frequently. Looking at the characters that make up the string `"sarsaparilla"` we can see that the letter `"a"` appears four times, more than any other letter, so the ...
{"functional": "_inputs = [['tomato'], [[1, 3, 3, 7]], [['redder']]]\n_outputs = [[['o', 't']], [[3]], [[]]]\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...
coding
393
Solve the programming task below in a Python markdown code block. This kata focuses on the Numpy python package and you can read up on the Numpy array manipulation functions here: https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.array-manipulation.html You will get two integers `N` and `M`. You must return a...
{"functional": "_inputs = [[10, 1], [10, 3], [10, 97]]\n_outputs = [[[[4, 0, 1, 2, 3], [9, 5, 6, 7, 8]]], [[[2, 3, 4, 0, 1], [7, 8, 9, 5, 6]]], [[[3, 4, 0, 1, 2], [8, 9, 5, 6, 7]]]]\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_t...
coding
269
Solve the programming task below in a Python markdown code block. Your friend has invited you to a party, and tells you to meet them in the line to get in. The one problem is it's a masked party. Everyone in line is wearing a colored mask, including your friend. Find which people in line could be your friend. Your fri...
{"functional": "_inputs = [[['blue', 'blue', 'red', 'red', 'blue', 'green']], [['blue', 'red', 'blue', 'blue', 'red', 'blue', 'red']], [['brown', 'brown', 'red', 'green']], [['red', 'blue', 'blue', 'red']], [['red', 'blue']], [['blue', 'green', 'red', 'green', 'blue', 'blue', 'red']], [['blue', 'blue', 'blue', 'blue', ...
coding
211
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0. In the ith move, you can choose one of the fol...
{"functional": "def check(candidate):\n assert candidate(moves = \"L_RL__R\") == 3\n assert candidate(moves = \"_R__LL_\") == 5\n assert candidate(moves = \"_______\") == 7\n\n\ncheck(Solution().furthestDistanceFromOrigin)"}
coding
159
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"]}
coding
540
Solve the programming task below in a Python markdown code block. You are given a string, $\mbox{S}$, consisting of lowercase English letters. A string is beautiful with respect to $\mbox{S}$ if it can be derived from $\mbox{S}$ by removing exactly $2$ characters. Find and print the number of different strings that a...
{"inputs": ["abba\n"], "outputs": ["4\n"]}
coding
308
Solve the programming task below in a Python markdown code block. This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest...
{"inputs": ["1 1\n100000\n1 1\n", "6 3\n1 4 5 5 4 3\n1 6\n4 4\n3 3\n", "6 3\n1 2 3 5 4 2\n1 2\n4 4\n3 6\n", "6 3\n1 6 3 4 4 1\n1 6\n2 6\n3 6\n", "6 3\n1 2 3 5 2 2\n1 6\n4 4\n3 6\n", "6 3\n1 2 3 5 4 2\n1 6\n4 4\n3 6\n", "6 3\n1 2 3 5 4 2\n1 6\n4 4\n3 5\n", "6 3\n1 4 3 5 4 2\n1 6\n4 4\n3 5\n"], "outputs": ["1\n", "2\n1\n...
coding
533
Solve the programming task below in a Python markdown code block. Background There is a message that is circulating via public media that claims a reader can easily read a message where the inner letters of each words is scrambled, as long as the first and last letters remain the same and the word contains all the lett...
{"functional": "_inputs = [['professionals'], ['i'], [''], ['me'], ['you'], ['card-carrying'], [\"shan't\"], ['-dcba'], ['dcba.'], [\"you've gotta dance like there's nobody watching, love like you'll never be hurt, sing like there's nobody listening, and live like it's heaven on earth.\"]]\n_outputs = [['paefilnoorsss'...
coding
316
Solve the programming task below in a Python markdown code block. Akash and Akhil are playing a game. They have $N$ balls numbered from $0$ to $N-1$. Akhil asks Akash to reverse the position of the balls, i.e., to change the order from say, 0,1,2,3 to 3,2,1,0. He further asks Akash to reverse the position of the balls ...
{"inputs": ["2\n3 1\n5 2\n"], "outputs": ["2\n4\n"]}
coding
386
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.   Please complete the following python code precisely: ```python class Solution...
{"functional": "def check(candidate):\n assert candidate(left = 5, right = 7) == 4\n assert candidate(left = 0, right = 0) == 0\n assert candidate(left = 1, right = 2147483647) == 0\n\n\ncheck(Solution().rangeBitwiseAnd)"}
coding
81
Solve the programming task below in a Python markdown code block. HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the val...
{"inputs": ["Q\n", "~\n", "8\n", "H\n", "!\n", "9\n", "3\n", "+\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n"]}
coding
280
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,9,7,3]) == 2\n assert candidate(nums = [-36,36]) == 72\n assert candidate(nums = [2,-1,0,4,-2,-9]) == 0\n\n\ncheck(Solution().minimumDifference)"}
coding
108
Solve the programming task below in a Python markdown code block. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≤ l ≤ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist on...
{"inputs": ["3 3\n", "6 4\n", "3 1\n", "7 3\n", "6 2\n", "1 1\n", "6 6\n", "5 1\n"], "outputs": ["111", "010101", "010", "0010010", "001001", "1", "111111", "00100"]}
coding
585
Solve the programming task below in a Python markdown code block. For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path). Constraints * 1 ≤ |V| ≤ 100000 * 0 ≤ di ≤ 10000 * 0 ≤ |E| ≤ 500000 * There are no parallel edges * Ther...
{"inputs": ["4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n0 2 4\n1 2 0\n2 3 1\n1 3 5", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 1 1\n1 2 5\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 2 1\n0 3 4\n1 2 2\n2 2 2\n1 3 2", "4 5 0\n0 2 2\n0 3 4\n1 3 2\n3 2 2\n1 3 2", ...
coding
426
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. You are allowed to permute nums into a new array perm of your choosing. We define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > n...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,2,1,3,1]) == 4\n assert candidate(nums = [1,2,3,4]) == 3\n\n\ncheck(Solution().maximizeGreatness)"}
coding
118
Solve the programming task below in a Python markdown code block. Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector ...
{"inputs": ["2 1\n..\n", "2 1\n..\n", "2 2\n..\n", "2 2\n..\n", "2 4\n..\n", "2 8\n..\n", "2 1\n..\n", "3 1\n.#.\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]}
coding
345
Solve the programming task below in a Python markdown code block. You are given a string q. A sequence of k strings s_1, s_2, ..., s_{k} is called beautiful, if the concatenation of these strings is string q (formally, s_1 + s_2 + ... + s_{k} = q) and the first characters of these strings are distinct. Find any beauti...
{"inputs": ["1\nk\n", "1\nk\n", "1\nl\n", "1\nm\n", "1\nj\n", "1\nzz\n", "26\na\n", "2\nab\n"], "outputs": ["YES\nk\n", "YES\nk\n", "YES\nl\n", "YES\nm\n", "YES\nj\n", "YES\nzz\n", "NO\n", "YES\na\nb\n"]}
coding
312
Solve the programming task below in a Python markdown code block. Who's interested in football? Rayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since. He's got proper treatment and ...
{"inputs": ["3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 2 2 3", "3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 1 2 3", "3\n6\n3 1 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 1 2 3", "3\n6\n3 1 1 4 2 4\n5\n2 4 3 2 1\n5\n4 3 1 2 3", "3\n6\n1 1 0 4 2 4\n5\n4 4 3 2 1\n5\n4 0 1 2 3", "3\n6\n1 1 0 4 2 4\n5\n4 7 3 2 2\n5\n4 0 1 2 3", "3\n6\n1 1 1 4...
coding
653
Solve the programming task below in a Python markdown code block. What's in a name? ..Or rather, what's a name in? For us, a particular string is where we are looking for a name. Task Test whether or not the string contains all of the letters which spell a given name, in order. The format A function passing two stri...
{"functional": "_inputs = [['Across the rivers', 'chris'], ['Next to a lake', 'chris'], ['Under a sea', 'chris'], ['A crew that boards the ship', 'chris'], ['A live son', 'Allison'], ['Just enough nice friends', 'Jennifer'], ['thomas', 'Thomas'], ['pippippi', 'Pippi'], ['pipipp', 'Pippi'], ['ppipip', 'Pippi']]\n_output...
coding
385
Solve the programming task below in a Python markdown code block. Let $f(i)$ denote the minimum positive integer $x$ such that $x$ is not a divisor of $i$. Compute $\sum_{i=1}^n f(i)$ modulo $10^9+7$. In other words, compute $f(1)+f(2)+\dots+f(n)$ modulo $10^9+7$. -----Input----- The first line contains a single in...
{"inputs": ["1\n75137\n", "1\n46880\n", "1\n25013\n", "1\n30498\n", "1\n44931\n", "1\n25621\n", "1\n41771\n", "1\n60060\n"], "outputs": ["209458\n", "130685\n", "69722\n", "85019\n", "125250\n", "71422\n", "116442\n", "167431\n"]}
coding
516
Solve the programming task below in a Python markdown code block. There are $n$ people who want to participate in a boat competition. The weight of the $i$-th participant is $w_i$. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with...
{"inputs": ["5\n5\n1 2 3 4 5\n8\n6 6 6 6 6 6 8 8\n8\n1 2 2 1 2 1 1 2\n3\n1 3 3\n6\n1 1 3 4 2 2\n", "5\n5\n1 2 3 4 5\n8\n6 6 6 6 6 6 8 8\n8\n1 2 2 1 2 1 1 2\n3\n1 3 3\n6\n1 1 3 4 2 2\n", "4\n14\n2 6 5 9 5 8 13 14 8 5 6 14 5 2\n36\n15 22 27 7 23 36 1 17 33 21 18 7 3 4 32 24 8 19 36 22 17 2 24 10 26 4 30 6 2 6 11 19 18 1 ...
coding
727
Solve the programming task below in a Python markdown code block. Chef had an array A with length N, but some of its elements got lost. Now, each element of this array is either unknown (denoted by -1) or a positive integer not exceeding K. Chef decided to restore the array A by replacing each unknown element by a posi...
{"inputs": ["3\n4 2 10\n2 3 5 4\nI 1 2\nD 3 4\n5 2 10\n-1 -1 -1 -1 -1\nI 1 3\nD 3 5\n6 2 2\n-1 -1 -1 -1 -1 -1\nI 1 4\nD 4 6"], "outputs": ["1\n8\n0"]}
coding
528
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.   Please complete the following python code precisely: ```python class Solution: def findDiagonalOrder(self, mat: Li...
{"functional": "def check(candidate):\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]]) == [1,2,4,7,5,3,6,8,9]\n assert candidate(mat = [[1,2],[3,4]]) == [1,2,3,4]\n\n\ncheck(Solution().findDiagonalOrder)"}
coding
75
Solve the programming task below in a Python markdown code block. There are $n$ athletes in front of you. Athletes are numbered from $1$ to $n$ from left to right. You know the strength of each athlete — the athlete number $i$ has the strength $s_i$. You want to split all athletes into two teams. Each team must have a...
{"inputs": ["5\n5\n3 1 2 7 4\n6\n2 2 3 2 1 3\n4\n7 9 3 0\n2\n1 1000\n3\n000 150 85\n", "5\n5\n1 1 2 7 4\n6\n2 2 3 2 2 5\n4\n7 9 3 0\n2\n1 1000\n3\n000 150 85\n", "5\n5\n3 1 2 7 4\n6\n2 2 3 2 1 3\n4\n2 9 3 0\n2\n1 1000\n3\n000 150 85\n", "5\n5\n1 1 2 7 4\n6\n2 2 3 3 4 5\n4\n7 9 3 0\n2\n0 1000\n3\n000 150 85\n", "5\n5\n3...
coding
676
Solve the programming task below in a Python markdown code block. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write ...
{"inputs": ["A\n", "A\n", "@\n", "aa\n", "aa\n", "ab\n", "ac\n", "Ann\n"], "outputs": ["NO", "NO\n", "NO\n", "NO", "NO\n", "NO\n", "NO\n", "YES"]}
coding
232
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Let's consider a set of points S. Initially, S is an empty set. Your task is to implement a data structure that can process the following queries efficiently: "+ X Y" - add a new po...
{"inputs": ["10\n+ 8 1\n- 1\n+ 3 9\n? 8 4\n? 8 8\n? 12 0\n+ 6 5\n? 7 8\n? 4 5\n- 9"], "outputs": ["10\n8\n2\n4\n11"]}
coding
676
Solve the programming task below in a Python markdown code block. Your colleagues have been good enough(?) to buy you a birthday gift. Even though it is your birthday and not theirs, they have decided to play pass the parcel with it so that everyone has an even chance of winning. There are multiple presents, and you wi...
{"functional": "_inputs = [['badpresent', 3], ['goodpresent', 9], ['crap', 10], ['bang', 27], ['dog', 23]]\n_outputs = [['Take this back!'], ['pxxmy{n|nw}'], ['acpr'], ['300'], ['pass out from excitement 23 times']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
266
Solve the programming task below in a Python markdown code block. Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi'...
{"inputs": ["121", "888", "435", "684", "394", "124", "143", "110"], "outputs": ["21\n", "271\n", "193\n", "243\n", "182\n", "24\n", "43\n", "10\n"]}
coding
238
Solve the programming task below in a Python markdown code block. Modify the `kebabize` function so that it converts a camel case string into a kebab case. Notes: - the returned string should only contain lowercase letters Also feel free to reuse/extend the following starter code: ```python def kebabize(string): ```
{"functional": "_inputs = [['myCamelCasedString'], ['myCamelHas3Humps'], ['SOS'], ['42'], ['CodeWars']]\n_outputs = [['my-camel-cased-string'], ['my-camel-has-humps'], ['s-o-s'], [''], ['code-wars']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i...
coding
70
Solve the programming task below in a Python markdown code block. Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is ve...
{"inputs": ["1 1\n1 0\n", "1 1\n1 0\n", "3 3\n2 0\n1 1\n3 2\n", "3 3\n3 0\n1 1\n2 2\n", "3 3\n3 0\n1 1\n2 2\n", "3 3\n2 0\n1 1\n3 2\n", "3 3\n2 0\n1 1\n2 2\n", "3 3\n2 -1\n1 1\n3 2\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
670
Solve the programming task below in a Python markdown code block. *Recreation of [Project Euler problem #6](https://projecteuler.net/problem=6)* Find the difference between the sum of the squares of the first `n` natural numbers `(1 <= n <= 100)` and the square of their sum. ## Example For example, when `n = 10`: * ...
{"functional": "_inputs = [[5], [10], [100]]\n_outputs = [[170], [2640], [25164150]]\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 F...
coding
288
Solve the programming task below in a Python markdown code block. Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is ge...
{"inputs": ["2\n1 1 1 2", "2\n1 2 1 3", "2\n1 1 1 3", "2\n2 2 1 3", "2\n2 1 1 1", "2\n2 2 1 5", "2\n4 1 1 1", "2\n0 2 1 5"], "outputs": ["0\n166374063\n166374063\n332748121\n", "0\n532396992\n582309210\n449209962\n", "0\n499122181\n499122181\n3\n", "0\n465847369\n665496240\n798595486\n", "0\n5\n5\n5\n", "0\n903173467\n...
coding
757
Solve the programming task below in a Python markdown code block. Salmon received an array $A$ of size $N$ and an array $B$ of size $M$ for Christmas. He would like to move all the elements in $B$ to $A$ using a special method described below. While $B$ is not empty, Salmon does the following operations in order: * R...
{"inputs": ["5 3\n10 5 2 5 4\n3 1 2"], "outputs": ["5"]}
coding
574
Solve the programming task below in a Python markdown code block. You are standing at the point $0$ on a coordinate line. Your goal is to reach the point $n$. In one minute, you can move by $2$ or by $3$ to the left or to the right (i. e., if your current coordinate is $x$, it can become $x-3$, $x-2$, $x+2$ or $x+3$). ...
{"inputs": ["1\n56\n", "1\n6942\n", "1\n10241\n", "1\n22812\n", "1\n99999\n", "1\n507348\n", "1\n123451\n", "4\n1\n3\n4\n12\n"], "outputs": ["19\n", "2314\n", "3414\n", "7604\n", "33333\n", "169116\n", "41151\n", "2\n1\n2\n4\n"]}
coding
301
Solve the programming task below in a Python markdown code block. Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number t...
{"functional": "_inputs = [['XXI'], ['I'], ['IV'], ['MMVIII'], ['MDCLXVI']]\n_outputs = [[21], [1], [4], [2008], [1666]]\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 ...
coding
285
Solve the programming task below in a Python markdown code block. A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher...
{"inputs": ["1\n(\n", "1\n(\n", "1\n)\n", "2\n((\n", "2\n((\n", "2\n()\n", "3\n(()\n", "3\n((*\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n", "-1\n", "-1\n"]}
coding
539
Solve the programming task below in a Python markdown code block. You are given an array of n integers a1... an. The cost of a subsegment is the number of unordered pairs of distinct indices within the subsegment that contain equal elements. Split the given array into k non-intersecting non-empty subsegments so that th...
{"inputs": ["2 2\n2 2\n", "7 3\n1 1 3 3 4 2 1\n", "7 3\n1 1 3 3 1 2 1\n", "7 3\n1 1 2 3 4 2 1\n", "7 3\n1 2 2 3 4 2 1\n", "7 3\n1 1 3 3 6 2 1\n", "7 3\n1 2 2 3 4 1 1\n", "7 6\n1 1 3 3 1 2 1\n"], "outputs": ["0", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
429
Solve the programming task below in a Python markdown code block. You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974". Constraints * 0 \leq N_1, N_2, N_3, N_4 \leq 9 * N_1, N_2, N_3 and N_4 are integers. Input Input is given from Standard Input in t...
{"inputs": ["1 2 3 1", "0 7 9 4", "1 3 3 1", "1 2 3 2", "1 0 3 2", "1 0 4 2", "1 0 0 2", "1 0 0 1"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
226
Solve the programming task below in a Python markdown code block. We define the function `f1(n,k)`, as the least multiple of `n` that has all its digits less than `k`. We define the function `f2(n,k)`, as the least multiple of `n` that has all the digits that are less than `k`. Each digit may occur more than once in...
{"functional": "_inputs = [[542, 5], [1750, 6], [14990, 7], [3456, 4], [30500, 3], [62550, 5], [568525, 7], [9567100, 8]]\n_outputs = [[547], [1799], [14996], [3462], [30501], [62557], [568531], [9567115]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ...
coding
657
Solve the programming task below in a Python markdown code block. # Task In the city, a bus named Fibonacci runs on the road every day. There are `n` stations on the route. The Bus runs from station1 to stationn. At the departure station(station1), `k` passengers get on the bus. At the second station(station2), a ...
{"functional": "_inputs = [[5, 7, 32, 4], [12, 23, 212532, 8]]\n_outputs = [[13], [252]]\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): retu...
coding
422
Solve the programming task below in a Python markdown code block. Chef has invested his money at an interest rate of X percent per annum while the current inflation rate is Y percent per annum. An investment is called *good* if and only if the interest rate of the investment is at least twice of the inflation rate. ...
{"inputs": ["5\n7 4\n6 3\n2 4\n10 10\n20 1\n"], "outputs": ["NO\nYES\nNO\nNO\nYES\n"]}
coding
453
Solve the programming task below in a Python markdown code block. You are given a set of N distinct points P_{1}, P_{2}, P_{3}, \ldots, P_{N} on a 2-D plane. A triplet (i, j, k) is called a holy triplet if 1 ≤ i < j < k ≤ N P_{i}, P_{j} and P_{k} are non-collinear and Any two of the points P_{i}, P_{j} and P_{k} are [...
{"inputs": ["1\n4\n0 1\n0 -1\n1 0\n-1 0"], "outputs": ["4"]}
coding
620
Solve the programming task below in a Python markdown code block. There is a building consisting of $10~000$ apartments numbered from $1$ to $10~000$, inclusive. Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are $11, 2, 777, 9999$ and so on. Our character is a troub...
{"inputs": ["4\n6\n9999\n4\n777\n", "4\n9\n9999\n4\n777\n", "4\n4\n9999\n4\n777\n", "4\n9\n9999\n1\n777\n", "4\n3\n9999\n1\n777\n", "4\n9\n9999\n2\n777\n", "4\n4\n9999\n6\n777\n", "4\n3\n9999\n1\n555\n"], "outputs": ["51\n90\n31\n66\n", "81\n90\n31\n66\n", "31\n90\n31\n66\n", "81\n90\n1\n66\n", "21\n90\n1\n66\n", "81\n...
coding
469
Solve the programming task below in a Python markdown code block. Kiteretsu goes to his Chemistry Lab to perform the perfect reaction. In his lab, he found N reagents numbered 1 to N. The i^{th} reagent has two properties - A_{i} and B_{i}. A reaction can be performed between the reagents i and j only if A_{i} ≤ j. ...
{"inputs": ["2\n5 2\n2 4 5 5 6\n1 3 2 2 5\n2 3\n2 3\n1 2\n"], "outputs": ["6\n-7\n"]}
coding
714
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of those operations. Please complete t...
{"functional": "def check(candidate):\n assert candidate(A = 1, B = 10) == 10\n assert candidate(A = 3, B = 4) == 12\n\n\ncheck(Solution().multiply)"}
coding
85
Solve the programming task below in a Python markdown code block. The working hours of Chef’s kitchen are from X pm to Y pm (1 ≤ X < Y ≤ 12). Find the number of hours Chef works. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test cas...
{"inputs": ["4\n1 2\n3 7\n9 11\n2 10\n"], "outputs": ["1\n4\n2\n8\n"]}
coding
319
Solve the programming task below in a Python markdown code block. Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
{"inputs": ["2\n0\n1 0\n", "3\n0 0\n0 1 1\n", "5\n0 1 1 3\n0 0 0 1 1\n", "6\n0 2 1 0 4\n1 1 0 0 1 0\n", "6\n0 2 1 0 4\n1 1 0 1 1 0\n", "6\n0 1 1 0 4\n1 1 0 1 1 0\n", "6\n0 1 1 0 4\n1 1 0 1 1 1\n", "6\n0 1 2 0 4\n1 1 0 0 1 0\n"], "outputs": ["1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
436
Solve the programming task below in a Python markdown code block. The lockdown hasn’t been great for our chef as his restaurant business got sabotaged because of lockdown, nevertheless no worries our chef is a multi-talented guy. Chef has decided to be a freelancer and work remotely. According to chef’s maths, he shoul...
{"inputs": ["3\n10 12 20\n20 25 30", "6\n1 2 0 6 3 7\n2 4 5 7 9 10"], "outputs": ["0 2", "0 1 3 5"]}
coding
326
Solve the programming task below in a Python markdown code block. This time minions are celebrating Diwali Festival. There are N minions in total. Each of them owns a house. On this Festival, Each of them wants to decorate their house. But none of them have enough money to do that. One of the minion, Kevin, requested G...
{"inputs": ["2\n4 9\n5 2 2 4\n4 9\n5 2 18 3"], "outputs": ["YES\nNO"]}
coding
442
Solve the programming task below in a Python markdown code block. Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order. Ada has a kitchen with two identical burners. For each valid $i$, to prepare the ...
{"inputs": ["3\n3\n2 2 2\n3\n1 2 3\n4\n2 3 4 5"], "outputs": ["4\n3\n7"]}
coding
570
Solve the programming task below in a Python markdown code block. Complete the function ```caffeineBuzz```, which takes a non-zero integer as it's one argument. If the integer is divisible by 3, return the string ```"Java"```. If the integer is divisible by 3 and divisible by 4, return the string ```"Coffee"``` If t...
{"functional": "_inputs = [[1], [3], [6], [12]]\n_outputs = [['mocha_missing!'], ['Java'], ['JavaScript'], ['CoffeeScript']]\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))...
coding
187
Solve the programming task below in a Python markdown code block. Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each secon...
{"inputs": ["3 1\n0.1\n", "3 1\n0.9\n", "3 3\n9.9\n", "3 1\n9.5\n", "3 1\n9.9\n", "3 2\n0.9\n", "3 0\n0.1\n", "3 2\n9.5\n"], "outputs": ["0.1", "1", "10", "10", "10", "1", "0.1\n", "10"]}
coding
622
Solve the programming task below in a Python markdown code block. Takahashi found an undirected connected graph with N vertices and M edges. The vertices are numbered 1 through N. The i-th edge connects vertices a_i and b_i, and has a weight of c_i. He will play Q rounds of a game using this graph. In the i-th round, ...
{"inputs": ["4 3\n1 2 3\n2 3 6\n3 4 5\n2\n2 3\n1 4", "4 3\n1 2 3\n2 3 6\n3 4 6\n2\n2 3\n1 4", "4 3\n1 2 3\n2 3 6\n3 4 7\n2\n2 3\n1 4", "4 3\n1 2 0\n2 3 6\n3 4 5\n2\n2 3\n1 4", "4 3\n1 2 3\n2 3 4\n3 4 5\n2\n2 3\n1 4", "4 6\n1 3 5\n4 2 6\n2 4 6\n3 2 2\n2 4 5\n2 2 3\n1\n2 3", "4 6\n2 3 7\n4 2 3\n2 4 3\n3 2 2\n2 4 5\n1 2 3...
coding
434
Solve the programming task below in a Python markdown code block. This is the performance version of [this kata](https://www.codewars.com/kata/59afff65f1c8274f270020f5). --- Imagine two rings with numbers on them. The inner ring spins clockwise and the outer ring spins anti-clockwise. We start with both rings aligned...
{"functional": "_inputs = [[5, 5], [2, 10], [10, 2], [7, 9], [1, 1], [16777216, 14348907]]\n_outputs = [[3], [13], [10], [4], [1], [23951671]]\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...
coding
431
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef went to the store in order to buy one can of coke. In the store, they offer $N$ cans of coke (numbered $1$ through $N$). For each valid $i$, th...
{"inputs": ["2\n3 2 5 4 6\n1 6\n2 8\n8 10\n3 5 10 20 30\n21 20\n22 22\n23 23"], "outputs": ["8\n-1"]}
coding
738
Solve the programming task below in a Python markdown code block. A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called k-balanced if every substring of size k of this bitstring has an equal amount of 0 and 1 characters (k/2 of each). You are given an integer k and a string s which i...
{"inputs": ["9\n6 4\n100111\n3 2\n1?1\n3 2\n0?1\n4 4\n????\n7 4\n?1??0?1\n10 8\n11???11?11\n4 2\n1??1\n4 4\n0??0\n6 2\n00????\n", "9\n6 4\n100110\n3 2\n1?1\n3 2\n0?1\n4 4\n????\n7 4\n1?0??1?\n10 6\n11???11?11\n4 2\n1??1\n4 4\n?0?0\n6 2\n????10\n", "9\n6 4\n100111\n3 2\n1?1\n3 2\n0?1\n4 4\n????\n7 4\n?1??0?1\n10 5\n11??...
coding
536
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a programming language with only four operations and one variable X: ++X and X++ increments the value of the variable X by 1. --X and X-- decrements the value of the variable X by 1. Initially, the value of...
{"functional": "def check(candidate):\n assert candidate(operations = [\"--X\",\"X++\",\"X++\"]) == 1\n assert candidate(operations = [\"++X\",\"++X\",\"X++\"]) == 3\n assert candidate(operations = [\"X++\",\"++X\",\"--X\",\"X--\"]) == 0\n\n\ncheck(Solution().finalValueAfterOperations)"}
coding
131
Solve the programming task below in a Python markdown code block. Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries. Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or...
{"inputs": ["1 5\n2 3\n", "1 5\n2 2\n", "1 5\n5 0\n", "1 5\n0 0\n", "1 5\n4 0\n", "1 5\n5 5\n", "1 5\n8 7\n", "1 5\n0 0\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "0\n", "2\n", "3\n", "0\n"]}
coding
545
Solve the programming task below in a Python markdown code block. Sehr Sus is an infinite hexagonal grid as pictured below, controlled by MennaFadali, ZerooCool and Hosssam. They love equilateral triangles and want to create $n$ equilateral triangles on the grid by adding some straight lines. The triangles must all be...
{"inputs": ["1\n1\n", "2\n10\n9\n", "2\n76\n15\n", "2\n2922\n2251\n", "4\n1\n2\n3\n4567\n", "1\n1000000000\n", "3\n390\n398\n285\n", "5\n66\n6666\n666666\n66666666\n666666666\n"], "outputs": ["2\n", "4\n4\n", "11\n5\n", "67\n59\n", "2\n2\n3\n83\n", "38730\n", "25\n25\n21\n", "10\n100\n1000\n10000\n31623\n"]}
coding
353
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. There is a party going on in a club situated in some city. N gangsters will attend that party. The i-th gangster comes to the party at the beginning of S_{i} time and will leave the party...
{"inputs": ["3\n3 2\n1 3\n3 5\n4 6\n4 3\n1 8\n2 9\n3 10\n4 11\n4 3\n1 5\n4 9\n8 13\n12 17"], "outputs": ["1\n2\n0"]}
coding
709
Solve the programming task below in a Python markdown code block. Given 2 elevators (named "left" and "right") in a building with 3 floors (numbered `0` to `2`), write a function `elevator` accepting 3 arguments (in order): - `left` - The current floor of the left elevator - `right` - The current floor of the right el...
{"functional": "_inputs = [[0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 0, 0], [0, 2, 1], [0, 0, 1], [0, 0, 2], [0, 2, 0], [0, 2, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 2], [2, 0, 0], [2, 0, 1], [2, 0, 2], [2, 1, 0], [2, 1, 1], [2, 1, 2], [2, 2, 0], [2, 2, 1], [2, 2, ...
coding
272
Solve the programming task below in a Python markdown code block. Alice has a binary string. She thinks a binary string is beautiful if and only if it doesn't contain the substring $\text{"010"}$. In one step, Alice can change a $0$ to a $1$ or vice versa. Count and print the minimum number of steps needed to make Al...
{"inputs": ["5\n01100\n", "7\n0101010\n", "10\n0100101010\n"], "outputs": ["0\n", "2 \n", "3\n"]}
coding
508
Solve the programming task below in a Python markdown code block. In this problem, you will be given a polynomial, you have to print what it becomes after differentiation. Following are the rules for differentiation: - For a polynomial f(x), its differentiation is defined as f'(x). - If a is a constant, then different...
{"inputs": ["2\n1\n1 2\n3\n1 3\n1 1\n1 0"], "outputs": ["2x^1\n3x^2 + 1"]}
coding
538
Solve the programming task below in a Python markdown code block. Write a function that returns the count of characters that have to be removed in order to get a string with no consecutive repeats. *Note:* This includes any characters ## Examples ```python 'abbbbc' => 'abc' # answer: 3 'abbcca' => 'abca' # ...
{"functional": "_inputs = [['abcdefg'], ['aabbccddeeffgg'], ['abcdeefee'], ['122453124'], ['@*$##^^^*)*'], ['abmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmvxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
coding
132
Solve the programming task below in a Python markdown code block. Kristen loves playing with and comparing numbers. She thinks that if she takes two different positive numbers, the one whose digits sum to a larger number is better than the other. If the sum of digits is equal for both numbers, then she thinks the small...
{"inputs": ["12\n"], "outputs": ["6\n"]}
coding
252
Solve the programming task below in a Python markdown code block. Chef and his best friend Aleksa are into mathematical games these days. Today, they have some ( ≥ 0 ) black cells represented as B, and a white cell represented as W, lying randomly in a straight line. They have decided to play with these cells. In a mov...
{"inputs": ["3\nW\nBW\nBWBB"], "outputs": ["Chef\nAleksa\nAleksa"]}
coding
556
Solve the programming task below in a Python markdown code block. You are given a list/array which contains only integers (positive and negative). Your job is to sum only the numbers that are the same and consecutive. The result should be one list. Extra credit if you solve it in one line. You can assume there is neve...
{"functional": "_inputs = [[[1, 4, 4, 4, 0, 4, 3, 3, 1]], [[1, 1, 7, 7, 3]], [[-5, -5, 7, 7, 12, 0]], [[3, 3, 3, 3, 1]], [[2, 2, -4, 4, 5, 5, 6, 6, 6, 6, 6, 1]], [[1, 1, 1, 1, 1, 3]], [[1, -1, -2, 2, 3, -3, 4, -4]], [[0, 1, 1, 2, 2]]]\n_outputs = [[[1, 12, 0, 4, 6, 1]], [[2, 14, 3]], [[-10, 14, 12, 0]], [[12, 1]], [[4,...
coding
264
Solve the programming task below in a Python markdown code block. Chef, being a Chess fan, was thrilled after he read the following news: [Michael Simkin, a postdoctoral fellow at Harvard University’s Center of Mathematical Sciences and Applications proved that for a large value of N, there are approximately (0.143 \c...
{"inputs": ["2\n4\n10"], "outputs": ["0\n36\n"]}
coding
469
Solve the programming task below in a Python markdown code block. The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then ...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["0\n0\n1 1\n0\n1 1\n2 3 5\n0\n1 1\n2 3 5\n8 13 21 34"]}
coding
217
Solve the programming task below in a Python markdown code block. Let's define a function $f(x)$ ($x$ is a positive integer) as follows: write all digits of the decimal representation of $x$ backwards, then get rid of the leading zeroes. For example, $f(321) = 123$, $f(120) = 21$, $f(1000000) = 1$, $f(111) = 111$. Let...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n6\n", "1\n5\n", "1\n8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
574
Solve the programming task below in a Python markdown code block. We need a function ```prime_bef_aft()``` that gives the largest prime below a certain given value ```n```, ```befPrime or bef_prime``` (depending on the language), and the smallest prime larger than this value, ```aftPrime/aft_prime``` (depending o...
{"functional": "_inputs = [[3], [4], [100], [97], [101], [120], [130]]\n_outputs = [[[2, 5]], [[3, 5]], [[97, 101]], [[89, 101]], [[97, 103]], [[113, 127]], [[127, 131]]]\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...
coding
275
Solve the programming task below in a Python markdown code block. Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t written a...
{"inputs": ["9 7\n", "3 1\n", "1 2\n", "1 3\n", "2 3\n", "3 2\n", "2 2\n", "2 1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
402
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef simulating the next process, imagine that we have an array A = {1, 2, ..., M}. Split it into two arrays with equal size with odd and even indexes from it. After that let'...
{"inputs": ["1\n6 1 2"], "outputs": ["4"]}
coding
609
Solve the programming task below in a Python markdown code block. # Task Given an array of 2^(k) integers (for some integer `k`), perform the following operations until the array contains only one element: ``` On the 1st, 3rd, 5th, etc. iterations (1-based) replace each pair of consecutive elements with their sum; On...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[3, 3, 5, 5]]]\n_outputs = [[186], [64], [60]]\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 i...
coding
310
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. There are N+1 lights. Lights are placed at (0, 0), (1, 0), (2, 0) ... (N, 0). Initially all the lights are on. You want to turn off all of them one after one. You want to follow a spec...
{"inputs": ["2\n1\n2", "2\n1\n4", "2\n2\n4", "2\n2\n1", "2\n0\n1", "2\n0\n2", "2\n2\n2", "2\n4\n2"], "outputs": ["2\n5", "2\n14\n", "5\n14\n", "5\n2\n", "0\n2\n", "0\n5\n", "5\n5\n", "14\n5\n"]}
coding
408
Solve the programming task below in a Python markdown code block. In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (blank, newl...
{"inputs": ["2\nThis is a sample piece of text to illustrate this \nproblem. If you are smart you will solve this right.\n"], "outputs": ["right this solve will you smart are you If problem\nthis illustrate to text of piece sample a is This"]}
coding
342
Solve the programming task below in a Python markdown code block. You have to create a method "compoundArray" which should take as input two int arrays of different length and return one int array with numbers of both arrays shuffled one by one. ```Example: Input - {1,2,3,4,5,6} and {9,8,7,6} Output - {1,9,2,8,3,7,4...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6], [9, 8, 7, 6]], [[0, 1, 2], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], [[11, 12], [21, 22, 23, 24]], [[2147483647, 2147483646, 2147483645, 2147483644, 2147483643], [9]], [[214, 215, 216, 217, 218], []], [[], [214, 215, 219, 217, 218]], [[], []]]\n_outputs = [[[1, 9, 2, 8, 3, 7, 4, 6...
coding
128
Solve the programming task below in a Python markdown code block. You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest. Example $candl...
{"inputs": ["4\n3 2 1 3\n"], "outputs": ["2\n"]}
coding
310
Solve the programming task below in a Python markdown code block. Flatland is a country with a number of cities, some of which have space stations. Cities are numbered consecutively and each has a road of $1km$ length connecting it to the next city. It is not a circular route, so the first city doesn't connect with t...
{"inputs": ["5 2\n0 4\n", "6 6\n0 1 2 4 3 5\n"], "outputs": ["2\n", "0\n"]}
coding
660
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Little Elephant from Zoo of Lviv likes to watch movies. There are N different movies (numbered from 0 to N − 1) he wants to watch in some order. Of course, he will watch each movie exactly once....
{"inputs": ["2\n3 1\n3 1 2\n4 3\n1 2 2 3"], "outputs": ["2\n24"]}
coding
449
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers. Let's call a pair of indices $i$, $j$ good if $1 \le i < j \le n$ and $\gcd(a_i, 2a_j) > 1$ (where $\gcd(x, y)$ is the greatest common divisor of $x$ and $y$). Find the maximum number of good index...
{"inputs": ["3\n4\n3 6 5 3\n2\n1 7\n5\n1 4 2 4 1\n", "1\n211\n1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
coding
391
Solve the programming task below in a Python markdown code block. Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset. k experienced teams are participating in ...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "1 2\n0 0\n", "2 1\n0\n0\n", "1 2\n0 1\n", "1 2\n0 0\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
coding
362
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"]}
coding
267
Solve the programming task below in a Python markdown code block. As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively. Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertice...
{"inputs": ["1\n1\n", "1\n8\n", "1\n1\n", "1\n8\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["1\n", "1\n", "1", "1", "1\n", "1\n", "1\n", "1\n"]}
coding
409
Solve the programming task below in a Python markdown code block. Problem H: Squid Multiplication Squid Eiko loves mathematics. Especially she loves to think about integer. One day, Eiko found a math problem from a website. "A sequence b ={ai + aj | i < j } is generated from a sequence a ={a0 , ... , an | ai is even ...
{"inputs": ["3\n6 10 14 15 27 35\n0\n1 7 7\n1", "3\n6 10 14 15 27 35\n0\n1 0 7\n1", "3\n6 10 14 15 27 35\n0\n0 0 7\n1", "3\n6 10 14 15 27 35\n0\n2 7 7\n1", "3\n6 10 14 15 27 35\n0\n30 3 8\n0", "3\n6 10 14 15 27 35\n0\n1 7 35\n1", "3\n6 10 14 15 27 35\n0\n3 4 35\n0", "3\n6 10 14 15 27 35\n0\n4 42 8\n0"], "outputs": ["2\...
coding
409
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. A version control system(VCS) is a repository of files, often the files for the source code of computer programs, with monitored access. Every change made to the source is tracked, alon...
{"inputs": ["2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n4 2 2\n1 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 5 6 7\n4 2 2\n1 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n4 2 2\n2 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n5 2 2\n2 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n4 2 2\n1 4\n1 4", "2\n7 4 6\n1 4 6 7\n1 2 3 5 6 7\n5 2 2\n2 4\n3 4", "2...
coding
747
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(...
coding
101
Solve the programming task below in a Python markdown code block. ## Task Given `n` representing the number of floors build a beautiful multi-million dollar mansions like the ones in the example below: ``` /\ / \ / \ /______\ number of floors 3 | | | | |______| /\ / \ ...
{"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[' /\\\\ \\n/__\\\\\\n|__|'], [' /\\\\ \\n / \\\\ \\n/____\\\\\\n| |\\n|____|'], [' /\\\\ \\n / \\\\ \\n / \\\\ \\n/______\\\\\\n| |\\n| |\\n|______|']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance...
coding
229
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two numbers arr1 and arr2 in base -2, return the result of adding them together. Each number is given in array format:  as an array of 0s and 1s, from most significant bit to least significant bit.  For example,...
{"functional": "def check(candidate):\n assert candidate(arr1 = [1,1,1,1,1], arr2 = [1,0,1]) == [1,0,0,0,0]\n assert candidate(arr1 = [0], arr2 = [0]) == [0]\n assert candidate(arr1 = [0], arr2 = [1]) == [1]\n\n\ncheck(Solution().addNegabinary)"}
coding
210
Solve the programming task below in a Python markdown code block. Holidays are coming up really soon. Rick realized that it's time to think about buying a traditional spruce tree. But Rick doesn't want real trees to get hurt so he decided to find some in an $n \times m$ matrix consisting of "*" and ".". To find every ...
{"inputs": ["4\n2 3\n.*.\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n5 7\n..*.*..\n.*****.\n*******\n.*****.\n..*.*..\n", "4\n2 3\n..*\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n5 7\n..*.*..\n.*****.\n*******\n.*****.\n..*.*..\n", "4\n2 3\n..*\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n1...
coding
643
Solve the programming task below in a Python markdown code block. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 2\n", "1\n1 3\n", "1\n0 1\n", "1\n2 1\n", "1\n2 2\n", "1\n2 0\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
559
Solve the programming task below in a Python markdown code block. Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains $26$ buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunction...
{"inputs": ["1\nqw\n", "1\nqw\n", "1\npw\n", "1\npx\n", "1\nqx\n", "1\nwq\n", "1\nvp\n", "1\nvo\n"], "outputs": ["qw\n", "qw\n", "pw\n", "px\n", "qx\n", "qw\n", "pv\n", "ov\n"]}
coding
506