task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Nobody knows, but $N$ frogs live in Chef's garden.
Now they are siting on the X-axis and want to speak to each other. One frog can send a message to another one if the distance between them is less or equal to $K$.
Chef knows all $P$ pairs of frogs, whic... | {"inputs": ["5 0 2\n0 2 9 3 7\n2 2\n1 4\n2 5", "5 1 2\n0 2 8 4 0\n1 2\n1 3\n4 5", "5 1 2\n0 2 8 4 0\n1 2\n1 1\n1 5", "5 0 3\n0 2 8 5 0\n1 2\n1 3\n4 5", "5 0 3\n0 2 3 5 0\n1 2\n1 3\n4 5", "5 6 3\n0 3 8 8 7\n1 2\n1 3\n2 5", "5 1 3\n0 2 8 5 0\n1 2\n1 3\n4 5", "5 0 3\n0 2 3 7 0\n1 2\n1 3\n4 5"], "outputs": ["Yes\nNo\n", "N... | 431 | 296 |
coding | Solve the programming task below in a Python markdown code block.
Vova is playing a computer game. There are in total $n$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $k$.
During each turn Vova can choose what to... | {"inputs": ["1\n1000000000 499999999 3 2\n", "1\n1000000000 999999999 2 1\n", "1\n1000000000 499999999 3 2\n", "1\n1000000000 999999999 2 1\n", "1\n1001000000 499999999 3 2\n", "1\n1000010000 999999999 2 1\n", "1\n1001000000 316833107 3 2\n", "1\n1000000000 499999999 3 1\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "10... | 689 | 296 |
coding | Solve the programming task below in a Python markdown code block.
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i.
You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.
Your objective is to maximize... | {"inputs": ["4 6\n2 1\n3 6\n4 8\n3 4", "4 6\n2 1\n3 6\n2 8\n3 4", "4 6\n2 1\n3 8\n2 8\n2 8", "4 2\n2 1\n3 8\n2 8\n2 8", "4 6\n2 1\n3 6\n4 8\n3 6", "4 6\n2 1\n3 1\n2 8\n3 1", "4 6\n2 1\n3 2\n2 2\n3 1", "4 6\n2 1\n3 2\n2 4\n3 1"], "outputs": ["10\n", "14\n", "17\n", "8\n", "12\n", "9\n", "4\n", "6\n"]} | 355 | 210 |
coding | Solve the programming task below in a Python markdown code block.
## Number pyramid
Number pyramid is a recursive structure where each next row is constructed by adding adjacent values of the current row. For example:
```
Row 1 [1 2 3 4]
Row 2 [3 5 7]
Row 3 [8 12]
Row 4 ... | {"functional": "_inputs = [[[1]], [[3, 5]], [[3, 9, 4]], [[5, 6, 7, 8]], [[13, 1, 21, 9]], [[13, 76, 21, 42, 63]]]\n_outputs = [[1], [8], [25], [52], [88], [674]]\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... | 221 | 237 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, your task is to count how many strings of length n can be formed under the following rules:
Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')
Each vowel 'a' may only be followed by an... | {"functional": "def check(candidate):\n assert candidate(n = 1) == 5\n assert candidate(n = 2) == 10\n assert candidate(n = 5) == 68\n\n\ncheck(Solution().countVowelPermutation)"} | 200 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of numbers, return the difference between the largest and smallest values.
For example:
`[23, 3, 19, 21, 16]` should return `20` (i.e., `23 - 3`).
`[1, 434, 555, 34, 112]` should return `554` (i.e., `555 - 1`).
The array will contain ... | {"functional": "_inputs = [[[1, 1]], [[-1, -1]], [[1, -1]], [[21, 34, 54, 43, 26, 12]], [[-1, -41, -77, -100]]]\n_outputs = [[0], [0], [2], [42], [99]]\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 i... | 164 | 228 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Some people are standing in a row in a park. There are trees between them which cannot be moved.
Your task is to rearrange the people by their heights in a non-descending order without moving the trees.
# Example
For `a = [-1, 150, 190, 17... | {"functional": "_inputs = [[[-1, 150, 190, 170, -1, -1, 160, 180]], [[-1, -1, -1, -1, -1]], [[4, 2, 9, 11, 2, 16]]]\n_outputs = [[[-1, 150, 160, 170, -1, -1, 180, 190]], [[-1, -1, -1, -1, -1]], [[2, 2, 4, 9, 11, 16]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 265 | 291 |
coding | Solve the programming task below in a Python markdown code block.
If the strings are consecutive, you can replace the characters with a rule to shorten the string. For example, for the string AAAA, the expression @ 4A will compress one character. Create a program that restores the character string compressed by this ru... | {"inputs": ["ab@5C1@8050\n@99,1=1@90", "ab@5C2@8050\n@99,1=1@90", "ab@5C2?8050\n@99,1=1@90", "ab@5C1@8050\nA99+1=1@90", "ab@5C2@8050\n@89,1=1@90", "ab@5C2?8050\n@91,1=9@90", "`b@5C1@8050\nA99+1=1@90", "ab@5C3@8050\n@89,1=1@90"], "outputs": ["abCCCCC10000000050\n999999999,1=1000000000", "abCCCCC20000000050\n999999999,1=... | 238 | 478 |
coding | Solve the programming task below in a Python markdown code block.
Manipulating numbers is at the core of a programmer's job. To test how well you know their properties, you are asked to solve the following problem.
You are given $n$ non-negative integers $a_1$, $a_2$, ..., $a_n$. You want to know whether it's possible... | {"inputs": ["3\n1\n9\n3\n40 50 90\n2\n1 4\n"], "outputs": ["Yes\nYes\nNo\n"]} | 530 | 39 |
coding | Solve the programming task below in a Python markdown code block.
**Step 1:** Create a function called `encode()` to replace all the lowercase vowels in a given string with numbers according to the following pattern:
```
a -> 1
e -> 2
i -> 3
o -> 4
u -> 5
```
For example, `encode("hello")` would return `"h2ll4"`. Ther... | {"functional": "_inputs = [['hello'], ['How are you today?'], ['This is an encoding test.']]\n_outputs = [['h2ll4'], ['H4w 1r2 y45 t4d1y?'], ['Th3s 3s 1n 2nc4d3ng t2st.']]\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, ab... | 193 | 210 |
coding | Solve the programming task below in a Python markdown code block.
Manasa has a string having N number of A's and 2*N number of B's. She wants to arrange these characters in such a way that in each prefix and in each suffix of the string the number of B's is greater than or equal to the number of A's. Given the value of... | {"inputs": ["2\n1\n2\n"], "outputs": ["1\n4\n"]} | 223 | 20 |
coding | Solve the programming task below in a Python markdown code block.
There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.
You have $b$ buns, $p$ beef patties and... | {"inputs": ["1\n0 4 4\n3 0\n", "1\n0 0 4\n3 0\n", "1\n0 0 4\n2 0\n", "1\n0 0 3\n2 0\n", "1\n1 0 3\n2 0\n", "1\n1 0 1\n2 0\n", "1\n1 0 1\n3 0\n", "1\n1 0 1\n4 0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 435 | 150 |
coding | Solve the programming task below in a Python markdown code block.
This is the hard version of this problem. The difference between easy and hard versions is only the constraints on $a_i$ and on $n$. You can make hacks only if both versions of the problem are solved.
Burenka is the crown princess of Buryatia, and soon ... | {"inputs": ["7\n4\n5 5 5 5\n3\n1 3 2\n2\n0 0\n3\n2 5 7\n6\n1 2 3 3 2 1\n10\n27 27 34 32 2 31 23 56 52 4\n5\n1822 1799 57 23 55\n", "1\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 268435456\n"],... | 734 | 313 |
coding | Solve the programming task below in a Python markdown code block.
Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of `0` or `1` for each term:
`25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1`
The choice of `0` and `1` is... not very binary. We shall perform the *true* binary... | {"functional": "_inputs = [[25], [47], [1], [3], [1234567]]\n_outputs = [[[1, 1, 1, -1, -1]], [[1, 1, -1, 1, 1, 1]], [[1]], [[1, 1]], [[1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n re... | 329 | 276 |
coding | Solve the programming task below in a Python markdown code block.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
... | {"inputs": ["2 2 0 4\n", "2 2 2 1\n", "6 7 5 8\n", "6 7 5 9\n", "6 7 5 7\n", "0 0 0 0\n", "1 1 0 4\n", "5 5 3 1\n"], "outputs": ["-1", "-1", "-1", "1", "-1", "-1", "2", "-1"]} | 620 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Consider an array $a$ of $n$ positive integers.
You may perform the following operation:
select two indices $l$ and $r$ ($1 \leq l \leq r \leq n$), then
decrease all elements $a_l, a_{l + 1}, \dots, a_r$ by $1$.
Let's call $f(a)$ the minimum number o... | {"inputs": ["3\n4\n2 3 5 4\n3\n1 2 3\n4\n3 1 3 2\n", "1\n5\n1000000000 1 1000000000 1 1000000000\n"], "outputs": ["YES\nYES\nNO\n", "NO\n"]} | 610 | 93 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given an array and your task will be to determine if an array is in ascending or descending order and if it is rotated or not.
Consider the array `[1,2,3,4,5,7,12]`. This array is sorted in `Ascending` order. If we rotate this... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 7]], [[7, 1, 2, 3, 4, 5]], [[2, 3, 4, 5, 7, 12]], [[7, 12, 1, 2, 3, 4, 5]], [[4, 5, 6, 1, 2, 3]], [[9, 8, 7, 6, 5]], [[5, 9, 8, 7, 6]], [[6, 5, 9, 8, 7]], [[9, 6, 7]], [[10, 12, 11]], [[13, 10, 11]]]\n_outputs = [['A'], ['RA'], ['A'], ['RA'], ['RA'], ['D'], ['RD'], ['RD'], ['... | 392 | 354 |
coding | Solve the programming task below in a Python markdown code block.
Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country.
Berland State University works every day of the week, but classes for guest studen... | {"inputs": ["1\n18738\n0 1 1 0 0 0 1\n", "1\n603269\n0 0 1 0 0 0 1\n", "1\n459971\n0 0 1 0 0 0 1\n", "1\n459971\n0 1 1 0 0 0 1\n", "1\n459971\n1 1 1 0 0 0 1\n", "1\n4034438\n1 0 1 0 0 1 1\n", "1\n4034438\n1 0 1 0 0 1 0\n", "1\n4034438\n0 0 1 0 0 1 0\n"], "outputs": ["43719\n", "2111439\n", "1609896\n", "1073263\n", "80... | 613 | 286 |
coding | Solve the programming task below in a Python markdown code block.
You are given $n$ sticks with positive integral length $a_1, a_2, \ldots, a_n$.
You can perform the following operation any number of times (possibly zero):
choose one stick, then either increase or decrease its length by $1$. After each operation, all... | {"inputs": ["4\n3\n1 2 3\n4\n7 3 7 3\n5\n3 4 2 1 1\n8\n3 1 4 1 5 9 2 6\n"], "outputs": ["2\n4\n1\n1\n"]} | 482 | 68 |
coding | Solve the programming task below in a Python markdown code block.
You are provided with array of positive non-zero ints and int n representing n-th power (n >= 2).
For the given array, calculate the sum of each value to the n-th power. Then subtract the sum of the original array.
Example 1: Input: {1, 2, 3}, 3 --> (1... | {"functional": "_inputs = [[[1, 2, 3], 3], [[1, 2], 5], [[3, 5, 7], 2], [[1, 2, 3, 4, 5], 3], [[2, 7, 13, 17], 2], [[2, 5, 8], 3], [[2, 4, 6, 8], 6], [[5, 10, 15], 4], [[3, 6, 9, 12], 3]]\n_outputs = [[30], [30], [68], [210], [472], [630], [312940], [61220], [2670]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if i... | 194 | 322 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position.
You are given an integer n. There is originally an array consisting of n in... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 2) == 1\n\n\ncheck(Solution().findDerangement)"} | 131 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Chef hates unoptimized codes and people who write such codes. One fine day he decided to look through the kitchen's codebase and found a function whose pseudo-code is given here:
input: integer N, list X[1, 2, ..., N], list Y[1, 2, ..., N]
output: inte... | {"inputs": ["2\n3\n1 3\n3 1\n1 2\n5\n1 3\n2 4\n1 2\n3 2\n3 4"], "outputs": ["0\n11"]} | 474 | 51 |
coding | Solve the programming task below in a Python markdown code block.
Sorry folks,, admin has no time to create a story for this problem...
You have two integers n and m and you have to print value of factorial(n)%m.
OUTPUT
a single integer containing answer of problem.
Input
23 14567
NOTE You do not need to create a p... | {"inputs": ["23 14567"], "outputs": ["12404"]} | 118 | 23 |
coding | Solve the programming task below in a Python markdown code block.
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple o... | {"inputs": ["4 7", "4 20", "4 37", "2 37", "6 20", "2 57", "1 67", "1 54"], "outputs": ["1\n", "3\n", "4\n", "5\n", "2\n", "5\n", "7\n", "6\n"]} | 218 | 85 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.
You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also giv... | {"functional": "def check(candidate):\n assert candidate(nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]) == 9\n assert candidate(nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]) == 0\n\n\ncheck(Solution().minimumScore)"} | 328 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Byteland is a beautiful land known because of its beautiful trees.
Misha has found a binary tree with $n$ vertices, numbered from $1$ to $n$. A binary tree is an acyclic connected bidirectional graph containing $n$ vertices and $n - 1$ edges. Each verte... | {"inputs": ["4\n2\n1 2\n4\n1 2\n2 3\n2 4\n7\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n15\n1 2\n2 3\n3 4\n4 5\n4 6\n3 7\n2 8\n1 9\n9 10\n9 11\n10 12\n10 13\n11 14\n11 15\n"], "outputs": ["0\n2\n2\n10\n"]} | 628 | 136 |
coding | Solve the programming task below in a Python markdown code block.
How many bees are in the beehive?
* bees can be facing UP, DOWN, LEFT, or RIGHT
* bees can share parts of other bees
Examples
Ex1
```
bee.bee
.e..e..
.b..eeb
```
*Answer: 5*
Ex2
```
bee.bee
e.e.e.e
eeb.eeb
```
*Answer: 8*
# Notes
* The ... | {"functional": "_inputs = [[None]]\n_outputs = [[0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_e... | 162 | 157 |
coding | Solve the programming task below in a Python markdown code block.
In this problem you will write a simple generator of Brainfuck (https://en.wikipedia.org/wiki/Brainfuck) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brain... | {"inputs": ["7\n", "3\n", "6\n", "1\n", "2\n", "0\n", "2+3\n", "9-7\n"], "outputs": ["+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++.... | 382 | 103 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1.
Your task is to find out if it is possible to rearrange characters in string s so that... | {"inputs": ["z\n", "abc\n", "bbcd\n", "abcd\n", "wxxyxxx\n", "xxxyxxx\n", "hfihihhfh\n", "hhihhhffh\n"], "outputs": ["YES\nz\n", "YES\nabc\n", "YES\ncbdb", "NO\n", "YES\nwxxxxxy", "YES\nxxxxxxy\n", "NO\n", "YES\nfhhhfhihh"]} | 341 | 101 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents:
positioni is the distance between t... | {"functional": "def check(candidate):\n assert candidate(cars = [[1,2],[2,1],[4,3],[7,2]]) == [1.00000,-1.00000,3.00000,-1.00000]\n assert candidate(cars = [[3,4],[5,4],[6,3],[9,1]]) == [2.00000,1.00000,1.50000,-1.00000]\n\n\ncheck(Solution().getCollisionTimes)"} | 268 | 136 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A of N elements. For any ordered triplet (i, j, k) such that i, j, and k are pairwise distinct and 1 ≤ i, j, k ≤ N, the value of this triplet is (A_{i}-A_{j})\cdot A_{k}. You need to find the maximum value among all possible ordere... | {"inputs": ["3\n3\n1 1 3\n5\n3 4 4 1 2\n5\n23 17 21 18 19"], "outputs": ["2\n12\n126"]} | 608 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
A programming contest will be held in the Russian Federation. The contest has N questions and has M participants. Question i has a score a_i, and it is known that participant j's ability is b_j. For problem i and participant j, partici... | {"inputs": ["6\n1 2 1 3 4 5\n7\n1 3 4 5 3 1 0\n2 8 5 3 4 5 3", "6\n1 2 1 5 4 5\n7\n1 3 4 7 3 1 0\n2 8 5 3 7 5 3", "6\n1 2 2 5 4 5\n7\n1 3 4 7 3 1 0\n2 8 5 3 7 5 3", "6\n1 2 1 6 3 1\n7\n1 3 4 7 3 1 0\n2 8 5 3 3 0 3", "6\n1 2 2 8 6 1\n7\n2 3 4 2 3 1 0\n1 8 1 3 3 1 1", "6\n1 2 1 5 4 5\n7\n1 3 3 7 3 1 0\n2 8 5 3 7 5 3", "6... | 701 | 494 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given a sequence $A_{1}, A_{2}, \dots, A_{N}$ of positive integers and an integer $K$. You are allowed to perform the following operation any number of times (includi... | {"inputs": ["2\n3 6\n10 15 30\n3 4\n5 10 20"], "outputs": ["YES\nNO"]} | 479 | 39 |
coding | Solve the programming task below in a Python markdown code block.
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you n... | {"inputs": ["2 100\n13 78\n", "4 1\n1 2 3 4\n", "4 1\n1 2 1 2\n", "4 4\n1 2 6 7\n", "4 1\n1 2 3 4\n", "4 4\n1 2 6 7\n", "4 1\n1 2 1 2\n", "2 100\n13 78\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n"]} | 581 | 150 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of all the arithmetic subsequences of nums.
A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two con... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,6,8,10]) == 7\n assert candidate(nums = [7,7,7,7,7]) == 16\n\n\ncheck(Solution().numberOfArithmeticSlices)"} | 244 | 64 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (No... | {"functional": "def check(candidate):\n assert candidate(\"Mr John Smith \", 13) == \"Mr%20John%20Smith\"\n assert candidate(\" \", 5) == \"%20%20%20%20%20\"\n\n\ncheck(Solution().replaceSpaces)"} | 119 | 74 |
coding | Solve the programming task below in a Python markdown code block.
If this challenge is too easy for you, check out:
https://www.codewars.com/kata/5cc89c182777b00001b3e6a2
___
Upside-Down Pyramid Addition is the process of taking a list of numbers and consecutively adding them together until you reach one number.
Wh... | {"functional": "_inputs = [[[5, 2, 1]], [[84, 42, 21, 10, 2]], [[83, 47, 28, 16, 7]], [[101, 57, 29, 13, 6]], [[66, 39, 25, 15, 7]], [[45, 25, 14, 8, 6]], [[60, 32, 16, 7, 4]], [[84, 44, 21, 8, 2]], [[51, 26, 13, 6, 2]], [[78, 42, 22, 11, 6]]]\n_outputs = [[[2, 1, 1]], [[4, 7, 3, 8, 2]], [[6, 4, 3, 9, 7]], [[1, 3, 9, 7... | 237 | 468 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group.
Given the integer n and the array dislikes... | {"functional": "def check(candidate):\n assert candidate(n = 4, dislikes = [[1,2],[1,3],[2,4]]) == True\n assert candidate(n = 3, dislikes = [[1,2],[1,3],[2,3]]) == False\n assert candidate(n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]) == False\n\n\ncheck(Solution().possibleBipartition)"} | 147 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Chef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however, the tot... | {"inputs": ["4\n1 1\n2\n2 4\n1 1\n3 6\n3 4 2\n3 6\n3 4 3"], "outputs": ["-1\n1\n2\n3"]} | 529 | 53 |
coding | Solve the programming task below in a Python markdown code block.
Well known investigative reporter Kim "Sherlock'' Bumjun needs your help! Today, his mission is to sabotage the operations of the evil JSA. If the JSA is allowed to succeed, they will use the combined power of the WQS binary search and the UFDS to take o... | {"inputs": ["1\n5\n4\n7\n6\n3\n1"], "outputs": ["7"]} | 317 | 24 |
coding | Solve the programming task below in a Python markdown code block.
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of t... | {"inputs": ["4\n4 0\n4 1\n4 2\n4 3\n"], "outputs": ["0 3\n1 2\n0 2\n1 3\n0 1\n2 3\n-1\n"]} | 550 | 55 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of $n$ integers. You are allowed to perform the following operation on it as many times as you want (0 or more times):
Choose $2$ indices $i$,$j$ where $1 \le i < j \le n$ and replace $a_k$ for all $i \leq k \leq j$ with $|a_i... | {"inputs": ["3\n3\n1 1 1\n2\n9 1\n3\n4 9 5\n"], "outputs": ["3\n16\n18\n"]} | 468 | 42 |
coding | Solve the programming task below in a Python markdown code block.
You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most... | {"inputs": ["1 2 1 5\n", "2 7 8 4\n", "2 5 8 4\n", "2 2 3 1\n", "1 1 1 2\n", "1 2 3 1\n", "4 2 5 28\n", "3 1 29 1\n"], "outputs": ["20\n", "25\n", "16\n", "3\n", "4\n", "2\n", "1893\n", "0\n"]} | 338 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you wa... | {"functional": "def check(candidate):\n assert candidate(numCourses = 2, prerequisites = [[1,0]]) == True\n assert candidate(numCourses = 2, prerequisites = [[1,0],[0,1]]) == False\n\n\ncheck(Solution().canFinish)"} | 151 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Nitin and Sobhagya were playing a game with coins. If Sobhagya has more coins then he is *winning*, otherwise Nitin is winning. Note that this means if both Nitin and Sobhagya have the same number of coins, then Nitin is winning.
Initially Nitin has A c... | {"inputs": ["3\n2 3 4 5\n3 3 3 3\n2 3 1 2\n"], "outputs": ["S\nN\nS\n"]} | 563 | 42 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$ of lowercase Latin letters.
The following operation can be used:
select one character (from 'a' to 'z') that occurs at least once in the string. And replace all such characters in the string with the previous one in alphabeti... | {"inputs": ["1\n15 1\nwaterwaterwater\n", "4\n3 2\ncba\n4 5\nfgde\n7 5\ngndcafb\n4 19\nekyv\n"], "outputs": ["vatervatervater\n", "aaa\nagaa\nbnbbabb\naapp\n"]} | 497 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers fro... | {"inputs": ["3\n", "5\n", "1\n", "2\n", "4\n", "6\n", "8\n", "6\n"], "outputs": ["2\n", "2\n", "1\n", "1\n", "1\n", "3\n", "2\n", "3\n"]} | 307 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.
He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a... | {"inputs": ["act\n2\ncat\ndog"], "outputs": ["Yes\nNo"]} | 373 | 22 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you need to write a function that will receive two strings (```n1``` and ```n2```), each representing an integer as a binary number. A third parameter will be provided (```o```) as a string representing one of the following operators: add, s... | {"functional": "_inputs = [['1', '1', 'add'], ['1', '1', 'subtract'], ['1', '1', 'multiply'], ['10', '10', 'multiply'], ['100', '10', 'subtract']]\n_outputs = [['10'], ['0'], ['1'], ['100'], ['10']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.is... | 216 | 217 |
coding | Solve the programming task below in a Python markdown code block.
As a strict big brother, I do limit my young brother Vasya on time he spends on computer games. I define a prime-time as a time period till which Vasya have a permission to play computer games. I specify start hour and end hour as pair of integers.
I ne... | {"functional": "_inputs = [[9, 10, 11], [12, 12, 13], [13, 10, 15], [14, 9, 14], [15, 8, 12], [20, 21, 1], [21, 21, 6], [17, 15, 3], [0, 22, 1], [1, 22, 1], [3, 23, 2], [20, 0, 23], [14, 2, 9], [9, 20, 11], [23, 23, 0], [11, 2, 9], [0, 20, 23], [4, 0, 3], [6, 2, 10]]\n_outputs = [[False], [True], [True], [False], [Fals... | 216 | 409 |
coding | Solve the programming task below in a Python markdown code block.
You are given two strings $s$ and $t$ consisting of lowercase Latin letters. Also you have a string $z$ which is initially empty. You want string $z$ to be equal to string $t$. You can perform the following operation to achieve this: append any subsequen... | {"inputs": ["3\naabce\nace\nabacaba\naax\nty\nyyt\n", "3\naabce\nace\nabbcaaa\naax\nty\nyyt\n", "3\naabcf\nace\nabbcaaa\naax\nty\nyyt\n", "3\necbaa\nace\nabbcaaa\naax\nty\nyyt\n", "3\nbaacf\nace\nabbcaaa\naax\nty\nyyt\n", "3\naabce\nace\nabacaba\naax\nty\nyyt\n", "11\na\naaaaaaaaaaa\ncba\nabcabcabcabcabcabcabc\nbvdhsdv... | 430 | 453 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If no such uncommon subsequence exists, return -1.
An uncommon subsequence between two strings is a string that is a su... | {"functional": "def check(candidate):\n assert candidate(a = \"aaa\", b = \"bbb\") == 3\n assert candidate(a = \"aaa\", b = \"aaa\") == -1\n\n\ncheck(Solution().findLUSlength)"} | 107 | 55 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integers num1 and num2, return the sum of the two integers.
Please complete the following python code precisely:
```python
class Solution:
def sum(self, num1: int, num2: int) -> int:
``` | {"functional": "def check(candidate):\n assert candidate(num1 = 12, num2 = 5) == 17\n assert candidate(num1 = -10, num2 = 4) == -6\n\n\ncheck(Solution().sum)"} | 69 | 59 |
coding | Solve the programming task below in a Python markdown code block.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls.... | {"inputs": ["1 1 C\nC\n", "2 2 W\nKW\nKW\n", "2 2 W\nKW\nKX\n", "2 2 W\nKW\nLW\n", "2 2 W\nKV\nLW\n", "3 2 W\nOO\nWW\nWW\n", "3 3 U\nUOO\nUVV\nUVV\n", "1 10 H\n....DDHHHH\n"], "outputs": ["0\n", "1\n", "2\n", "2\n", "2\n", "1\n", "2\n", "1\n"]} | 351 | 136 |
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 | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s consisting only of characters a, b and c.
Return the number of substrings containing at least one occurrence of all these characters a, b and c.
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(s = \"abcabc\") == 10\n assert candidate(s = \"aaacb\") == 3\n assert candidate(s = \"abc\") == 1\n\n\ncheck(Solution().numberOfSubstrings)"} | 86 | 59 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth.
Note that the root node is at depth 1.
The adding rule is:
Given the integer depth, for each... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,6,3,1,5]), val = 1, depth = 2), tree_node([4,1,1,2,None,None,6,3,1,5]))\n assert is_same_tree(candidate(root = tree_node([4,2,None,3,1]), val = 1, depth = 3), tree_node([4,2,None,1,1,3,None,None,1]))\n\n\ncheck(Solution().... | 275 | 126 |
coding | Solve the programming task below in a Python markdown code block.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples o... | {"inputs": ["6 5 2 1", "9 5 2 1", "0 5 2 1", "6 3 2 1", "12 5 2 1", "-1 5 2 1", "-1 0 2 0", "-1 0 1 0"], "outputs": ["0\n", "3\n", "-6\n", "2", "6\n", "-7\n", "-3\n", "-2\n"]} | 438 | 110 |
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 consisting of positive integers, representing targets on a number line. You are also given an integer space.
You have a machine which can destroy targets. Seeding the machine with ... | {"functional": "def check(candidate):\n assert candidate(nums = [3,7,8,1,1,5], space = 2) == 1\n assert candidate(nums = [1,3,5,2,4,6], space = 2) == 1\n assert candidate(nums = [6,2,5], space = 100) == 2\n\n\ncheck(Solution().destroyTargets)"} | 163 | 96 |
coding | Solve the programming task below in a Python markdown code block.
# Task
If string has more than one neighboring dashes(e.g. --) replace they with one dash(-).
Dashes are considered neighbors even if there is some whitespace **between** them.
# Example
For `str = "we-are- - - code----warriors.-"`
The result ... | {"functional": "_inputs = [['we-are- - - code----warriors.-'], ['a---b- - -c'], ['a------'], ['Lorem - ipsum- - - dolor sit amet, consectetur adipiscing elit. Praesent tristique lectus non erat dapibus tincidunt. Integer non nibh fermentum, cursus-diam -------pharetra, mattis--risus.-------']]\n_outputs = [['we-are- co... | 136 | 304 |
coding | Solve the programming task below in a Python markdown code block.
There are three airports A, B and C, and flights between each pair of airports in both directions.
A one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C a... | {"inputs": ["3 1 3", "2 3 4", "3 1 2", "3 1 0", "1 1 3", "3 0 0", "1 6 5", "1 6 6"], "outputs": ["4\n", "5\n", "3\n", "1\n", "2\n", "0\n", "6\n", "7\n"]} | 361 | 94 |
coding | Solve the programming task below in a Python markdown code block.
There are N rabbits, numbered 1 through N.
The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i.
For a pair of rabbits i and j (i<j), we call the pair (i,j) a friendly pair if the following condition is met.
* ... | {"inputs": ["3\n3 3 1", "3\n2 0 1", "3\n3 0 1", "3\n2 0 0", "3\n2 1 1", "3\n3 3 2", "3\n3 0 0", "3\n2 3 1"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0"]} | 222 | 109 |
coding | Solve the programming task below in a Python markdown code block.
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular (shortly, RBS) if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this ... | {"inputs": ["2\n()\n", "2\n()\n", "2\n()\n", "4\n(())\n", "4\n(())\n", "4\n()()\n", "4\n(())\n", "8\n((()))()\n"], "outputs": ["00\n", "00\n", "00\n", "0110\n", "0110\n", "0000", "0110\n", "01001000\n"]} | 692 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.
Magically, all the numbers were shuffled in arbitrary order while this note was passed t... | {"inputs": ["01\n0\n", "13\n3\n", "14\n4\n", "21\n2\n", "12\n2\n", "10\n0\n", "10\n0\n", "13\n3\n"], "outputs": ["0\n", "3\n", "4\n", "2\n", "2\n", "0\n", "0", "3"]} | 318 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Cowboy Vlad has a birthday today! There are $n$ children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitra... | {"inputs": ["2\n8 1\n", "2\n5 32\n", "2\n5 42\n", "2\n5 28\n", "2\n5 16\n", "2\n5 27\n", "2\n5 17\n", "2\n9 17\n"], "outputs": ["1 8\n", "5 32\n", "5 42\n", "5 28\n", "5 16\n", "5 27\n", "5 17\n", "9 17\n"]} | 558 | 132 |
coding | Solve the programming task below in a Python markdown code block.
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n ... | {"inputs": ["3\n3 2 1\n", "3\n2 1 3\n", "3\n1 2 3\n", "3\n3 1 2\n", "5\n4 2 1 3 5\n", "5\n3 2 1 4 5\n", "5\n4 1 2 3 5\n", "10\n1 9 8 10 2 3 4 6 5 7\n"], "outputs": ["1\n", "2\n", "3\n", "2\n", "3\n", "3\n", "4\n", "6\n"]} | 487 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Fox Ciel studies number theory.
She thinks a non-empty set S contains non-negative integers is perfect if and only if for any $a, b \in S$ (a can be equal to b), $(a \text{xor} b) \in S$. Where operation xor means exclusive or operation (http://en.wikip... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "8\n", "5\n", "6\n", "0\n"], "outputs": ["2\n", "3\n", "5\n", "6\n", "17\n", "8\n", "11\n", "1\n"]} | 327 | 72 |
coding | Solve the programming task below in a Python markdown code block.
In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.
Given a string S of length N and an inte... | {"inputs": ["18\nRETSULCAIDEMOGNAWD\n1\n18", "18\nDDEDDDMMMMMCCCCCCC\n1\n18", "18\nDWANGOMEDIACLUSTER\n1\n32", "18\nDDDDDDMMMMMCCCCCCC\n1\n29", "18\nDDEDDDMMNMMCCCCCCC\n1\n18", "18\nDDDDDDMMMMMCCCCCCC\n1\n11", "18\nDCDDDDMMMMMDCCCCCC\n1\n11", "18\nDDEDDDMMMMMCCCCCCC\n1\n11"], "outputs": ["0\n", "175\n", "1\n", "210\n",... | 521 | 184 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: Whe... | {"inputs": ["9 2", "28 0", "28 2", "28 3", "53 3", "53 6", "53 0", "84 0"], "outputs": ["9\n", "29\n", "28\n", "27\n", "52\n", "49\n", "54\n", "85\n"]} | 249 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Real stupidity beats artificial intelligence every time.
— Terry Pratchett, Hogfather, Discworld
You are given a string $s$ of length $n$ and a number $k$. Let's denote by $rev(s)$ the reversed string $s$ (i.e. $rev(s) = s_n s_{n-1} ... s_1$). You can ... | {"inputs": ["1\n2 1\nab\n", "1\n3 1\naab\n", "1\n3 1\nabc\n", "1\n4 1\nabcd\n", "1\n4 2\nabca\n", "4\n3 2\naab\n3 3\naab\n7 1\nabacaba\n2 0\nab\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n2\n1\n1\n"]} | 523 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematica... | {"inputs": ["2 2\n1 1\n", "1 1\n1 1\n", "2 4\n6 6\n", "3 3\n1 1\n", "4 4\n1 1\n", "2 2\n1 2\n", "0 1\n1 1\n", "2 4\n6 8\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | 502 | 118 |
coding | Solve the programming task below in a Python markdown code block.
The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by sum of some numbers which are prime. Chef wrote those numbers in dairy. Cheffina came and saw what the chef was doing. Cheffina im... | {"inputs": ["2\n12 2\n11 2"], "outputs": ["1\n0"]} | 258 | 24 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and a positive integer x.
You are initially at position 0 in the array and you can visit other positions according to the following rules:
If you are currently in position... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,6,1,9,2], x = 5) == 13\n assert candidate(nums = [2,4,6,8], x = 3) == 20\n\n\ncheck(Solution().maxScore)"} | 182 | 71 |
coding | Solve the programming task below in a Python markdown code block.
JJ has an array A. He can perform the following operation on A:
Divide A into two subsequences P and Q such that each A_{i} belongs to either P or Q.
Set A := P\ \texttt{concat}\ Q
Here \texttt{concat} denotes the concatenation operation. For e.g. [2,... | {"inputs": ["3\n6\n4 5 6 1 2 3\n5\n1 3 5 2 4\n5\n5 10 7 11 9\n"], "outputs": ["YES\nNO\nYES\n"]} | 605 | 58 |
coding | Solve the programming task below in a Python markdown code block.
## Task
Generate a sorted list of all possible IP addresses in a network.
For a subnet that is not a valid IPv4 network return `None`.
## Examples
```
ipsubnet2list("192.168.1.0/31") == ["192.168.1.0", "192.168.1.1"]
ipsubnet2list("213.256.46.160/28")... | {"functional": "_inputs = [['192.168.1.0/31'], ['195.20.15.0/28'], ['174.0.153.152/29'], ['213.192.46.160/28'], ['213.256.46.160/28']]\n_outputs = [[['192.168.1.0', '192.168.1.1']], [['195.20.15.1', '195.20.15.2', '195.20.15.3', '195.20.15.4', '195.20.15.5', '195.20.15.6', '195.20.15.7', '195.20.15.8', '195.20.15.9', '... | 148 | 769 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.
You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will brea... | {"functional": "def check(candidate):\n assert candidate(n = 2) == 2\n assert candidate(n = 100) == 14\n\n\ncheck(Solution().twoEggDrop)"} | 190 | 48 |
coding | Solve the programming task below in a Python markdown code block.
any()
This expression returns True if any element of the iterable is true.
If the iterable is empty, it will return False.
Code
>>> any([1>0,1==0,1<0])
True
>>> any([1<0,2<1,3<2])
False
all()
This expression returns True if all of the elements of... | {"inputs": ["5\n12 9 61 5 14\n"], "outputs": ["True\n"]} | 337 | 27 |
coding | Solve the programming task below in a Python markdown code block.
The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$.
Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to comp... | {"inputs": ["6\n0 1\n18 0\n18 0\n3 3\n1 8\n2 7", "6\n0 1\n18 0\n18 0\n3 3\n1 8\n4 7", "6\n0 11\n70 0\n18 5\n5 3\n1 8\n2 5", "6\n0 11\n70 0\n18 5\n3 3\n1 8\n2 5", "6\n0 11\n26 0\n18 5\n3 3\n1 8\n2 5", "6\n0 11\n26 0\n18 5\n3 3\n1 8\n2 4", "6\n0 11\n26 0\n18 5\n3 3\n1 8\n2 7", "6\n0 11\n18 0\n18 5\n3 3\n1 8\n2 7"], "outp... | 253 | 276 |
coding | Solve the programming task below in a Python markdown code block.
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For e... | {"inputs": ["1\n1\n", "1\n1\n", "1\n1\n", "4\n2 1 4 3\n", "4\n2 1 3 4\n", "4\n1 2 4 3\n", "4\n1 4 2 3\n", "4\n3 1 2 4\n"], "outputs": ["1\n", "1\n", "1\n", "3 4 2 1\n", "-1\n", "-1\n", "1 3 4 2\n", "2 3 1 4\n"]} | 371 | 134 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length 2N, containing N occurrences of `a` and N occurrences of `b`.
You will choose some of the characters in S. Here, for each i = 1,2,...,N, it is not allowed to choose exactly one of the following two: the i-th occurrence... | {"inputs": ["3\nbabbaa", "3\naabbba", "3\nbababa", "3\naaabbb", "3\nbbaaba", "3\naabbab", "3\nababab", "3\nabbbaa"], "outputs": ["bbaa\n", "ba\n", "bababa\n", "ab\n", "bbaaba\n", "abab\n", "ababab\n", "bbaa\n"]} | 271 | 103 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness.
You are given an array richer where richer[i] = [ai, bi] indicates that ai has... | {"functional": "def check(candidate):\n assert candidate(richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]) == [5,5,2,5,4,5,6,7]\n assert candidate(richer = [], quiet = [0]) == [0]\n\n\ncheck(Solution().loudAndRich)"} | 219 | 110 |
coding | Solve the programming task below in a Python markdown code block.
A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously.
He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from t... | {"inputs": ["2\n8\n2", "2\n8\n4", "2\n4\n4", "2\n8\n6", "2\n4\n1", "2\n4\n0", "2\n10\n4", "2\n10\n6"], "outputs": ["0\n", "0\n", "0\n", "2\n", "0\n", "1\n", "1\n", "4\n"]} | 305 | 96 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The... | {"functional": "def check(candidate):\n assert candidate(digits = [1,2,3]) == [1,2,4]\n assert candidate(digits = [4,3,2,1]) == [4,3,2,2]\n assert candidate(digits = [0]) == [1]\n\n\ncheck(Solution().plusOne)"} | 117 | 78 |
coding | Solve the programming task below in a Python markdown code block.
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of... | {"inputs": ["2 0\n2 1\n", "2 5\n5 4\n", "2 0\n2 1\n", "2 5\n5 4\n", "2 2\n7 0\n", "2 5\n5 5\n", "2 5\n7 5\n", "2 2\n7 5\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "5\n", "0\n", "0\n", "0\n"]} | 609 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.
The bombs are represented by a... | {"functional": "def check(candidate):\n assert candidate(bombs = [[2,1,3],[6,1,4]]) == 2\n assert candidate(bombs = [[1,1,5],[10,10,5]]) == 1\n assert candidate(bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]) == 5\n\n\ncheck(Solution().maximumDetonation)"} | 220 | 109 |
coding | Solve the programming task below in a Python markdown code block.
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in... | {"inputs": ["2\n1 1\n1 2\n", "2\n1 1\n4 4\n", "2\n1 1\n5 1\n", "2\n1 1\n1 1\n", "2\n1 1\n1 0\n", "2\n1 1\n1 3\n", "2\n1 1\n0 4\n", "2\n1 1\n5 0\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n"]} | 608 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
N first-year students of the Faculty of Information Science and Technology of R University take the final exam of the lecture called Programming Exercise 1. The test is a perfect score of m. In other words, the score that one student c... | {"inputs": ["5 100", "5 110", "5 111", "6 110", "9 110", "9 100", "5 101", "9 000"], "outputs": ["0 0 0 100 100\n", "0 0 0 110 110\n", "0 0 0 111 111\n", "0 0 0 0 110 110\n", "0 0 0 0 0 110 110 110 110\n", "0 0 0 0 0 100 100 100 100\n", "0 0 0 101 101\n", "0 0 0 0 0 0 0 0 0\n"]} | 352 | 220 |
coding | Solve the programming task below in a Python markdown code block.
Poker Nim is another $2$-player game that's a simple variation on a Nim game. The rules of the games are as follows:
The game starts with $n$ piles of chips indexed from $\mbox{0}$ to $n-1$. Each pile $\boldsymbol{i}$ (where $0\leq i<n$) has $c_i$ chips... | {"inputs": ["2\n2 5\n1 2\n3 5\n2 1 3\n"], "outputs": ["First\nSecond\n"]} | 502 | 34 |
coding | Solve the programming task below in a Python markdown code block.
You are given integers A and B, each between 1 and 3 (inclusive).
Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.
-----Constraints-----
- All values in input are integers.
- 1 \leq A, B \l... | {"inputs": ["1 1", "2 4", "1 3", "2 0", "2 3", "2 6", "2 1", "3 3"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n"]} | 183 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Tunnel formula
One day while exploring an abandoned mine, you found a long formula S written in the mine. If you like large numbers, you decide to take out the choke and add `(` or `)` so that the result of the formula calculation is as large as possibl... | {"inputs": ["0-(2+3-4+5)", "0-(2+3-3+5)", "2-(2+3-4+5)", "1-(3+2-4+5)", "2-(2-3+4+5)", "0-(3+4-4+5)", "3+(2-4-4+5)", "2-(2+2-4+5)"], "outputs": ["4\n", "3\n", "6\n", "5\n", "12\n", "2\n", "10\n", "7\n"]} | 443 | 129 |
coding | Solve the programming task below in a Python markdown code block.
Our hardworking chef is bored of sleeping in his restaurants. He has decided to settle down. The first thing he must do is to find a suitable location to build a palatial home.
Think of the city as a two-dimensional grid. There are N restaurants in t... | {"inputs": ["3\n5\n0 0\n0 0\n1 0\n0 1\n0 -1\n5\n31 3\n30 -6\n20 15\n25 18\n25 38\n1\n0 0\n1 1", "3\n5\n0 0\n0 0\n1 0\n0 1\n0 -1\n5\n31 5\n30 -6\n20 15\n25 18\n25 38\n1\n0 0\n1 1", "3\n5\n0 0\n-1 0\n1 0\n0 1\n0 -1\n5\n4 7\n30 -41\n20 8\n26 18\n25 38\n2\n0 0\n1 1", "3\n5\n0 0\n0 0\n1 0\n0 1\n0 -1\n5\n31 5\n30 -6\n26 15\n... | 423 | 592 |
coding | Solve the programming task below in a Python markdown code block.
There is Kannon-do in the mountain behind Ichiro's house. There are 30 steps from the foot to this Kannon-do, and Ichiro goes to Kannon-do almost every day. Ichiro can go up the stairs up to 3 steps with one foot. While playing, I noticed that there are ... | {"inputs": ["1\n2\n4\n0\n0", "1\n0\n14\n6\n0", "1\n2\n21\n0\n0", "1\n1\n16\n5\n0", "1\n1\n16\n0\n1", "1\n20\n7\n5\n0", "1\n26\n0\n9\n0", "1\n9\n1\n20\n0"], "outputs": ["1\n1\n1\n", "1\n", "1\n1\n62\n", "1\n1\n3\n1\n", "1\n1\n3\n", "1\n34\n1\n1\n", "1\n1288\n", "1\n1\n1\n34\n"]} | 346 | 171 |
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. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.
Return the number of steps performed until nums becomes a non-decreasing ... | {"functional": "def check(candidate):\n assert candidate(nums = [5,3,4,4,7,3,6,11,8,5,11]) == 3\n assert candidate(nums = [4,5,7,7,13]) == 0\n\n\ncheck(Solution().totalSteps)"} | 106 | 74 |
coding | Solve the programming task below in a Python markdown code block.
\textit {Life is change, change is stability.}
Chef calls a sequence of integers A_{1}, A_{2}, \ldots, A_{N} stable if all the elements in the sequence are equal.
Chef gives you a sequence A_{1}, A_{2}, \ldots, A_{N}. You may perform the following ope... | {"inputs": ["2\n3\n1 1 1\n2\n69 96"], "outputs": ["0\n1"]} | 568 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions:
1 <= pivot < n
nums[0] + nums[1] + ... + nums[pivot - 1] == ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,-1,2], k = 3) == 1\n assert candidate(nums = [0,0,0], k = 1) == 2\n assert candidate(nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33) == 4\n\n\ncheck(Solution().waysToPartition)"} | 184 | 114 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is... | {"functional": "def check(candidate):\n assert candidate(source = \"abc\", target = \"abcbc\") == 2\n assert candidate(source = \"abc\", target = \"acdbc\") == -1\n assert candidate(source = \"xyz\", target = \"xzyxz\") == 3\n\n\ncheck(Solution().shortestWay)"} | 146 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in seq... | {"inputs": ["1 1\n0\n", "1 2\n1\n", "1 1\n0\n", "1 2\n1\n", "1 2\n0\n", "1 0\n1\n", "1 2\n-1\n", "1 2\n-1\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "-1\n", "-1\n"]} | 380 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another o... | {"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n1 1\n", "2\n2 2\n", "2\n2 4\n", "2\n1 4\n", "2\n4 3\n", "2\n8 3\n"], "outputs": ["3", "2", "2\n", "4\n", "6\n", "5\n", "7\n", "11\n"]} | 614 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (`HH:MM:SS`)
* `HH` = hours, padded to 2 digits, range: 00 - 99
* `MM` = minutes, padded to 2 digits, range: 00 - 59
* `SS` = seconds... | {"functional": "_inputs = [[0], [59], [60], [3599], [3600], [86399], [86400], [359999]]\n_outputs = [['00:00:00'], ['00:00:59'], ['00:01:00'], ['00:59:59'], ['01:00:00'], ['23:59:59'], ['24:00:00'], ['99:59:59']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 168 | 273 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the ith item. You are also given a rule represented by two strings, ruleKey and ruleValue.
The ith item... | {"functional": "def check(candidate):\n assert candidate(items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"lenovo\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"color\", ruleValue = \"silver\") == 1\n assert candidate(items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"phone\"],[... | 179 | 112 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.