task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Given an array $a$ of length $n$ and an integer $k$, you are tasked to find any two numbers $l$ and $r$ ($l \leq r$) such that:
For each $x$ $(l \leq x \leq r)$, $x$ appears in $a$ at least $k$ times (i.e. $k$ or more array elements are equal to $x$).
... | {"inputs": ["1\n1 1\n114514\n", "4\n7 2\n11 11 12 13 13 14 14\n5 1\n6 3 5 2 1\n6 4\n4 3 4 3 3 4\n14 2\n1 1 2 2 2 3 3 3 3 4 4 4 4 4\n"], "outputs": ["114514 114514\n", "13 14\n1 3\n-1\n1 4\n"]} | 679 | 148 |
coding | 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"]} | 552 | 47 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.
Return the length of n. If there is no such n, return -1.
Note... | {"functional": "def check(candidate):\n assert candidate(k = 1) == 1\n assert candidate(k = 2) == -1\n assert candidate(k = 3) == 3\n\n\ncheck(Solution().smallestRepunitDivByK)"} | 118 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered bot... | {"inputs": ["1 2 1\n1\n2 1\n", "1 2 1\n1\n2 1\n", "1 2 1\n2\n2 1\n", "1 2 31\n1\n1 2\n", "1 2 23\n1\n1 2\n", "1 2 31\n1\n1 2\n", "2 2 2\n2 1\n1 2\n", "2 2 2\n2 1\n1 2\n"], "outputs": ["1\n", "1\n", "2\n", "62\n", "46\n", "\n62\n", "2\n", "2\n"]} | 660 | 161 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.
Given an array changed, return original... | {"functional": "def check(candidate):\n assert candidate(changed = [1,3,4,2,6,8]) == [1,3,4]\n assert candidate(changed = [6,3,0,1]) == []\n assert candidate(changed = [1]) == []\n\n\ncheck(Solution().findOriginalArray)"} | 119 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
The Physics teacher in Tanu's class is teaching concepts of a bouncing ball. The rubber ball that she is using has the property that if the ball is dropped from height H then, it bounces back to... | {"inputs": ["2\n3 2\n2 2 2\n3 2\n2 1 4"], "outputs": ["3\n3"]} | 534 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could p... | {"inputs": ["2\n2 4\n6 8", "2\n4 4\n6 8", "2\n2 7\n6 8", "2\n2 9\n3 7", "2\n1 0\n3 4", "2\n2 9\n4 7", "2\n1 0\n1 4", "2\n1 5\n3 42"], "outputs": ["6\n13\n", "1\n13\n", "24\n13\n", "38\n23\n", "0\n5\n", "38\n19\n", "0\n7\n", "13\n736\n"]} | 377 | 154 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.
Return the sorted array.
Please co... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,2,2,3]) == [3,1,1,2,2,2]\n assert candidate(nums = [2,3,1,3,2]) == [1,3,3,2,2]\n assert candidate(nums = [-1,1,-6,4,5,-6,1,4,1]) == [5,-1,4,4,-6,-6,1,1,1]\n\n\ncheck(Solution().frequencySort)"} | 89 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.
However, there are city restrictions on the heights of the new buildings:
The height of each buildin... | {"functional": "def check(candidate):\n assert candidate(n = 5, restrictions = [[2,1],[4,1]]) == 2\n assert candidate(n = 6, restrictions = []) == 5\n assert candidate(n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]) == 5\n\n\ncheck(Solution().maxBuilding)"} | 219 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: the more a number is, the closer it is to the right end of the piano ke... | {"inputs": ["1\n1\n", "1\n50\n", "1\n68\n", "1\n72\n", "1\n10\n", "1\n14\n", "1\n12\n", "1\n17\n"], "outputs": ["1", "1 \n", "1", "1", "1", "1", "1", "1"]} | 615 | 87 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given a number `n`, return a string representing it as a sum of distinct powers of three, or return `"Impossible"` if that's not possible to achieve.
# Input/Output
`[input]` integer `n`
A positive integer n.
`1 ≤ n ≤ 10^16`.
`[output]` a... | {"functional": "_inputs = [[4], [2], [28], [84], [1418194818], [87754], [531441], [8312964441463288], [5559060566575209], [243]]\n_outputs = [['3^1+3^0'], ['Impossible'], ['3^3+3^0'], ['3^4+3^1'], ['Impossible'], ['3^10+3^9+3^8+3^7+3^5+3^3+3^1+3^0'], ['3^12'], ['Impossible'], ['3^33+3^9+3^1'], ['3^5']]\nimport math\nde... | 328 | 327 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:
* Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with... | {"inputs": ["`?c\nder\ncod", "`?d\nder\ncod", "`?d\nddr\ncod", "`?d\nddr\ncoe", "`?d\nddr\ncof", "`>d\nddr\ncof", "d>`\nddr\ncof", "d>_\nddr\ncof"], "outputs": ["7\n", "8\n", "7\n", "7\n", "7\n", "8\n", "9\n", "9\n"]} | 256 | 116 |
coding | Solve the programming task below in a Python markdown code block.
After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys... | {"inputs": ["3 1 3\n1\n2\n3\n", "4 0 4\n1\n2\n3\n4\n", "4 1 4\n1\n2\n3\n4\n", "5 2 5\n1\n2\n2\n4\n5\n", "5 2 5\n1\n2\n3\n1\n5\n", "5 2 5\n1\n3\n3\n1\n5\n", "5 2 5\n1\n3\n3\n2\n5\n", "5 2 5\n1\n2\n3\n4\n5\n"], "outputs": ["..X", "....", "...X", "...XX", "....X", "....X", "....X", "...XX"]} | 725 | 170 |
coding | Solve the programming task below in a Python markdown code block.
We need you to implement a method of receiving commands over a network, processing the information and responding.
Our device will send a single packet to you containing data and an instruction which you must perform before returning your reply.
To kee... | {"functional": "_inputs = [['H1H10F1200120008F4F4'], ['D7D70F1200250015G8G8'], ['X7X7B7A201400058L0L0'], ['Y2Y2B7A210000902N5N5'], ['R5R5C3D900120008K4K4'], ['S2S2C3D900250005I9I9'], ['E4E40F1239128908Z3Z3'], ['A6A6C3D911150015M0M0'], ['T7T7B7A200258908P2P2'], ['S4S4B7A201153215U8U8']]\n_outputs = [['H1H1FFFF00200000F4... | 481 | 559 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an encoded string s. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
If the character read is a letter, that letter is written onto ... | {"functional": "def check(candidate):\n assert candidate(s = \"leet2code3\", k = 10) == \"o\"\n assert candidate(s = \"ha22\", k = 5) == \"h\"\n assert candidate(s = \"a2345678999999999999999\", k = 1) == \"a\"\n\n\ncheck(Solution().decodeAtIndex)"} | 145 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Iahub got bored, so he invented a game to be played on paper.
He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values ak ... | {"functional": "_inputs = [[[1, 0, 0, 1, 0, 0]], [[1, 0, 0, 1]], [[1]], [[0]], [[1, 0, 0, 0, 1, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1]]]\n_o... | 492 | 434 |
coding | Solve the programming task below in a Python markdown code block.
The Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen.
After the fighting stopped, Heidi gave them another task to waste their time on.
There are $n$ ... | {"inputs": ["5 1\n1 1\n1 -2\n0 1\n0 0\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n0 1\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n0 1\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n0 2\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n-1 0\n2 0\n", "1 1000000\n1000000 -419484\n", "5 1\n1 1\n2 -2\n0 1\n-1 0\n2 0\n"], "outputs": ["3\n", "3\n", "3... | 513 | 249 |
coding | Solve the programming task below in a Python markdown code block.
We have a permutation P = P_1, P_2, \ldots, P_N of 1, 2, \ldots, N.
You have to do the following N - 1 operations on P, each exactly once, in some order:
- Swap P_1 and P_2.
- Swap P_2 and P_3.
\vdots
- Swap P_{N-1} and P_N.
Your task is to sort P in ... | {"inputs": ["5\n2 4 1 5 3\n", "5\n5 4 3 2 1\n"], "outputs": ["4\n2\n3\n1\n", "-1\n"]} | 464 | 48 |
coding | Solve the programming task below in a Python markdown code block.
The `depth` of an integer `n` is defined to be how many multiples of `n` it is necessary to compute before all `10` digits have appeared at least once in some multiple.
example:
```
let see n=42
Multiple value digits comment
42*1 ... | {"functional": "_inputs = [[8], [13], [7], [25], [42], [1]]\n_outputs = [[12], [8], [10], [36], [9], [10]]\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(... | 337 | 192 |
coding | Solve the programming task below in a Python markdown code block.
A: Union Ball
Problem Statement
There are N balls in a box. The i-th ball is labeled with a positive integer A_i.
You can interact with balls in the box by taking actions under the following rules:
* If integers on balls in the box are all odd or all... | {"inputs": ["3\n6 5 6", "3\n3 5 6", "3\n6 6 6", "3\n3 6 6", "3\n6 6 2", "3\n6 9 2", "3\n6 0 2", "3\n6 1 2"], "outputs": ["2\n", "1\n", "0\n", "2\n", "0\n", "2\n", "0\n", "2\n"]} | 439 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the rig... | {"inputs": ["8 1 0\n1\n1 8\n", "1 1 0\n1\n1 8\n", "1 2 0\n1\n1 8\n", "1 3 0\n1\n1 8\n", "10 1 1\n1\n1 9\n", "4 1 2\n1\n1 10\n", "10 1 1\n1\n1 8\n", "10 1 0\n1\n1 8\n"], "outputs": ["0\n", "-1\n", "-1\n", "-1\n", "0\n", "-1\n", "0\n", "0\n"]} | 730 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with t... | {"inputs": ["1\nA\n", "1\ng\n", "1\nA\n", "1\ng\n", "1\nh\n", "1\ni\n", "1\nf\n", "1\ne\n"], "outputs": ["1\n", "1\n", "1", "1", "1\n", "1\n", "1\n", "1\n"]} | 480 | 84 |
coding | Solve the programming task below in a Python markdown code block.
For an array A of length N, let F(A) denote the sum of the product of all the subarrays of A. Formally,
F(A) = \sum_{L=1}^N \sum_{R=L}^N (\prod_{i=L}^R A_{i}\right )
For example, let A = [1, 0, 1], then there are 6 possible subarrays:
Subarray [1, 1]... | {"inputs": ["4\n3\n1 0 1\n1\n0\n2\n1 1\n4\n1 1 0 1\n"], "outputs": ["2\n0\n3\n4\n"]} | 481 | 48 |
coding | Solve the programming task below in a Python markdown code block.
Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.
Find the maximum decimal number without zeroes and with no equal digits in a... | {"inputs": ["5\n1\n2\n3\n4\n5\n"], "outputs": ["1\n2\n21\n121\n212\n"]} | 441 | 37 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.
Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perf... | {"inputs": ["7\n", "1\n", "6\n", "65\n", "11\n", "12\n", "1752\n", "449171\n"], "outputs": ["2\n", "1\n", "1\n", "12\n", "2\n", "3\n", "319\n", "81668\n"]} | 329 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Sort the given strings in alphabetical order, case **insensitive**. For example:
```
["Hello", "there", "I'm", "fine"] --> ["fine", "Hello", "I'm", "there"]
["C", "d", "a", "B"]) --> ["a", "B", "C", "d"]
```
Also feel free to reuse/extend... | {"functional": "_inputs = [[['Hello', 'there', \"I'm\", 'fine']], [['C', 'd', 'a', 'B']], [['CodeWars']], [[]]]\n_outputs = [[['fine', 'Hello', \"I'm\", 'there']], [['a', 'B', 'C', 'd']], [['CodeWars']], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ret... | 111 | 212 |
coding | Solve the programming task below in a Python markdown code block.
For an array A of length N, let F(A) denote the sum of the product of all the subarrays of A. Formally,
F(A) = \sum_{L=1}^N \sum_{R=L}^N (\prod_{i=L}^R A_{i}\right )
For example, let A = [1, 0, 1], then there are 6 possible subarrays:
Subarray [1, 1]... | {"inputs": ["4\n3\n1 0 1\n1\n0\n2\n1 1\n4\n1 1 0 1\n"], "outputs": ["16\n0\n6\n120\n"]} | 641 | 51 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.
Please complete the following py... | {"functional": "def check(candidate):\n assert candidate(nums = [3,1,2,2,2,1,3], k = 2) == 4\n assert candidate(nums = [1,2,3,4], k = 1) == 0\n\n\ncheck(Solution().countPairs)"} | 109 | 71 |
coding | 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"]} | 487 | 107 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
Split the array into one or more disjoint subarrays such that:
Each element of the array belongs to exactly one subarray, and
The GCD of the elements of ea... | {"functional": "def check(candidate):\n assert candidate(nums = [12,6,3,14,8]) == 2\n assert candidate(nums = [4,12,6,14]) == 1\n\n\ncheck(Solution().minimumSplits)"} | 156 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
Please note that you should find all ... | {"inputs": ["4\n1 0\n2 2\n0 2\n0 1", "4\n1 0\n3 2\n0 2\n0 1", "4\n1 0\n2 2\n1 2\n0 1", "4\n1 1\n3 2\n0 2\n0 1", "4\n2 0\n2 2\n1 2\n0 1", "4\n1 1\n3 0\n0 2\n0 1", "4\n1 1\n3 1\n0 2\n0 1", "4\n2 1\n3 1\n0 2\n0 1"], "outputs": ["4\n1 0\n2 2\n0 2\n0 1\n", "4\n1 0\n3 2\n0 2\n0 1\n", "4\n1 0\n2 2\n1 2\n0 1\n", "4\n0 1\n1 1\n... | 351 | 314 |
coding | Solve the programming task below in a Python markdown code block.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Yo... | {"inputs": ["2 4\n", "4 7\n", "1 8\n", "9 3\n", "2 7\n", "4 3\n", "3 2\n", "3 2\n"], "outputs": ["4 0 \n0 4 \n", "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 \n", "8 \n", "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 ... | 333 | 378 |
coding | Solve the programming task below in a Python markdown code block.
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middl... | {"inputs": ["1\n2\n", "1\n1\n", "1\n3\n", "1\n3\n", "1\n1\n", "1\n4\n", "1\n8\n", "1\n2\n"], "outputs": ["1/2\n", "0/1\n", "1/4\n", "1/4", "0/1", "3/8\n", "43/128\n", "1/2"]} | 605 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful wi... | {"inputs": ["30 120.00\n\n", "42 120.00\n\n", "300 120.00\n\n"], "outputs": ["89.50", "120.00", "120.00"]} | 281 | 69 |
coding | Solve the programming task below in a Python markdown code block.
Omkar's most recent follower, Ajit, has entered the Holy Forest. Ajit realizes that Omkar's forest is an n by m grid (1 ≤ n, m ≤ 2000) of some non-negative integers. Since the forest is blessed by Omkar, it satisfies some special conditions:
1. For an... | {"inputs": ["3\n5 3\n###\n###\n###\n###\n0##\n3 3\n###\n###\n#0#\n2 4\n####\n####\n", "5\n5 4\n0000\n0000\n00#0\n0000\n0000\n4 4\n#000\n00#0\n#000\n0000\n4 3\n000\n0#0\n#00\n000\n5 1\n0\n0\n0\n0\n0\n2 8\n00#00000\n000#000#\n", "1\n6 10\n0####0###0\n00#000##00\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\... | 630 | 840 |
coding | Solve the programming task below in a Python markdown code block.
As we all know, a palindrome is a word that equals its reverse. Here are some examples of palindromes: malayalam, gag, appa, amma.
We consider any sequence consisting of the letters of the English alphabet to be a word. So axxb,abbba and bbbccddx are wor... | {"inputs": ["5\nabbba", "12\nabcbcabbacba"], "outputs": ["5\nabbba", "8\nbcabbacb"]} | 440 | 35 |
coding | Solve the programming task below in a Python markdown code block.
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic perform... | {"inputs": ["1\n5\n3\n", "1\n1\n2\n", "1\n1\n1\n", "1\n1\n1\n", "1\n1\n2\n", "1\n1\n3\n", "1\n2\n3\n", "1\n2\n4\n"], "outputs": ["-1\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 505 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Chef Avi likes the number K. Given a list of N integers, help him find the sum of all distinct numbers repeating exactly K times. Each of those numbers should be considered only once in the sum, not K times.
------ Input Format ------
- First line wil... | {"inputs": ["3\n4 1\n2 3 4 4\n5 3\n9 9 1 1 9\n2 1\n2 2"], "outputs": ["5\n9\n-1"]} | 327 | 51 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.
The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order.
A va... | {"functional": "def check(candidate):\n assert candidate(p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,12]) == False\n assert candidate(p1 = [1,0], p2 = [-1,0], p3 = [0,1], p4 = [0,-1]) == True\n\n\ncheck(Solution().validSquare)"} | 143 | 96 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a[0 \ldots n-1]$ of length $n$ which consists of non-negative integers. Note that array indices start from zero.
An array is called good if the parity of each index matches the parity of the element at that index. More formally, ... | {"inputs": ["7\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n", "7\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n", "4\n4\n3 2 7 6\n3\n6 4 4\n1\n7\n7\n7 7 2 2 2 3 2\n", "4\n4\n6 2 7 6\n3\n6 4 4\n1\n7\n7\n6 7 4 2 2 3 2\n", "4\n4\n6 2 7 6\n3\n6 4 4\n1\n8\n7\n6 7 4 2 2 0 2\n", "4\n4\n6 2 7 1\n3\n6 2 4\n1\n8\n7\n6 7 4 2 2 0 2\n"... | 621 | 427 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid.
A uni-value grid is a grid where all the elements of it are equal.
Return ... | {"functional": "def check(candidate):\n assert candidate(grid = [[2,4],[6,8]], x = 2) == 4\n assert candidate(grid = [[1,5],[2,3]], x = 1) == 5\n assert candidate(grid = [[1,2],[3,4]], x = 2) == -1\n\n\ncheck(Solution().minOperations)"} | 130 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Arun has an integer N. His friend likes the number 1, so Arun wants to reduce N to 1.
To do so, he can perform the following move several times (possibly, zero):
Pick two integers X and Y such that X+Y is even and X^{Y} is a divisor of N. Then, replace ... | {"inputs": ["2\n25\n24\n"], "outputs": ["1\n-1"]} | 453 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a link... | {"functional": "def check(candidate):\n assert is_same_list(candidate(l1 = list_node([7,2,4,3]), l2 = list_node([5,6,4])), list_node([7,8,0,7]))\n assert is_same_list(candidate(l1 = list_node([2,4,3]), l2 = list_node([5,6,4])), list_node([8,0,7]))\n assert is_same_list(candidate(l1 = list_node([0]), l2 = list_... | 163 | 135 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the ith monster... | {"functional": "def check(candidate):\n assert candidate(dist = [1,3,4], speed = [1,1,1]) == 3\n assert candidate(dist = [1,1,2,3], speed = [1,1,1,1]) == 1\n assert candidate(dist = [3,2,4], speed = [5,3,2]) == 1\n\n\ncheck(Solution().eliminateMaximum)"} | 257 | 99 |
coding | Solve the programming task below in a Python markdown code block.
The bear has a string s = s_1s_2... s_{|}s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = s_{i}s_{i} + 1... s_{j} co... | {"inputs": ["a\n", "a\n", "`\n", "_\n", "^\n", "]\n", "\\\n", "[\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 486 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)).
Please complete the following python code pre... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,3], nums2 = [2]) == 2.00000\n assert candidate(nums1 = [1,2], nums2 = [3,4]) == 2.50000\n\n\ncheck(Solution().findMedianSortedArrays)"} | 95 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Frieza wants to become immortal. In order to do that he must acquire all the seven dragon balls. In a legendary fight, he is able to defeat Kami, the Guardian of the dragon balls. Now he has come across a case that contains the dragon balls and he needs ... | {"inputs": ["2\nkrillinisdead\nfuturetrunks"], "outputs": ["122111221\n132114"]} | 629 | 36 |
coding | Solve the programming task below in a Python markdown code block.
A number is called 2050-number if it is $2050$, $20500$, ..., ($2050 \cdot 10^k$ for integer $k \ge 0$).
Given a number $n$, you are asked to represent $n$ as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-nu... | {"inputs": ["1\n1\n", "1\n1\n", "1\n62\n", "1\n57\n", "1\n68\n", "1\n12\n", "1\n10\n", "1\n22\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 347 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Chef Shifu and Chef Po are participating in the Greatest Dumpling Fight of 2012.
Of course, Masterchef Oogway has formed the rules of the fight.
There is a long horizontal rope of infinite length with a center point P.
Initially both Chef Shifu and Chef... | {"inputs": ["3\n2 5 0 6 0\n1 4 4 5 2\n10 12 3 1 8", "3\n2 5 0 6 0\n1 4 5 5 2\n10 12 3 1 8", "3\n2 4 0 32 0\n2 1 6 5 1\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 5 5 2\n5 12 3 1 12", "3\n2 4 0 32 0\n2 1 6 5 2\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 8 5 2\n5 12 3 1 12", "3\n2 4 3 6 7\n1 2 4 5 1\n10 12 3 9 16", "3\n2 4 0 10 0\n0 4 4 5 1\n... | 533 | 354 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
While vacationing in Egypt, Chef found a recipe of an ancient dish. The receipt is a sequence of hieroglyphs written on a magic paper - it survived for thousands of years! Th... | {"inputs": ["3\n3 3\n1 2\n2 3\n1 3\n3 2\n1 2\n1 3\n5 4\n1 3\n2 3\n3 4\n2 5"], "outputs": ["1\n2\n2"]} | 660 | 64 |
coding | Solve the programming task below in a Python markdown code block.
For a set $S$ of integers, perform a sequence of the following operations. Note that multiple elements can have equivalent values in $S$.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report ... | {"inputs": ["10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n0 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 0\n2 2\n1 1\n1 2\n1 3\n0 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 5\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 0\n2 2\n1 1\n1 1\n1 3\n1 4\n0 1 1", "10\n0 0\n0 1\n0 2... | 448 | 550 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Russian also.
Chef plays with the sequence of N numbers. During a single move Chef is able to choose a non-decreasing subsequence of the sequence and to remove it from the sequence. Help him to remove all the numbers in the m... | {"inputs": ["3 \n1 2 3", "3 \n1 2 5", "3 \n5 1 0", "3 \n1 2 8", "3 \n1 1 8", "3 \n2 1 3", "3 \n2 1 5", "3 \n2 2 5"], "outputs": ["1", "1\n", "3\n", "1\n", "1\n", "2\n", "2\n", "1\n"]} | 304 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectiv... | {"inputs": ["2 7 5", "2 7 3", "2 4 3", "2 4 1", "2 4 0", "3 4 0", "4 4 0", "1 0 1"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 206 | 94 |
coding | Solve the programming task below in a Python markdown code block.
A greek once sifted some numbers. And it did something wonderful!
-----Input:-----
- First line will contain an integer $N$
-----Output:-----
Output in a single line answer to the problem.
-----Constraints-----
- $1 \leq N \leq 10^5$
-----Sample Inpu... | {"inputs": ["10", "20"], "outputs": ["4", "8"]} | 112 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array $a=[1, 3, 3, 7]$ is good because there is the element $a_4=7$ which equals to the sum $1 + 3 + 3$.
You are given an array $... | {"inputs": ["2\n4 5\n", "2\n2 2\n", "2\n1 1\n", "2\n1 5\n", "2\n1 2\n", "2\n5 1\n", "2\n1 5\n", "2\n1 1\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]} | 756 | 110 |
coding | Solve the programming task below in a Python markdown code block.
You get a new job working for Eggman Movers. Your first task is to write a method that will allow the admin staff to enter a person’s name and return what that person's role is in the company.
You will be given an array of object literals holding the c... | {"functional": "_inputs = [['Dipper Pines'], ['Morty Smith'], ['Anna Bell'], ['Anna'], ['Bell Anna'], ['Jewel Bell'], ['Bell Jewel']]\n_outputs = [['Does not work here!'], ['Truck Driver'], ['Admin'], ['Does not work here!'], ['Does not work here!'], ['Receptionist'], ['Does not work here!']]\nimport math\ndef _deep_eq... | 524 | 225 |
coding | Solve the programming task below in a Python markdown code block.
There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.
He can climb up one or two steps at a time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is da... | {"inputs": ["1 0\n", "2 0\n", "7 0\n", "25 0\n", "4 1\n3", "6 1\n1", "4 1\n2", "5 1\n1"], "outputs": ["1\n", "2\n", "21\n", "121393\n", "2\n", "5\n", "1\n", "3\n"]} | 385 | 97 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.
Please complete the following python code... | {"functional": "def check(candidate):\n assert candidate(coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]) == True\n assert candidate(coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]) == False\n\n\ncheck(Solution().checkStraightLine)"} | 95 | 86 |
coding | Solve the programming task below in a Python markdown code block.
A palindrome is a series of characters that read the same forwards as backwards such as "hannah", "racecar" and "lol".
For this Kata you need to write a function that takes a string of characters and returns the length, as an integer value, of longest a... | {"functional": "_inputs = [['A'], ['Hannah'], ['xyz__a_/b0110//a_zyx'], ['$aaabbbccddd_!jJpqlQx_.///yYabababhii_'], ['']]\n_outputs = [[1], [6], [13], [25], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)... | 160 | 216 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes.
You are also given a 2D integer array query. For each query[i] = [row1i, col1i, row2i, co... | {"functional": "def check(candidate):\n assert candidate(n = 3, queries = [[1,1,2,2],[0,0,1,1]]) == [[1,1,0],[1,2,1],[0,1,1]]\n assert candidate(n = 2, queries = [[0,0,1,1]]) == [[1,1],[1,1]]\n\n\ncheck(Solution().rangeAddQueries)"} | 207 | 100 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
1. Append a_i to the end of b.
2. Reverse the order of the elements in b.
F... | {"inputs": ["3\n2 2 3", "3\n4 2 3", "3\n6 2 3", "3\n6 2 5", "3\n6 4 5", "3\n2 4 5", "3\n2 2 5", "3\n2 2 4"], "outputs": ["3 2 2\n", "3 4 2\n", "3 6 2\n", "5 6 2\n", "5 6 4\n", "5 2 4\n", "5 2 2\n", "4 2 2\n"]} | 278 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many ... | {"inputs": ["8\n", "1\n", "9\n", "5\n", "2\n", "6\n", "4\n", "3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 275 | 70 |
coding | Solve the programming task below in a Python markdown code block.
To help Lavanya learn all about binary numbers and binary sequences, her father has bought her a collection of square tiles, each of which has either a 0 or a 1 written on it. Her brother Nikhil has played a rather nasty prank. He has glued together pair... | {"inputs": ["4"], "outputs": ["5"]} | 405 | 12 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi.
How many ways are there to choose K consecutive integers?
Constraints
* All values in input are integers.
* 1 \leq K \leq N \leq 50
Input
Input is given from S... | {"inputs": ["6 2", "2 1", "2 0", "0 0", "0 1", "6 1", "9 0", "6 0"], "outputs": ["5\n", "2\n", "3\n", "1\n", "0\n", "6\n", "10\n", "7\n"]} | 127 | 79 |
coding | Solve the programming task below in a Python markdown code block.
Chef is not feeling well today. He measured his body temperature using a thermometer and it came out to be X °F.
A person is said to have fever if his body temperature is strictly greater than 98 °F.
Determine if Chef has fever or not.
------ Input F... | {"inputs": ["3\n98\n100\n96\n"], "outputs": ["NO\nYES\nNO\n"]} | 309 | 28 |
coding | Solve the programming task below in a Python markdown code block.
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of ... | {"inputs": ["1\n0\n", "3\n8 1 2\n", "3\n1 1 2\n", "3\n1 1 1\n", "3\n3 3 0\n", "3\n4 3 0\n", "3\n4 3 1\n", "3\n5 3 1\n"], "outputs": ["0\n", "7\n", "1\n", "0\n", "3\n", "4\n", "3\n", "4\n"]} | 311 | 114 |
coding | Solve the programming task below in a Python markdown code block.
-----Input-----
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
-----Output-----
Output "YES" or "NO".
-----Examples-----
Input
NEAT
Output
YES
Input
WORD
Output... | {"inputs": ["Q\n", "Q\n", "P\n", "O\n", "AI\n", "IS\n", "IS\n", "JS\n"], "outputs": ["YES\n", "YES", "YES\n", "YES\n", "YES\n", "NO\n", "NO", "YES\n"]} | 124 | 68 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given an initial string `s`, switch case of the minimal possible number of letters to make the whole string written in the upper case or in the lower case.
# Input/Output
`[input]` string `s`
String of odd length consisting of English letters.... | {"functional": "_inputs = [['asdERvT'], ['oyTYbWQ'], ['bbiIRvbcW'], ['rWTmvcoRWEWQQWR']]\n_outputs = [['asdervt'], ['OYTYBWQ'], ['bbiirvbcw'], ['RWTMVCORWEWQQWR']]\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... | 150 | 212 |
coding | Solve the programming task below in a Python markdown code block.
Have you heard about the myth that [if you fold a paper enough times, you can reach the moon with it](http://scienceblogs.com/startswithabang/2009/08/31/paper-folding-to-the-moon/)? Sure you have, but exactly how many? Maybe it's time to write a program ... | {"functional": "_inputs = [[384000000], [5e-05], [1e-07], [0], [-1]]\n_outputs = [[42], [0], [0], [0], [None]]\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 ... | 242 | 196 |
coding | Solve the programming task below in a Python markdown code block.
The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson.
Nam created a sequence a consisting of n (1 ≤ n ... | {"inputs": ["1\n4\n", "1\n7\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n11\n", "2\n5 4\n", "2\n5 4\n"], "outputs": ["3\n", "3", "3", "3", "3", "3", "22\n", "22"]} | 667 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Kulyash loves perfect squares and hates perfect cubes.
For any natural number N,
F(N) = \texttt{number of perfect squares smaller than or equal to } N - \texttt{number of positive perfect cubes smaller than or equal to } N.
Kulyash gives you an int... | {"inputs": ["3\n1\n3\n3151\n"], "outputs": ["4\n25\n11397376\n"]} | 450 | 35 |
coding | Solve the programming task below in a Python markdown code block.
Professor GukiZ makes a new robot. The robot are in the point with coordinates (x_1, y_1) and should go to the point (x_2, y_2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot... | {"inputs": ["0 0\n4 5\n", "3 4\n6 1\n", "0 0\n4 6\n", "0 0\n2 1\n", "1 5\n6 4\n", "0 0\n5 4\n", "0 0\n4 0\n", "9 1\n1 1\n"], "outputs": ["5\n", "3\n", "6\n", "2\n", "5\n", "5\n", "4\n", "8\n"]} | 314 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of intege... | {"inputs": ["1 3 1\n", "2 7 1\n", "1 1 1\n", "2 2 1\n", "1 1 1\n", "2 2 1\n", "2 7 1\n", "1 7 1\n"], "outputs": ["1\n", "64\n", "1\n", "2\n", "1", "2\n", "64\n", "1\n"]} | 342 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Below is a right-angled triangle:
```
|\
| \
| \
| \
o | \ h
| \
| θ \
|_______\
a
```
Your challange is to write a function (```missingAngle``` in C/C#, ```missing_angle``` in Ruby), that calculates the angle θ in de... | {"functional": "_inputs = [[0, 400, 300], [5, 4, 0], [8, 0, 5], [16.7, 0, 12.3], [7, 5, 0]]\n_outputs = [[37], [37], [39], [47], [44]]\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, (lis... | 179 | 224 |
coding | Solve the programming task below in a Python markdown code block.
Beaches are filled with sand, water, fish, and sun. Given a string, calculate how many times the words `"Sand"`, `"Water"`, `"Fish"`, and `"Sun"` appear without overlapping (regardless of the case).
## Examples
```python
sum_of_a_beach("WAtErSlIde") ... | {"functional": "_inputs = [['SanD'], ['sunshine'], ['sunsunsunsun'], ['123FISH321'], ['weoqipurpoqwuirpousandiupqwoieurioweuwateruierqpoiweurpouifiShqowieuqpwoeuisUn'], ['sAnDsandwaTerwatErfishFishsunsunsandwater'], ['joifjepiojfoiejfoajoijawoeifjowejfjoiwaefjiaowefjaofjwoj fawojef '], ['jwefjwjfsandsandwaterwaterfishf... | 188 | 490 |
coding | Solve the programming task below in a Python markdown code block.
This semester, Chef took X courses. Each course has Y units and each unit has Z chapters in it.
Find the total number of chapters Chef has to study this semester.
------ Input Format ------
- The first line will contain T, the number of test cases. T... | {"inputs": ["3\n1 1 1\n2 1 2\n1 2 3"], "outputs": ["1\n4\n6"]} | 322 | 34 |
coding | Solve the programming task below in a Python markdown code block.
D: Is greed the best?
story
In Japan, where there are 1, 5, 10, 50, 100, 500 yen coins, it is known that the number of coins can be minimized by using as many coins as possible when paying a certain amount. ..
If the amount of coins is different from ... | {"inputs": ["2 6", "6 7", "5 7", "4 5", "7 9", "3 4", "2 7", "2 3"], "outputs": ["-1\n", "12\n", "10\n", "8\n", "14\n", "6\n", "-1\n", "-1\n"]} | 350 | 82 |
coding | Solve the programming task below in a Python markdown code block.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and ... | {"inputs": ["1 1\nR\n", "1 1\nR\n", "1 2\nRB\n", "1 2\nRG\n", "1 2\nRG\n", "1 2\nRB\n", "1 3\nGRB\n", "1 3\nRGG\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]} | 404 | 104 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.
Return the number of connected components in the gra... | {"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[0, 1], [1, 2], [3, 4]]) == 2\n assert candidate(n = 5, edges = [[0,1], [1,2], [2,3], [3,4]]) == 1\n\n\ncheck(Solution().countComponents)"} | 105 | 85 |
coding | Solve the programming task below in a Python markdown code block.
A game is played on a strip consisting of N cells consecutively numbered from 1 to N.
Alice has her token on cell A. Borys has his token on a different cell B.
Players take turns, Alice moves first. The moving player must shift his or her token from it... | {"inputs": ["8 2 4", "3 1 2", "3 2 2", "8 2 3", "0 2 2", "7 2 3", "0 2 1", "7 2 5"], "outputs": ["Alice\n", "Borys\n", "Alice\n", "Borys\n", "Alice\n", "Borys\n", "Borys\n", "Borys\n"]} | 297 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Formula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race.
Given the current ranking in the competition and points distribution for the next race, your task is to calculat... | {"inputs": ["1 1\n5\n5\n", "1 1\n5\n5\n", "1 1\n5\n7\n", "1 1\n5\n8\n", "1 1\n1\n5\n", "1 1\n5\n9\n", "1 1\n1\n3\n", "1 1\n5\n0\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 418 | 117 |
coding | Solve the programming task below in a Python markdown code block.
In Chefland, everyone who earns strictly more than Y rupees per year, has to pay a tax to Chef. Chef has allowed a special scheme where you can invest any amount of money and claim exemption for it.
You have earned X (X > Y) rupees this year. Find the m... | {"inputs": ["4\n4 2\n8 7\n5 1\n2 1\n"], "outputs": ["2\n1\n4\n1\n"]} | 447 | 36 |
coding | 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 search tree and an array queries of size n consisting of positive integers.
Find a 2D array answer of size n where answer[i] = [mini, maxi]:
mini is the largest value in the tree th... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([6,2,13,1,4,9,15,None,None,None,None,None,None,14]), queries = [2,5,16]) == [[2,2],[4,6],[15,-1]]\n assert candidate(root = tree_node([4,None,9]), queries = [3]) == [[-1,4]]\n\n\ncheck(Solution().closestNodes)"} | 217 | 106 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A wonderful string is a string where at most one letter appears an odd number of times.
For example, "ccjjc" and "abab" are wonderful, but "ab" is not.
Given a string word that consists of the first ten lowercase En... | {"functional": "def check(candidate):\n assert candidate(word = \"aba\") == 4\n assert candidate(word = \"aabb\") == 9\n assert candidate(word = \"he\") == 2\n\n\ncheck(Solution().wonderfulSubstrings)"} | 149 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Create a method (**JS**: function) `every` which returns every nth element of an array.
### Usage
With no arguments, `array.every` it returns every element of the array.
With one argument, `array.every(interval)` it returns every `interval`th element... | {"functional": "_inputs = [[[None, None, None, None, None], 2]]\n_outputs = [[[None, None, None]]]\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) != le... | 299 | 169 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:
You will pick any pizza slice.
Your friend Alice will pick the next slice in the anti-clockwise direction of... | {"functional": "def check(candidate):\n assert candidate(slices = [1,2,3,4,5,6]) == 10\n assert candidate(slices = [8,9,8,6,1,1]) == 16\n\n\ncheck(Solution().maxSizeSlices)"} | 156 | 69 |
coding | Solve the programming task below in a Python markdown code block.
Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this characte... | {"inputs": ["a\n", "a\n", "a\n", "a\n", "b\n", "b\n", "a\n", "c\n"], "outputs": ["a\n", "a\n", "a\n", "a\n", "b\n", "b\n", "a\n", "c\n"]} | 180 | 70 |
coding | Solve the programming task below in a Python markdown code block.
When working with color values it can sometimes be useful to extract the individual red, green, and blue (RGB) component values for a color. Implement a function that meets these requirements:
+ Accepts a case-insensitive hexadecimal color string as its... | {"functional": "_inputs = [['#FF9933'], ['#beaded'], ['#000000'], ['#111111'], ['#Fa3456']]\n_outputs = [[{'r': 255, 'g': 153, 'b': 51}], [{'r': 190, 'g': 173, 'b': 237}], [{'r': 0, 'g': 0, 'b': 0}], [{'r': 17, 'g': 17, 'b': 17}], [{'r': 250, 'g': 52, 'b': 86}]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isins... | 216 | 295 |
coding | Solve the programming task below in a Python markdown code block.
Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.
Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of ... | {"inputs": ["2 2\n2 6\n3 100\n", "1 1\n1889\n2867\n", "1 1\n1889\n2867\n", "2 2\n2 6\n3 100\n", "2 3\n10 10\n1 1 1\n", "2 3\n10 10\n1 1 2\n", "2 3\n10 10\n0 1 2\n", "2 3\n10 10\n0 1 0\n"], "outputs": ["11\n", "1889\n", "1889\n", "11\n", "6\n", "8\n", "6\n", "2\n"]} | 386 | 182 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We are given hours, a list of the number of hours worked per day for a given employee.
A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.
A well-performing i... | {"functional": "def check(candidate):\n assert candidate(hours = [9,9,6,0,6,6,9]) == 3\n assert candidate(hours = [6,6,6]) == 0\n\n\ncheck(Solution().longestWPI)"} | 139 | 61 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N. Find if it is possible to represent N as the sum of several(possibly zero) 2's and several(possibly zero) 7's.
Formally, find if there exist two integers X, Y \ (X, Y ≥ 0) such that 2 \cdot X + 7\cdot Y = N.
------ Input Fo... | {"inputs": ["4\n2\n5\n7\n11\n"], "outputs": ["YES\nNO\nYES\nYES\n"]} | 377 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Chef and Chefina are at positions X and Y on a number line.
They both love badminton.
It is known that badminton courts are located at every integer point.
They want to find a court such that the *maximum* distance travelled by either of them is minim... | {"inputs": ["4\n3 5\n7 6\n1 10\n63 31\n"], "outputs": ["1\n1\n5\n16\n"]} | 352 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and s... | {"inputs": ["1\n5\n4 9 1 32 13"], "outputs": ["3"]} | 343 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Space Coconut Crab
Space coconut crab
English text is not available in this practice contest.
Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crustacean in... | {"inputs": ["1\n3\n2\n3\n76\n116\n0", "1\n2\n4\n3\n76\n324\n0", "1\n1\n2\n0\n76\n116\n0", "1\n1\n1\n3\n333\n54\n0", "1\n2\n6\n1\n347\n31\n0", "1\n2\n4\n3\n76\n1250\n0", "1\n2\n3\n3\n76\n1250\n0", "1\n3\n3\n3\n76\n1250\n0"], "outputs": ["1\n3\n2\n3\n10\n14\n", "1\n2\n2\n3\n10\n18\n", "1\n1\n2\n", "1\n1\n1\n3\n21\n10\n",... | 707 | 271 |
coding | Solve the programming task below in a Python markdown code block.
#Permutation position
In this kata you will have to permutate through a string of lowercase letters, each permutation will start at ```a``` and you must calculate how many iterations it takes to reach the current permutation.
##examples
```
input: 'a'
... | {"functional": "_inputs = [['a'], ['z'], ['aaa'], ['aaab'], ['foo']]\n_outputs = [[1], [26], [1], [2], [3759]]\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 ... | 154 | 184 |
coding | Solve the programming task below in a Python markdown code block.
Notes
Template in C
Constraints
2 ≤ the number of operands in the expression ≤ 100
1 ≤ the number of operators in the expression ≤ 99
-1 × 109 ≤ values in the stack ≤ 109
Input
An expression is given in a line. Two consequtive symbols (operand or op... | {"inputs": ["1 3 +", "0 3 +", "0 3 *", "0 5 +", "0 1 +", "6 7 *", "0 4 +", "0 0 *"], "outputs": ["4\n", "3\n", "0\n", "5\n", "1\n", "42\n", "4\n", "0\n"]} | 162 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Input Format
N K
a_1 a_2 a_3 ... a_N
Output Format
Print the minimum cost in one line. In the end put a line break.
Constraints
* 1 ≤ K ≤ N ≤ 15
* 1 ≤ a_i ≤ 10^9
Scoring
Subtask 1 [120 points]
* N = K
Subtask 2 [90 points]
* N ≤ 5
* a_i ... | {"inputs": ["5 5\n862 3408 1332 53 2597", "5 5\n862 3408 1332 56 2597", "5 5\n862 2044 1332 56 2597", "5 5\n862 3170 3598 192 3424", "5 5\n862 3170 3598 212 3424", "5 5\n862 3170 6376 212 3424", "5 5\n862 3170 6694 212 3424", "5 5\n862 3170 6694 212 3205"], "outputs": ["6248\n", "6245\n", "2703\n", "3583\n", "3563\n", ... | 296 | 283 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a stick of length L. Chef wants to break the stick into K parts such that each part has a non-zero length.
Let the lengths of the K parts be A_{1}, A_{2}, \ldots, A_{K} (Note that A_{1} + A_{2} + \ldots + A_{K} = L and A_{i} is a positive inte... | {"inputs": ["2\n4 3\n2 2\n"], "outputs": ["1\n0\n"]} | 516 | 24 |
coding | Solve the programming task below in a Python markdown code block.
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
There are $n$ boxes in front of you. For each $\boldsymbol{i}$, box $\boldsymbol{i}$ contains $r[i]$ red balls, $g[i]$ green balls, and $b[i]$ blu... | {"inputs": ["3\n1 1 1\n1 1 1\n1 1 1\n"], "outputs": ["6\n"]} | 449 | 32 |
coding | Solve the programming task below in a Python markdown code block.
There are N cards placed face down in a row. On each card, an integer 1 or 2 is written.
Let A_i be the integer written on the i-th card.
Your objective is to guess A_1, A_2, ..., A_N correctly.
You know the following facts:
- For each i = 1, 2, ..., M,... | {"inputs": ["3 1\n2 2 1", "3 1\n3 2 1", "6 1\n3 2 1", "4 1\n2 2 1", "8 1\n1 2 1", "6 1\n1 1 1", "8 1\n2 2 2", "3 1\n3 3 1"], "outputs": ["3\n", "2\n", "5\n", "4\n", "7\n", "6\n", "8\n", "3\n"]} | 423 | 126 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.