task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. Write a comparator for a list of phonetic words for the letters of the [greek alphabet](https://en.wikipedia.org/wiki/Greek_alphabet). A comparator is: > *a custom comparison function of two arguments (iterable elements) which should return a negative, ...
{"functional": "_inputs = [['chi', 'chi']]\n_outputs = [[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\n return all...
303
159
coding
Solve the programming task below in a Python markdown code block. To participate in a prize draw each one gives his/her firstname. Each letter of a firstname has a value which is its rank in the English alphabet. `A` and `a` have rank `1`, `B` and `b` rank `2` and so on. The *length* of the firstname is added to th...
{"functional": "_inputs = [['Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin', [4, 2, 1, 4, 3, 1, 2], 4], ['Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden', [1, 3, 5, 5, 3, 6], 2], ['Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth', [3, 1, 4, 4, 3, 2], 4], ['Lagon,Lily', [1, 5], 2], ['Elijah,Michael,Avery,Sophia,Samantha...
497
734
coding
Solve the programming task below in a Python markdown code block. Ganesh lives in Gopalmath. He is looking for Jojo. So he decides to collect Aadhar Card Information of all the citizens of India from UIDAI. Someone told Ganesh that the sum of all the digits of Jojo’s Aadhar number is divisible by 10 and it is greater t...
{"inputs": ["1\n3"], "outputs": ["37"]}
332
15
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible. Return t...
{"functional": "def check(candidate):\n assert candidate(arr = [9,12,3,7,15], target = 5) == 2\n assert candidate(arr = [1000000,1000000,1000000], target = 1) == 999999\n assert candidate(arr = [1,2,4,8,16], target = 0) == 0\n\n\ncheck(Solution().closestToTarget)"}
141
117
coding
Solve the programming task below in a Python markdown code block. Our hardworking chef is bored of sleeping in his restaurants. He has decided to settle down. The first thing he must do is to find a suitable location to build a palatial home. Think of the city as a two-dimensional grid. There are N restaurants in t...
{"inputs": ["3\n5\n0 0\n0 0\n1 0\n0 1\n0 -1\n5\n31 3\n30 -6\n20 15\n25 18\n25 38\n1\n0 0\n1 1", "3\n5\n0 0\n0 0\n1 0\n0 1\n0 -1\n5\n31 5\n30 -6\n20 15\n25 18\n25 38\n1\n0 0\n1 1", "3\n5\n0 0\n-1 0\n1 0\n0 1\n0 -1\n5\n4 7\n30 -41\n20 8\n26 18\n25 38\n2\n0 0\n1 1", "3\n5\n0 0\n0 0\n1 0\n0 1\n0 -1\n5\n31 5\n30 -6\n26 15\n...
423
592
coding
Solve the programming task below in a Python markdown code block. A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today yo...
{"inputs": ["1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n6\n", "3\n2 1 1\n", "3\n4 1 1\n"], "outputs": ["1\n1 ", "-1", "-1\n", "-1\n", "-1\n", "-1\n", "2\n1 1 2 ", "-1\n"]}
527
99
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Russian] and [Bengali]. Chef opened a company which manufactures cars and bikes. Each car requires 4 tyres while each bike requires 2 tyres. Chef has a total of N tyres (N is even). He wants to manufacture maximum number of ...
{"inputs": ["3\n8\n2\n6\n"], "outputs": ["NO\nYES\nYES"]}
387
23
coding
Solve the programming task below in a Python markdown code block. Chef has two integers A and B. Chef wants to find the minimum value of \texttt{lcm}(A, X) - \texttt{gcd}(B, X) where X is any positive integer. Help him determine this value. Note: \texttt{gcd}(P, Q) denotes the [greatest common divisor] of P and Q a...
{"inputs": ["3\n12 15\n5 50\n9 11\n"], "outputs": ["9\n0\n8\n"]}
439
34
coding
Solve the programming task below in a Python markdown code block. A string with length $L$ is called rich if $L \ge 3$ and there is a character which occurs in this string strictly more than $L/2$ times. You are given a string $S$ and you should answer $Q$ queries on this string. In each query, you are given a substrin...
{"inputs": ["1\n10 2\nhelloworld\n1 3\n1 10"], "outputs": ["NO\nYES"]}
338
31
coding
Solve the programming task below in a Python markdown code block. Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She...
{"inputs": ["XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XO........\n.XO.......\n..XO......\n....O.....\n....X.....\...
320
403
coding
Solve the programming task below in a Python markdown code block. You are given a regular N-gon with vertices at (cos(2πi / N), sin(2πi / N)), ∀ i ∈ [0,N-1]. Some of these vertices are blocked and all others are unblocked. We consider triangles with vertices at the vertices of N-gon and with at least one vertex at unbl...
{"inputs": ["1\n4\n1111\n"], "outputs": ["6\n"]}
334
21
coding
Solve the programming task below in a Python markdown code block. Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identi...
{"inputs": ["Z\n", "A\n", "B\n", "C\n", "D\n", "E\n", "F\n", "G\n"], "outputs": ["NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
323
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.   Please com...
{"functional": "def check(candidate):\n assert candidate(nums = [4,7,9,10], k = 1) == 5\n assert candidate(nums = [4,7,9,10], k = 3) == 8\n assert candidate(nums = [1,2,4], k = 3) == 6\n\n\ncheck(Solution().missingElement)"}
93
88
coding
Solve the programming task below in a Python markdown code block. You are given two positive integers N and K. You have to perform the following operation exactly K times: - For the current value of N, choose any positive integer D such that D is a [divisor] of N and multiply D with N. Formally, N := (N * D) such tha...
{"inputs": ["3\n1 5\n2 2\n10 1"], "outputs": ["1\n30\n180"]}
701
32
coding
Solve the programming task below in a Python markdown code block. _A mad sociopath scientist just came out with a brilliant invention! He extracted his own memories to forget all the people he hates! Now there's a lot of information in there, so he needs your talent as a developer to automatize that task for him._ > Y...
{"functional": "_inputs = [['Bryan Joubert'], ['Jesse Cox, !Selena Gomez'], ['!Eleena Daru, Obi-Wan Kenobi, Eleena Daru, Jar-Jar Binks'], ['Digital Daggers, !Kiny Nimaj, Rack Istley, Digital Daggers, Digital Daggers'], ['Albert Einstein, !Sarah Connor, Marilyn Monroe, Abraham Lincoln, Sarah Connor, Sean Connery, Marily...
299
404
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes labelled from 0 to n - 1, and an ...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[1,0],[1,2],[1,3]]) == [1]\n assert candidate(n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]) == [3,4]\n\n\ncheck(Solution().findMinHeightTrees)"}
255
87
coding
Solve the programming task below in a Python markdown code block. ## Check Digits Some numbers are more important to get right during data entry than others: a common example is product codes. To reduce the possibility of mistakes, product codes can be crafted in such a way that simple errors are detected. This is do...
{"functional": "_inputs = [['036532'], ['12388878'], ['111111111'], ['9735597355'], ['2356'], ['6789']]\n_outputs = [['0365327'], ['123888782'], ['1111111118'], ['97355973550'], ['23566'], ['6789X']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i...
573
261
coding
Solve the programming task below in a Python markdown code block. Chef Watson uses a social network called ChefBook, which has a new feed consisting of posts by his friends. Each post can be characterized by f - the identifier of the friend who created the post, p - the popularity of the post(which is pre-calculated by...
{"inputs": ["2 4\n1 2\n1 1 WhoDoesntLoveChefBook\n2 2 WinterIsComing\n3 10 TheseViolentDelightsHaveViolentEnds\n4 3 ComeAtTheKingBestNotMiss"], "outputs": ["WinterIsComing\nWhoDoesntLoveChefBook\nTheseViolentDelightsHaveViolentEnds\nComeAtTheKingBestNotMiss"]}
525
89
coding
Solve the programming task below in a Python markdown code block. Write a function that reverses the bits in an integer. For example, the number `417` is `110100001` in binary. Reversing the binary is `100001011` which is `267`. You can assume that the number is not negative. Also feel free to reuse/extend the follow...
{"functional": "_inputs = [[417], [267], [0], [2017], [1023], [1024]]\n_outputs = [[267], [417], [0], [1087], [1023], [1]]\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)):\...
105
207
coding
Solve the programming task below in a Python markdown code block. Every Turkish citizen has an identity number whose validity can be checked by these set of rules: - It is an 11 digit number - First digit can't be zero - Take the sum of 1st, 3rd, 5th, 7th and 9th digit and multiply it by 7. Then subtract the sum of 2n...
{"functional": "_inputs = [[6923522112], [692352217312], ['x5810a78432'], [36637640050], [12762438338], ['03868894286'], [10000000146], [19415235426], [16691067984], [72097107542], [57040492705]]\n_outputs = [[False], [False], [False], [True], [False], [False], [True], [True], [False], [True], [False]]\nimport math\nde...
479
326
coding
Solve the programming task below in a Python markdown code block. Takahashi is a member of a programming competition site, ButCoder. Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating. The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or ...
{"inputs": ["0 6", "2 1", "3 1", "3 0", "1 0", "1 2", "2 2", "2 4"], "outputs": ["1006\n", "801\n", "701\n", "700\n", "900\n", "902\n", "802\n", "804\n"]}
286
95
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j]. Return the maximum difference. If no s...
{"functional": "def check(candidate):\n assert candidate(nums = [7,1,5,4]) == 4\n assert candidate(nums = [9,4,3,2]) == -1\n assert candidate(nums = [1,5,2,10]) == 9\n\n\ncheck(Solution().maximumDifference)"}
119
74
coding
Solve the programming task below in a Python markdown code block. Alice has a grid with $2$ rows and $n$ columns. She fully covers the grid using $n$ dominoes of size $1 \times 2$ — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino. Now, she decided to show one row ...
{"inputs": ["4\n1\nU\n2\nLR\n5\nLRDLR\n6\nUUUUUU\n"], "outputs": ["D\nLR\nLRULR\nDDDDDD\n"]}
432
44
coding
Solve the programming task below in a Python markdown code block. A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible. INPUT First line is T, ...
{"inputs": ["6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii"], "outputs": ["38\n51\n9\n1\n77\n95"]}
184
120
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the environment does not allow y...
{"functional": "def check(candidate):\n assert candidate(x = 123) == 321\n assert candidate(x = -123) == -321\n assert candidate(x = 120) == 21\n assert candidate(x = 0) == 0\n\n\ncheck(Solution().reverse)"}
118
77
coding
Solve the programming task below in a Python markdown code block. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Fol...
{"inputs": ["1\n0 -1 -1\n", "1\n0 -1 -1\n", "1\n1 -1 -1\n", "1\n4277071 -1 -1\n", "1\n73706168 -1 -1\n", "1\n493041212 -1 -1\n", "1\n815121916 -1 -1\n", "1\n901418150 -1 -1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
640
155
coding
Solve the programming task below in a Python markdown code block. There is an integer $n$ without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns. On her turn, Alice must swap any two digits of the integer that are on different po...
{"inputs": ["3\n12\n132\n487456398\n"], "outputs": ["2\n1\n3\n"]}
365
35
coding
Solve the programming task below in a Python markdown code block. Introduction to Disjunctions In logic and mathematics, a disjunction is an operation on 2 or more propositions. A disjunction is true if and only if 1 or more of its operands is true. In programming, we typically denote a disjunction using "||", but in...
{"functional": "_inputs = [[[False, True, True], False], [[False, True, False], False], [[False, True, True, True], True], [[True, True, True], False], [[True, True, True, True], False]]\n_outputs = [[True], [True], [True], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin...
403
212
coding
Solve the programming task below in a Python markdown code block. Given time in 24-hour format, convert it to words. ``` For example: 13:00 = one o'clock 13:09 = nine minutes past one 13:15 = quarter past one 13:29 = twenty nine minutes past one 13:30 = half past one 13:31 = twenty nine minutes to two 13:45 = qua...
{"functional": "_inputs = [['13:00'], ['13:09'], ['13:15'], ['13:29'], ['13:30'], ['13:31'], ['13:45'], ['13:59'], ['00:48'], ['00:08'], ['12:00'], ['00:00'], ['19:01'], ['07:01'], ['01:59'], ['12:01'], ['00:01'], ['11:31'], ['23:31'], ['11:45'], ['11:59'], ['23:45'], ['23:59'], ['01:45']]\n_outputs = [[\"one o'clock\"...
216
460
coding
Solve the programming task below in a Python markdown code block. Note: This kata is inspired by [Convert a Number to a String!](http://www.codewars.com/kata/convert-a-number-to-a-string/). Try that one too. ## Description We need a function that can transform a string into a number. What ways of achieving this do yo...
{"functional": "_inputs = [['4']]\n_outputs = [[4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq...
191
155
coding
Solve the programming task below in a Python markdown code block. Bob has a server farm crunching numbers. He has `nodes` servers in his farm. His company has a lot of work to do. The work comes as a number `workload` which indicates how many jobs there are. Bob wants his servers to get an equal number of jobs each. ...
{"functional": "_inputs = [[2, 4], [3, 3], [3, 9], [2, 5], [4, 10], [4, 5], [1, 1], [2, 1], [5, 4], [5, 1]]\n_outputs = [[[[0, 1], [2, 3]]], [[[0], [1], [2]]], [[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [[[0, 1, 2], [3, 4]]], [[[0, 1, 2], [3, 4, 5], [6, 7], [8, 9]]], [[[0, 1], [2], [3], [4]]], [[[0]]], [[[0], []]], [[[0], [1...
406
355
coding
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"]}
217
61
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are meeting after a long time. As usual they love to play some math games. This times Alice takes the call and decides the game. The game is very simple, Alice says out an integer and Bob has to say whether the number is prime or not. Bob a...
{"inputs": ["5\n14\n3\n28\n1000\n849", "5\n32\n19\n20\n1100\n793", "5\n32\n28\n20\n1100\n793", "5\n32\n31\n20\n1100\n793", "5\n10\n31\n20\n1100\n793", "5\n10\n31\n20\n1101\n793", "5\n14\n22\n28\n1010\n849", "5\n10\n31\n39\n1100\n793"], "outputs": ["no\nyes\nno\nno\nno\n", "no\nyes\nno\nno\nno\n", "no\nno\nno\nno\nno\n"...
260
269
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers. Initially all elements of $a$ are either $0$ or $1$. You need to process $q$ queries of two kinds: 1 x : Assign to $a_x$ the value $1 - a_x$. 2 k : Print the $k$-th largest value of the array. As ...
{"inputs": ["1 1\n0\n2 1\n", "1 1\n0\n2 1\n", "5 5\n1 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n", "5 5\n0 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n", "5 5\n1 1 1 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n", "5 5\n1 1 1 1 0\n2 3\n1 2\n2 3\n2 1\n2 2\n", "5 5\n0 1 0 0 0\n2 3\n1 2\n2 3\n2 1\n2 3\n", "5 5\n1 1 1 1 0\n2 5\n1 2\n2 3\n2 1\n2 5\n"], "ou...
633
314
coding
Solve the programming task below in a Python markdown code block. The pizza store wants to know how long each order will take. They know: - Prepping a pizza takes 3 mins - Cook a pizza takes 10 mins - Every salad takes 3 mins to make - Every appetizer takes 5 mins to make - There are 2 pizza ovens - 5 pizzas can fit i...
{"functional": "_inputs = [[2, 0, 0], [3, 1, 2], [0, 3, 2], [13, 0, 0], [6, 2, 4], [6, 1, 3], [5, 3, 4]]\n_outputs = [[13], [14.5], [19], [39.5], [26], [19], [29]]\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=to...
187
243
coding
Solve the programming task below in a Python markdown code block. Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n. Tanya plans her journey as follows. First of all, she will choose some city c_1...
{"inputs": ["2\n2 2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n", "2\n3 1\n", "2\n1 0\n", "2\n2 0\n", "2\n1 -1\n"], "outputs": ["2\n", "3\n", "2\n", "1\n", "3\n", "1\n", "2\n", "1\n"]}
655
102
coding
Solve the programming task below in a Python markdown code block. This kata is based on a [variation](https://www.codewars.com/kata/happy-numbers-5) of *Happy Numbers* by TySlothrop. It is advisable to complete it first to grasp the idea and then move on to this one. ___ Hello, my dear friend, and welcome to another ...
{"functional": "_inputs = [[10], [50], [100]]\n_outputs = [[[1, 7, 10]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math...
443
294
coding
Solve the programming task below in a Python markdown code block. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number...
{"inputs": ["4\n180.3\n168.2\n165.5\n175.3", "4\n180.3\n168.42932428490565\n165.5\n175.3", "4\n180.68754203533285\n168.42932428490565\n165.5\n175.3", "4\n180.95536695412983\n168.42932428490565\n165.5\n175.3", "4\n180.95536695412983\n168.42932428490565\n165.65038418972082\n175.3", "4\n186.487152384495\n176.2575594727457...
564
657
coding
Solve the programming task below in a Python markdown code block. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp n...
{"inputs": ["1\na\nb\n", "1\nz\ny\n", "2\nab\nac\n", "2\nba\nca\n", "2\nac\ncb\n", "2\nab\nba\n", "2\ner\nre\n", "3\ntoy\ntry\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n"]}
398
104
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n. The sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])2 for each 0 <= i < n. You a...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0) == 579\n assert candidate(nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1) == 43\n\n\ncheck(Solution().minSumSquareDiff)"}
229
115
coding
Solve the programming task below in a Python markdown code block. There are N computers and N sockets in a one-dimensional world. The coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It is guaranteed that these 2N coordinates are pairwise distinct. Snuke wants to connect each compu...
{"inputs": ["2\n-1\n1\n7\n78", "2\n1\n11\n4\n68", "2\n0\n2\n3\n312", "2\n0\n2\n20\n48", "2\n2\n11\n4\n68", "2\n1\n2\n3\n312", "2\n0\n2\n20\n56", "2\n0\n2\n21\n78"], "outputs": ["2\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n"]}
255
142
coding
Solve the programming task below in a Python markdown code block. Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. Ki...
{"inputs": ["a\nb\n", "a\nb\n", "a\nc\n", "ddddd\nd\n", "ww?ww\nw\n", "?????\nn\n", "ww?ww\nw\n", "?????\nn\n"], "outputs": ["0\n", "0", "0\n", "5\n", "5\n", "5\n", "5", "5"]}
426
88
coding
Solve the programming task below in a Python markdown code block. Do the following for a four-digit number N consisting of numbers 0-9. 1. Let L be the number obtained as a result of arranging the numerical values ​​of each of the N digits in descending order. 2. Let S be the number obtained as a result of arranging t...
{"inputs": ["6174\n3729\n90\n0000", "6174\n990\n3333\n0000", "6174\n503\n4924\n0000", "6174\n3985\n3333\n0000", "6174\n1779\n3333\n0000", "6174\n1779\n2211\n0000", "6174\n2012\n3078\n0000", "6174\n3985\n5889\n0000"], "outputs": ["0\n3\n4\n", "0\n4\nNA\n", "0\n5\n4\n", "0\n3\nNA\n", "0\n6\nNA\n", "0\n6\n4\n", "0\n3\n2\n...
480
234
coding
Solve the programming task below in a Python markdown code block. In my town ,there live a coder named Chef . He is a cool programmer . One day , he participate in a programming contest ,the contest give him only one problem . If he can’t solve the problem ,the problem setter will kill him . But the round allow you to ...
{"inputs": ["2\n3 5 6 5\n2\n4 5\n6 8\n3 4 7 10\n1\n7 4"], "outputs": ["Test case : 1\nYES\nNO\n3.000000\nTest case : 2\nNO\n3.328201"]}
444
88
coding
Solve the programming task below in a Python markdown code block. Write function alternateCase which switch every letter in string from upper to lower and from lower to upper. E.g: Hello World -> hELLO wORLD Also feel free to reuse/extend the following starter code: ```python def alternateCase(s): ```
{"functional": "_inputs = [['ABC'], [''], [' '], ['Hello World'], ['cODEwARS'], ['i LIKE MAKING KATAS VERY MUCH'], ['HuMpTy DuMpTy SaT On A WaLl'], ['aBracaDabRa'], ['Hickory DICKORY dock'], ['Jack JUMPED over THE CaNdLeStIcK']]\n_outputs = [['abc'], [''], [' '], ['hELLO wORLD'], ['CodeWars'], ['I like making katas ver...
66
305
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums of length n. A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime. ...
{"functional": "def check(candidate):\n assert candidate(nums = [4,7,8,15,3,5]) == 2\n assert candidate(nums = [4,7,15,8,3,5]) == -1\n\n\ncheck(Solution().findValidSplit)"}
255
66
coding
Solve the programming task below in a Python markdown code block. Mike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height a_{i} off the ground. Besides, let the sequence a_{i} increase, that is, a_{i} < a_{i} + 1 for all i from 1 to n - 1; we will call such sequence a...
{"inputs": ["3\n1 4 6\n", "3\n2 4 6\n", "3\n1 4 6\n", "3\n2 7 1000\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n", "3\n30 61 381\n", "3\n30 55 539\n"], "outputs": ["5\n", "4\n", "5\n", "998\n", "2\n", "4\n", "351\n", "509\n"]}
621
143
coding
Solve the programming task below in a Python markdown code block. Write a function `getDrinkByProfession`/`get_drink_by_profession()` that receives as input parameter a string, and produces outputs according to the following table: Input Output "Jabroni" "Patron Tequila" "School Counselor" "Anything with Alcoho...
{"functional": "_inputs = [['jabrOni'], ['scHOOl counselor'], ['prOgramMer'], ['bike ganG member'], ['poLiTiCian'], ['rapper'], ['pundit'], ['Pug'], ['jabrOnI'], ['scHOOl COUnselor'], ['prOgramMeR'], ['bike GanG member'], ['poLiTiCiAN'], ['RAPPer'], ['punDIT'], ['pUg']]\n_outputs = [['Patron Tequila'], ['Anything with ...
236
320
coding
Solve the programming task below in a Python markdown code block. Zonal Computing Olympiad 2012, 26 Nov 2011 We consider sequences of opening and closing brackets with two types of brackets, () and []. A bracket sequence is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the u...
{"inputs": ["14\n1 1 3 4 2 2 3 3 3 1 2 4 4 4"], "outputs": ["2 6 8"]}
649
45
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 a positive integer x. You are initially at position 0 in the array and you can visit other positions according to the following rules: If you are currently in position...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,6,1,9,2], x = 5) == 13\n assert candidate(nums = [2,4,6,8], x = 3) == 20\n\n\ncheck(Solution().maxScore)"}
182
71
coding
Solve the programming task below in a Python markdown code block. Laurel and Hardy have $n$ piles of chocolates with each pile containing some number of chocolates. The piles are arranged from left to right in a non decreasing order based on the number of chocolates in each pile. They play the following game. For eve...
{"inputs": ["5\n1 1 2 2 3\n"], "outputs": ["5\n"]}
446
24
coding
Solve the programming task below in a Python markdown code block. Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so ...
{"inputs": ["1 0\n5\n", "1 0\n8\n", "1 0\n3\n", "3 1\n108\n", "3 2\n108\n", "5 2\n39923\n", "5 2\n20409\n", "5 2\n59455\n"], "outputs": ["5\n", "8\n", "3\n", "27\n", "9\n", "2667\n", "792\n", "2409\n"]}
445
127
coding
Solve the programming task below in a Python markdown code block. In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures. City i is established in year Y_i and belongs to Prefecture P_i. You can assume that there are no multiple cities that are established in the same ...
{"inputs": ["1 1\n1 852958660\n", "2 3\n1 32\n2 63\n1 6", "4 3\n2 5\n2 49\n2 12", "4 3\n2 5\n4 49\n1 12", "2 3\n2 4\n1 7\n2 528", "5 2\n1 63\n4 63\n0 9", "2 3\n1 32\n2 63\n1 4", "2 3\n2 39\n2 0\n1 12"], "outputs": ["000001000001\n", "000001000002\n000002000001\n000001000001\n", "000002000001\n000002000003\n000002000002...
504
446
coding
Solve the programming task below in a Python markdown code block. Kepler’s Law states that the planets move around the sun in elliptical orbits with the sun at one focus. Kepler's 3rd law is The Law of Periods, according to which: The square of the time period of the planet is directly proportional to the cube of the ...
{"inputs": ["3\n1 1 1 1\n1 2 3 4\n1 8 2 8"], "outputs": ["Yes\nNo\nYes"]}
504
40
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings words and an integer k, return the k most frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical o...
{"functional": "def check(candidate):\n assert candidate(words = [\"i\",\"love\",\"leetcode\",\"i\",\"love\",\"coding\"], k = 2) == [\"i\",\"love\"]\n assert candidate(words = [\"the\",\"day\",\"is\",\"sunny\",\"the\",\"the\",\"the\",\"sunny\",\"is\",\"is\"], k = 4) == [\"the\",\"is\",\"sunny\",\"day\"]\n\n\nchec...
98
103
coding
Solve the programming task below in a Python markdown code block. # Task: We define the "self reversed power sequence" as one shown below: Implement a function that takes 2 arguments (`ord max` and `num dig`), and finds the smallest term of the sequence whose index is less than or equal to `ord max`, and has exactl...
{"functional": "_inputs = [[5, 10], [7, 11], [7, 14], [8, 16], [10, 20]]\n_outputs = [[[True, 10]], [[False, -1]], [[True, 13]], [[True, 15]], [[True, 17]]]\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 ...
406
219
coding
Solve the programming task below in a Python markdown code block. Chef is playing a game with two of his friends. In this game, each player chooses an integer between $1$ and $P$ inclusive. Let's denote the integers chosen by Chef, friend 1 and friend 2 by $i$, $j$ and $k$ respectively; then, Chef's score is (((Nmodi)...
{"inputs": ["2\n4 4\n3 4"], "outputs": ["9\n13"]}
515
23
coding
Solve the programming task below in a Python markdown code block. William has an array of $n$ integers $a_1, a_2, \dots, a_n$. In one move he can swap two neighboring items. Two items $a_i$ and $a_j$ are considered neighboring if the condition $|i - j| = 1$ is satisfied. William wants you to calculate the minimal numb...
{"inputs": ["1\n3\n1 1 1\n", "1\n3\n1 1 1\n", "1\n3\n1 1 0\n", "1\n3\n0 3 0\n", "1\n3\n1 2 0\n", "1\n3\n1 3 0\n", "1\n3\n0 3 1\n", "1\n3\n0 2 1\n"], "outputs": ["-1\n", "-1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
631
135
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros. For example, "0.1.2.201" and "192.168.1.1" are valid IP addr...
{"functional": "def check(candidate):\n assert candidate(s = \"25525511135\") == [\"255.255.11.135\",\"255.255.111.35\"]\n assert candidate(s = \"0000\") == [\"0.0.0.0\"]\n assert candidate(s = \"101023\") == [\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]\n\n\ncheck(Solution().restoreI...
214
165
coding
Solve the programming task below in a Python markdown code block. John is developing a system to report fuel usage but needs help with the coding. First, he needs you to write a function that, given the actual consumption (in l/100 km) and remaining amount of petrol (in l), will give you how many kilometers you'll be ...
{"functional": "_inputs = [[10, 60], [8, 0], [6.4, 54], [9.3, 87.3], [11.7, 63.4]]\n_outputs = [[600], [0], [843.75], [938.71], [541.88]]\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, (...
269
228
coding
Solve the programming task below in a Python markdown code block. Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with n vertices and a root in the vertex 1. There is an ant in each leaf of the tree. In one second some ants can simu...
{"inputs": ["2\n2 1\n", "10\n1 3\n4 3\n10 4\n5 6\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n10 4\n5 5\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n10 4\n7 5\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n10 6\n7 5\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n9 4\n10 6\n6 2\n5 2\n7 6\n8 8\n7 9\n", "10\n1 3\n4 2\n10 4\n8 6\n...
301
339
coding
Solve the programming task below in a Python markdown code block. You are standing at point $(0,0)$ on an infinite plane. In one step, you can move from some point $(x_f,y_f)$ to any point $(x_t,y_t)$ as long as the Euclidean distance, $\sqrt{(x_f-x_t)^2+(y_f-y_t)^2}$, between the two points is either $\boldsymbol{a}$ ...
{"inputs": ["3\n2 3 1\n1 2 0\n3 4 11\n"], "outputs": ["2\n0\n3\n"]}
602
37
coding
Solve the programming task below in a Python markdown code block. Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array of `numbers` and the second is the `divisor`. ## Example ```python divisible_by([1, 2, 3, 4, 5, 6], 2) == [2, 4...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6], 2], [[1, 2, 3, 4, 5, 6], 3], [[0, 1, 2, 3, 4, 5, 6], 4], [[0], 4], [[1, 3, 5], 2], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1]]\n_outputs = [[[2, 4, 6]], [[3, 6]], [[0, 4]], [[0]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if...
115
330
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k. An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from th...
{"functional": "def check(candidate):\n assert candidate(nums = [3,5,2,6], k = 2) == [2,6]\n assert candidate(nums = [2,4,3,3,5,4,9,6], k = 4) == [2,3,3,4]\n\n\ncheck(Solution().mostCompetitive)"}
188
84
coding
Solve the programming task below in a Python markdown code block. There is a game that uses numbers called "Fizz Buzz". In this game, multiple players count the numbers one by one, starting with 1, and each player says only one number after the previous player. At that time, you must say "Fizz" if it is divisible by 3,...
{"inputs": ["5 7\n1\n0\nFizz\n4\nBuzz\n6\n7\n3 5\n1\n2\n3\n4\n5\n0 0", "5 7\n1\n0\nFizz\n4\nBuzz\n6\n2\n3 5\n1\n2\n3\n4\n5\n0 0", "5 7\n1\n0\nFizz\n2\nBuzz\n6\n2\n3 5\n1\n2\n4\n4\n8\n0 0", "5 7\n1\n0\nFizz\n2\nzuzB\n6\n2\n3 5\n1\n2\n4\n4\n8\n0 0", "5 7\n1\n2\nFizz\n4\nBuzz\n6\n7\n3 5\n1\n1\n3\n4\n5\n0 0", "5 7\n1\n0\nF...
629
372
coding
Solve the programming task below in a Python markdown code block. During their New Year holidays, Alice and Bob play the following game using an array $a$ of $n$ integers: Players take turns, Alice moves first. Each turn a player chooses any element and removes it from the array. If Alice chooses even value, then sh...
{"inputs": ["2\n3\n1 1 234872\n4\n5 2 7 3\n", "2\n3\n1 1 234872\n4\n5 2 7 3\n", "2\n3\n1 1 234872\n4\n5 2 7 2\n", "2\n3\n1 1 199277\n4\n2 0 7 3\n", "2\n3\n1 1 234872\n4\n1 0 7 2\n", "2\n3\n1 1 199277\n4\n2 0 7 1\n", "2\n3\n1 2 234872\n4\n5 2 7 2\n", "2\n3\n2 1 234872\n4\n5 2 7 3\n"], "outputs": ["Alice\nBob\n", "Alice\...
650
272
coding
Solve the programming task below in a Python markdown code block. Cities on a map are connected by a number of roads. The number of roads between each city is in an array and city ${0}$ is the starting location. The number of roads from city ${0}$ to city ${1}$ is the first value in the array, from city ${1}$ to city...
{"inputs": ["2\n3\n1 3\n4\n2 2 2\n"], "outputs": ["3\n8\n"]}
499
30
coding
Solve the programming task below in a Python markdown code block. There is a strange counter. At the first second, it displays the number $3$. Each second, the number displayed by decrements by $\mbox{1}$ until it reaches $\mbox{1}$. In next second, the timer resets to $2\times\textbf{the initial number for the prior c...
{"inputs": ["4\n"], "outputs": ["6\n"]}
311
14
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer.   Please complet...
{"functional": "def check(candidate):\n assert candidate(nums = [10,2]) == \"210\"\n assert candidate(nums = [3,30,34,5,9]) == \"9534330\"\n\n\ncheck(Solution().largestNumber)"}
90
67
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Andrash study in Uzhland National University. Now is the time of exam results. Andrash similar to other students, hopes that this scores in the exam could fetch him a scholar...
{"inputs": ["2\n5\n3 5 4 4 3\n5\n3 4 4 4 5"], "outputs": ["No\nYes"]}
552
38
coding
Solve the programming task below in a Python markdown code block. The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of...
{"inputs": ["2\n", "7\n", "7\n", "3\n", "5\n", "8\n", "6\n", "9\n"], "outputs": ["25", "25", "25\n", "25\n", "25\n", "25\n", "25\n", "25\n"]}
193
76
coding
Solve the programming task below in a Python markdown code block. For this kata, you are given three points ```(x1,y1,z1)```, ```(x2,y2,z2)```, and ```(x3,y3,z3)``` that lie on a straight line in 3-dimensional space. You have to figure out which point lies in between the other two. Your function should return 1, 2, or...
{"functional": "_inputs = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 0, 6, -2, 8, 3, 0, 4], [0.25, 0.5, 0.75, 3.25, -0.5, -0.25, 1.0, 0.25, 0.5], [1, 0, 4, 5, 0, 6, -7, 0, 0], [-1, 0, 2, -2, 4, -1, -3, 8, -4]]\n_outputs = [[2], [3], [3], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or is...
150
322
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A value-equal string is a string where all characters are the same. For example, "1111" and "33" are value-equal strings. In contrast, "123" is not a value-equal string. Given a digit string s, decompose the string ...
{"functional": "def check(candidate):\n assert candidate(s = \"000111000\") == False\n assert candidate(s = \"00011111222\") == True\n assert candidate(s = \"01110002223300\") == False\n\n\ncheck(Solution().isDecomposable)"}
173
85
coding
Solve the programming task below in a Python markdown code block. You have $a$ coins of value $n$ and $b$ coins of value $1$. You always pay in exact change, so you want to know if there exist such $x$ and $y$ that if you take $x$ ($0 \le x \le a$) coins of value $n$ and $y$ ($0 \le y \le b$) coins of value $1$, then t...
{"inputs": ["1\n2 2 3 55\n", "1\n2 2 3 43\n", "1\n2 2 3 33\n", "1\n2 2 4 33\n", "1\n2 4 4 33\n", "1\n2 4 5 33\n", "1\n2 8 5 33\n", "1\n1 8 5 33\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
398
142
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a sorted unique integer array nums. A range [a,b] is the set of all integers from a to b (inclusive). Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, e...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,2,4,5,7]) == [\"0->2\",\"4->5\",\"7\"]\n assert candidate(nums = [0,2,3,4,6,8,9]) == [\"0\",\"2->4\",\"6\",\"8->9\"]\n\n\ncheck(Solution().summaryRanges)"}
161
89
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers where heights[i] represents the height of the ith person. A person ...
{"functional": "def check(candidate):\n assert candidate(heights = [10,6,8,5,11,9]) == [3,1,2,1,1,0]\n assert candidate(heights = [5,1,2,3,10]) == [4,1,1,1,0]\n\n\ncheck(Solution().canSeePersonsCount)"}
193
88
coding
Solve the programming task below in a Python markdown code block. Scheduling is how the processor decides which jobs(processes) get to use the processor and for how long. This can cause a lot of problems. Like a really long process taking the entire CPU and freezing all the other processes. One solution is Shortest Job...
{"functional": "_inputs = [[[100], 0], [[3, 10, 20, 1, 2], 0], [[3, 10, 20, 1, 2], 1], [[3, 10, 10, 20, 1, 2], 1], [[3, 10, 10, 20, 1, 2], 2], [[3, 10, 20, 1, 2, 3], 5], [[3, 10, 20, 1, 2, 10, 10], 5]]\n_outputs = [[100], [6], [16], [16], [26], [9], [26]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a...
437
323
coding
Solve the programming task below in a Python markdown code block. As part of this Kata, you need to find the length of the sequence in an array, between the first and the second occurrence of a specified number. For example, for a given array `arr` [0, -3, 7, 4, 0, 3, 7, 9] Finding length between two `7`s li...
{"functional": "_inputs = [[[1], 0], [[1], 1], [[-7, 3, -7, -7, 2, 1], -7], [[-7, 3, -7, -7, 2, -7], -7]]\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, ...
196
217
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence A=(A_{1}, A_{2},\dots, A_{N}) of length N and an integer M such that 0 ≤ M < \sum\limits_{i=1}^N A_{i}. An integer sequence B=(B_{1}, B_{2},\dots, B_{N}) of length N is called *good* if: 0 ≤ B_{i} ≤ A_{i} for each 1≤ i...
{"inputs": ["4\n4 4\n1 3 5 7\n4 4\n5 5 5 5\n4 0\n4 6 9 12\n6 10\n15 9 3 8 14 17"], "outputs": ["3\n4\n1\n7\n"]}
655
76
coding
Solve the programming task below in a Python markdown code block. There are 3^N people dancing in circle. We denote with 0,1,\dots, 3^{N}-1 the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person. The people are going ...
{"inputs": ["1\nRRS", "1\nSRR", "1\nSSR", "1\nRSR", "1\nRRR", "1\nRSS", "1\nSRS", "2\nSRRRSSSSR"], "outputs": ["1 0 2 ", "2 1 0 ", "1 2 0 ", "0 2 1 ", "0 1 2 ", "1 2 0 ", "2 0 1", "4 6 5 1 3 2 7 0 8 "]}
519
125
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed integer array tickets of length n wh...
{"functional": "def check(candidate):\n assert candidate(tickets = [2,3,2], k = 2) == 6\n assert candidate(tickets = [5,1,1,1], k = 0) == 8\n\n\ncheck(Solution().timeRequiredToBuy)"}
216
67
coding
Solve the programming task below in a Python markdown code block. Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i. Constraints * 1 ≤ length of T ≤ 1000000 * 1 ≤ length of P_i ≤ 1000 * 1 ≤ Q ≤ 10000 * The input consists of alphabetical characters and digi...
{"inputs": ["aabaaa\n4\nab\nba\nbb\nxyz", "aabaaa\n4\nab\nba\nba\nxyz", "aabaaa\n4\nba\nbb\nac\nzyx", "aabaaa\n4\nca\nab\nba\nzyx", "aacaaa\n4\nba\nb`\nac\nzyx", "aacaaa\n4\nca\nb`\nac\nzyx", "aabaaa\n4\na`\nab\nca\nyzx", "aadaaa\n4\nca\nb`\nca\nzyx"], "outputs": ["1\n1\n0\n0\n", "1\n1\n1\n0\n", "1\n0\n0\n0\n", "0\n1\n...
185
209
coding
Solve the programming task below in a Python markdown code block. Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to...
{"inputs": ["3 0010\n3\n101\n5", "3 1\n575\n3\n9\n15", "3 1\n668\n3\n9\n15", "3 2\n668\n3\n9\n15", "3 2\n668\n6\n9\n15", "3 2\n668\n1\n9\n15", "3 1010\n17\n101\n6", "3 0010\n17\n101\n6"], "outputs": ["-30\n", "-193\n", "-224\n", "-223\n", "-111\n", "-673\n", "150\n", "-16\n"]}
456
183
coding
Solve the programming task below in a Python markdown code block. You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can only take one ticket at a time, then they go back in the last position of t...
{"functional": "_inputs = [[[2, 5, 3, 6, 4], 0], [[2, 5, 3, 6, 4], 1], [[2, 5, 3, 6, 4], 2], [[2, 5, 3, 6, 4], 3], [[2, 5, 3, 6, 4], 4]]\n_outputs = [[6], [18], [12], [20], [17]]\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=...
393
256
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity. Your job at...
{"functional": "def check(candidate):\n assert candidate(lowLimit = 1, highLimit = 10) == 2\n assert candidate(lowLimit = 5, highLimit = 15) == 2\n assert candidate(lowLimit = 19, highLimit = 28) == 2\n\n\ncheck(Solution().countBalls)"}
204
81
coding
Solve the programming task below in a Python markdown code block. Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered t...
{"inputs": ["1\n0\n1\n4\n", "1\n7\n1\n7\n", "1\n0\n0\n0\n", "1\n0\n1\n4\n", "1\n0\n0\n0\n", "1\n7\n1\n7\n", "1\n0\n2\n4\n", "1\n7\n1\n3\n"], "outputs": ["0\n", "7\n", "0\n", "0\n", "0\n", "7\n", "0\n", "7\n"]}
590
118
coding
Solve the programming task below in a Python markdown code block. Chefland is a grid with N$N$ rows and M$M$ columns. Each cell of this grid is either empty or contains a house. The distance between a pair of houses is the Manhattan distance between the cells containing them. For each d$d$ between 1$1$ and N+M−2$N+M-2$...
{"inputs": ["1\n3 4\n0011\n0000\n0100"], "outputs": ["1 0 1 1 0"]}
461
39
coding
Solve the programming task below in a Python markdown code block. Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so ...
{"inputs": ["1 0\n5\n", "1 0\n5\n", "3 1\n108\n", "3 2\n108\n", "3 1\n159\n", "3 1\n177\n", "3 1\n297\n", "3 1\n196\n"], "outputs": ["5", "5\n", "27", "9", "84\n", "102\n", "135\n", "122\n"]}
452
119
coding
Solve the programming task below in a Python markdown code block. There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordina...
{"inputs": ["1 1\n0\n0\n", "1 1\n1\n1\n", "1 1\n0\n1\n", "1 1\n5\n5\n", "1 1\n0\n0\n", "1 1\n5\n5\n", "1 1\n0\n1\n", "1 1\n1\n1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
639
118
coding
Solve the programming task below in a Python markdown code block. # Task The game starts with `n` people standing in a circle. The presenter counts `m` people starting with the first one, and gives `1` coin to each of them. The rest of the players receive `2` coins each. After that, the last person who received `1` co...
{"functional": "_inputs = [[5, 1], [8, 3], [75, 34], [82, 49], [73, 38], [86, 71], [61, 17], [42, 38], [29, 5], [64, 49], [61, 20], [88, 52]]\n_outputs = [[[5, 24]], [[7, 51]], [[35, 4238]], [[48, 5091]], [[61, 3996]], [[10, 6275]], [[26, 3000]], [[12, 1578]], [[28, 740]], [[43, 3327]], [[32, 2922]], [[59, 5856]]]\nimp...
653
352
coding
Solve the programming task below in a Python markdown code block. You are given two integers, $N$ and $\mbox{M}$. Count the number of strings of length $N$ (under the alphabet set of size $\mbox{M}$) that doesn't contain any palindromic string of the length greater than $\mbox{1}$ as a consecutive substring. Input For...
{"inputs": ["2\n2 2\n2 3\n"], "outputs": ["2\n6\n"]}
463
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a pattern and a string s, return true if s matches the pattern. A string s matches a pattern if there is some bijective mapping of single characters to non-empty strings such that if each character in pattern is...
{"functional": "def check(candidate):\n assert candidate(pattern = \"abab\", s = \"redblueredblue\") == True\n assert candidate(pattern = \"aaaa\", s = \"asdasdasdasd\") == True\n assert candidate(pattern = \"aabb\", s = \"xyzabcxzyabc\") == False\n\n\ncheck(Solution().wordPatternMatch)"}
135
82
coding
Solve the programming task below in a Python markdown code block. Freddy has a really fat left pinky finger, and every time Freddy tries to type an ```A```, he accidentally hits the CapsLock key! Given a string that Freddy wants to type, emulate the keyboard misses where each ```A``` supposedly pressed is replaced wit...
{"functional": "_inputs = [['aAaaaaAaaaAAaAa'], ['The end of the institution, maintenance, and administration of government, is to secure the existence of the body politic, to protect it, and to furnish the individuals who compose it with the power of enjoying in safety and tranquillity their natural rights, and the bl...
554
405
coding
Solve the programming task below in a Python markdown code block. For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n. For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it e...
{"inputs": ["1 0\n", "2 0\n", "3 0\n", "1 1\n", "2 1\n", "3 1\n", "4 1\n", "5 1\n"], "outputs": ["1\n", "2\n", "3\n", "10\n", "10\n", "30\n", "20\n", "10\n"]}
251
91
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A valid encoding of an array of words is any reference string s and array of indices indices such that: words.length == indices.length The reference string s ends with the '#' character. For each index indices[i], th...
{"functional": "def check(candidate):\n assert candidate(words = [\"time\", \"me\", \"bell\"]) == 10\n assert candidate(words = [\"t\"]) == 2\n\n\ncheck(Solution().minimumLengthEncoding)"}
142
55
coding
Solve the programming task below in a Python markdown code block. There are n incoming messages for Vasya. The i-th message is going to be received after t_{i} minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). ...
{"inputs": ["1 6 4 3 9\n2\n", "1 6 4 3 9\n2\n", "4 5 5 3 5\n1 5 5 4\n", "4 5 5 3 5\n2 5 5 4\n", "4 5 5 3 5\n1 5 5 4\n", "5 3 1 1 3\n2 2 2 1 1\n", "5 5 3 4 5\n1 2 3 4 5\n", "5 6 1 1 3\n2 2 2 1 1\n"], "outputs": ["6\n", "6\n", "20\n", "20\n", "20\n", "15\n", "35\n", "30\n"]}
502
198
coding
Solve the programming task below in a Python markdown code block. We have N balance beams numbered 1 to N. The length of each beam is 1 meters. Snuke walks on Beam i at a speed of 1/A_i meters per second, and Ringo walks on Beam i at a speed of 1/B_i meters per second. Snuke and Ringo will play the following game: * ...
{"inputs": ["2\n0 2\n1 2", "2\n2 1\n2 6", "2\n3 2\n1 2", "3\n1 1\n5 2\n6 3", "3\n1 1\n6 0\n1 3", "3\n4 1\n5 2\n6 3", "3\n1 2\n5 0\n14 3", "3\n1 4\n5 0\n14 3"], "outputs": ["3 4", "2 3", "1 4", "0 1", "4 9", "0 1", "1 6", "1 4"]}
681
156
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return true if it is a power of four. Otherwise, return false. An integer n is a power of four, if there exists an integer x such that n == 4x.   Please complete the following python code precisely...
{"functional": "def check(candidate):\n assert candidate(n = 16) == True\n assert candidate(n = 5) == False\n assert candidate(n = 1) == True\n\n\ncheck(Solution().isPowerOfFour)"}
92
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2 of length n. Let's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or num...
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,3,1], nums2 = [1,2,1]) == 2\n assert candidate(nums1 = [1,3,2,1], nums2 = [2,2,3,4]) == 4\n assert candidate(nums1 = [1,1], nums2 = [2,2]) == 2\n\n\ncheck(Solution().maxNonDecreasingLength)"}
188
103
coding
Solve the programming task below in a Python markdown code block. A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and c...
{"inputs": ["1 1 2 1 1\n2 1\n", "1 1 2 2 1\n2 1\n", "1 1 2 3 1\n2 1\n", "1 1 1 1 1\n2 1\n", "1 1 0 2 1\n2 1\n", "1 1 2 6 1\n2 1\n", "2 1 1 1 1\n2 1\n", "2 1 2 6 1\n2 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
737
166