task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:
0 <= i < n - 1, and
sarr[i+1] - sarr[i] > 1
Here, sorted(arr) is the function th... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,4]) == 3\n assert candidate(nums = [1,3,3,3,5]) == 8\n\n\ncheck(Solution().sumImbalanceNumbers)"} | 161 | 59 |
coding | Solve the programming task below in a Python markdown code block.
# Let's watch a parade!
## Brief
You're going to watch a parade, but you only care about one of the groups marching. The parade passes through the street where your house is. Your house is at number `location` of the street. Write a function `parade_time... | {"functional": "_inputs = [[['a', 'b', 'c', 'd', 'e', 'f'], 3, 2, 'c'], [['c', 'b', 'c', 'd', 'e', 'f'], 3, 2, 'c'], [['a', 'b', 'c', 'd', 'e', 'f'], 3, 2, 'g'], [['a', 'b', 'c', 'c', 'e', 'c'], 7, 1, 'c'], [['a', 'b', 'c', 'd', 'e', 'f'], 1, 2, 'b'], [['a', 'b', 'c', 'd', 'e', 'b'], 1, 2, 'b']]\n_outputs = [[[3]], [[2... | 467 | 344 |
coding | Solve the programming task below in a Python markdown code block.
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the... | {"inputs": ["sunday\nsunday\n", "monday\nmonday\n", "monday\nfriday\n", "monday\nsunday\n", "friday\nmonday\n", "friday\nsunday\n", "sunday\nmonday\n", "sunday\nfriday\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | 427 | 102 |
coding | Solve the programming task below in a Python markdown code block.
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements.
Your goal is to obt... | {"inputs": ["3\n1\n1\n5\n2 3 5 7 8\n2\n2 4\n", "3\n1\n1\n5\n2 4 5 7 8\n2\n1 2\n", "3\n1\n1\n5\n2 4 5 6 8\n2\n1 2\n", "3\n1\n2\n5\n3 4 5 7 9\n2\n2 4\n", "3\n1\n1\n5\n2 4 5 7 9\n2\n1 4\n", "3\n1\n1\n5\n1 4 5 7 8\n2\n1 2\n", "3\n1\n2\n5\n1 4 5 7 8\n2\n1 2\n", "3\n1\n1\n5\n1 4 5 7 9\n2\n1 4\n"], "outputs": ["1\n3\n2\n", "1... | 729 | 278 |
coding | 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)"} | 175 | 78 |
coding | Solve the programming task below in a Python markdown code block.
# Task
You are given an array of integers `a` and a non-negative number of operations `k`, applied to the array. Each operation consists of two parts:
```
find the maximum element value of the array;
replace each element a[i] with (maximum element value... | {"functional": "_inputs = [[[-4, 0, -1, 0], 2], [[0, -1, 0, 0, -1, -1, -1, -1, 1, -1], 1], [[-1], 10000]]\n_outputs = [[[0, 4, 3, 4]], [[1, 2, 1, 1, 2, 2, 2, 2, 0, 2]], [[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... | 604 | 253 |
coding | Solve the programming task below in a Python markdown code block.
You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can... | {"inputs": ["2 2 1 0 0 1\n", "5 3 6 3 3 12\n", "5 3 6 3 1 12\n", "2 4 3 -1 3 7\n", "3 4 -8 5 6 -3\n", "4 4 3 2 10 -1\n", "3 5 -4 -7 5 0\n", "1 5 -4 -7 5 0\n"], "outputs": ["1", "2", "2\n", "2", "3", "1", "2", "8\n"]} | 453 | 147 |
coding | Solve the programming task below in a Python markdown code block.
problem
JOI, who has been suffering from his winter vacation homework every time, decided to do his homework systematically this time. Homework is a national language and math drill, with a national language drill on page A and a math drill on page B.
... | {"inputs": ["20\n2\n6\n3\n1", "20\n4\n0\n6\n1", "20\n8\n9\n7\n1", "20\n4\n6\n3\n1", "20\n4\n6\n6\n1", "20\n1\n4\n6\n6", "20\n4\n0\n6\n2", "20\n1\n4\n6\n2"], "outputs": ["14\n", "19\n", "11\n", "14\n", "14\n", "19\n", "19\n", "18\n"]} | 386 | 142 |
coding | Solve the programming task below in a Python markdown code block.
You get any card as an argument. Your task is to return a suit of this card.
Our deck (is preloaded):
```python
DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS',
'2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','K... | {"functional": "_inputs = [['3C'], ['QS'], ['9D'], ['JH']]\n_outputs = [['clubs'], ['spades'], ['diamonds'], ['hearts']]\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 ... | 267 | 179 |
coding | Solve the programming task below in a Python markdown code block.
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a... | {"inputs": ["1\n0\n", "1\n-1\n", "1\n-1\n", "2\n0 0\n0 0\n", "2\n0 1\n1 0\n", "2\n0 1\n1 1\n", "2\n1 1\n1 0\n", "2\n-1 0\n0 0\n"], "outputs": ["0\n", "0 ", "0 ", "0 0 ", "1 1 ", "1 1 ", "1 1 ", "0 0 "]} | 708 | 123 |
coding | Solve the programming task below in a Python markdown code block.
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column f... | {"inputs": ["2 1\nb\na\n", "2 1\nb\n`\n", "2 2\nfb\nye\n", "2 2\nfb\ney\n", "2 2\nfb\nez\n", "2 2\nfb\nze\n", "2 2\nfc\nez\n", "2 3\naxc\nbxa\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "0\n"]} | 379 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Chef is playing a video game, and is now fighting the final boss.
The boss has H health points. Each attack of Chef reduces the health of the boss by X.
Chef also has a special attack that can be used at most once, and will decrease the health of the ... | {"inputs": ["4\n100 25 40\n100 29 45\n46 1 2\n78 15 78\n"], "outputs": ["4\n3\n45\n1\n"]} | 487 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Your friend has invited you to a party, and tells you to meet them in the line to get in. The one problem is it's a masked party. Everyone in line is wearing a colored mask, including your friend. Find which people in line could be your friend.
Your fri... | {"functional": "_inputs = [[['blue', 'blue', 'red', 'red', 'blue', 'green']], [['blue', 'red', 'blue', 'blue', 'red', 'blue', 'red']], [['brown', 'brown', 'red', 'green']], [['red', 'blue', 'blue', 'red']], [['red', 'blue']], [['blue', 'green', 'red', 'green', 'blue', 'blue', 'red']], [['blue', 'blue', 'blue', 'blue', ... | 211 | 307 |
coding | Solve the programming task below in a Python markdown code block.
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly k months. He looked at the calendar and learned that at the moment is the month number s. Vasya immediately got interes... | {"inputs": ["May\n4\n", "May\n7\n", "May\n5\n", "July\n4\n", "May\n44\n", "July\n2\n", "June\n1\n", "May\n48\n"], "outputs": ["September\n", "December\n", "October\n", "November\n", "January\n", "September\n", "July\n", "May\n"]} | 270 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Define n!! as
n!! = 1 \* 3 \* 5 \* ... \* n if n is odd,
n!! = 2 \* 4 \* 6 \* ... \* n if n is even.
Hence 8!! = 2 \* 4 \* 6 \* 8 = 384, there is no zero at the end.
30!! has 3 zeros at the end.
For a positive integer n, please count how many z... | {"functional": "_inputs = [[8], [30], [487], [500]]\n_outputs = [[0], [3], [0], [62]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return ... | 183 | 181 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array A of length N.
He calls an index i (1 ≤ i ≤ N) *good* if there exists some j \neq i such that A_{i} = A_{j}.
Chef can perform the following operation at most once:
Choose any [subsequence] of the array A and add any positive integer ... | {"inputs": ["3\n6\n1 3 5 2 4 8\n4\n2 3 4 5\n7\n1 1 2 2 3 4 4\n"], "outputs": ["4\n4\n7\n"]} | 329 | 58 |
coding | Solve the programming task below in a Python markdown code block.
*Words that contain many consecutive consonants, like "schtschurowskia", are generally considered somewhat hard to pronounce.*
We say that a word is *hard to pronounce* if it contains 4 or more consonants in a row; otherwise it is *easy to pronounce*. F... | {"inputs": ["5\n5\napple\n15\nschtschurowskia\n6\npolish\n5\ntryst\n3\ncry"], "outputs": ["YES\nNO\nYES\nNO\nYES\n"]} | 592 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Tanya wants to go on a journey across the cities of Berland. There are $n$ cities situated along the main railroad line of Berland, and these cities are numbered from $1$ to $n$.
Tanya plans her journey as follows. First of all, she will choose some cit... | {"inputs": ["2\n2 1\n", "2\n1 1\n", "2\n1 2\n", "2\n1 2\n", "2\n2 2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n"], "outputs": ["2\n", "1\n", "3\n", "3\n", "2\n", "3\n", "2\n", "1\n"]} | 701 | 102 |
coding | Solve the programming task below in a Python markdown code block.
You are given N points (x_i,y_i) located on a two-dimensional plane.
Consider a subset S of the N points that forms a convex polygon.
Here, we say a set of points S forms a convex polygon when there exists a convex polygon with a positive area that has t... | {"inputs": ["1\n0 100", "1\n0 101", "1\n0 111", "1\n1 111", "1\n2 111", "1\n2 101", "1\n4 101", "1\n0 001"], "outputs": ["0", "0", "0", "0", "0", "0", "0", "0"]} | 433 | 102 |
coding | Solve the programming task below in a Python markdown code block.
[Generala](https://en.wikipedia.org/wiki/Generala) is a dice game popular in South America. It's very similar to [Yahtzee](https://en.wikipedia.org/wiki/Yahtzee) but with a different scoring approach. It is played with 5 dice, and the possible results ar... | {"functional": "_inputs = [['55555'], ['44444'], ['44441'], ['33233'], ['22262'], ['12121'], ['44455'], ['66116'], ['12345'], ['23456'], ['34561'], ['13564'], ['62534'], ['44421'], ['61623'], ['12346']]\n_outputs = [[50], [50], [40], [40], [40], [30], [30], [30], [20], [20], [20], [20], [20], [0], [0], [0]]\nimport mat... | 578 | 320 |
coding | Solve the programming task below in a Python markdown code block.
Uppal-balu is busy in extraction of gold from ores. He got an assignment from his favorite professor MH sir, but he got stuck in a problem. Can you help Uppal-balu to solve the problem.
You are given an array $a_1$, $a_2$, $\dots$, $a_n$ of length $n$. Y... | {"inputs": ["7 3 4\n8 2 3 7 8 1 1", "8 3 5\n7 2 1 3 6 5 6 2"], "outputs": ["5", "5"]} | 559 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Mandarin chinese
, Russian and Vietnamese as well.
Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$).
The difficulty of a problem can be calculated as follows:
- Let's deno... | {"inputs": ["3 3\n16 24 60\n498 861 589\n14 24 62\n72 557 819\n16 15 69\n435 779 232"], "outputs": ["2\n1\n3"]} | 624 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Chef is given two integers A and C such that A ≤ C.
Chef wants to find whether there exists any integer B such that A, B, and C are in [arithmetic progression].
------ Input Format ------
- The first line of input will contain a single integer T, de... | {"inputs": ["4\n3 5\n6 6\n2 7\n1 9\n"], "outputs": ["4\n6\n-1\n5\n"]} | 331 | 37 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1. The matrix is disconnected if there is no path from (0... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1],[1,0,0],[1,1,1]]) == True\n assert candidate(grid = [[1,1,1],[1,0,1],[1,1,1]]) == False\n\n\ncheck(Solution().isPossibleToCutPath)"} | 211 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Meera bought a house on Mars, and plans to decorate it with chains of alien flowers. Each flower is either red ($\mbox{R}$) or blue ($\mbox{B}$), and Meera knows how many occurrences of RR, RB, BB, and BR she wants to see in a chain.
The diagram be... | {"inputs": ["1 1 2 1\n"], "outputs": ["5\n"]} | 502 | 20 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.
The numeric value... | {"functional": "def check(candidate):\n assert candidate(n = 3, k = 27) == \"aay\"\n assert candidate(n = 5, k = 73) == \"aaszz\"\n\n\ncheck(Solution().getSmallestString)"} | 246 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Arrow is getting paranoid about Malcom merlyn, his arch-enemy. All his efforts to subdue Merlyn have been in vain. These days Arrow is working on a problem with John Diggle. Diggle mentioned that the Felicity has been facing weird problem with their supe... | {"inputs": ["4\n1\n3\n5\n11"], "outputs": ["-1\n555\n33333\n55555533333"]} | 455 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
There are n chocolates, and you are given an array of n numbers where the i-th number A_{i} is the flavour type of the i-th chocolate. Sebrina wants to eat as many differe... | {"inputs": ["3\n2 1\n1 2\n4 2\n1 1 1 1\n5 3\n50 50 50 100 100"], "outputs": ["1\n1\n2"]} | 553 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that s_{i} > w_{i} and s_{j} < w_{j}. Here sign s_{i} represents the i-th digit of string s, simi... | {"inputs": ["1\n?\n?\n", "1\n?\n?\n", "2\n90\n09\n", "2\n11\n55\n", "2\n12\n?9\n", "2\n12\n?9\n", "2\n39\n09\n", "2\n11\n61\n"], "outputs": ["0\n", "0", "1\n", "0\n", "1\n", "1", "0\n", "0\n"]} | 432 | 112 |
coding | Solve the programming task below in a Python markdown code block.
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
It should remove all values from list `a`, which are present in list `b`.
```python
array_diff([1,2],[1]) == [2]
```
If a value... | {"functional": "_inputs = [[[1, 2], [1]], [[1, 2, 2], [1]], [[1, 2, 2], [2]], [[1, 2, 2], []], [[], [1, 2]]]\n_outputs = [[[2]], [[2, 2]], [[1]], [[1, 2, 2]], [[]]]\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=t... | 163 | 223 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n which is the length of a 0-indexed array nums, and a 0-indexed 2D-array ranges, which is a list of sub-ranges of nums (sub-ranges may overlap).
Each row ranges[i] has exactly 2 cells:
range... | {"functional": "def check(candidate):\n assert candidate(n = 10, ranges = [[3,5],[7,8]]) == [[0,2],[6,6],[9,9]]\n assert candidate(n = 3, ranges = [[0,2]]) == []\n assert candidate(n = 7, ranges = [[2,4],[0,3]]) == [[5,6]]\n\n\ncheck(Solution().findMaximalUncoveredRanges)"} | 264 | 105 |
coding | Solve the programming task below in a Python markdown code block.
The itertools module standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an iterator algebra making it possible to construct specialized tools succinctly and efficiently in pure Pyt... | {"inputs": ["4 \na a c d\n2\n"], "outputs": ["0.8333\n"]} | 477 | 26 |
coding | Solve the programming task below in a Python markdown code block.
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x?
-----Constraints-----
- 0 ≤ a ≤ b ≤ 10^{18}
- 1 ≤ x ≤ 10^{18}
-----Input-----
The input is given... | {"inputs": ["0 5 2", "0 2 2", "0 2 4", "9 7 2", "1 3 4", "4 8 2", "9 9 2", "0 5 1"], "outputs": ["3\n", "2\n", "1\n", "-1\n", "0\n", "3", "0", "6"]} | 167 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Four-digit palindromes start with `[1001,1111,1221,1331,1441,1551,1551,...]` and the number at position `2` is `1111`.
You will be given two numbers `a` and `b`. Your task is to return the `a-digit` palindrome at position `b` if the palindromes were a... | {"functional": "_inputs = [[2, 2], [3, 10], [4, 5], [5, 19], [6, 3], [6, 20], [7, 3]]\n_outputs = [[22], [191], [1441], [11811], [102201], [119911], [1002001]]\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... | 267 | 240 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.
You are also given an array queries where queries[j] = [xj, yj... | {"functional": "def check(candidate):\n assert candidate(points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]) == [3,2,2]\n assert candidate(points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]) == [2,3,2,4]\n\n\ncheck(Solution().countPoints)"} | 181 | 135 |
coding | Solve the programming task below in a Python markdown code block.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed dir... | {"inputs": ["1\n1\n0\n", "1\n1\n1\n", "2\n1 2\n0 0\n", "2\n1 2\n1 1\n", "2\n2 1\n0 1\n", "2\n1 2\n1 0\n", "2\n2 1\n1 1\n", "2\n1 2\n0 1\n"], "outputs": ["1\n", "0\n", "3\n", "3\n", "0\n", "2\n", "1\n", "2\n"]} | 511 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Hardy wants to test Ramanujam of his Mathematical skills. So he gives him a puzzle which is described below.
Puzzle:
There are 100 doors, numbered 1,2,....100 .Initially all doors are closed.
Now a person comes(lets call him the 1st person)he opens the ... | {"inputs": ["400012 31\n10194\n59030\n6930\n39402\n24765\n38154\n147756\n25399\n221328\n30059\n71528\n128184\n18710\n79764\n47450\n176355\n8061\n7335\n82824\n61380\n286810\n634\n7410\n153984\n2277\n46980\n12568\n18390\n173054\n20181\n184416"], "outputs": ["1252\n5968\n890\n4148\n2739\n4027\n13656\n2800\n19724\n3250\n70... | 594 | 363 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$, consisting only of Latin letters 'a', and a string $t$, consisting of lowercase Latin letters.
In one move, you can replace any letter 'a' in the string $s$ with a string $t$. Note that after the replacement string $s$ might ... | {"inputs": ["3\naaaa\na\naa\nabc\na\nb\n"], "outputs": ["1\n-1\n2\n"]} | 469 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Because my other two parts of the serie were pretty well received I decided to do another part.
Puzzle Tiles
You will get two Integer n (width) and m (height) and your task is to draw following pattern. Each line is seperated with '\n'.
Both integers... | {"functional": "_inputs = [[1, 1], [3, 2]]\n_outputs = [[' _( )__\\n _| _|\\n(_ _ (_\\n |__( )_|'], [' _( )__ _( )__ _( )__\\n _| _| _| _|\\n(_ _ (_ _ (_ _ (_\\n |__( )_|__( )_|__( )_|\\n |_ |_ |_ |_\\n _) _ _) _ _) _ _)\\n |__( )_|__( )_|__( )_|']]\nimport math\ndef _deep... | 395 | 263 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array A of length N. He can perform the following operation on A:
1) Select an index i (1 ≤ i ≤ N - 1) and select an integer X (1 ≤ X < 2^{20}). \\
2) Set A_{i} := (A_{i} \oplus X) and A_{i + 1} := (A_{i + 1} \oplus X). (Here, \oplus denote... | {"inputs": ["3\n4\n3 2 2 3\n6\n0 1 2 3 4 5\n3\n1 2 4\n"], "outputs": ["YES\nNO\nYES\n"]} | 567 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subse... | {"inputs": ["1\n3 4\n1 2 3", "1\n3 4\n0 2 3", "1\n0 4\n0 2 2", "1\n0 8\n0 2 0", "1\n3 1\n1 2 3", "1\n0 4\n0 0 0", "1\n0 8\n0 3 0", "1\n0 4\n0 2 3"], "outputs": ["7", "7\n", "6\n", "10\n", "3\n", "4\n", "11\n", "7\n"]} | 428 | 143 |
coding | Solve the programming task below in a Python markdown code block.
How many different ways can you make change for an amount, given a list of coins? In this problem, your code will need to efficiently compute the answer.
Task
Write a program that, given
An amount N and types of infinite available coins M.
A list of ... | {"inputs": ["4 3\n1 2 3", "240 23\n23 20 35 42 19 3 34 9 28 38 13 41 26 14 27 39 24 37 46 29 43 1 21", "250 26\n8 47 13 24 25 31 32 35 3 19 40 48 1 4 17 38 22 30 33 15 44 46 36 9 20 49"], "outputs": ["4", "127101770", "3542323427"]} | 319 | 198 |
coding | Solve the programming task below in a Python markdown code block.
A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:
- S is a palindrome.
- Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindr... | {"inputs": ["ddd\n", "gvg\n", "llvee", "elvle", "elvld", "elvdl", "eludl", "ldule"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 248 | 76 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] t... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,1,1,2]) == [5,0,3,4,0]\n assert candidate(nums = [0,5,3]) == [0,0,0]\n\n\ncheck(Solution().distance)"} | 121 | 68 |
coding | Solve the programming task below in a Python markdown code block.
One day, Wet Shark was given an array $X=\{x_1,x_2,\ldots,x_m\}$. As always, he started playing with its subsequences.
When you came to know about this habit, you presented him a task of finding all pairs of subsequences, $(A,B)$, which satisfies all o... | {"inputs": ["4 5 3\n1 1 1 4\n"], "outputs": ["3\n"]} | 717 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has a string $s$ of length $n$ consisting only of digits 0 and 1. Also he has an array $a$ of length $n$.
Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from ... | {"inputs": ["1\n1\n1337\n", "1\n1\n1337\n", "5\n10011\n8 7 55 0 4\n", "5\n10111\n8 7 60 0 5\n", "5\n01111\n5 1 37 3 5\n", "5\n10011\n8 7 71 0 4\n", "5\n10011\n8 7 55 0 5\n", "5\n10111\n8 7 55 0 5\n"], "outputs": ["1337\n", "1337\n", "71\n", "76\n", "47\n", "87\n", "71\n", "71\n"]} | 450 | 198 |
coding | Solve the programming task below in a Python markdown code block.
Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC^2 (Handbook of Crazy Constructions) and looks for the right chapter:
How to build... | {"inputs": ["5 1\n", "2 2\n", "3 2\n", "1 1\n", "1 1\n", "2 1\n", "3 4\n", "3 1\n"], "outputs": ["5\n", "5\n", "9\n", "1\n", "1\n", "2\n", "34\n", "3\n"]} | 505 | 87 |
coding | Solve the programming task below in a Python markdown code block.
In programming you know the use of the logical negation operator (**!**), it reverses the meaning of a condition.
Your task is to complete the function 'negationValue()' that takes a string of negations with a value and returns what the value would be i... | {"functional": "_inputs = [['!', False], ['!', True], ['!!!', []]]\n_outputs = [[True], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a)... | 169 | 172 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef and his friend John have not see each other for years. They are both are looking forward to meeting again in the city they both grew up in.
The city has N public square... | {"inputs": ["2\n6 2\n1 3 1\n2 3 2\n3 4 3\n4 5 4\n4 6 5\n1 5\n6 6\n1 3 1\n2 3 2\n3 4 3\n4 5 4\n4 6 5\n1 2 3 4 5 6"], "outputs": ["4 1\n29 6"]} | 671 | 103 |
coding | Solve the programming task below in a Python markdown code block.
The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.
There is a permutation $p_i$ of number... | {"inputs": ["2\n3 4 2 1\n", "2\n1 4 4 2\n", "2\n1 2 4 2\n", "2\n3 4 2 1\n", "3\n6 3 2 5 4 1\n", "3\n5 4 1 6 3 2\n", "3\n5 4 1 6 3 2\n", "3\n6 1 2 5 4 2\n"], "outputs": ["-1\n", "-1\n", "-1\n", "\n-1\n", "3\n", "2\n", "2\n", "-1\n"]} | 453 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that will return true if all numbers in the sequence follow the same counting pattern. If the sequence of numbers does not follow the same pattern, the function should return false.
Sequences will be presented in an array of varied len... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 8, 7, 8, 9]], [[2, 8, 6, 7, 4, 3, 1, 5, 9]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 5, 6, 7, 8]], [[1, 3, 5, 7, 9, 11, 13, 15]], [[1, 3, 5, 7, 8, 12, 14, 16]], [[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]], [[0, 2, 4, 6, 8]], [[2, 4, 6, 8, 10]], [[2, 4, 6, 8, 10, 12, 14, 16, 1... | 118 | 641 |
coding | Solve the programming task below in a Python markdown code block.
$n$ fishermen have just returned from a fishing vacation. The $i$-th fisherman has caught a fish of weight $a_i$.
Fishermen are going to show off the fish they caught to each other. To do so, they firstly choose an order in which they show their fish (e... | {"inputs": ["2\n1 1\n", "2\n1 1\n", "3\n4 2 1\n", "3\n4 9 1\n", "3\n4 3 1\n", "3\n4 6 1\n", "3\n4 2 1\n", "4\n1 1 4 9\n"], "outputs": ["0\n", "0\n", "6\n", "6\n", "0\n", "0\n", "6\n", "20\n"]} | 469 | 117 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i].
Return the total number of bad pairs in nums.
Please complete the following python code p... | {"functional": "def check(candidate):\n assert candidate(nums = [4,1,3,3]) == 5\n assert candidate(nums = [1,2,3,4,5]) == 0\n\n\ncheck(Solution().countBadPairs)"} | 100 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$... | {"inputs": ["1\n6\n"], "outputs": ["Richard\n"]} | 466 | 16 |
coding | Solve the programming task below in a Python markdown code block.
In your class, you have started lessons about [arithmetic progression](https://en.wikipedia.org/wiki/Arithmetic_progression). Since you are also a programmer, you have decided to write a function that will return the first `n` elements of the sequence wi... | {"functional": "_inputs = [[1, 2, 5], [1, 0, 5], [1, -3, 10], [100, -10, 10]]\n_outputs = [['1, 3, 5, 7, 9'], ['1, 1, 1, 1, 1'], ['1, -2, -5, -8, -11, -14, -17, -20, -23, -26'], ['100, 90, 80, 70, 60, 50, 40, 30, 20, 10']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):... | 218 | 298 |
coding | Solve the programming task below in a Python markdown code block.
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them.
-----Input---... | {"inputs": ["3\n0 1 1\n1 0 4\n1 4 0\n", "3\n0 1 1\n1 0 1\n1 1 0\n", "3\n0 1 1\n1 0 1\n1 1 0\n", "3\n0 1 1\n1 0 8\n1 4 0\n", "3\n0 1 1\n1 0 4\n1 4 0\n", "3\n0 72 17\n72 0 8\n17 8 0\n", "3\n0 99 73\n99 0 8\n73 8 0\n", "3\n0 99 73\n99 0 8\n73 8 0\n"], "outputs": ["2\n", "1\n", "1", "2\n", "2", "25\n", "81\n", "81"]} | 289 | 226 |
coding | Solve the programming task below in a Python markdown code block.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
- In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q)... | {"inputs": ["4\n1 2 3 3\n3\n1 2\n3 4\n2 4", "4\n2 1 1 1\n3\n1 2\n2 1\n3 5", "4\n1 2 3 3\n3\n1 2\n3 4\n0 4", "4\n0 1 1 1\n3\n1 2\n2 1\n3 5", "4\n1 3 3 3\n3\n1 2\n3 4\n0 4", "4\n1 3 4 3\n3\n1 2\n3 4\n0 4", "4\n0 2 4 3\n3\n1 2\n3 4\n0 4", "4\n0 2 4 4\n3\n1 4\n3 4\n0 4"], "outputs": ["10\n12\n16\n", "8\n4\n4\n", "10\n12\n1... | 380 | 287 |
coding | Solve the programming task below in a Python markdown code block.
A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t.
You are given a sequence b0, b1, ..., bn - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the l... | {"inputs": ["2 1\n1 2\n", "2 1\n1 1\n", "2 7\n1 1\n", "2 1\n2 5\n", "2 2\n1 1\n", "2 1\n4 5\n", "2 2\n1 0\n", "2 12\n1 1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "1\n", "0\n", "1\n", "1\n"]} | 200 | 119 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.
A substring is a contiguous sequence of chara... | {"functional": "def check(candidate):\n assert candidate(s = \"0110\", n = 3) == True\n assert candidate(s = \"0110\", n = 4) == False\n\n\ncheck(Solution().queryString)"} | 101 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a matrix $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$).
You need to fill the matrix with can... | {"inputs": ["2\n4 4 4 6\n3 4 4 5"], "outputs": ["48\n30"]} | 360 | 32 |
coding | Solve the programming task below in a Python markdown code block.
You have a card deck of $n$ cards, numbered from top to bottom, i. e. the top card has index $1$ and bottom card — index $n$. Each card has its color: the $i$-th card has color $a_i$.
You should process $q$ queries. The $j$-th query is described by inte... | {"inputs": ["5 1\n1 2 3 4 5\n1\n", "5 1\n1 2 3 4 5\n1\n", "5 1\n1 4 3 4 5\n1\n", "5 1\n1 2 3 4 5\n2\n", "5 1\n2 5 1 8 5\n1\n", "5 1\n1 4 3 4 6\n1\n", "5 1\n1 2 3 4 6\n1\n", "5 1\n1 4 3 5 5\n1\n"], "outputs": ["1 ", "1 ", "1 ", "2 ", "3 ", "1 ", "1 ", "1 "]} | 609 | 175 |
coding | Solve the programming task below in a Python markdown code block.
M-kun is a brilliant air traffic controller.
On the display of his radar, there are N airplanes numbered 1, 2, ..., N, all flying at the same altitude.
Each of the airplanes flies at a constant speed of 0.1 per second in a constant direction. The curren... | {"inputs": ["2\n10 -1 U\n3 0 D", "2\n10 -1 U\n2 0 D", "2\n20 1 U\n11 47 D", "2\n20 1 U\n11 37 D", "2\n20 0 U\n11 37 D", "2\n20 0 U\n12 37 D", "2\n20 0 U\n12 70 D", "2\n10 0 U\n3 103 D"], "outputs": ["SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n"]} | 574 | 162 |
coding | Solve the programming task below in a Python markdown code block.
You are given two arrays A and B, both of length N.
You would like to choose exactly K distinct indices i_{1},i_{2}, \ldots, i_{K} such that \min(A_{i_{1}}+A_{i_{2}}+ \ldots + A_{i_{K}}, B_{i_{1}}+B_{i_{2}}+\ldots + B_{i_{K}}) is maximized. Find this ma... | {"inputs": ["3\n5 3\n4 2 3 1 4\n3 2 5 5 1\n4 2\n1 2 3 4\n4 3 2 1\n6 3\n8 10 3 6 7 2\n4 8 4 1 1 6\n"], "outputs": ["9\n5\n18\n"]} | 553 | 92 |
coding | Solve the programming task below in a Python markdown code block.
We have a large square grid with H rows and W columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection ... | {"inputs": ["2 3 1 1\n", "10 7 3 4\n", "100000 100000 99999 99999\n", "100000 100000 44444 55555\n"], "outputs": ["2\n", "3570\n", "1\n", "738162020\n"]} | 285 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Chef goes to the supermarket to buy some items. Luckily there's a sale going on under which Chef gets the following offer:
If Chef buys 3 items then he gets the item (out of those 3 items) having the lowest price as free.
For e.g. if Chef bought 3 it... | {"inputs": ["3\n6 2 4\n3 3 3\n8 4 4\n"], "outputs": ["10\n6\n12\n"]} | 402 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices w... | {"inputs": ["5\n1\n3\n3\n4\n100", "5\n1\n2\n3\n4\n110", "5\n1\n2\n1\n4\n110", "5\n1\n4\n1\n4\n110", "5\n1\n2\n3\n4\n101", "5\n1\n3\n3\n4\n110", "5\n1\n2\n3\n4\n111", "5\n1\n2\n2\n4\n110"], "outputs": ["26\n728\n728\n1404\n508533804\n", "26\n52\n728\n1404\n316452997\n", "26\n52\n26\n1404\n316452997\n", "26\n1404\n26\n14... | 504 | 343 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Princess Rupsa saw one of her friends playing a special game. The game goes as follows:
N+1 numbers occur sequentially (one at a time) from A_{0} to A_{N}.
You must write th... | {"inputs": ["2\n1\n1 2\n2\n1 2 1", "2\n1\n1 2\n2\n2 2 1", "2\n1\n1 2\n2\n2 2 0", "2\n1\n1 0\n2\n2 2 0", "2\n1\n1 0\n2\n3 2 0", "2\n1\n1 2\n2\n1 2 2", "2\n1\n1 2\n2\n2 3 1", "2\n1\n1 2\n2\n2 1 0"], "outputs": ["4\n14", "4\n24\n", "4\n16\n", "0\n16\n", "0\n24\n", "4\n20\n", "4\n34\n", "4\n8\n"]} | 667 | 196 |
coding | Solve the programming task below in a Python markdown code block.
Alexandra has a paper strip with n numbers on it. Let's call them a_{i} from left to right.
Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:
Each piece should contain at least l numbers.
The ... | {"inputs": ["1 0 1\n0\n", "1 0 1\n0\n", "1 0 1\n0\n", "1 100 2\n42\n", "1 100 2\n42\n", "1 100 2\n14\n", "1 100 2\n40\n", "1 0 1\n-98876039\n"], "outputs": ["1\n", "1\n", "1", "-1\n", "-1", "-1\n", "-1\n", "1\n"]} | 338 | 136 |
coding | Solve the programming task below in a Python markdown code block.
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at le... | {"inputs": ["3\n2\n10\n3\n001\n4\n0100"], "outputs": ["YES\nNO\nYES"]} | 622 | 34 |
coding | Solve the programming task below in a Python markdown code block.
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$.
You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times:
... | {"inputs": ["5\n5\n2 0 1 -1 0\n3\n1000000000 1000000000 0\n4\n0 0 0 0\n8\n3 0 2 -10 10 -30 30 0\n9\n1 0 0 1 -1 0 1 0 -1\n"], "outputs": ["3\n1\n4\n4\n5\n"]} | 642 | 112 |
coding | Solve the programming task below in a Python markdown code block.
You are given four integer values $a$, $b$, $c$ and $m$.
Check if there exists a string that contains:
$a$ letters 'A';
$b$ letters 'B';
$c$ letters 'C';
no other letters;
exactly $m$ pairs of adjacent equal letters (exactly $m$ such positions $i$ ... | {"inputs": ["1\n2 1 4 4\n", "1\n1 1 4 4\n", "1\n1 1 1 46\n", "1\n1 1 1 46\n", "1\n1 1 2 46\n", "1\n1 1 2 55\n", "1\n1 1 3 55\n", "1\n1 2 3 55\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 378 | 140 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
Note: A leaf is a node with no children.
Please complet... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == 2\n assert candidate(root = tree_node([2,None,3,None,4,None,5,None,6])) == 5\n\n\ncheck(Solution().minDepth)"} | 145 | 71 |
coding | Solve the programming task below in a Python markdown code block.
This is an easier version of the problem. In this version $n \le 1000$
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "3\n4 3 8\n", "3\n10 6 8\n", "3\n10 3 8\n", "3\n4 3 16\n", "3\n4 6 16\n"], "outputs": ["1 \n", "1\n", "2\n", "3 3 8\n", "10 6 6 \n", "10 3 3\n", "3 3 16\n", "4 6 16\n"]} | 675 | 136 |
coding | Solve the programming task below in a Python markdown code block.
You are given a valid XML document, and you have to print the maximum level of nesting in it. Take the depth of the root as $\mbox{0}$.
Input Format
The first line contains $N$, the number of lines in the XML document.
The next $N$ lines follow conta... | {"inputs": ["6\n<feed xml:lang='en'>\n <title>HackerRank</title>\n <subtitle lang='en'>Programming challenges</subtitle>\n <link rel='alternate' type='text/html' href='http://hackerrank.com/'/>\n <updated>2013-12-25T12:00:00</updated>\n</feed>\n"], "outputs": ["1\n"]} | 250 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Chef Ada has a matrix with $N$ rows (numbered $1$ through $N$ from top to bottom) and $N$ columns (numbered $1$ through $N$ from left to right) containing all integers between $1$ and $N^2$ inclusive. For each valid $i$ and $j$, let's denote the cell in ... | {"inputs": ["1\n4\n1 2 9 13\n5 6 10 14\n3 7 11 15\n4 8 12 16"], "outputs": ["2"]} | 678 | 53 |
coding | Solve the programming task below in a Python markdown code block.
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once:
Select a [subsequence] of A and add X to all the elements of that subsequence.
For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subseque... | {"inputs": ["3\n2 1\n1 2\n4 1\n2 2 3 3\n5 2\n5 3 6 2 8\n"], "outputs": ["3\n15\n43\n"]} | 629 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of integers `a` and integers `t` and `x`, count how many elements in the array you can make equal to `t` by **increasing** / **decreasing** it by `x` (or doing nothing).
*EASY!*
```python
# ex 1
a = [11, 5, 3]
t = 7
x = 2
count(a, t, x)... | {"functional": "_inputs = [[[11, 5, 3], 7, 2], [[-4, 6, 8], -7, -3]]\n_outputs = [[3], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r... | 268 | 185 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n grid of characters board and a string word, return true if word exists in the grid.
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vert... | {"functional": "def check(candidate):\n assert candidate(board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\") == True\n assert candidate(board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\") == True\n asse... | 108 | 153 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We have two special characters:
The first character can be represented by one bit 0.
The second character can be represented by two bits (10 or 11).
Given a binary array bits that ends with 0, return true if the las... | {"functional": "def check(candidate):\n assert candidate(bits = [1,1,1,0]) == False\n\n\ncheck(Solution().isOneBitCharacter)"} | 109 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Two players are playing a game on a $15\times15$ chessboard. The rules of the game are as follows:
The game starts with $\boldsymbol{\mbox{k}}$ coins located at one or more $(x,y)$ coordinates on the board (a single cell may contain more than one coin).... | {"inputs": ["2\n3\n5 4\n5 8\n8 2\n6\n7 1\n7 2\n7 3\n7 4\n7 4\n7 4\n"], "outputs": ["First\nSecond\n"]} | 604 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question.
Suppose you are given a positive integer $a$. You want to choose some integer $b$ from $1$ to $a - 1$ inclusive in such a way that the gr... | {"inputs": ["1\n4\n", "1\n7\n", "1\n2\n", "1\n9\n", "1\n8\n", "1\n6\n", "1\n3\n", "1\n5\n"], "outputs": ["7\n", "1\n", "3\n", "15\n", "15\n", "7\n", "1\n", "7\n"]} | 574 | 88 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer array $a_1, a_2, \ldots, a_n$.
The array $b$ is called to be a subsequence of $a$ if it is possible to remove some elements from $a$ to get $b$.
Array $b_1, b_2, \ldots, b_k$ is called to be good if it is not empty and for ever... | {"inputs": ["1\n7\n", "1\n32\n", "2\n1 2\n", "1\n688\n", "2\n1 2\n", "1\n1469\n", "1\n2185\n", "1\n89751\n"], "outputs": ["1\n", "1\n", "3", "1\n", "3\n", "1\n", "1\n", "1\n"]} | 535 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, y_{i}).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every poi... | {"inputs": ["4\n1 0 3 0\n", "4\n1 0 1 4\n", "4\n0 0 4 0\n", "4\n0 0 1 3\n", "4\n1 3 4 4\n", "4\n2 2 4 5\n", "4\n1 3 3 6\n", "4\n1 3 4 4\n"], "outputs": ["No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n"]} | 424 | 134 |
coding | Solve the programming task below in a Python markdown code block.
# Longest Palindromic Substring (Linear)
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,
'madam' or 'racecar'. Even the letter 'x' is considered a palindrome.
For this Kata, you are given a string ```s```. Wr... | {"functional": "_inputs = [['babad'], ['madam'], ['dde'], ['ababbab'], ['abababa'], ['banana'], ['abba'], ['cbbd'], ['zz'], ['dddd'], [''], ['abcdefghijklmnopqrstuvwxyz'], ['ttaaftffftfaafatf'], ['bbaaacc'], ['m']]\n_outputs = [['bab'], ['madam'], ['dd'], ['babbab'], ['abababa'], ['anana'], ['abba'], ['bb'], ['zz'], ['... | 489 | 271 |
coding | Solve the programming task below in a Python markdown code block.
Your car is old, it breaks easily. The shock absorbers are gone and you think it can handle about 15 more bumps before it dies totally.
Unfortunately for you, your drive is very bumpy! Given a string showing either flat road ("\_") or bumps ("n"), work ... | {"functional": "_inputs = [['n'], ['_nnnnnnn_n__n______nn__nn_nnn'], ['______n___n_'], ['nnnnnnnnnnnnnnnnnnnnn']]\n_outputs = [['Woohoo!'], ['Car Dead'], ['Woohoo!'], ['Car Dead']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_to... | 124 | 209 |
coding | Solve the programming task below in a Python markdown code block.
White Falcon just solved the data structure problem below using heavy-light decomposition. Can you help her find a new solution that doesn't require implementing any fancy techniques?
There are $2$ types of query operations that can be performed on a t... | {"inputs": ["3 3\n0 1\n1 2\n1 0 1\n1 1 2\n2 0 2\n"], "outputs": ["3\n"]} | 404 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs... | {"inputs": [".\n", "+\n", ">\n", "<\n", ",\n", "-\n", "[\n", "]\n"], "outputs": ["12\n", "10\n", "8\n", "9\n", "13\n", "11\n", "14\n", "15\n"]} | 509 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Alice, the president of club FCB, wants to build a team for the new volleyball tournament. The team should consist of p players playing in p different positions. She also recognizes the importance of audience support, so she wants to select k people as p... | {"inputs": ["2 1 1\n30 9\n46\n73\n", "2 1 1\n30 9\n46\n87\n", "2 1 1\n76 91\n34\n77\n", "2 1 1\n76 146\n34\n77\n", "2 1 1\n76 291\n34\n77\n", "2 1 1\n76 291\n35\n77\n", "2 1 1\n131 291\n35\n77\n", "4 1 2\n2 4 10 3\n18\n19\n23\n3\n"], "outputs": ["103", "117\n", "153", "180\n", "325\n", "326\n", "326\n", "32\n"]} | 617 | 222 |
coding | Solve the programming task below in a Python markdown code block.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya ... | {"inputs": ["1 7 3\n", "0 1 0\n", "0 0 0\n", "0 0 1\n", "0 0 2\n", "0 1 0\n", "0 1 1\n", "0 1 2\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n"]} | 378 | 102 |
coding | Solve the programming task below in a Python markdown code block.
This is a story of a world somewhere far from the earth. In this world, the land is parted into a number of countries ruled by empires. This world is not very peaceful: they have been involved in army race.
They are competing in production of missiles i... | {"inputs": ["3 3\n3 8 1 1\n2 1 5\n2 3 3\n3 3\n3 2 3 1\n2 1 5\n2 3 3\n0 0", "3 6\n3 8 1 1\n2 1 5\n2 3 3\n3 3\n3 2 5 1\n2 1 8\n2 3 3\n0 0", "3 3\n3 4 1 1\n2 1 5\n2 3 3\n3 6\n3 2 5 1\n2 1 5\n2 3 3\n0 0", "3 3\n3 8 1 1\n2 1 6\n2 3 3\n3 3\n3 2 3 1\n2 2 5\n2 2 3\n0 0", "3 3\n3 8 1 1\n2 1 5\n2 3 3\n3 3\n3 2 5 1\n2 1 5\n2 3 3\... | 742 | 478 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Russian] and [Bengali].
There's a zebra crossing appearing in the middle of nowhere with N blocks in it. The colors of the zebra crossing is represented by a binary string S, where S_{i} is 1 if the i-th block from the left ... | {"inputs": ["3\n6 2\n100101\n5 1\n10111\n6 1\n000000\n"], "outputs": ["6\n2\n-1\n"]} | 519 | 51 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed permutation of n integers nums.
A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want u... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,4,3]) == 2\n assert candidate(nums = [2,4,1,3]) == 3\n assert candidate(nums = [1,3,4,2,5]) == 0\n\n\ncheck(Solution().semiOrderedPermutation)"} | 154 | 77 |
coding | Solve the programming task below in a Python markdown code block.
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length st... | {"inputs": ["A\n", "A\n", "B\n", "C\n", "AA\n", "AB\n", "AA\n", "AB\n"], "outputs": ["-1", "-1\n", "-1", "-1", "-1", "-1", "-1\n", "-1\n"]} | 584 | 66 |
coding | Solve the programming task below in a Python markdown code block.
You are given a decimal representation of an integer $x$ without leading zeros.
You have to perform the following reduction on it exactly once: take two neighboring digits in $x$ and replace them with their sum without leading zeros (if the sum is $0$, ... | {"inputs": ["2\n10057\n90\n"], "outputs": ["10012\n9\n"]} | 446 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Lot of museum allow you to be a member, for a certain amount `amount_by_year` you can have unlimitted acces to the museum.
In this kata you should complete a function in order to know after how many visit it will be better to take an annual pass. The f... | {"functional": "_inputs = [[40, 15], [30, 10], [80, 15]]\n_outputs = [[3], [3], [6]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return F... | 112 | 183 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer $n$.
Let's define $s(n)$ as the string "BAN" concatenated $n$ times. For example, $s(1)$ = "BAN", $s(3)$ = "BANBANBAN". Note that the length of the string $s(n)$ is equal to $3n$.
Consider $s(n)$. You can perform the following ... | {"inputs": ["2\n1\n2\n"], "outputs": ["1\n1 3\n1\n1 6\n"]} | 655 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q_1q_2... q_{k}. The algorithm consists of two steps:
Find any continuous... | {"inputs": ["x\n1\n1 1\n", "x\n1\n1 1\n", "x\n1\n1 0\n", "zyxxxxxxyyz\n5\n5 5\n1 3\n1 6\n1 4\n3 6\n", "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6\n", "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 1\n", "zyxxxxxxyyz\n5\n2 5\n1 3\n1 11\n1 4\n3 1\n", "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 2\n"], "outputs": ["YES\n", "YES\n", "YE... | 576 | 262 |
coding | Solve the programming task below in a Python markdown code block.
To pass the series of gates guarded by the owls, Kenneth needs to present them each with a highly realistic portrait of one. Unfortunately, he is absolutely rubbish at drawing, and needs some code to return a brand new portrait with a moment's notice.
... | {"functional": "_inputs = [['xwe'], ['kuawd6r8q27y87t93r76352475437'], ['t6ggggggggWw'], ['xweWXo']]\n_outputs = [[\"XW''0v0''WX\"], [\"UAW8Y8T''0v0''T8Y8WAU\"], [\"TWW''0v0''WWT\"], [\"XWWXO''0v0''OXWWX\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | 250 | 259 |
coding | Solve the programming task below in a Python markdown code block.
You have two friends. You want to present each of them several positive integers. You want to present cnt_1 numbers to the first friend and cnt_2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that ... | {"inputs": ["3 1 2 3\n", "1 3 2 3\n", "1 1 2 3\n", "1 2 2 3\n", "2 1 2 3\n", "2 1 2 3\n", "1 2 2 3\n", "1 1 2 3\n"], "outputs": ["5\n", "4\n", "2\n", "3\n", "3\n", "3\n", "3\n", "2\n"]} | 461 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Famous wizard Sumar moonji kumaru is stuck in a huge room and has to save Hermione Granger from a monster. Kumaru is at location P1 given by integral coordinates (x_{1},y_{1}) and Hermione is at location P2 given by integral coordinates (x_{2},y_{2}).
S... | {"inputs": ["3\n0 2 4 0\n2 2 5 5\n1 9 8 16\n"], "outputs": ["1\n2\n6\n"]} | 499 | 43 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.