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.
Consider the string `"1 2 36 4 8"`. Lets take pairs of these numbers, concatenate each pair and determine how many of them of divisible by `k`.
```Pearl
If k = 3, we get following numbers ['12', '18', '21', '24', '42', '48', '81', '84'], all divisible... | {"functional": "_inputs = [['1 2 36 4 8', 2], ['1 2 36 4 8', 3], ['1 2 36 4 8', 4], ['1 2 36 4 8', 8]]\n_outputs = [[16], [8], [11], [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, (... | coding | 342 |
Solve the programming task below in a Python markdown code block.
We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written,... | {"inputs": ["abaa\nab", "`caa\nca", "accc\nac", "aba`\nab", "`baa\nab", "`baa\nac", "`caa\nac", "`caa\ncb"], "outputs": ["1\n", "2\n", "3\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 372 |
Solve the programming task below in a Python markdown code block.
##Task:
You have to write a function **pattern** which creates the following pattern upto n number of rows. *If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.*
##Pattern:
(n)
(n)(n-1)
(n)(n-1)(n-2)
... | {"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['2\\n21'], ['5\\n54\\n543\\n5432\\n54321'], [''], ['']]\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, t... | coding | 275 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i].
Return any permutation of nums1 that max... | {"functional": "def check(candidate):\n assert candidate(nums1 = [2,7,11,15], nums2 = [1,10,4,11]) == [2,11,7,15]\n assert candidate(nums1 = [12,24,8,32], nums2 = [13,25,32,11]) == [24,32,8,12]\n\n\ncheck(Solution().advantageCount)"} | coding | 117 |
Solve the programming task below in a Python markdown code block.
There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital.
Each town in the kingdom has a Teleporter, a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town ... | {"inputs": ["3 1\n3 3 1", "3 1\n2 1 1", "3 2\n3 3 1", "3 4\n3 3 1", "3 4\n1 3 1", "3 7\n1 3 1", "3 2\n3 3 2", "3 2\n1 3 1"], "outputs": ["2\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "0\n"]} | coding | 349 |
Solve the programming task below in a Python markdown code block.
You have N soldiers numbered from 1 to N. Each of your soldiers is either a liar or a truthful person. You have M sets of information about them. Each set of information tells you the number of liars among a certain range of your soldiers. Let L be the t... | {"inputs": ["3 2\n1 2 1\n2 3 1\n", "20 11\n3 8 4\n1 9 6\n1 13 9\n5 11 5\n4 19 12\n8 13 5\n4 8 4\n7 9 2\n10 13 3\n7 16 7\n14 19 4\n"], "outputs": ["1 2\n", "13 14\n"]} | coding | 470 |
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 elements that have both a strictly smaller and a strictly greater element appear in nums.
Please complete the following python code precisely:
```python
class Soluti... | {"functional": "def check(candidate):\n assert candidate(nums = [11,7,2,15]) == 2\n assert candidate(nums = [-3,3,3,90]) == 2\n\n\ncheck(Solution().countElements)"} | coding | 74 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D array of strings equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] means that Ai / Bi = values[i].
Determine if there exists a contradiction in the equations... | {"functional": "def check(candidate):\n assert candidate(equations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"a\",\"c\"]], values = [3,0.5,1.5]) == False\n assert candidate(equations = [[\"le\",\"et\"],[\"le\",\"code\"],[\"code\",\"et\"]], values = [2,5,0.5]) == True\n\n\ncheck(Solution().checkContradictions)"} | coding | 171 |
Solve the programming task below in a Python markdown code block.
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his ... | {"inputs": ["B\n1 1 1\n1 1 1\n381\n", "B\n1 1 1\n1 1 1\n381\n", "B\n1 2 1\n1 1 1\n381\n", "BSC\n3 5 6\n7 3 9\n100\n", "BSC\n3 5 6\n7 3 9\n100\n", "BSC\n3 5 9\n7 3 9\n100\n", "BSC\n3 5 9\n7 3 5\n100\n", "BSC\n3 5 9\n7 3 5\n101\n"], "outputs": ["382\n", "382\n", "382\n", "10\n", "10\n", "11\n", "12\n", "12\n"]} | coding | 675 |
Solve the programming task below in a Python markdown code block.
You are playing euchre and you want to know the new score after finishing a hand. There are two teams and each hand consists of 5 tricks. The team who wins the majority of the tricks will win points but the number of points varies. To determine the numbe... | {"functional": "_inputs = [[[4, 0], 1, False, [2, 2, 2, 2, 2]], [[4, 2], 1, True, [2, 2, 2, 2, 2]], [[4, 4], 2, False, [2, 2, 2, 2, 2]], [[4, 6], 2, True, [2, 2, 2, 2, 2]], [[7, 2], 1, False, [1, 2, 2, 2, 2]], [[7, 4], 1, True, [1, 2, 2, 2, 2]], [[7, 6], 2, False, [1, 2, 2, 2, 2]], [[7, 7], 2, True, [1, 2, 2, 2, 2]], [... | coding | 278 |
Solve the programming task below in a Python markdown code block.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordin... | {"inputs": ["2\n0 0\n2 2\n", "2\n0 0\n0 3\n", "2\n0 1\n1 0\n", "2\n0 1\n1 0\n", "2\n0 0\n2 8\n", "2\n0 0\n2 4\n", "2\n0 0\n0 1\n", "2\n0 0\n2 2\n"], "outputs": ["4\n", "9\n", "1\n", "1\n", "64\n", "16\n", "1\n", "4\n"]} | coding | 317 |
Solve the programming task below in a Python markdown code block.
Manasa recently lost a bet to Amit. To settle the problem, they are playing a game:
They have N balls in front of them. Each ball, except the 1st ball, is numbered from 0 to 9. The 1st ball is numbered from 1 to 9.
Amit calculates all the subsequenc... | {"inputs": ["111\n", "123\n"], "outputs": ["147\n", "177\n"]} | coding | 572 |
Solve the programming task below in a Python markdown code block.
You are given an array A of size N.
A partitioning of the array A is the splitting of A into one or more non-empty contiguous subarrays such that each element of A belongs to exactly one of these subarrays.
Find the number of ways to partition A such t... | {"inputs": ["3\n3\n1 2 3\n4\n4 4 4 4\n5\n1 2 3 3 5"], "outputs": ["2\n1\n5\n"]} | coding | 552 |
Solve the programming task below in a Python markdown code block.
The summer is at its peak in Chefland. Chef is planning to purchase a water cooler to keep his room cool. He has two options available:
Rent a cooler at the cost of X coins per month.
Purchase a cooler for Y coins.
Chef wonders what is the maximum numb... | {"inputs": ["2\n5 12\n5 5"], "outputs": ["2\n0"]} | coding | 406 |
Solve the programming task below in a Python markdown code block.
Write a program that will calculate the number of trailing zeros in a factorial of a given number.
`N! = 1 * 2 * 3 * ... * N`
Be careful `1000!` has 2568 digits...
For more info, see: http://mathworld.wolfram.com/Factorial.html
## Examples
```pyth... | {"functional": "_inputs = [[0], [6], [30], [100], [1000], [100000], [1000000000]]\n_outputs = [[0], [1], [7], [24], [249], [24999], [249999998]]\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 isinstan... | coding | 208 |
Solve the programming task below in a Python markdown code block.
Given a string `S` and a character `C`, return an array of integers representing the shortest distance from the current character in `S` to `C`.
### Notes
* All letters will be lowercase.
* If the string is empty, return an empty array.
* If the charac... | {"functional": "_inputs = [['lovecodewars', 'e'], ['aaaaa', 'a'], ['aabbaabb', 'a'], ['aaaabbbb', 'b'], ['aaaaa', 'b'], ['lovecoding', ''], ['', '']]\n_outputs = [[[3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 4]], [[0, 0, 0, 0, 0]], [[0, 0, 1, 1, 0, 0, 1, 2]], [[4, 3, 2, 1, 0, 0, 0, 0]], [[]], [[]], [[]]]\nimport math\ndef _deep_... | coding | 234 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minim... | {"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]) == [[0,1],[2,3,4,5]]\n assert candidate(n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]) == [[],[0,1,2,3]]\n\n\ncheck(Solution().findCriticalAndPseudoCriticalEdges)"} | coding | 228 |
Solve the programming task below in a Python markdown code block.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so... | {"inputs": ["4 3\nijiem 6 578\ntaishn 6 1917\nshowa 62 3104\nheisfi 25 2431\n1126\n1917\n1988\n1 1\nuniwersalcemtury 170 2168\n3\n0 0", "4 3\nmeiji 4 18\ntaiohs 6 1917\nawohs 53 315\ngeisei 32 6266\n139\n1917\n1988\n1 1\nuniversalcentury 123 2168\n2611\n0 0", "4 3\nmeiji 10 704\ntaitho 6 1917\nasowh 62 1987\nheisei 33 ... | coding | 739 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums of length n.
The distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5]) == [-3,-1,1,3,5]\n assert candidate(nums = [3,2,3,4,2]) == [-2,-1,0,2,3]\n\n\ncheck(Solution().distinctDifferenceArray)"} | coding | 175 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ consisting of lowercase Latin letters. Let the length of $s$ be $|s|$. You may perform several operations on this string.
In one operation, you can choose some index $i$ and remove the $i$-th character of $s$ ($s_i$) if at lea... | {"inputs": ["1\na\n", "1\nt\n", "1\nz\n", "1\nt\n", "1\nz\n", "1\na\n", "1\ns\n", "1\ny\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 683 |
Solve the programming task below in a Python markdown code block.
You are given a three-digit positive integer N.
Determine whether N is a palindromic number.
Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
-----Constraints-----
- 100≤N≤999
- N is an integer.
... | {"inputs": ["559", "676", "665", "179", "129", "371", "344", "158"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 160 |
Solve the programming task below in a Python markdown code block.
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.
Note t... | {"inputs": ["4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n", "3 1000000000\n-5 -1 1\n", "1 14751211\n847188590\n", "2 1000000000\n-14348867 1760823\n", "10 5\n31 36 43 47 48 50 56 69 71 86\n", "10 50\n1 4 20 27 65 79 82 83 99 100\n"], "outputs": ["4\n", "2\n", "1\n", "1\n", "0\n", "0\n", "2\n", "25\n"]} | coding | 375 |
Solve the programming task below in a Python markdown code block.
# Definition
An **_element is leader_** *if it is greater than The Sum all the elements to its right side*.
____
# Task
**_Given_** an *array/list [] of integers* , **_Find_** *all the **_LEADERS_** in the array*.
___
# Notes
* **_Array/list_** siz... | {"functional": "_inputs = [[[1, 2, 3, 4, 0]], [[16, 17, 4, 3, 5, 2]], [[-1, -29, -26, -2]], [[-36, -12, -27]], [[5, 2]], [[0, -1, -29, 3, 2]]]\n_outputs = [[[4]], [[17, 5, 2]], [[-1]], [[-36, -12]], [[5, 2]], [[0, -1, 3, 2]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, floa... | coding | 647 |
Solve the programming task below in a Python markdown code block.
Little09 and his friends are playing a game. There are $n$ players, and the temperature value of the player $i$ is $i$.
The types of environment are expressed as $0$ or $1$. When two players fight in a specific environment, if its type is $0$, the playe... | {"inputs": ["2\n4\n001\n4\n101\n"], "outputs": ["1 1 3 \n1 2 3 \n"]} | coding | 552 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time.
You a... | {"functional": "def check(candidate):\n assert candidate(n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]) == [1,2]\n assert candidate(n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]) == [0,1]\n\n\ncheck(Solution().countServers)"} | coding | 183 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.
You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[ro... | {"functional": "def check(candidate):\n assert candidate(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]) == [1,0]\n assert candidate(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]) == [1,1]\n assert candidate(n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]) == [1,1,0]\n\n\ncheck(Solut... | coding | 298 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has 3 bags that she wants to take on a flight. They weigh A, B, and C kgs respectively. She wants to check-in exactly two of these bags and carry the rem... | {"inputs": ["3\n1 1 1 15 5\n8 7 6 15 5\n8 5 7 15 6"], "outputs": ["YES\nNO\nYES"]} | coding | 505 |
Solve the programming task below in a Python markdown code block.
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper... | {"inputs": ["3\n1 1000 1\n", "6\n3 2 1 2 3 3\n"], "outputs": ["0\n", "8\n"]} | coding | 549 |
Solve the programming task below in a Python markdown code block.
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not thre... | {"inputs": ["1\n3\n", "1\n2\n", "1\n3\n", "1\n2\n", "1\n1\n", "2\n1\n2\n", "2\n3\n3\n", "2\n2\n1\n"], "outputs": ["NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | coding | 441 |
Solve the programming task below in a Python markdown code block.
Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized **only** if the original word was capitalized (known as Upper Camel Case, also often referred to as... | {"functional": "_inputs = [[''], ['the_stealth_warrior'], ['The-Stealth-Warrior'], ['A-B-C']]\n_outputs = [[''], ['theStealthWarrior'], ['TheStealthWarrior'], ['ABC']]\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_to... | coding | 137 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:
For a query of type 1, queries[i] = [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nu... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]) == [3]\n assert candidate(nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]) == [5]\n\n\ncheck(Solution().handleQuery)"} | coding | 249 |
Solve the programming task below in a Python markdown code block.
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it... | {"inputs": ["4\n", "2\n", "8\n", "3\n", "1\n", "7\n", "9\n", "6\n"], "outputs": ["0 1\n", "0 1\n", "0 3\n", "0 1\n", "0 0\n", "0 2\n", "0 3\n", "0 2\n"]} | coding | 201 |
Solve the programming task below in a Python markdown code block.
The robot is placed in the top left corner of a grid, consisting of $n$ rows and $m$ columns, in a cell $(1, 1)$.
In one step, it can move into a cell, adjacent by a side to the current one:
$(x, y) \rightarrow (x, y + 1)$;
$(x, y) \rightarrow (x + 1,... | {"inputs": ["1\n2 3 1 3 0\n", "1\n2 3 1 3 1\n", "1\n776 123 5 7 3\n", "1\n1000 1000 99 99 2\n", "1\n1000 1000 99 9 21\n", "1\n1000 1000 10 10 0\n", "2\n2 3 1 3 0\n2 3 1 3 1\n", "2\n3 3 2 2 1\n5 5 3 3 1\n"], "outputs": ["3\n", "-1\n", "897\n", "1998\n", "1998\n", "1998\n", "3\n-1\n", "-1\n8\n"]} | coding | 636 |
Solve the programming task below in a Python markdown code block.
Chef has the binary representation S of a number X with him. He can modify the number by applying the following operation exactly once:
Make X := X \oplus \lfloor \frac{X}{2^{Y}} \rfloor, where (1 ≤ Y ≤ |S|) and \oplus denotes the [bitwise XOR operation]... | {"inputs": ["4\n2\n10\n2\n11\n3\n101\n3\n110\n"], "outputs": ["1\n2\n1\n2\n"]} | coding | 683 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:
Each element p[i][j] is calculated as the produ... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,2],[3,4]]) == [[24,12],[8,6]]\n assert candidate(grid = [[12345],[2],[1]]) == [[2],[0],[0]]\n\n\ncheck(Solution().constructProductMatrix)"} | coding | 146 |
Solve the programming task below in a Python markdown code block.
You are given an array A of length N.
You can perform the following operation on the array, as long as it has more than one element:
Choose any two adjacent elements, remove them from the array and insert their sum at that position.
Formally, if the cu... | {"inputs": ["4\n3\n5 2 3\n2\n6 9\n5\n3 6 5 4 9\n3\n3 3 3\n"], "outputs": ["1\n1\n2\n0\n"]} | coding | 616 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).
The distance between two points on the X-Y plane is the Eucli... | {"functional": "def check(candidate):\n assert candidate(points = [[1,3],[-2,2]], k = 1) == [[-2,2]]\n assert candidate(points = [[3,3],[5,-1],[-2,4]], k = 2) == [[3,3],[-2,4]]\n\n\ncheck(Solution().kClosest)"} | coding | 163 |
Solve the programming task below in a Python markdown code block.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, t... | {"inputs": ["3", "4"], "outputs": ["2 5 63", "2 5 20 63"]} | coding | 362 |
Solve the programming task below in a Python markdown code block.
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain.
Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.
Constraints
You can assume that:
* $ -100 \leq x_1, y_1... | {"inputs": ["0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0", "0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.8224818410475855 1.0 4.0 5.0 3.0 -1.0 3.0", "0.4580529168787624 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.8224818410475855 1.0 4.0 5.0 3.0 -1.0 3.0", "0.4580529168787624 0.0 2.0 0.842157591240854 2.0 2.0 1.... | coding | 349 |
Solve the programming task below in a Python markdown code block.
Tom is very fond of adding values , so what he does whenever he gets a value he adds all its digits and forms a new value and checks it whether it has become a single digit or not and if it does not even becomes a single digit he apply the operation agai... | {"inputs": ["72\n147\n1009\n994\n5564\n9999\n1547\n18894\n1475\n5554\n8457\n32254\n14562\n18995\n5624\n65412\n1235\n2356\n1113\n1555\n4631\n8641\n2945\n8466\n3214\n4412\n6594\n3120\n55\n964\n1584\n6645\n3472\n12\n6642\n34454\n4851\n6524\n6314\n7516\n9547\n8714\n8214\n6425\n7132\n5621\n1203\n2350\n563\n1223\n4584\n6424\... | coding | 242 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.
If it is possible, return any [i, j] with i +... | {"functional": "def check(candidate):\n assert candidate(arr = [1,0,1,0,1]) == [0,3]\n assert candidate(arr = [1,1,0,1,1]) == [-1,-1]\n assert candidate(arr = [1,1,0,0,1]) == [0,2]\n\n\ncheck(Solution().threeEqualParts)"} | coding | 254 |
Solve the programming task below in a Python markdown code block.
You are given an H \times W grid. The square at the top-left corner will be represented by (0, 0), and the square at the bottom-right corner will be represented by (H-1, W-1).
Of those squares, N squares (x_1, y_1), (x_2, y_2), ..., (x_N, y_N) are paint... | {"inputs": ["2 3\n1\n0 1", "2 3\n1\n0 2", "2 4\n1\n0 1", "2 4\n0\n0 1", "4 4\n0\n0 1", "6 4\n0\n0 1", "3 3\n1\n0 1", "4 3\n1\n0 1"], "outputs": ["20", "16", "48", "56", "320", "920", "59", "130"]} | coding | 545 |
Solve the programming task below in a Python markdown code block.
# Task
You are given integer `n` determining set S = {1, 2, ..., n}. Determine if the number of k-element subsets of S is `ODD` or `EVEN` for given integer k.
# Example
For `n = 3, k = 2`, the result should be `"ODD"`
In this case, we have 3 2-ele... | {"functional": "_inputs = [[3, 2], [2, 1], [1, 1], [20, 10], [48, 12]]\n_outputs = [['ODD'], ['EVEN'], ['ODD'], ['EVEN'], ['EVEN']]\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, ... | coding | 305 |
Solve the programming task below in a Python markdown code block.
Xander Cage has a list of cities he can visit on his new top-secret mission. He represents each city as a tuple of $(latitude,longitude,height,points)$. The values of $latitude$, $longitude$, and $height$ are distinct across all cities.
We define a miss... | {"inputs": ["3 1 1\n1 1 1 3\n2 2 2 -1\n3 3 3 3\n"], "outputs": ["5\n"]} | coding | 673 |
Solve the programming task below in a Python markdown code block.
Aureole the Techno-cultural fest of JEC thought of conducting a workshop on big data, as the topic is hot everyone wants to take part but due to limited seats in the Jashan Auditorium there is a selection criteria, a problem is given.
the problem states ... | {"inputs": ["1\naaabb"], "outputs": ["-40"]} | coding | 336 |
Solve the programming task below in a Python markdown code block.
*Mario has reached Bowser's Castle and is inches away from rescuing Princess Peach. He has to answer the following problem at the gate to be allowed to enter. Can you help him?*
Let S(M) denote the set of all [prime] [factors] of M.
Given two positive... | {"inputs": ["3\n21 63\n72 72\n25 20"], "outputs": ["YES\nYES\nNO"]} | coding | 451 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of n integers arr.
The interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|... | {"functional": "def check(candidate):\n assert candidate(arr = [2,1,3,1,2,3,3]) == [4,2,7,2,4,4,5]\n assert candidate(arr = [10,5,10,10]) == [5,0,3,4]\n\n\ncheck(Solution().getDistances)"} | coding | 145 |
Solve the programming task below in a Python markdown code block.
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and a_{i} is the length of i-th segment. No two seg... | {"inputs": ["1 1\n1\n", "1 2\n1\n", "1 6\n5\n", "1 5\n2\n", "1 3\n1\n", "1 7\n5\n", "1 1\n3\n", "1 3\n2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n).
Little penguin Polo loves walking aroun... | {"inputs": ["8 5\n", "9 8\n", "2 2\n", "2 1\n", "8 8\n", "1 1\n", "3 3\n", "8 1\n"], "outputs": ["16875\n", "2097152\n", "2\n", "1\n", "2097152\n", "1\n", "9\n", "823543\n"]} | coding | 418 |
Solve the programming task below in a Python markdown code block.
You know that 1 kg of pulp can be used to make 1000 pages and 1 notebook consists of 100 pages.
Suppose a notebook factory receives N kg of pulp, how many notebooks can be made from that?
------ Input Format ------
- First line will contain T, the n... | {"inputs": ["3\n1\n100\n50\n"], "outputs": ["10\n1000\n500\n"]} | coding | 319 |
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 an integer x.
Find the minimum absolute difference between two elements in the array that are at least x indices apart.
In other words, find two indices i and j such th... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,4], x = 2) == 0\n assert candidate(nums = [5,3,2,10,15], x = 1) == 1\n assert candidate(nums = [1,2,3,4], x = 3) == 3\n\n\ncheck(Solution().minAbsoluteDifference)"} | coding | 139 |
Solve the programming task below in a Python markdown code block.
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping su... | {"inputs": ["aaa\na\nb\n", "cumurcumur\num\ncur\n", "cumurcumur\nul\ncur\n", "abbbaaccca\nba\naca\n", "cunurcumur\nul\ncur\n", "abbbaaccca\nab\naca\n", "xxxbbbcccoca\nca\ncb\n", "xxxbbbcccoca\nca\nca\n"], "outputs": ["aaa\n", "umumcurcur\n", "curcurmmuu", "babaacabcc", "curcurmnuu", "ababacabcc\n", "cacbcbcboxxx\n", "c... | coding | 390 |
Solve the programming task below in a Python markdown code block.
Ignoring the air resistance, velocity of a freely falling object $v$ after $t$ seconds and its drop $y$ in $t$ seconds are represented by the following formulas:
$ v = 9.8 t $
$ y = 4.9 t^2 $
A person is trying to drop down a glass ball and check whet... | {"inputs": ["25.4\n25.4", "26.000450676027395\n25.4", "26.601491934975797\n25.4", "44.72115406668142\n44.101745823639", "38.4955310270825\n37.15642943049945", "60.63345250628777\n63.4141206664841", "73.9111092448129\n75.52007039121814", "35.31260445827307\n34.47301494550142"], "outputs": ["8\n8", "8\n8\n", "9\n8\n", "2... | coding | 262 |
Solve the programming task below in a Python markdown code block.
As a strict big brother, I do limit my young brother Vasya on time he spends on computer games. I define a prime-time as a time period till which Vasya have a permission to play computer games. I specify start hour and end hour as pair of integers.
I ne... | {"functional": "_inputs = [[9, 10, 11], [12, 12, 13], [13, 10, 15], [14, 9, 14], [15, 8, 12], [20, 21, 1], [21, 21, 6], [17, 15, 3], [0, 22, 1], [1, 22, 1], [3, 23, 2], [20, 0, 23], [14, 2, 9], [9, 20, 11], [23, 23, 0], [11, 2, 9], [0, 20, 23], [4, 0, 3], [6, 2, 10]]\n_outputs = [[False], [True], [True], [False], [Fals... | coding | 216 |
Solve the programming task below in a Python markdown code block.
Your work is to write a method that takes a value and an index, and returns the value with the bit at given index flipped.
The bits are numbered from the least significant bit (index 1).
Example:
```python
flip_bit(15, 4) == 7 # 15 in binary is 1111, a... | {"functional": "_inputs = [[0, 16], [2147483647, 31], [127, 8]]\n_outputs = [[32768], [1073741823], [255]]\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(... | coding | 246 |
Solve the programming task below in a Python markdown code block.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the... | {"inputs": ["300 0\n", "5 100\n", "5 100\n", "4 100\n", "360 0\n", "7 100\n", "700 0\n", "6 100\n"], "outputs": ["300\n", "5\n", "5\n", "4\n", "360\n", "7\n", "700\n", "6\n"]} | coding | 224 |
Solve the programming task below in a Python markdown code block.
The enmity between Logan and Donald Pierce never ceases to exist.
However, once Logan and Donald came face to face. Donald got agitated and asked Logan to prove his true mettle by solving a puzzle.
Logan is provided an array Arr[] of N integers. ... | {"inputs": ["1\n4\n1 1 1 1"], "outputs": ["0"]} | coding | 349 |
Solve the programming task below in a Python markdown code block.
Write function bmi that calculates body mass index (bmi = weight / height ^ 2).
if bmi <= 18.5 return "Underweight"
if bmi <= 25.0 return "Normal"
if bmi <= 30.0 return "Overweight"
if bmi > 30 return "Obese"
Also feel free to reuse/extend the follo... | {"functional": "_inputs = [[50, 1.8], [80, 1.8], [90, 1.8], [110, 1.8], [50, 1.5]]\n_outputs = [['Underweight'], ['Normal'], ['Overweight'], ['Obese'], ['Normal']]\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... | coding | 103 |
Solve the programming task below in a Python markdown code block.
Your colleagues have been looking over you shoulder. When you should have been doing your boring real job, you've been using the work computers to smash in endless hours of codewars.
In a team meeting, a terrible, awful person declares to the group that... | {"functional": "_inputs = [[{'tim': 0, 'jim': 2, 'randy': 0, 'sandy': 7, 'andy': 0, 'katie': 5, 'laura': 1, 'saajid': 2, 'alex': 3, 'john': 2, 'mr': 0}, 'laura'], [{'tim': 1, 'jim': 3, 'randy': 9, 'sandy': 6, 'andy': 7, 'katie': 6, 'laura': 9, 'saajid': 9, 'alex': 9, 'john': 9, 'mr': 8}, 'katie'], [{'tim': 2, 'jim': 4,... | coding | 366 |
Solve the programming task below in a Python markdown code block.
We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s_1, s_2, ..., s_{k}. After that, in each of these strings we swapped exactly two characters (the characters we swapped could b... | {"inputs": ["1 2\nyu\n", "1 2\nyu\n", "1 3\nvts\n", "1 3\nvts\n", "2 2\nnm\nnm\n", "2 2\nab\ncd\n", "2 2\nac\nca\n", "2 2\nnm\nnm\n"], "outputs": ["uy\n", "uy\n", "tvs\n", "tvs\n", "mn\n", "-1\n", "-1\n", "mn\n"]} | coding | 448 |
Solve the programming task below in a Python markdown code block.
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, .... | {"inputs": ["2 2\n", "9 3\n", "1 2\n", "2 3\n", "4 4\n", "4 4\n", "1 2\n", "4 4\n"], "outputs": ["3\n", "13\n", "1\n", "2\n", "5\n", "5\n", "1\n", "5\n"]} | coding | 308 |
Solve the programming task below in a Python markdown code block.
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights.
You... | {"inputs": ["1 0 0 0\n0\n", "1 0 0 0\n1\n", "1 0 0 1\n1\n", "2 0 0 0\n1 1\n", "2 0 0 0\n2 1\n", "2 0 0 0\n0 1\n", "2 0 0 1\n0 1\n", "2 0 0 1\n-1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 440 |
Solve the programming task below in a Python markdown code block.
Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square... | {"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n10\n01\n", "2\n10\n01\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1", "1", "1\n", "1"]} | coding | 378 |
Solve the programming task below in a Python markdown code block.
# Task
We know that some numbers can be split into two primes. ie. `5 = 2 + 3, 10 = 3 + 7`. But some numbers are not. ie. `17, 27, 35`, etc..
Given a positive integer `n`. Determine whether it can be split into two primes. If yes, return the maximum pr... | {"functional": "_inputs = [[1], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [20], [100]]\n_outputs = [[0], [0], [4], [6], [9], [10], [15], [14], [25], [0], [35], [91], [2491]]\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, re... | coding | 311 |
Solve the programming task below in a Python markdown code block.
You will be given a string.
You need to return an array of three strings by gradually pulling apart the string.
You should repeat the following steps until the string length is 1:
a) remove the final character from the original string, add to solutio... | {"functional": "_inputs = [['reusetestcasesbitcointakeovertheworldmaybewhoknowsperhaps'], ['turnsoutrandomtestcasesareeasierthanwritingoutbasicones'], ['exampletesthere'], ['letstalkaboutjavascriptthebestlanguage'], ['iwanttotraveltheworldwritingcodeoneday'], ['letsallgoonholidaysomewhereverycold']]\n_outputs = [[['spa... | coding | 164 |
Solve the programming task below in a Python markdown code block.
Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.
In general, different values of HP are grouped into $4$ categories: Category $A$ if HP is in th... | {"inputs": ["6\n", "4\n", "5\n", "8\n", "3\n", "9\n", "0\n", "2\n"], "outputs": ["1 B\n", "1 A\n", "0 A\n", "1 A\n", "2 A\n", "0 A\n", "1 A\n", "1 B\n"]} | coding | 640 |
Solve the programming task below in a Python markdown code block.
Sebi lives in Chefland where the government is extremely corrupt that usually makes fool out of public by announcing eye catching but non-sustainable schemes. Recently there was a move to increase tourism in the country that was highly lauded. Sebi wants... | {"inputs": ["3\n1 2 3\n1 3 2"], "outputs": ["2.333333"]} | coding | 715 |
Solve the programming task below in a Python markdown code block.
-----
HALLOWEEN EVE
-----
In some other world, today is Halloween Eve.There are N trees planted in Mr. Smith’s
garden. The height of the i-th tree (1≤i≤N) is h i meters.
He decides to choose K trees from these trees and decorate them with electric light... | {"inputs": ["5 3\n10\n15\n11\n14\n12"], "outputs": ["2"]} | coding | 307 |
Solve the programming task below in a Python markdown code block.
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as ... | {"inputs": ["0\n", "3\n", "8\n", "9\n", "1\n", "3\n", "5\n", "9\n"], "outputs": ["0", "1", "1", "1", "1", "1", "1", "1\n"]} | coding | 402 |
Solve the programming task below in a Python markdown code block.
For every good kata idea there seem to be quite a few bad ones!
In this kata you need to check the provided array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I sm... | {"functional": "_inputs = [[['bad', 'bad', 'bad']], [['good', 'bad', 'bad', 'bad', 'bad']], [['good', 'bad', 'bad', 'bad', 'bad', 'good', 'bad', 'bad', 'good']]]\n_outputs = [['Fail!'], ['Publish!'], ['I smell a series!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):... | coding | 142 |
Solve the programming task below in a Python markdown code block.
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is as... | {"inputs": ["3 3\n", "7 4\n", "2 8\n", "4 4\n", "8 8\n", "2 2\n", "6 1\n", "4 5\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | coding | 531 |
Solve the programming task below in a Python markdown code block.
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by s... | {"inputs": ["1 2 3 3\nw\n", "1 2 6 3\nw\n", "1 2 6 5\nw\n", "1 3 6 5\nw\n", "1 3 3 3\nw\n", "1 3 6 3\nw\n", "4 2 3 16\nwwhw\n", "4 2 3 14\nwwhw\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "3\n", "3\n"]} | coding | 596 |
Solve the programming task below in a Python markdown code block.
Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the elemen... | {"inputs": ["1\n8", "1\n1", "1\n0", "1\n2", "1\n6", "1\n18", "1\n31", "1\n10"], "outputs": ["8\n", "1\n", "0\n", "2\n", "6\n", "18\n", "31\n", "10"]} | coding | 406 |
Solve the programming task below in a Python markdown code block.
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly ... | {"inputs": ["[\n", "|\n", "]\n", ":\n", "b\n", "c\n", "s\n", "z\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 342 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.
The string is called alternating if no two adjacent characters are equal. For example, the strin... | {"functional": "def check(candidate):\n assert candidate(s = \"111000\") == 1\n assert candidate(s = \"010\") == 0\n assert candidate(s = \"1110\") == -1\n\n\ncheck(Solution().minSwaps)"} | coding | 134 |
Solve the programming task below in a Python markdown code block.
Authors have come up with the string $s$ consisting of $n$ lowercase Latin letters.
You are given two permutations of its indices (not necessary equal) $p$ and $q$ (both of length $n$). Recall that the permutation is the array of length $n$ which contai... | {"inputs": ["3 2\n1 2 3\n1 3 2\n", "3 2\n3 1 2\n3 2 1\n", "3 2\n3 1 2\n3 2 1\n", "3 3\n3 1 2\n3 2 1\n", "3 4\n1 2 3\n1 3 2\n", "3 6\n3 1 2\n3 2 1\n", "3 6\n3 1 2\n3 1 2\n", "3 7\n3 1 2\n3 2 1\n"], "outputs": ["YES\nabb\n", "YES\nbba\n", "YES\nbba\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 506 |
Solve the programming task below in a Python markdown code block.
collections.deque()
A deque is a double-ended queue. It can be used to add or remove elements from both ends.
Deques support thread safe, memory efficient appends and pops from either side of the deque with approximately the same $O(1)$ performance i... | {"inputs": ["6\nappend 1\nappend 2\nappend 3\nappendleft 4\npop\npopleft\n"], "outputs": ["1 2\n"]} | coding | 479 |
Solve the programming task below in a Python markdown code block.
An array is called `zero-balanced` if its elements sum to `0` and for each positive element `n`, there exists another element that is the negative of `n`. Write a function named `ìsZeroBalanced` that returns `true` if its argument is `zero-balanced` arra... | {"functional": "_inputs = [[[3]], [[-3]], [[0, 0, 0, 0, 0, 0]], [[0, 1, -1]], [[]], [[3, -2, -1]], [[0]], [[1, 1, -2]], [[-1, 1, -2, 2, -2, -2, -4, 4]], [[0, 0, 0, 0, 0]]]\n_outputs = [[False], [False], [True], [True], [False], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ... | coding | 119 |
Solve the programming task below in a Python markdown code block.
In this kata, your job is to return the two distinct highest values in a list. If there're less than 2 unique values, return as many of them, as possible.
The result should also be ordered from highest to lowest.
Examples:
```
[4, 10, 10, 9] => [10,... | {"functional": "_inputs = [[[]], [[15]], [[15, 20, 20, 17]]]\n_outputs = [[[]], [[15]], [[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=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != l... | coding | 134 |
Solve the programming task below in a Python markdown code block.
You are given a connected undirected weighted graph consisting of $n$ vertices and $m$ edges.
You need to print the $k$-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ a... | {"inputs": ["2 1 1\n1 2 123456789\n", "2 1 1\n1 2 123456789\n", "6 10 5\n2 5 1\n5 3 9\n6 2 2\n1 3 1\n5 1 8\n6 5 10\n1 6 5\n6 4 6\n3 6 2\n3 4 5\n", "6 10 5\n2 5 1\n5 3 9\n6 2 2\n1 3 1\n5 1 8\n6 5 10\n1 6 5\n6 4 6\n3 6 2\n3 4 5\n", "7 15 18\n2 6 3\n5 7 4\n6 5 4\n3 6 9\n6 7 7\n1 6 4\n7 1 6\n7 2 1\n4 3 2\n3 2 8\n5 3 6\n2 5... | coding | 678 |
Solve the programming task below in a Python markdown code block.
Chef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only.
Chef's canvas is N millimeters ... | {"inputs": ["3\n4\n1 5 5 5\n3\n1 1 1 5\n3\n5 5 2", "3\n4\n1 5 5 5\n3\n1 2 1 5\n3\n5 5 2", "3\n4\n1 5 5 6\n4\n1 1 1 5\n3\n5 5 2", "3\n4\n1 5 5 5\n3\n1 2 1 5\n3\n5 5 3", "3\n4\n1 5 5 5\n3\n1 2 1 5\n3\n5 1 3", "3\n4\n1 5 5 5\n3\n1 2 1 5\n3\n1 1 3", "3\n4\n2 5 5 5\n3\n1 2 1 5\n3\n1 1 3", "3\n4\n1 5 5 6\n3\n1 1 1 5\n3\n5 5 ... | coding | 679 |
Solve the programming task below in a Python markdown code block.
You're given a string $\mbox{S}$ of $N$ characters. It's known that the string consists of lowercase Latin letters. The string is generated randomly. That means that every symbol is chosen randomly and independently from others from the set {'a', 'b', ..... | {"inputs": ["4 4 \naaab\n1 a\n2 b\n3 c\n4 d\n"], "outputs": ["7\n7\n9\n10\n"]} | coding | 712 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.
In one move, we may choose two adjacent nodes and move one coi... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,0,0])) == 2\n assert candidate(root = tree_node([0,3,0])) == 3\n\n\ncheck(Solution().distributeCoins)"} | coding | 185 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
You are given an array A consisting of N integers and Q queries. Each query is described by two integers L and R. For each query, output the number of tuples ... | {"inputs": ["1\n6 3\n1 2 3 4 5 6\n1 3\n2 5\n1 6"], "outputs": ["1\n2\n10"]} | coding | 491 |
Solve the programming task below in a Python markdown code block.
You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full number, he has to start counting them from 1.
As a good parent, you will sit and count with him... | {"functional": "_inputs = [[5], [3], [9], [10], [20]]\n_outputs = [[[1, 2, 3, 4, 5]], [[1, 2, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin... | coding | 174 |
Solve the programming task below in a Python markdown code block.
In this kata, you should calculate type of triangle with three given sides ``a``, ``b`` and ``c`` (given in any order).
If all angles are less than ``90°``, this triangle is ``acute`` and function should return ``1``.
If one angle is strictly ``90°``, ... | {"functional": "_inputs = [[1, 2, 3], [5.5, 4.5, 10], [7, 3, 2], [5, 10, 5], [3, 3, 0], [3, 3, 1], [5, 5, 5], [122.14, 222.11, 250], [8, 5, 7], [100000, 100005, 111111], [3, 4, 5], [21, 220, 221], [8.625, 33.625, 32.5], [65, 56, 33], [68000, 285000, 293000], [2, 4, 5], [105, 100, 6], [102, 200, 250], [65, 55, 33], [7, ... | coding | 412 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
You are given a tree of $N$ nodes rooted at node $1$. Each node $u$ initially has a positive value $a_{u}$ associated with it.
You randomly choose one node i... | {"inputs": ["3\n1\n1\n4\n1 2\n2 3\n2 4\n1 1 1 2\n7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n1 2 3 4 1 2 1\n"], "outputs": ["1\n4\n14\n"]} | coding | 716 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A parentheses string is valid if and only if:
It is the empty string,
It can be written as AB (A concatenated with B), where A and B are valid strings, or
It can be written as (A), where A is a valid string.
You are... | {"functional": "def check(candidate):\n assert candidate(s = \"())\") == 1\n assert candidate(s = \"(((\") == 3\n\n\ncheck(Solution().minAddToMakeValid)"} | coding | 169 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian] and [Mandarin Chinese].
You are given two integers A, B. You have to choose an integer X in the range [minimum(A, B), maximum(A, B)] such that:
\Big \lceil \frac{B - X}{2} \Big \rceil + \Big \lceil \frac{X - A}{2} ... | {"inputs": ["3\n2 2\n1 11\n13 6\n"], "outputs": ["0\n6\n-3"]} | coding | 601 |
Solve the programming task below in a Python markdown code block.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor... | {"inputs": ["8 1 1\n", "1 1 1\n", "1 1 1\n", "1 1 0\n", "8 1 2\n", "2 1 0\n", "8 1 0\n", "4 1 0\n"], "outputs": ["4\n", "1\n", "1", "1", "6", "1", "1", "1"]} | coding | 249 |
Solve the programming task below in a Python markdown code block.
The *fuel economy* of a car is the distance which it can travel on one litre of fuel.
The base fuel economy (i.e, its fuel economy when there is only one person - the driver - in the car) of a certain car is M kilometres per litre. It was also observed ... | {"inputs": ["3\n5 10 20\n1 6 10\n4 6 1"], "outputs": ["120\n60\n3"]} | coding | 542 |
Solve the programming task below in a Python markdown code block.
Recently, Mishka started noticing that his keyboard malfunctions — maybe it's because he was playing rhythm games too much. Empirically, Mishka has found out that every other time he presses a key, it is registered as if the key was pressed twice. For ex... | {"inputs": ["4\n4\nossu\n2\naa\n6\naddonn\n3\nqwe\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | coding | 600 |
Solve the programming task below in a Python markdown code block.
Given a string, s, return a new string that orders the characters in order of frequency.
The returned string should have the same number of characters as the original string.
Make your transformation stable, meaning characters that compare equal shou... | {"functional": "_inputs = [['Hello world'], [''], ['wubz dermatoglyphics'], ['Four score and seven years ago'], ['Hello He worldwrd']]\n_outputs = [['lllooHe wrd'], [''], ['wubz dermatoglyphics'], [' eeeeorsorasarsaonnFucdvyg'], ['lllHeo He wordwrd']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | coding | 305 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
Naveej is from a tribe that speaks some weird language - their alphabet consists of N distinct characters.
He has an array A = [A_{1}, A_{2}, \dots, A_{N}], where A_{i... | {"inputs": ["2\n1\n4\n3\n4 3 1\n"], "outputs": ["0\n1\n"]} | coding | 679 |
Solve the programming task below in a Python markdown code block.
The [Chinese zodiac](https://en.wikipedia.org/wiki/Chinese_zodiac) is a repeating cycle of 12 years, with each year being represented by an animal and its reputed attributes. The lunar calendar is divided into cycles of 60 years each, and each year has a... | {"functional": "_inputs = [[1965], [1938], [1998], [2016], [1924], [1968], [2162], [6479], [3050], [6673], [6594], [9911], [2323], [3448], [1972]]\n_outputs = [['Wood Snake'], ['Earth Tiger'], ['Earth Tiger'], ['Fire Monkey'], ['Wood Rat'], ['Earth Monkey'], ['Water Dog'], ['Earth Goat'], ['Metal Dog'], ['Water Rooster... | coding | 365 |
Solve the programming task below in a Python markdown code block.
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely l... | {"inputs": ["4", "0", "1", "2", "7", "5", "8", "6"], "outputs": ["8\n", "1\n", "2\n", "4\n", "14\n", "10\n", "18\n", "13\n"]} | coding | 201 |
Solve the programming task below in a Python markdown code block.
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first... | {"inputs": ["1\n9124\n", "1\n9602\n", "1\n16966\n", "1\n52232\n", "1\n13891\n", "1\n72551\n", "1\n74714\n", "1\n25335\n"], "outputs": ["4\n", "9\n", "1\n", "5\n", "9\n", "1\n", "5\n", "1\n"]} | coding | 567 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A split of an integer array is good if:
The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.
The sum of the elements in left is less than or equal to ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,1]) == 1\n assert candidate(nums = [1,2,2,2,5,0]) == 3\n assert candidate(nums = [3,2,1]) == 0\n\n\ncheck(Solution().waysToSplit)"} | coding | 165 |
Solve the programming task below in a Python markdown code block.
To destroy humanity, The Monster Association sent $n$ monsters to Earth's surface. The $i$-th monster has health $h_i$ and power $p_i$.
With his last resort attack, True Spiral Incineration Cannon, Genos can deal $k$ damage to all monsters alive. In oth... | {"inputs": ["1\n2 1\n1000000000 1\n1 1000000000\n", "3\n6 7\n18 5 13 9 10 1\n2 7 2 1 2 6\n3 4\n5 5 5\n4 4 4\n3 2\n2 1 3\n1 1 1\n"], "outputs": ["NO\n", "YES\nNO\nYES\n"]} | coding | 642 |
Solve the programming task below in a Python markdown code block.
It is holi festival, festival of colors. Devu is having fun playing holi and is throwing balloons with his girlfriend Glynis. Police saw this mischief and tried arresting his girlfriend, Devu being a mathematician asked police not to arrest his girlfrien... | {"inputs": ["1\n2 1 2 2 15\n"], "outputs": ["1\n"]} | coding | 371 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.