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.
Chef has a recipe book. He wishes to read it completely as soon as possible so that he could try to cook the dishes mentioned in the book.
The pages of the book are numbered $1$ through $N$. Over a series of days, Chef wants to read each page. On each da... | {"inputs": ["1\n5\n"], "outputs": ["2\n3 1 2 5\n2 3 4"]} | coding | 596 |
Solve the programming task below in a Python markdown code block.
Little chief has his own restaurant in the city. There are N workers there. Each worker has his own salary. The salary of the i-th worker equals to W_{i} (i = 1, 2, ..., N). Once, chief decided to equalize all workers, that is, he wants to make salaries ... | {"inputs": ["2\n3\n1 4 3\n2\n7 2", "2\n3\n1 0 3\n2\n8 2", "2\n3\n1 4 3\n2\n42 7", "2\n3\n1 4 3\n2\n47 7", "2\n3\n1 4 3\n2\n20 7", "2\n3\n1 4 3\n2\n20 8", "2\n3\n1 0 2\n2\n1 17", "2\n3\n1 4 3\n2\n20 2"], "outputs": ["5\n5\n", "4\n6\n", "5\n35\n", "5\n40\n", "5\n13\n", "5\n12\n", "3\n16\n", "5\n18\n"]} | coding | 485 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer n, you can apply one of the following operations:
If n is even, replace n with n / 2.
If n is odd, replace n with either n + 1 or n - 1.
Return the minimum number of operations needed for n ... | {"functional": "def check(candidate):\n assert candidate(n = 8) == 3\n assert candidate(n = 7) == 4\n assert candidate(n = 4) == 2\n\n\ncheck(Solution().integerReplacement)"} | coding | 110 |
Solve the programming task below in a Python markdown code block.
Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $n$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bill... | {"inputs": ["1\n30\n30\n", "1\n30\n30\n", "1\n29\n30\n", "1\n29\n33\n", "1\n29\n25\n", "50\n60\n70\n", "90\n80\n89\n", "30\n31\n30\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "50\n", "10\n", "30\n"]} | coding | 531 |
Solve the programming task below in a Python markdown code block.
Given an Array and an Example-Array to sort to, write a function that sorts the Array following the Example-Array.
Assume Example Array catalogs all elements possibly seen in the input Array. However, the input Array does not necessarily have to have al... | {"functional": "_inputs = [[[1, 2, 3, 4, 5], [2, 3, 4, 1, 5]], [[1, 2, 3, 3, 3, 4, 5], [2, 3, 4, 1, 5]], [[1, 2, 3, 3, 3, 5], [2, 3, 4, 1, 5]], [[1, 2, 3, 3, 3, 5], [3, 4, 5, 6, 9, 11, 12, 13, 1, 7, 8, 2, 10]], [['a', 'a', 'b', 'f', 'd', 'a'], ['c', 'a', 'd', 'b', 'e', 'f']]]\n_outputs = [[[2, 3, 4, 1, 5]], [[2, 3, 3, ... | coding | 144 |
Solve the programming task below in a Python markdown code block.
Snuke is having a barbeque party.
At the party, he will make N servings of Skewer Meal.
Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.
Also, he has an infi... | {"inputs": ["1\n1 1\n", "2\n1 3 1 1", "2\n1 2 1 2", "2\n1 2 0 1", "2\n2 0 0 0", "2\n1 3 1 2", "2\n1 3 1 2\n", "2\n2 -1 0 0"], "outputs": ["1\n", "2\n", "3\n", "1\n", "0\n", "3", "3\n", "-1\n"]} | coding | 319 |
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is constraints.
You are given a sequence $a$ consisting of $n$ positive integers.
Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements... | {"inputs": ["6\n8\n1 2 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 1 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n3 1\n3\n3 1 2\n", "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 1\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 2... | coding | 757 |
Solve the programming task below in a Python markdown code block.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any no... | {"inputs": ["1\n1 1\n", "2\n1 110\n2 1 10\n", "2\n1 100\n2 1 10\n", "2\n2 60 2\n3 1 000 4\n", "2\n2 60 2\n3 1 000 5\n", "2\n2 200 1\n3 1 100 2\n", "2\n2 200 2\n3 1 100 2\n", "2\n2 200 2\n3 1 000 2\n"], "outputs": ["1 0\n", "111 10\n", "101 10\n", "61 6\n", "61 7\n", "301 3\n", "301 4\n", "201 4\n"]} | coding | 544 |
Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots , a_n$. Array is good if for each pair of indexes $i < j$ the condition $j - a_j \ne i - a_i$ holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily... | {"inputs": ["1\n3\n4 2 1\n", "1\n3\n4 2 1\n", "1\n3\n6 2 1\n", "1\n8\n1 2 3 4 5 6 7 8\n", "1\n8\n1 2 3 4 5 6 7 8\n", "1\n8\n1 2 2 4 5 6 7 8\n", "1\n8\n1 2 4 4 5 6 7 8\n", "1\n8\n1 2 2 4 5 6 7 6\n"], "outputs": ["4 2 1\n", "4 2 1\n", "6 2 1\n", "8 7 6 5 4 3 2 1\n", "8 7 6 5 4 3 2 1\n", "8 7 6 5 4 2 2 1\n", "8 7 6 5 4 4 ... | coding | 413 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
Let's define a function F(X) as follows:
F(X) = \frac{X}{Y}
where Y is the largest perfect square that divides X.
For example,
The largest perfect squar... | {"inputs": ["3\n3\n2 3 12\n4 \n1 2 3 4\n3\n2 3 7"], "outputs": ["2\n5\n3"]} | coding | 707 |
Solve the programming task below in a Python markdown code block.
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutive... | {"inputs": ["P\n", "C\n", "CP\n", "PC\n", "PPPP\n", "PPPPP\n", "CPCCPPC\n", "CPPCCPC\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "1\n", "5\n", "5\n"]} | coding | 503 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of non-empty subarrays with the leftmost element of the subarray not larger than other elements in the subarray.
A subarray is a contiguous part of an array.
Please com... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,2,5,3]) == 11\n assert candidate(nums = [3,2,1]) == 3\n assert candidate(nums = [2,2,2]) == 6\n\n\ncheck(Solution().validSubarrays)"} | coding | 94 |
Solve the programming task below in a Python markdown code block.
The T9 typing predictor helps with suggestions for possible word combinations on an old-style numeric keypad phone. Each digit in the keypad (2-9) represents a group of 3-4 letters. To type a letter, press once the key which corresponds to the letter gro... | {"functional": "_inputs = [[['hello', 'world'], '43556'], [['good', 'home', 'new'], '4663'], [['gone', 'hood', 'good', 'old'], '4663'], [['Hello', 'world'], '43556'], [['gOOD', 'hOmE', 'NeW'], '4663'], [['goNe', 'hood', 'GOOD', 'old'], '4663'], [[], '43556'], [['gold'], '4663'], [['gone', 'hood', 'good', 'old'], '729']... | coding | 490 |
Solve the programming task below in a Python markdown code block.
Apparently "Put A Pillow On Your Fridge Day is celebrated on the 29th of May each year, in Europe and the U.S. The day is all about prosperity, good fortune, and having bit of fun along the way."
All seems very weird to me.
Nevertheless, you will be gi... | {"functional": "_inputs = [[['EvH/KNikBiyxfeyK/miCMj', 'I/HwjnHlFLlahMOKNadps']], [['\\\\DjQ\\\\[zv]SpG]Z/[Qm\\\\eLL', 'amwZArsaGRmibriXBgTRZp']], [['n', 'B']], [['yF[CeAAiNihWEmKxJc/NRMVn', 'rMeIa\\\\KAfbjuLiTnAQxNw[XB']], [['inECnBMAA/u', 'ABAaIUOUx/M']]]\n_outputs = [[False], [False], [True], [True], [True]]\nimport... | coding | 261 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k tim... | {"functional": "def check(candidate):\n assert candidate(s = \"iiii\", k = 1) == 36\n assert candidate(s = \"leetcode\", k = 2) == 6\n\n\ncheck(Solution().getLucky)"} | coding | 310 |
Solve the programming task below in a Python markdown code block.
Step through my `green glass door`.
You can take the `moon`, but not the `sun`.
You can take your `slippers`, but not your `sandals`.
You can go through `yelling`, but not `shouting`.
You can't run through `fast`, but you can run with `speed`.
You c... | {"functional": "_inputs = [['moon'], ['test'], ['glasses'], ['airplane'], ['free'], ['branch'], ['aardvark']]\n_outputs = [[True], [False], [True], [False], [True], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_t... | coding | 149 |
Solve the programming task below in a Python markdown code block.
It is an interesting exercise to write a program to print out all permutations of $1, 2, …, n$. However, since there are $6227020800$ permutations of $1, 2, …, 13$, it is unlikely that we would ever run this program on an input of size more than $10$.
Ho... | {"inputs": ["3 2\n3 1 2\n2 3 1\n"], "outputs": ["3 2 1\n3 1 2 "]} | coding | 483 |
Solve the programming task below in a Python markdown code block.
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name_1price_1nam... | {"inputs": ["a1.01\n", "a0.11\n", "a0.01\n", "a0.40\n", "a0.11\n", "a0.40\n", "a1.01\n", "a0.01\n"], "outputs": ["1.01\n", "0.11\n", "0.01\n", "0.40\n", "0.11", "0.40", "1.01", "0.01"]} | coding | 547 |
Solve the programming task below in a Python markdown code block.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable.
For each i=2,3,...,2K, find the following value modulo 998244353:
- The number of combinations of N sides shown by the dice such that ... | {"inputs": ["3 6", "1 5", "2 3", "5 3", "5 5", "3 5", "4 8", "6 6"], "outputs": ["13\n13\n4\n13\n13\n", "0\n", "2\n2\n2\n", "30\n30\n25\n25\n20\n25\n25\n30\n30\n", "91\n91\n61\n61\n36\n61\n61\n91\n91\n", "11\n11\n4\n11\n11\n", "81\n81\n32\n32\n32\n81\n81\n", "336\n336\n231\n231\n146\n146\n146\n231\n231\n336\n336\n"]} | coding | 420 |
Solve the programming task below in a Python markdown code block.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. Y... | {"inputs": ["xxxxxxxx", "xoxoxoxoxoxoxo", "oxoxowoxoxoxox", "oxoxowoooxoxxx", "xxxoxooowoxoxo", "xoxoxooxwoxoxo", "xoxoyoxoxoxoxo", "xxxoxoooooxwxo"], "outputs": ["NO", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 275 |
Solve the programming task below in a Python markdown code block.
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integ... | {"inputs": ["1\n64\n", "1\n64\n", "1\n33\n", "1\n42\n", "1\n69\n", "2\n15 4\n", "2\n15 5\n", "2\n70 70\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n"]} | coding | 348 |
Solve the programming task below in a Python markdown code block.
Jeff got 2n real numbers a_1, a_2, ..., a_2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows: choose indexe... | {"inputs": ["1\n0.001 0.001\n", "1\n0.900 0.900\n", "1\n1.100 1.200\n", "1\n0.061 0.330\n", "1\n0.001 0.001\n", "1\n0.900 0.900\n", "1\n1.100 1.200\n", "1\n0.061 0.330\n"], "outputs": ["0.998\n", "0.800\n", "0.700\n", "0.609\n", "0.998\n", "0.800\n", "0.700\n", "0.609\n"]} | coding | 567 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Alice and Bob, both have to drink water. But they both don't want to go, so they will play a game to decide who will fetch water for both of them. Alice will choose a number randomly between 1 ... | {"inputs": ["3\n1 1\n1 2\n2 3", "3\n1 1\n1 3\n2 3", "3\n1 2\n1 3\n2 3", "3\n1 1\n1 1\n2 3", "3\n1 1\n2 1\n2 3", "3\n1 3\n1 3\n2 2", "3\n1 1\n2 1\n1 3", "3\n1 2\n2 1\n2 3"], "outputs": ["0/1\n1/2\n1/2", "0/1\n1/3\n1/2\n", "1/2\n1/3\n1/2\n", "0/1\n0/1\n1/2\n", "0/1\n1/2\n1/2\n", "1/3\n1/3\n1/2\n", "0/1\n1/2\n1/3\n", "1/2... | coding | 428 |
Solve the programming task below in a Python markdown code block.
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that: 1 ≤ a ≤ n. If it's Mahmou... | {"inputs": ["1\n", "2\n", "5\n", "3\n", "4\n", "6\n", "7\n", "8\n"], "outputs": ["Ehab", "Mahmoud", "Ehab", "Ehab", "Mahmoud", "Mahmoud", "Ehab", "Mahmoud"]} | coding | 295 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0.
A grandparent of a node is the parent of its parent ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([6,7,8,2,7,1,3,9,None,1,4,None,None,None,5])) == 18\n\n\ncheck(Solution().sumEvenGrandparent)"} | coding | 157 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a complete binary tree, return the number of the nodes in the tree.
According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,6])) == 6\n assert candidate(root = tree_node([])) == 0\n assert candidate(root = tree_node([1])) == 1\n\n\ncheck(Solution().countNodes)"} | coding | 188 |
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 size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index i is nums[i]. Each chocolate is of a different type, a... | {"functional": "def check(candidate):\n assert candidate(nums = [20,1,15], x = 5) == 13\n assert candidate(nums = [1,2,3], x = 4) == 6\n\n\ncheck(Solution().minCost)"} | coding | 178 |
Solve the programming task below in a Python markdown code block.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time ... | {"inputs": ["2\n", "3\n", "4\n", "6\n", "9\n", "4\n", "3\n", "6\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "2\n", "2", "1", "3"]} | coding | 368 |
Solve the programming task below in a Python markdown code block.
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclu... | {"inputs": ["1 1\n5\n", "1 2\n57\n", "1 2\n74\n", "1 2\n49\n", "1 2\n68\n", "1 2\n84\n", "1 2\n59\n", "2 1\n4\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 354 |
Solve the programming task below in a Python markdown code block.
You are given a positive integer $x$. Check whether the number $x$ is representable as the sum of the cubes of two positive integers.
Formally, you need to check if there are two integers $a$ and $b$ ($1 \le a, b$) such that $a^3+b^3=x$.
For example, i... | {"inputs": ["1\n999999999999\n", "1\n999999999999\n", "1\n1000000000000\n", "1\n1000000000000\n", "2\n405527623378\n5204291237\n", "2\n620475187705\n5204291237\n", "2\n620475187705\n5369629849\n", "2\n392481106372\n5369629849\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n... | coding | 521 |
Solve the programming task below in a Python markdown code block.
Well, those numbers were right and we're going to feed their ego.
Write a function, isNarcissistic, that takes in any amount of numbers and returns true if all the numbers are narcissistic. Return false for invalid arguments (numbers passed in as string... | {"functional": "_inputs = [[11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 22, 9], ['4'], ['4', 7, '9'], ['words'], [[1, 2]], [407, 8208], [-1], [''], ['', 407], [407, ''], [5, '', 407], [9474], [{}]]\n_outputs = [[False], [True], [False], [True], [True], [False], [False], [True], [False], [False], [Fals... | coding | 132 |
Solve the programming task below in a Python markdown code block.
A simple string contains a large repetition of letters within it. This problem is related to string handling and manipulation. An original message is sent from planet Earth to planet Cybertron in form of a string. However, the letter position and string... | {"inputs": ["information"], "outputs": ["i2n2f1o2r1m1a1t1"]} | coding | 214 |
Solve the programming task below in a Python markdown code block.
One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference ... | {"inputs": ["2+2\n", "1+2\n", "2+2\n", "45+5\n", "45+5\n", "5+55\n", "5+54\n", "55+4\n"], "outputs": ["-46\n", "-47\n", "-46\n", "0\n", "0\n", "-440\n", "-441\n", "9\n"]} | coding | 184 |
Solve the programming task below in a Python markdown code block.
Let's call a sequence $b_1, b_2, b_3 \dots, b_{k - 1}, b_k$ almost increasing if $$\min(b_1, b_2) \le \min(b_2, b_3) \le \dots \le \min(b_{k - 1}, b_k).$$ In particular, any sequence with no more than two elements is almost increasing.
You are given a s... | {"inputs": ["3\n8\n1 2 7 3 2 1 2 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 3 2 1 2 5\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 6 2 1 1 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 1 2 1 1 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 6 2 1 4 4\n2\n2 1\n7\n7 3 3 2 6 3 7\n", "3\n8\n1 2 7 1 2 1 1 3\n2\n2 1\n7\n4 1 5 2 ... | coding | 461 |
Solve the programming task below in a Python markdown code block.
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all pow... | {"inputs": ["hg\n", "hg\n", "hh\n", "gh\n", "gi\n", "fi\n", "gj\n", "fj\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 417 |
Solve the programming task below in a Python markdown code block.
Given a time in AM/PM format as a string, convert it to military (24-hour) time as a string.
Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock
Sample Inpu... | {"functional": "_inputs = [['12:00:01AM'], ['01:02:03AM'], ['02:04:05AM'], ['03:06:07AM'], ['04:08:09AM'], ['05:10:11AM'], ['06:12:13AM'], ['07:14:15AM'], ['08:16:17AM'], ['09:18:19AM'], ['10:20:21AM'], ['11:22:23AM'], ['12:24:25PM'], ['01:26:27PM'], ['02:28:29PM'], ['03:30:31PM'], ['04:32:33PM'], ['05:34:35PM'], ['06:... | coding | 200 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums sorted in non-decreasing order and an integer target, return true if target is a majority element, or false otherwise.
A majority element in an array nums is an element that appears more th... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,5,5,5,5,5,6,6], target = 5) == True\n assert candidate(nums = [10,100,101,101], target = 101) == False\n\n\ncheck(Solution().isMajorityElement)"} | coding | 107 |
Solve the programming task below in a Python markdown code block.
# One is the loneliest number
## Task
The range of vision of a digit is its own value. `1` can see one digit to the left and one digit to the right,` 2` can see two digits, and so on.
Thus, the loneliness of a digit `N` is the sum of the digits which ... | {"functional": "_inputs = [[34315], [123456], [8854778], [65432165432], [0], [1], [11111]]\n_outputs = [[True], [True], [False], [False], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol... | coding | 312 |
Solve the programming task below in a Python markdown code block.
# Task
You are given a `moment` in time and space. What you must do is break it down into time and space, to determine if that moment is from the past, present or future.
`Time` is the sum of characters that increase time (i.e. numbers in range ['1'..... | {"functional": "_inputs = [['12:30 am'], ['12:02 pm'], ['01:00 pm'], ['11:12 am'], ['05:20 pm'], ['04:20 am']]\n_outputs = [[[False, False, True]], [[False, True, False]], [[True, False, False]], [[False, False, True]], [[False, False, True]], [[False, True, False]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if ... | coding | 451 |
Solve the programming task below in a Python markdown code block.
Return the century of the input year. The input will always be a 4 digit string, so there is no need for validation.
### Examples
```
"1999" --> "20th"
"2011" --> "21st"
"2154" --> "22nd"
"2259" --> "23rd"
"1124" --> "12th"
"2000" --> "20th"
```
Also f... | {"functional": "_inputs = [['1999']]\n_outputs = [['20th']]\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(... | coding | 142 |
Solve the programming task below in a Python markdown code block.
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of th... | {"inputs": ["1\n3", "1\n1", "1\n2", "1\n7", "1\n6", "1\n4", "1\n8", "1\n5"], "outputs": ["1", "2\n", "-1\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 179 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.
If there is more than one possible answer, return... | {"functional": "def check(candidate):\n assert candidate(words = [\"w\",\"wo\",\"wor\",\"worl\", \"world\"]) == \"world\"\n assert candidate(words = [\"a\", \"banana\", \"app\", \"appl\", \"ap\", \"apply\", \"apple\"]) == \"apple\"\n\n\ncheck(Solution().longestWord)"} | coding | 138 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and ... | {"functional": "def check(candidate):\n assert candidate(apples = [1,2,3,5,2], days = [3,2,1,4,2]) == 7\n assert candidate(apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]) == 5\n\n\ncheck(Solution().eatenApples)"} | coding | 193 |
Solve the programming task below in a Python markdown code block.
Have a look at the following numbers.
```
n | score
---+-------
1 | 50
2 | 150
3 | 300
4 | 500
5 | 750
```
Can you find a pattern in it? If so, then write a function `getScore(n)`/`get_score(n)`/`GetScore(n)` which returns the score for any ... | {"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [30], [100], [123], [1000], [1234], [10000], [12345]]\n_outputs = [[50], [150], [300], [500], [750], [1050], [1400], [1800], [2250], [2750], [10500], [23250], [252500], [381300], [25025000], [38099750], [2500250000], [3810284250]]\nimpo... | coding | 210 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5], requests = [[1,3],[0,1]]) == 19\n assert candidate(nums = [1,2,3,4,5,6], requests = [[0,1]]) == 11\n assert candidate(nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]) == 47\n\n\ncheck(Solution().maxSumRangeQuery)"} | coding | 162 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the great... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,6]) == True\n assert candidate(nums = [3,9,5]) == False\n assert candidate(nums = [4,3,12,8]) == True\n\n\ncheck(Solution().canTraverseAllPairs)"} | coding | 167 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth.
Return the number of '*'... | {"functional": "def check(candidate):\n assert candidate(s = \"l|*e*et|c**o|*de|\") == 2\n assert candidate(s = \"iamprogrammer\") == 0\n assert candidate(s = \"yo|uar|e**|b|e***au|tifu|l\") == 5\n\n\ncheck(Solution().countAsterisks)"} | coding | 131 |
Solve the programming task below in a Python markdown code block.
Petya has an array of integers a_1, a_2, …, a_n. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it.
Petya likes to challenge himself, so he wants to sort array using only 3-cycles. More formally, i... | {"inputs": ["7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 3 3\n3\n2 1 3\n3\n3 1 2\n4\n2 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 3 3\n3\n2 1 2\n3\n3 1 1\n4\n2 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 2 3\n3\n2 1 3\n3\n3 2 1\n4\n2 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 3 3\n3\n2 1 2\n3\n3 2 1\n4\n4 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 2... | coding | 629 |
Solve the programming task below in a Python markdown code block.
Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i... | {"inputs": ["5\n4\n0 2 1 7\n5 12 29 8\n4\n1 1 0 2\n5 3 33 20\n4\n4 3 9 1\n0 9 5 2\n2\n1 1\n0 2\n1\n1\n666\n", "5\n4\n0 2 1 7\n5 12 29 8\n4\n2 1 0 2\n5 3 33 20\n4\n4 3 9 1\n0 9 5 2\n2\n1 1\n0 2\n1\n1\n666\n", "5\n4\n1 3 0 4\n5 9 15 20\n4\n1 2 2 2\n6 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n2 1\n5 9\n1\n1\n25\n", "5\n4\n1 3 1 ... | coding | 741 |
Solve the programming task below in a Python markdown code block.
=====Function Descriptions=====
mean
The mean tool computes the arithmetic mean along the specified axis.
import numpy
my_array = numpy.array([ [1, 2], [3, 4] ])
print numpy.mean(my_array, axis = 0) #Output : [ 2. 3.]
print numpy.mean(my_arra... | {"inputs": ["2 2\n1 2\n3 4"], "outputs": ["[1.5 3.5]\n[1. 1.]\n1.118033988749895"]} | coding | 580 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a list of preferences for n friends, where n is always even.
For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list i... | {"functional": "def check(candidate):\n assert candidate(n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]) == 2\n assert candidate(n = 2, preferences = [[1], [0]], pairs = [[1, 0]]) == 0\n assert candidate(n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, ... | coding | 264 |
Solve the programming task below in a Python markdown code block.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be ... | {"inputs": ["9\n", "7\n", "1\n", "5\n", "6\n", "2\n", "8\n", "3\n"], "outputs": ["504\n", "210\n", "1\n", "60\n", "60\n", "2\n", "280\n", "6\n"]} | coding | 274 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
At ... | {"functional": "def check(candidate):\n assert candidate(memory1 = 2, memory2 = 2) == [3,1,0]\n assert candidate(memory1 = 8, memory2 = 11) == [6,0,4]\n\n\ncheck(Solution().memLeak)"} | coding | 204 |
Solve the programming task below in a Python markdown code block.
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i.
How many squares i satisfy both of the following conditions?
* The assigned number, i, is odd.
* The written in... | {"inputs": ["5\n1 5 4 5 7", "5\n0 4 4 5 7", "5\n0 4 4 5 0", "5\n1 4 4 5 7", "5\n0 5 4 5 7", "5\n1 3 4 6 7", "5\n2 5 4 5 7", "5\n1 4 4 7 7"], "outputs": ["2\n", "1\n", "0\n", "2\n", "1\n", "2\n", "1\n", "2\n"]} | coding | 220 |
Solve the programming task below in a Python markdown code block.
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.
After finishing the document, she noticed that she... | {"inputs": ["2017/01/06", "2017/01/32", "2017/01//7", "2010/01/77", "2010/01/76", "2016/01/70", "2016/01/80", "2017/01/21"], "outputs": ["2018/01/06\n", "2018/01/32\n", "2018/01//7\n", "2018/01/77\n", "2018/01/76\n", "2018/01/70\n", "2018/01/80\n", "2018/01/21\n"]} | coding | 262 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a linked list, and an integer k.
Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed).
Pleas... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 2), list_node([1,4,3,2,5]))\n assert is_same_list(candidate(head = list_node([7,9,6,6,7,8,3,0,9,5]), k = 5), list_node([7,9,6,6,8,7,3,0,9,5]))\n assert is_same_list(candidate(head = list_node([1]), k = 1), ... | coding | 146 |
Solve the programming task below in a Python markdown code block.
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was tha... | {"inputs": ["6\n", "9\n", "8\n", "71\n", "13\n", "16\n", "26\n", "19\n"], "outputs": ["byte\n", "byte\n", "byte\n", "byte\n", "byte\n", "byte\n", "byte\n", "byte\n"]} | coding | 561 |
Solve the programming task below in a Python markdown code block.
Harvey Specter has agreed to take Mike Ross to a meeting filled with brilliant scientists at NSA Headquarters. But, as always, it's not going to be easy for Mike. He has to solve a puzzle given by Harvey.
Harvey gives two numbers N and K and defines a ... | {"inputs": ["2\n10 4\n7 3\n"], "outputs": ["10\n7\n"]} | coding | 385 |
Solve the programming task below in a Python markdown code block.
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic tea... | {"inputs": ["1\n9876\n", "1\n1234\n", "1\n2771\n", "1\n2705\n", "2\n2004\n1000\n", "2\n9988\n8899\n", "2\n2037\n2025\n", "2\n2099\n1000\n"], "outputs": ["1876\n", "1034\n", "1771\n", "1705\n", "1004\n1004\n", "No solution", "1037\n2005\n", "1099\n1100\n"]} | coding | 654 |
Solve the programming task below in a Python markdown code block.
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bil... | {"inputs": ["4\n", "5\n", "1\n", "7\n", "7\n", "6\n", "1\n", "5\n"], "outputs": ["4\n", "1\n", "1\n", "3\n", "3\n", "2\n", "1\n", "1\n"]} | coding | 298 |
Solve the programming task below in a Python markdown code block.
You are given an array A of N positive integers.
In one operation, you can do the following:
Choose an index i (1 ≤ i ≤ N), and change the value of A_{i} to either (A_{i})^2 or \lfloor \sqrt{A_{i}} \rfloor.
Find the minimum number of operations requir... | {"inputs": ["3\n4\n1 3 9 9\n4\n1 9 3 9\n3\n4 2 1\n"], "outputs": ["0\n1\n3\n"]} | coding | 561 |
Solve the programming task below in a Python markdown code block.
George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George's current array as b_1, b_2, ..., b_{|}b| (record |b| ... | {"inputs": ["7\n", "1\n", "1\n", "7\n", "6\n", "3\n", "45\n", "10\n"], "outputs": ["1", "1", "1", "1", "1\n", "1\n", "1", "1"]} | coding | 699 |
Solve the programming task below in a Python markdown code block.
It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x.
For example, the prairie partitions of 12,... | {"inputs": ["1\n1\n", "1\n2\n", "1\n4\n", "1\n7\n", "1\n6\n", "1\n14\n", "1\n16\n", "1\n23\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 500 |
Solve the programming task below in a Python markdown code block.
One day Vasya got hold of information on the Martian dollar course in bourles for the next n days. The buying prices and the selling prices for one dollar on day i are the same and are equal to ai. Vasya has b bourles. He can buy a certain number of doll... | {"inputs": ["2 4\n6 7\n", "2 2\n6 7\n", "2 4\n3 7\n", "1 1472\n77\n", "1 1653\n77\n", "1 3232\n22\n", "1 2592\n31\n", "1 1653\n11\n"], "outputs": ["4\n", "2\n", "8\n", "1472\n", "1653\n", "3232\n", "2592\n", "1653\n"]} | coding | 267 |
Solve the programming task below in a Python markdown code block.
Chef is playing badminton today. The service rules of this singles game of badminton are as follows:
1. The player who starts the game serves from the right side of their court.
2. Whenever a player wins a point, they serve next.
3. If the server has won... | {"inputs": ["4\n2\n9\n53\n746"], "outputs": ["2\n5\n27\n374"]} | coding | 411 |
Solve the programming task below in a Python markdown code block.
Chef wants to make a purchase. For this, he needs X gold coins, but he has none at the moment.
Chef has N fixed deposits, the i^{th} of which is worth A_{i} coins. He wants to open the minimum number of these deposits so that he has at least X coins.
Y... | {"inputs": ["4\n4 6\n4 3 5 1\n3 15\n1 5 3\n2 5\n10 3\n4 7\n1 2 3 4"], "outputs": ["2\n-1\n1\n2"]} | coding | 609 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer num, return the number of digits in num that divide num.
An integer val divides nums if nums % val == 0.
Please complete the following python code precisely:
```python
class Solution:
def countD... | {"functional": "def check(candidate):\n assert candidate(num = 7) == 1\n assert candidate(num = 121) == 2\n assert candidate(num = 1248) == 4\n\n\ncheck(Solution().countDigits)"} | coding | 76 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Suppose we have a file system that stores both files and directories. An example of one system is represented in the following picture:
Here, we have dir as the only directory in the root. dir contains two subdirecto... | {"functional": "def check(candidate):\n assert candidate(input = \"dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext\") == 20\n assert candidate(input = \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\") == 32\n assert candidate(input = \"a\") == 0\n ... | coding | 438 |
Solve the programming task below in a Python markdown code block.
We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.
In how many ways can we choose three of the sticks with different lengths that can form a triangle?
That is, find the number of triples of integers (i, j, k) (1 \leq i ... | {"inputs": ["1\n1\n", "2\n1 0", "2\n0 0", "2\n0 1", "2\n3 0", "2\n3 1", "2\n2 1", "2\n2 2"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 316 |
Solve the programming task below in a Python markdown code block.
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had n buyers and each of them bought exact... | {"inputs": ["1 2\nhalfplus\n", "1 2\nhalfplus\n", "1 4\nhalfplus\n", "1 0\nhalfplus\n", "2 10\nhalf\nhalfplus\n", "2 12\nhalf\nhalfplus\n", "2 16\nhalf\nhalfplus\n", "2 10\nhalf\nhalfplus\n"], "outputs": ["1\n", "1\n", "2\n", "0\n", "15\n", "18\n", "24\n", "15\n"]} | coding | 496 |
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 buses of length n, where buses[i] represents the departure time of the ith bus. You are also given a 0-indexed integer array passengers of length m, where passengers[j] represen... | {"functional": "def check(candidate):\n assert candidate(buses = [10,20], passengers = [2,17,18,19], capacity = 2) == 16\n assert candidate(buses = [20,30,10], passengers = [19,13,26,4,25,11,21], capacity = 2) == 20\n\n\ncheck(Solution().latestTimeCatchTheBus)"} | coding | 295 |
Solve the programming task below in a Python markdown code block.
Chef loves arrays. But he really loves a specific kind of them - Rainbow Arrays.
The array is a Rainbow Array if it has such a structure:
- The first a1 elements equal to 1.
- The next a2 elements equal to 2.
- The next a3 elements equal to 3.
- Th... | {"inputs": ["12", "25", "17", "32", "16", "42", "22", "20"], "outputs": ["0\n", "924\n", "28\n", "5005\n", "7\n", "38760\n", "210\n", "84\n"]} | coding | 488 |
Solve the programming task below in a Python markdown code block.
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off... | {"inputs": ["2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["0 2\n", "0 1\n", "0 2\n", "0 2\n", "0 2\n", "1 2\n", "2 2\n", "2 3\n"]} | coding | 232 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the ot... | {"inputs": ["4\n2 2 2\n3 8 2\n1 6 2\n4 16 5", "4\n2 2 2\n2 8 2\n2 15 4\n4 6 4", "4\n2 2 2\n3 6 2\n1 6 2\n4 16 1", "4\n5 0 1\n4 7 1\n1 15 0\n3 3 3", "4\n5 0 1\n7 7 1\n1 15 0\n3 3 3", "4\n2 0 1\n3 0 2\n1 15 2\n2 20 5", "4\n2 0 1\n2 12 1\n1 22 2\n2 0 1", "4\n2 2 2\n3 8 2\n1 15 2\n4 16 5"], "outputs": ["0\n1\n1\n0\n", "0\n... | coding | 682 |
Solve the programming task below in a Python markdown code block.
You are given two integer sequences, each of length N: a_1, ..., a_N and b_1, ..., b_N.
There are N^2 ways to choose two integers i and j such that 1 \leq i, j \leq N. For each of these N^2 pairs, we will compute a_i + b_j and write it on a sheet of pape... | {"inputs": ["1\n0\n0\n", "2\n1 2\n3 4\n", "5\n1 2 3 4 5\n1 2 3 4 5\n", "6\n4 6 0 0 3 3\n0 5 6 5 0 3\n"], "outputs": ["0\n", "2\n", "2\n", "8\n"]} | coding | 440 |
Solve the programming task below in a Python markdown code block.
Most of this problem is by the original author of [the harder kata](https://www.codewars.com/kata/556206664efbe6376700005c), I just made it simpler.
I read a book recently, titled "Things to Make and Do in the Fourth Dimension" by comedian and mathemati... | {"functional": "_inputs = [[1232], [123220], [0], [1], [141], [1234], [21234], [81352], [987654], [1020005], [9876545], [381654729], [1073741823]]\n_outputs = [[True], [False], [True], [True], [True], [False], [False], [False], [True], [True], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if... | coding | 620 |
Solve the programming task below in a Python markdown code block.
The athletics competition 200M semi-final three races were held. Eight players (24 players in total) will participate in each group. A total of eight players, including the top two players in each group and the top two players from all the players in eac... | {"inputs": ["18 25.46\n16 26.23\n3 23.00\n10 24.79\n5 22.88\n11 23.87\n19 23.90\n1 25.11\n23 23.88\n4 23.46\n7 24.12\n12 22.91\n13 21.99\n14 22.86\n21 23.12\n9 24.09\n17 22.51\n22 23.49\n6 23.02\n20 22.23\n8 21.89\n15 24.14\n8 23.77\n2 23.42", "18 25.46\n16 26.23\n3 23.00\n10 24.79\n5 22.88\n11 23.87\n19 23.90\n1 25.11... | coding | 656 |
Solve the programming task below in a Python markdown code block.
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'.
He wants to find the length of the smallest substring, which satisfies the following conditions:
Length of the substring is at least $2$
'a' occurs strictly more times ... | {"inputs": ["3\n2\naa\n5\ncbabb\n8\ncacabccc\n"], "outputs": ["2\n-1\n3\n"]} | coding | 509 |
Solve the programming task below in a Python markdown code block.
Your car is old, it breaks easily. The shock absorbers are gone and you think it can handle about 15 more bumps before it dies totally.
Unfortunately for you, your drive is very bumpy! Given a string showing either flat road ("\_") or bumps ("n"), work ... | {"functional": "_inputs = [['n'], ['_nnnnnnn_n__n______nn__nn_nnn'], ['______n___n_'], ['nnnnnnnnnnnnnnnnnnnnn']]\n_outputs = [['Woohoo!'], ['Car Dead'], ['Woohoo!'], ['Car Dead']]\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_to... | coding | 124 |
Solve the programming task below in a Python markdown code block.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an ... | {"inputs": ["3", "4", "2", "6", "5", "9", "8", "1"], "outputs": ["2\n", "4\n", "2\n", "4\n", "4\n", "8\n", "8\n", "1"]} | coding | 227 |
Solve the programming task below in a Python markdown code block.
Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens.
All characters in this game are lowercase English letters. There are two players: Mister B and his co... | {"inputs": ["1 1 1 1\n", "4 1 1 9\n", "4 5 1 1\n", "3 3 3 8\n", "4 1 1 4\n", "1 2 1 1\n", "5 3 3 8\n", "1 1 1 2\n"], "outputs": ["1", "7", "1", "3", "4\n", "1\n", "3\n", "1\n"]} | coding | 539 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.
Please complete the following python c... | {"functional": "def check(candidate):\n assert candidate(arr = [3,1,2,4]) == 17\n assert candidate(arr = [11,81,94,43,3]) == 444\n\n\ncheck(Solution().sumSubarrayMins)"} | coding | 98 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping:
"1" -> 'A'
"2" -> 'B'
...
"25" -> 'Y'
"26" -> 'Z'
However, while decoding the message, you realiz... | {"functional": "def check(candidate):\n assert candidate(s = \"12\") == 2\n assert candidate(s = \"226\") == 3\n assert candidate(s = \"06\") == 0\n\n\ncheck(Solution().numDecodings)"} | coding | 292 |
Solve the programming task below in a Python markdown code block.
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence ... | {"inputs": ["2\n4\n-4\n", "2\n1\n-1\n", "2\n-4\n4\n", "2\n-5\n6\n", "2\n-5\n6\n", "2\n-4\n4\n", "2\n1\n-1\n", "2\n-5\n9\n"], "outputs": ["second\n", "second\n", "first\n", "first\n", "first\n", "first\n", "second\n", "first\n"]} | coding | 492 |
Solve the programming task below in a Python markdown code block.
The Chef and his assistant are, by far, the two best cooks in the kitchen. They can prepare many dishes in far less time than the other cooks in the kitchen. Also, the Chef and his assistant are able to prepare many dishes in succession, but any other co... | {"inputs": ["2\n7\n10 1\n10 2\n10 1\n10 2\n10 1\n3 1\n3 1\n3\n1 2\n1 3\n1 4"], "outputs": ["4\n1"]} | coding | 539 |
Solve the programming task below in a Python markdown code block.
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optim... | {"inputs": ["1 0\n", "8 7\n", "9 0\n", "20 1\n", "10 1\n", "59 3\n", "16 1\n", "10 0\n"], "outputs": ["1\n", "8\n", "9\n", "19\n", "9\n", "59\n", "16\n", "10\n"]} | coding | 347 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. There is a complete binary tree with 2n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2n - 1 - 1] has two children where:
... | {"functional": "def check(candidate):\n assert candidate(n = 3, queries = [[5,3],[4,7],[2,3]]) == [4,5,3]\n assert candidate(n = 2, queries = [[1,2]]) == [2]\n\n\ncheck(Solution().cycleLengthQueries)"} | coding | 295 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1].
We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After... | {"functional": "def check(candidate):\n assert candidate(arr = [4,3,2,1,0]) == 1\n assert candidate(arr = [1,0,2,3,4]) == 4\n\n\ncheck(Solution().maxChunksToSorted)"} | coding | 125 |
Solve the programming task below in a Python markdown code block.
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented... | {"inputs": ["a\nz\n", "b\ng\n", "a\ng\n", "a\nza\n", "ba\na\n", "a\naa\n", "a\nab\n", "`\nza\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 339 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's apartment consists of $M$ floors (numbered $1$ through $M$), and there's an elevator that is used to move between different floors. The elevat... | {"inputs": ["5\n4 5\n2 3 4 3\n4 5\n2 -1 4 3\n4 5\n1 -1 -1 5\n5 4\n-1 -1 3 -1 -1\n5 5\n-1 -1 3 -1 -1\n"], "outputs": ["1\n1\n-1\n1\n0\n"]} | coding | 569 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots , a_n$.
In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For exam... | {"inputs": ["1\n5\n3 3 3 3 3\n", "1\n5\n3 3 3 3 3\n", "1\n5\n3 3 0 3 3\n", "1\n5\n3 3 1 3 3\n", "1\n5\n3 0 1 4 3\n", "1\n5\n2 1 0 2 2\n", "1\n5\n0 3 0 3 3\n", "1\n5\n3 0 1 3 3\n"], "outputs": ["5\n", "5\n", "5\n", "4\n", "3\n", "2\n", "5\n", "4\n"]} | coding | 522 |
Solve the programming task below in a Python markdown code block.
Give the summation of all even numbers in a Fibonacci sequence up to, but not including, the maximum value.
The Fibonacci sequence is a series of numbers where the next value is the addition of the previous two values. The series starts with 0 and 1:
0... | {"functional": "_inputs = [[0], [10], [5], [100], [1000], [1000000], [100000000], [1000000000], [2147483647], [-1]]\n_outputs = [[0], [10], [2], [44], [798], [1089154], [82790070], [350704366], [1485607536], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 157 |
Solve the programming task below in a Python markdown code block.
Write a function that returns the number of '2's in the factorization of a number.
For example,
```python
two_count(24)
```
should return 3, since the factorization of 24 is 2^3 x 3
```python
two_count(17280)
```
should return 7, since the factorizatio... | {"functional": "_inputs = [[24], [17280], [222222222222], [256], [1], [2], [482848428248882482], [7], [7777777777777777], [84934656]]\n_outputs = [[3], [7], [1], [8], [0], [1], [1], [0], [0], [20]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isc... | coding | 159 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].
base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 e... | {"functional": "def check(candidate):\n assert candidate(nums = [2, 1, 3]) == False\n assert candidate(nums = [1, 3, 3, 2]) == True\n assert candidate(nums = [1, 1]) == True\n assert candidate(nums = [3, 4, 4, 1, 2, 1]) == False\n\n\ncheck(Solution().isGood)"} | coding | 183 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Haku has been newly hired by Chef to clean tables at his restaurant. So whenever a customer wants a table, Haku must clean it.
But Haku happens to be a lazy boy. So in the morning, when the res... | {"inputs": ["4\n2 4\n1 2 3 4\n3 2\n4 1\n3 6\n1 2 1 3 4 1\n3 5\n1 2 1 3 4"], "outputs": ["4\n2\n4\n4"]} | coding | 706 |
Solve the programming task below in a Python markdown code block.
There are N towers in the town where Ikta lives. Each tower is given a different number from 0 to N-1, and the tower with number i is called tower i. Curious Ikta was interested in the height of the N towers and decided to make a table T showing the magn... | {"inputs": ["1", "3\n0 2\n0 1", "3\n1 2\n0 1", "3\n1 0\n0 2", "3\n1 1\n0 2", "3\n1 1\n1 2", "3\n0 1\n2 2", "3\n1 0\n2 2"], "outputs": ["1", "3\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 622 |
Solve the programming task below in a Python markdown code block.
Find the intersection of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$.
Constraints
* $1 \leq n, m \leq 200,000$
* $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$
* $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$
Input
... | {"inputs": ["4\n1 3 5 8\n5\n1 3 5 9 7", "4\n1 2 5 8\n5\n2 3 5 9 7", "4\n1 2 5 8\n7\n0 3 5 9 9", "4\n1 2 0 8\n9\n1 3 5 9 6", "4\n1 2 5 8\n5\n4 3 5 9 11", "4\n1 2 5 8\n9\n2 3 5 9 11", "4\n1 2 9 8\n5\n4 3 5 9 11", "4\n1 2 5 8\n9\n1 3 5 9 11"], "outputs": ["1\n3\n5\n", "2\n5\n", "5\n", "1\n", "5\n", "2\n5\n", "9\n", "1\n5\... | coding | 278 |
Solve the programming task below in a Python markdown code block.
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (x_{i}, y_{i}). We know that no two bombs are at the same point and that no bomb is at point w... | {"inputs": ["2\n1 0\n1 0\n", "2\n1 1\n1 0\n", "2\n2 1\n0 -1\n", "2\n2 1\n1 -1\n", "2\n2 2\n1 -1\n", "2\n2 0\n1 -1\n", "2\n3 0\n1 -1\n", "2\n1 0\n1 -1\n"], "outputs": ["8\n1 1 R\n2\n1 1 L\n3\n1 1 R\n2\n1 1 L\n3\n", "10\n1 1 R\n2\n1 1 L\n3\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n", "10\n1 1 D\n2\n1 1 U\n3\n1 2 R\n1 1 U\n2\n1 ... | coding | 745 |
Solve the programming task below in a Python markdown code block.
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings!
Th... | {"inputs": ["4 1\n(\n", "8 1\n(\n", "9 1\n(\n", "4 1\n(\n", "2 2\n)(\n", "2 2\n))\n", "2 2\n)(\n", "2 2\n))\n"], "outputs": ["4\n", "56\n", "0\n", "4\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 487 |
Solve the programming task below in a Python markdown code block.
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot.
One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to t... | {"inputs": ["1\n1\n1\n", "1\n2\n2\n", "1\n4\n4\n", "1\n0\n0\n", "1\n8\n8\n", "1\n9\n9\n", "1\n5\n5\n", "1\n11\n11\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 460 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.