problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Teams $A$ and $B$ are having a penalty shoot-out to decide the winner of their football match. Each team gets to take a shot $N$ times, and the team... | {"inputs": ["2\n3\n101011\n3\n100001"], "outputs": ["4\n6"]} | coding | 767 |
Solve the programming task below in a Python markdown code block.
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game a... | {"inputs": ["2\n1 2\n1 2\n", "2\n0 2\n1 2\n", "2\n1 2\n1 2\n", "2\n46 6\n6 46\n", "2\n46 6\n6 46\n", "2\n46 6\n12 46\n", "2\n75 6\n12 46\n", "2\n75 6\n12 34\n"], "outputs": ["0\n", "0\n", "0\n", "2\n", "2\n", "1\n", "0\n", "0\n"]} | coding | 537 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([10,5,15,3,7,None,18]), low = 7, high = 15) == 32\n assert candidate(root = tree_node([10,5,15,3,7,13,18,1,None,6]), low = 6, high = 10) == 23\n\n\ncheck(Solution().rangeSumBST)"} | coding | 145 |
Solve the programming task below in a Python markdown code block.
Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.
Now it's time for Timofey birthday, and his mother asked him to remove the tree. ... | {"inputs": ["2\n1 2\n1 1\n", "2\n1 2\n1 2\n", "2\n1 2\n1 0\n", "2\n1 2\n2 2\n", "3\n2 1\n2 3\n4 4 4\n", "3\n1 2\n1 3\n1 2 2\n", "3\n2 1\n2 3\n1 2 3\n", "3\n2 1\n2 3\n4 4 5\n"], "outputs": ["YES\n1", "YES\n1\n", "YES\n1\n", "YES\n1\n", "YES\n1", "YES\n1", "YES\n2", "YES\n2"]} | coding | 504 |
Solve the programming task below in a Python markdown code block.
There is an array of strings. All strings contains similar _letters_ except one. Try to find it!
```python
find_uniq([ 'Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a' ]) # => 'BbBb'
find_uniq([ 'abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba' ]) # =>... | {"functional": "_inputs = [[['Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a']], [['abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba']], [['silvia', 'vasili', 'victor']], [['Tom Marvolo Riddle', 'I am Lord Voldemort', 'Harry Potter']], [['', '', '', 'a', '', '']], [[' ', ' ', ' ', 'a', ' ', '']], [['foobar', 'barfo... | coding | 276 |
Solve the programming task below in a Python markdown code block.
You are given an array A of size N. In one operation, you can:
Choose an index i (1≤ i ≤ N) and increase A_{i} by 1.
Find the minimum number of operations required to convert the array A into a *permutation* of size N. If it is impossible to do so, prin... | {"inputs": ["4\n4\n3 1 1 2\n3\n0 3 3\n3\n3 2 1\n3\n2 0 1\n"], "outputs": ["3\n-1\n0\n3"]} | coding | 718 |
Solve the programming task below in a Python markdown code block.
Lumpy is a bus driver. Today, the conductor is absent so Lumpy has to do the conductor's job as well. There are N creatures in the bus. Sometimes the creatures don't carry change and can't pay the exact amount of the fare. Each creature in the bus today ... | {"inputs": ["3\n3 3 0\n1 2 2\n3 2 1\n1 2 1\n4 5 4\n2 3 4 5"], "outputs": ["2\n3\n3"]} | coding | 636 |
Solve the programming task below in a Python markdown code block.
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
To make a "red bouquet", it needs 3 red flowers. To make a "green bouquet", it needs... | {"inputs": ["3 6 9\n", "4 4 4\n", "0 0 0\n", "0 3 6\n", "7 8 9\n", "8 8 9\n", "3 5 5\n", "0 1 1\n"], "outputs": ["6\n", "4\n", "0\n", "3\n", "7\n", "8\n", "4\n", "0\n"]} | coding | 289 |
Solve the programming task below in a Python markdown code block.
There are N students in a school.
We will divide these students into some groups, and in each group they will discuss some themes.
You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many g... | {"inputs": ["8\n", "2\n", "9\n", "1\n", "296\n", "303\n", "807\n", "596\n"], "outputs": ["2\n", "0\n", "3\n", "0\n", "98\n", "101\n", "269\n", "198\n"]} | coding | 185 |
Solve the programming task below in a Python markdown code block.
Rohit has n empty boxes lying on the ground in a line. The size of the boxes is given in the form of an array $a$. The size of the ith box is denoted by $a[i]$. Since Rohit has a tiny room, there is a shortage of space. Therefore, he has to reduce the nu... | {"inputs": ["5\n16\n1\n4\n8\n2"], "outputs": ["3"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes inequalities. Please help him to solve next one.
Given four integers a, b, c, d. Find number of solutions x < y, where a ≤ x ≤ b and c ≤ y ≤ d and x, y integers.
... | {"inputs": ["1\n2 3 3 4", "1\n2 999999 1 1000000"], "outputs": ["3", "499998500001"]} | coding | 309 |
Solve the programming task below in a Python markdown code block.
Problem Statement
It is 2042 and we are surrounded by cyborgs everywhere. Geneo is one such cyborg with a human body and an electronic brain. To monitor skills and health of Geneo he is posed with questions everyday. On one fine day Geneo was asked the f... | {"inputs": ["2\n10 6\nabcdefghij\n10 1\nqwertyuiop"], "outputs": ["10 1\n159 1"]} | coding | 475 |
Solve the programming task below in a Python markdown code block.
Regular Tic-Tac-Toe is boring.
That's why in this Kata you will be playing Tic-Tac-Toe in **3D** using a 4 x 4 x 4 matrix!
# Kata Task
Play the game. Work out who wins.
Return a string
* `O wins after moves`
* `X wins after moves`
* `No winner`... | {"functional": "_inputs = [[[]]]\n_outputs = [['No winner']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all... | coding | 210 |
Solve the programming task below in a Python markdown code block.
# Definition
A **number** is called **_Automorphic number_** if and only if *its square ends in the same digits as the number itself*.
___
# Task
**_Given_** a **number** *determine if it Automorphic or not* .
___
# Warm-up (Highly recommended)
# [P... | {"functional": "_inputs = [[1], [3], [6], [9], [25], [53], [76], [95], [625], [225]]\n_outputs = [['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst... | coding | 675 |
Solve the programming task below in a Python markdown code block.
There are N boxes arranged in a circle. The i-th box contains A_i stones.
Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation:
* Select one box. Let the box be the i-th box. Then, fo... | {"inputs": ["4\n2 2 3 1", "4\n2 2 3 2", "4\n2 1 3 2", "4\n4 1 3 2", "4\n4 1 3 0", "4\n4 1 3 1", "4\n4 1 6 2", "4\n0 1 9 6"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 268 |
Solve the programming task below in a Python markdown code block.
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume ... | {"inputs": ["3 0\n", "1 0\n", "3 0\n", "4 3\n1 2 1\n2 3 1\n3 1 1\n", "4 3\n1 4 1\n2 3 1\n4 2 2\n", "4 3\n1 4 1\n2 3 1\n4 2 2\n", "4 2\n1 2 1\n2 3 1\n3 1 1\n", "4 2\n1 2 1\n2 3 1\n3 1 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "2\n", "2\n", "1\n", "1\n"]} | coding | 573 |
Solve the programming task below in a Python markdown code block.
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in n steps, at each step the processor gets some instru... | {"inputs": ["2 1 1 2\n1\n", "3 1 1 3\n2\n", "2 1 1 3\n2\n", "3 1 1 5\n3\n", "5 1 1 4\n1\n", "2 1 2 9\n9\n", "2 1 1 5\n1\n", "2 1 4 8\n5\n"], "outputs": ["Correct\n", "Correct\n", "Incorrect\n", "Correct\n", "Correct\n", "Correct\n", "Correct\n", "Incorrect\n"]} | coding | 482 |
Solve the programming task below in a Python markdown code block.
There are N islands lining up from west to east, connected by N-1 bridges.
The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.
One day, disputes took place between some islands, and there were M requests from the... | {"inputs": ["2 1\n1 2\n", "5 2\n2 4\n2 5", "5 2\n1 5\n2 5", "5 1\n1 5\n2 5", "5 1\n0 5\n2 5", "5 2\n1 4\n2 8", "5 2\n0 5\n2 5", "4 1\n1 5\n2 5"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 302 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The set [1, 2, 3, ..., n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for n = 3:
"123"
"132"
"213"
"231"
"312"
"321"
Given n an... | {"functional": "def check(candidate):\n assert candidate(n = 3, k = 3) == \"213\"\n assert candidate(n = 4, k = 9) == \"2314\"\n assert candidate(n = 3, k = 1) == \"123\"\n\n\ncheck(Solution().getPermutation)"} | coding | 140 |
Solve the programming task below in a Python markdown code block.
A wildlife study involving ducks is taking place in North America. Researchers are visiting some wetlands in a certain area taking a survey of what they see. The researchers will submit reports that need to be processed by your function.
## Input
The ... | {"functional": "_inputs = [[['Redhead 5', 'Labrador Duck 9', 'Blue-Winged Teal 25', \"Steller's Eider 200\"]], [['Canvasback 10', 'Mallard 150', 'American Wigeon 45', 'Baikal Teal 3', \"Barrow's Goldeneye 6\", 'Surf Scoter 12']], [['Redhead 3', 'Gadwall 1', 'Smew 4', 'Greater Scaup 10', 'Redhead 3', 'Gadwall 9',... | coding | 588 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.
You examine the typed characters of the keyboard. ... | {"functional": "def check(candidate):\n assert candidate(name = \"alex\", typed = \"aaleex\") == True\n assert candidate(name = \"saeed\", typed = \"ssaaedd\") == False\n\n\ncheck(Solution().isLongPressedName)"} | coding | 123 |
Solve the programming task below in a Python markdown code block.
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{... | {"inputs": ["1 1\n6\n1 1\n", "1 1\n6\n1 1\n", "1 1\n7\n1 1\n", "1 1\n5\n1 1\n", "1 1\n2\n1 1\n", "1 1\n3\n1 1\n", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2\n", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2\n"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\nYes\nYes\nYes\nYes\n", "Yes\nYes\nYes\nYes\nYes\n"]} | coding | 518 |
Solve the programming task below in a Python markdown code block.
You are given a colored permutation $p_1, p_2, \dots, p_n$. The $i$-th element of the permutation has color $c_i$.
Let's define an infinite path as infinite sequence $i, p[i], p[p[i]], p[p[p[i]]] \dots$ where all elements have same color ($c[i] = c[p[i]... | {"inputs": ["3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 8 7 5 8 4\n", "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 5 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "3\n4\n1 3 4 2\n1 1 2 3\n5\n2 3 4 5 1\... | coding | 757 |
Solve the programming task below in a Python markdown code block.
In Russia, there is an army-purposed station named UVB-76 or "Buzzer" (see also https://en.wikipedia.org/wiki/UVB-76). Most of time specific "buzz" noise is being broadcasted, but on very rare occasions, the buzzer signal is interrupted and a voice trans... | {"functional": "_inputs = [['Is this a right message?'], ['MDZHB 85 596 KLASA 81 00 02 91'], ['MDZHB 12 733 EDINENIE 67 79 66 32'], ['MDZHV 60 130 VATRUKH 58 89 54 54'], ['MDZHB 85 596 BRAMIRKA 81 00 02 91'], ['MDZHB 12 733 INITIAL 67 79 66 32'], ['MDZHB 60 130 KROLI5T 58 89 54 54'], ['MDZHB 85 596 KAMASIT 81 00 02 91'... | coding | 270 |
Solve the programming task below in a Python markdown code block.
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0.
You are given a sequence h=\{h_1,h_2,h_3,......\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by ... | {"inputs": ["1\n7\n", "4\n1 4 2 1", "4\n1 8 2 1", "4\n1 2 2 2", "4\n1 2 2 1", "4\n1 2 2 1\n", "4\n1 12 2 1", "4\n1 12 0 2"], "outputs": ["7\n", "4\n", "8\n", "2\n", "2", "2\n", "12\n", "14\n"]} | coding | 302 |
Solve the programming task below in a Python markdown code block.
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite nu... | {"inputs": ["2\n6 12 10\n4 3 10\n", "2\n8 12 10\n4 3 10\n", "2\n8 12 10\n4 6 10\n", "2\n6 12 10\n4 3 10\n", "2\n14 12 10\n4 6 10\n", "2\n19 12 10\n4 6 10\n", "1\n1 5244319080000 30030\n", "1\n1 5942671135120 30030\n"], "outputs": ["Finite\nInfinite\n", "Infinite\nInfinite\n", "Infinite\nInfinite\n", "Finite\nInfinite\n... | coding | 407 |
Solve the programming task below in a Python markdown code block.
You are a teacher at a cram school for elementary school pupils.
One day, you showed your students how to calculate division of fraction in a class of mathematics. Your lesson was kind and fluent, and it seemed everything was going so well - except for ... | {"inputs": ["1 3\n1 6\n3 9\n2 200\n7 99\n0 0", "1 3\n1 6\n6 9\n2 377\n7 99\n0 0", "1 3\n1 2\n6 9\n2 377\n7 99\n0 0", "2 3\n1 6\n6 9\n2 200\n7 24\n0 0", "1 3\n1 6\n6 18\n2 457\n7 2\n0 0", "1 5\n1 6\n6 18\n2 457\n7 2\n0 0", "2 7\n2 8\n3 4\n2 200\n2 62\n0 0", "2 7\n2 8\n5 8\n2 200\n2 62\n0 0"], "outputs": ["0 1\n1 1\n0 1\... | coding | 476 |
Solve the programming task below in a Python markdown code block.
-----Problem-----
Nikki's latest work is writing a story of letters. However, she finds writing story so boring that, after working for three hours, she realized that all she has written are M long words consisting entirely of letters A and B. Having... | {"inputs": ["3\nABAB\nAABB\nABBA"], "outputs": ["2"]} | coding | 446 |
Solve the programming task below in a Python markdown code block.
"Ring Ring!!"
Sherlock's phone suddenly started ringing. And it was none other than Jim Moriarty..
"Long time no see ! You miss me right ? Anyway we'll talk about it later . Let me first tell you something. Dr.Watson is with me . And you've got only on... | {"inputs": ["2\n4 4\n6 5"], "outputs": ["EVEN\nODD"]} | coding | 332 |
Solve the programming task below in a Python markdown code block.
Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x_1 = a, another one is in the point x_2 = b.
Each of the friends can move by one along the line in any direction unlimited number of times. When ... | {"inputs": ["3\n4\n", "1\n2\n", "2\n1\n", "2\n1\n", "1\n2\n", "1\n4\n", "3\n7\n", "3\n4\n"], "outputs": ["1\n", "1\n", "1\n", "1", "1", "4\n", "6\n", "1"]} | coding | 505 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n integer matrix grid containing distinct positive integers.
You have to replace each integer in the matrix with a positive integer satisfying the following conditions:
The relative order of ever... | {"functional": "def check(candidate):\n assert candidate(grid = [[3,1],[2,5]]) == [[2,1],[1,2]]\n assert candidate(grid = [[10]]) == [[1]]\n\n\ncheck(Solution().minScore)"} | coding | 284 |
Solve the programming task below in a Python markdown code block.
You are given a bracket sequence $s$ consisting of $n$ opening '(' and closing ')' brackets.
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the or... | {"inputs": ["1\n)\n", "1\n(\n", "1\n)\n", "2\n((\n", "2\n))\n", "2\n)(\n", "2\n)(\n", "2\n((\n"], "outputs": ["0\n", "0\n", "0", "1\n", "1\n", "0\n", "0", "1"]} | coding | 320 |
Solve the programming task below in a Python markdown code block.
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.... | {"inputs": ["1\n2\n9 8\n", "1\n2\n4 3\n", "1\n2\n6 5\n", "1\n2\n4 3\n", "1\n2\n9 8\n", "1\n2\n6 5\n", "1\n2\n10 8\n", "1\n2\n10 8\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 573 |
Solve the programming task below in a Python markdown code block.
There is a complete graph of m vertices. Initially, the edges of the complete graph are uncolored. Sunuke did the following for each i (1 ≤ i ≤ n): Select ai vertices from the complete graph and color all edges connecting the selected vertices with color... | {"inputs": ["2\n6\n3", "2\n6\n2", "2\n5\n2", "2\n1\n2", "2\n1\n3", "2\n8\n3", "2\n5\n1", "2\n3\n2"], "outputs": ["8\n", "7\n", "6\n", "2\n", "3\n", "10\n", "5\n", "4\n"]} | coding | 167 |
Solve the programming task below in a Python markdown code block.
Tenten runs a weapon shop for ninjas. Today she is willing to sell $n$ shurikens which cost $1$, $2$, ..., $n$ ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is f... | {"inputs": ["1\n- 1\n+\n", "1\n+\n- 1\n", "1\n+\n- 1\n", "1\n- 1\n+\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "3\n+\n+\n+\n- 2\n- 1\n- 2\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "4\n+\n+\n- 2\n+\n- 3\n+\n- 1\n- 4\n"], "outputs": ["NO\n", "YES\n1 \n", "YES\n1\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n4 2 3 1 \n"]} | coding | 723 |
Solve the programming task below in a Python markdown code block.
Mr. Chanek gives you a sequence a indexed from 1 to n. Define f(a) as the number of indices where a_i = i.
You can pick an element from the current sequence and remove it, then concatenate the remaining elements together. For example, if you remove the... | {"inputs": ["1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n5\n", "1\n7\n", "1\n3\n", "1\n83\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 368 |
Solve the programming task below in a Python markdown code block.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combin... | {"inputs": ["5 7\n0 0", "2 7\n0 0", "7 9\n0 0", "5 6\n0 0", "7 6\n0 0", "2 2\n0 0", "7 2\n0 0", "6 9\n0 0"], "outputs": ["1\n", "0\n", "3\n", "1\n", "1\n", "0\n", "0\n", "3\n"]} | coding | 205 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$. And you have a function $f(x)$ defined as:
f(x) = 1, if $x$ is a vowel
f(x) = 0, if $x$ is a constant
Your task is to apply the above function on all the characters in the string s and convert
the obtained binary string in d... | {"inputs": ["1\nhello"], "outputs": ["9"]} | coding | 262 |
Solve the programming task below in a Python markdown code block.
Professor GukiZ makes a new robot. The robot are in the point with coordinates (x_1, y_1) and should go to the point (x_2, y_2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot... | {"inputs": ["0 0\n4 5\n", "3 4\n6 1\n", "0 0\n4 6\n", "0 0\n2 1\n", "1 5\n6 4\n", "0 0\n5 4\n", "0 0\n4 0\n", "9 1\n1 1\n"], "outputs": ["5\n", "3\n", "6\n", "2\n", "5\n", "5\n", "4\n", "8\n"]} | coding | 314 |
Solve the programming task below in a Python markdown code block.
We have a country containing _N _cities. Each day we choose 2 cities such that there is no road between them and build a road between them. We choose each pair of nonadjacent cities with equal probability. Let X be the number of days before we obtain a c... | {"inputs": ["3\n", "4\n"], "outputs": ["2\n", "3\n"]} | coding | 311 |
Solve the programming task below in a Python markdown code block.
We have N bricks arranged in a row from left to right.
The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.
Among them, you can break at most N-1 bricks of your choice.
Let us say there are K bricks remaining. Snuke will be sa... | {"inputs": ["1\n2", "1\n0", "1\n4", "1\n5", "1\n3", "1\n6", "1\n7", "1\n1"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0"]} | coding | 305 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.
The value of |x| is defined as:
x if x >= 0.
-x if x < 0.
Please complete the followi... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,1], k = 1) == 4\n assert candidate(nums = [1,3], k = 3) == 0\n assert candidate(nums = [3,2,1,5,4], k = 2) == 3\n\n\ncheck(Solution().countKDifference)"} | coding | 114 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a pattern and a string s, return true if s matches the pattern.
A string s matches a pattern if there is some bijective mapping of single characters to non-empty strings such that if each character in pattern is... | {"functional": "def check(candidate):\n assert candidate(pattern = \"abab\", s = \"redblueredblue\") == True\n assert candidate(pattern = \"aaaa\", s = \"asdasdasdasd\") == True\n assert candidate(pattern = \"aabb\", s = \"xyzabcxzyabc\") == False\n\n\ncheck(Solution().wordPatternMatch)"} | coding | 135 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s of lowercase English letters and an integer array shifts of the same length.
Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').
For exam... | {"functional": "def check(candidate):\n assert candidate(s = \"abc\", shifts = [3,5,9]) == \"rpl\"\n\n\ncheck(Solution().shiftingLetters)"} | coding | 168 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from... | {"functional": "def check(candidate):\n assert candidate(arr = [1,-2,0,3]) == 4\n assert candidate(arr = [1,-2,-2,3]) == 3\n assert candidate(arr = [-1,-1,-1,-1]) == -1\n\n\ncheck(Solution().maximumSum)"} | coding | 133 |
Solve the programming task below in a Python markdown code block.
Given a string of integers, return the number of odd-numbered substrings that can be formed.
For example, in the case of `"1341"`, they are `1, 1, 3, 13, 41, 341, 1341`, a total of `7` numbers.
`solve("1341") = 7`. See test cases for more examples.
... | {"functional": "_inputs = [['1341'], ['1357'], ['13471'], ['134721'], ['1347231'], ['13472315']]\n_outputs = [[7], [10], [12], [13], [20], [28]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstan... | coding | 215 |
Solve the programming task below in a Python markdown code block.
A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.
On the i-th day the festival will show a movie of genre a_{i}. W... | {"inputs": ["2 2\n1 2\n", "2 2\n1 2\n", "7 3\n3 1 3 2 3 1 2\n", "7 3\n3 1 2 2 3 1 2\n", "7 3\n3 1 2 3 3 1 2\n", "7 3\n3 1 3 2 3 1 2\n", "10 3\n1 1 2 3 2 3 3 1 1 3\n", "10 2\n1 2 2 1 1 2 1 1 2 2\n"], "outputs": ["1", "1\n", "1", "1\n", "1\n", "1\n", "3", "1"]} | coding | 676 |
Solve the programming task below in a Python markdown code block.
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r).
He has a set that consists of n integer segments: [l_1; r_1], [l_2; r_2], ..., [l_{n}; r_{n}]. We know that no two segments of this set intersect. In one move Polo ... | {"inputs": ["1 7\n0 0\n", "1 7\n0 0\n", "1 1\n0 0\n", "1 2\n0 0\n", "2 3\n1 2\n3 4\n", "2 1\n1 2\n3 4\n", "2 3\n1 2\n3 7\n", "2 2\n1 2\n3 4\n"], "outputs": ["6\n", "6\n", "0\n", "1\n", "2\n", "0\n", "2\n", "0\n"]} | coding | 442 |
Solve the programming task below in a Python markdown code block.
An area named Renus, is divided into $(N \times M)$ cells. According to archaeological survey the area contains huge amount of treasure. Some cells out of $(N \times M)$ cells contain treasure. But problem is, you can't go to every cell as some of the ce... | {"inputs": ["1\n3 3\n2\n1 1\n1 3\n2\n2 1\n2 2"], "outputs": ["0 1 0\nX X 1\n4 3 2"]} | coding | 666 |
Solve the programming task below in a Python markdown code block.
Taro and Hanako decided to play hit-and-blow. The hit-and-blow rules are as follows.
* Separated into questioners and respondents.
* The questioner decides a 4-digit number (correct answer) that does not include duplicate numbers.
* Respondents guess th... | {"inputs": ["1234 5678\n1234 1354\n1234 1200\n1230 1023\n0123 1234\n0 0", "1234 5678\n1234 1354\n1234 1234\n1957 1023\n0123 1234\n0 0", "2530 9673\n2102 1354\n1234 1234\n1230 1849\n0123 1863\n0 0", "1234 5678\n1234 2600\n1234 1234\n1230 1023\n0123 1234\n0 0", "1234 9188\n2242 1354\n1234 1234\n1230 1023\n0123 1797\n0 0"... | coding | 462 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the availability time slots arrays slots1 and slots2 of two people and a meeting duration duration, return the earliest time slot that works for both of them and is of duration duration.
If there is no common ti... | {"functional": "def check(candidate):\n assert candidate(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8) == [60,68]\n assert candidate(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12) == []\n\n\ncheck(Solution().minAvailableDuration)"} | coding | 202 |
Solve the programming task below in a Python markdown code block.
Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts share... | {"inputs": ["1 1\n+ 1\n", "2 1\n- 2\n", "2 1\n- 2\n", "1 1\n+ 1\n", "3 1\n- 2\n", "3 1\n- 3\n", "20 1\n- 16\n", "20 1\n- 16\n"], "outputs": ["1\n1 ", "2\n1 2 ", "2\n1 2 \n", "1\n1 \n", "3\n1 2 3\n", "3\n1 2 3\n", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | coding | 614 |
Solve the programming task below in a Python markdown code block.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or ... | {"inputs": ["1 1 1\n0\n", "1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "1 1 1\n0\n", "2 1 1\n1\n1\n", "2 1 1\n1\n0\n", "2 1 1\n0\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n1\n", "0\n0\n", "0\n0\n"]} | coding | 602 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.
Please complete the following python code precisely:
```python
class Solution:
def maximalSq... | {"functional": "def check(candidate):\n assert candidate(matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]) == 4\n assert candidate(matrix = [[\"0\",\"1\"],[\"1\",\"0\"]]) == 1\n assert candidate(matrix = [[\"0\"]]) == 0\n... | coding | 80 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Bob and Alice are playing a game with the following rules:
Initially, they have an integer sequence $A_{1}, A_{2}, \ldots, A_{N}$; in addition, Bob h... | {"inputs": ["2\n5 3 2\n1 2 3 4 5\n5 2 4\n1 2 3 4 5"], "outputs": ["ALICE\nBOB"]} | coding | 541 |
Solve the programming task below in a Python markdown code block.
There are $n$ students standing in a circle in some order. The index of the $i$-th student is $p_i$. It is guaranteed that all indices of students are distinct integers from $1$ to $n$ (i. e. they form a permutation).
Students want to start a round danc... | {"inputs": ["1\n11\n11 2 3 4 5 6 7 8 9 10 1\n", "1\n11\n11 2 1 4 5 6 7 8 9 10 1\n", "1\n11\n11 2 1 4 5 6 7 9 9 10 1\n", "1\n11\n11 2 3 4 5 6 7 4 9 10 1\n", "1\n11\n11 2 3 4 5 6 7 13 9 10 1\n", "1\n11\n11 2 3 4 5 6 7 13 5 10 1\n", "1\n11\n11 2 3 6 5 6 7 13 5 10 1\n", "1\n11\n11 2 6 6 5 6 7 13 5 10 1\n"], "outputs": ["NO... | coding | 605 |
Solve the programming task below in a Python markdown code block.
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he n... | {"inputs": ["3\n5 3 2\n", "3\n1 2 2\n", "3\n5 4 2\n", "3\n5 7 2\n", "3\n3 7 2\n", "3\n5 5 2\n", "3\n5 4 3\n", "3\n3 0 2\n"], "outputs": ["3\n", "1\n", "1\n", "3\n", "3\n", "3\n", "2\n", "1\n"]} | coding | 208 |
Solve the programming task below in a Python markdown code block.
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candle... | {"inputs": ["4 2\n", "6 3\n", "1 2\n", "1 3\n", "1 4\n", "2 2\n", "3 2\n", "3 3\n"], "outputs": ["7\n", "8\n", "1\n", "1\n", "1\n", "3\n", "5\n", "4\n"]} | coding | 267 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane... | {"functional": "def check(candidate):\n assert candidate(towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2) == [2,1]\n assert candidate(towers = [[23,11,21]], radius = 9) == [23,11]\n assert candidate(towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2) == [1,2]\n\n\ncheck(Solution().bestCoordinate)"} | coding | 332 |
Solve the programming task below in a Python markdown code block.
10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two contests.... | {"inputs": ["10\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n", "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323\n", "100\n41 60\n89 29\n11 59\n41 43\n7 32\n41 47\n19 59\n3 67\n74 91\n99 10\n29 44\n35 36\n61 44\n84 14\n3 70\n1 18\n42 79\n96 8\n37 4\n64 12\n1 14\n27 28\n66 2\n48 28\n94 69\n61 99\n8... | coding | 419 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains... | {"functional": "def check(candidate):\n assert candidate(text = \" this is a sentence \") == \"this is a sentence\"\n assert candidate(text = \" practice makes perfect\") == \"practice makes perfect \"\n assert candidate(text = \"hello world\") == \"hello world\"\n assert candidate(tex... | coding | 159 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented by a 0). All cells outside the grid are co... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1,0],[1,1,1,1]]) == 2\n assert candidate(grid = [[1,1,1],[1,1,1]]) == 2\n assert candidate(grid = [[1,0,1],[0,0,0],[1,0,1]]) == 0\n assert candidate(grid = [[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]]) == 13\n\n\ncheck(Solution().cou... | coding | 426 |
Solve the programming task below in a Python markdown code block.
Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II.
* insert $k$: Insert a node containing $k$ as key into $T$.
* find $k$: Report whether $T$ has a node containing... | {"inputs": ["18\ninsert 4\ninsert 2\ninsert 3\ninsert 7\ninsert 8\ninsert 1\nfind 0\nfind 2\nfind 3\nfind 4\nfind 5\nfind 6\nfind 3\nfind 5\nprint\ndelete 3\ndelete 7\nprint", "18\ninsert 8\ninsert 2\ninsert 3\ninsert 7\ninsert 22\ninsert 1\nfind 1\nfind 2\nfind 1\nfind 4\nfind 5\nfind 6\nfind 7\nfind 8\nprint\ndelete ... | coding | 609 |
Solve the programming task below in a Python markdown code block.
At the legendary times of Nonsenso wars in ISM Dhanbad, there was a neck to neck competition between Barney Stinson and Sheldon Cooper. They both were on level 19. After trying too hard both of them could not decipher the nonsense, so they decided to pla... | {"inputs": ["2\n721011081081113287111114108100\n871011089911110910132116111327311010010597"], "outputs": ["Hello World\nWelcome to India"]} | coding | 258 |
Solve the programming task below in a Python markdown code block.
BerPhone X is almost ready for release with n applications being preinstalled on the phone. A category of an application characterizes a genre or a theme of this application (like "game", "business", or "education"). The categories are given as integers ... | {"inputs": ["3\n11\n1 5 1 3 1 5 1 1 1 1 5\n6\n1 2 2 2 2 1\n5\n4 3 3 1 2\n", "3\n11\n1 5 1 3 1 2 1 1 1 1 5\n6\n1 2 2 2 4 1\n5\n4 3 3 1 2\n", "3\n11\n1 5 1 3 2 2 1 1 1 1 5\n6\n1 2 2 2 4 2\n5\n4 3 3 1 2\n", "3\n11\n1 5 1 2 2 2 1 1 1 1 5\n6\n1 2 2 2 4 2\n5\n4 3 3 1 2\n", "3\n11\n2 5 1 5 1 5 1 1 1 1 5\n6\n1 2 2 2 2 1\n5\n4 ... | coding | 522 |
Solve the programming task below in a Python markdown code block.
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs th... | {"inputs": ["2\n010 0", "2\n001 0", "2\n101 0", "2\n111 0", "2\n110 0", "2\n110 1", "2\n100 1", "2\n010 1"], "outputs": ["10 0\n", "1 0\n", "101 0\n", "111 0\n", "110 0\n", "110 1\n", "100 1\n", "10 1\n"]} | coding | 391 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. We say that two integers x and y form a prime number pair if:
1 <= x <= y <= n
x + y == n
x and y are prime numbers
Return the 2D sorted list of prime number pairs [xi, yi]. The list shou... | {"functional": "def check(candidate):\n assert candidate(n = 10) == [[3,7],[5,5]]\n assert candidate(n = 2) == []\n\n\ncheck(Solution().findPrimePairs)"} | coding | 158 |
Solve the programming task below in a Python markdown code block.
John is very good in shooting. We wants to get admitted in HackerEarth Shooting Academy (HESA). But HESA take very hard interview process to select the candidates. In the Interview process, an assignment is given to John.
In this assignment, some amount... | {"inputs": ["5\n27 3\n64 4\n23 5\n10 2\n12 4"], "outputs": ["3 0\n3 0\n0 23\n1 5\n1 3"]} | coding | 244 |
Solve the programming task below in a Python markdown code block.
Story:
In the realm of numbers, the apocalypse has arrived. Hordes of zombie numbers have infiltrated and are ready to turn everything into undead. The properties of zombies are truly apocalyptic: they reproduce themselves unlimitedly and freely interact... | {"functional": "_inputs = [[[7, 11]], [[1, 7, 15]], [[2, 10]], [[687, 829, 998]], [[]], [[1]]]\n_outputs = [[59], [0], [-1], [45664], [-1], [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 isinstan... | coding | 420 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integer arrays nums and target, of the same length.
In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and:
set nums[i] = nums[i] + 2 and
set nu... | {"functional": "def check(candidate):\n assert candidate(nums = [8,12,6], target = [2,14,10]) == 2\n assert candidate(nums = [1,2,5], target = [4,1,3]) == 1\n assert candidate(nums = [1,1,1,1,1], target = [1,1,1,1,1]) == 0\n\n\ncheck(Solution().makeSimilar)"} | coding | 166 |
Solve the programming task below in a Python markdown code block.
Implement the [Polybius square cipher](http://en.wikipedia.org/wiki/Polybius_square).
Replace every letter with a two digit number. The first digit is the row number, and the second digit is the column number of following square. Letters `'I'` and `'J'`... | {"functional": "_inputs = [['POLYBIUS'], ['CODEWARS'], ['POLYBIUS SQUARE CIPHER']]\n_outputs = [['3534315412244543'], ['1334141552114243'], ['3534315412244543 434145114215 132435231542']]\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,... | coding | 324 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M ... | {"functional": "def check(candidate):\n assert candidate(s = \"III\") == 3\n assert candidate(s = \"LVIII\") == 58\n assert candidate(s = \"MCMXCIV\") == 1994\n\n\ncheck(Solution().romanToInt)"} | coding | 343 |
Solve the programming task below in a Python markdown code block.
Consider the following array:
```
[1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 12345678910, 1234567891011...]
```
If we join these blocks of numbers, we come up with an infinite sequence which starts with `112123123412345123456...`. ... | {"functional": "_inputs = [[1], [2], [3], [100], [2100], [31000], [55], [123456], [123456789], [999999999999999999], [1000000000000000000], [999999999999999993]]\n_outputs = [[1], [1], [2], [1], [2], [2], [1], [6], [3], [4], [1], [7]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstanc... | coding | 309 |
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 an integer $N$. Find the largest integer between $1$ and $10$ (inclusive) which divides $N$.
------ Input ------
The first and only l... | {"inputs": ["91", "24"], "outputs": ["7", "8"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin, Russian and Vietnamese as well.
There are N sets of integers from 1 to K both inclusive. Find out number of pairs of sets whose union contains all the K elements.
------ Input ------
The first line contains an i... | {"inputs": ["3\n2 2\n1 1\n1 1\n3 2\n2 1 2\n2 1 2\n2 1 2\n3 4\n3 1 2 3\n4 1 2 3 4\n3 2 3 4"], "outputs": ["0\n3\n3"]} | coding | 429 |
Solve the programming task below in a Python markdown code block.
Chefina has an array A consisting of N positive integers.
A permutation subsequence of length M is a subsequence that represents a permutation of length M.
Now, Chefina asks Chef to find the count of permutation subsequences in array A.
The count can ... | {"inputs": ["2\n5\n1 2 3 2 4\n6\n1 3 5 8 9 8\n"], "outputs": ["7\n1"]} | coding | 494 |
Solve the programming task below in a Python markdown code block.
You are given an integer $x$ of $n$ digits $a_1, a_2, \ldots, a_n$, which make up its decimal notation in order from left to right.
Also, you are given a positive integer $k < n$.
Let's call integer $b_1, b_2, \ldots, b_m$ beautiful if $b_i = b_{i+k}$ ... | {"inputs": ["2 1\n33\n", "2 1\n99\n", "2 1\n31\n", "2 1\n33\n", "2 1\n12\n", "2 1\n31\n", "2 1\n12\n", "2 1\n33\n"], "outputs": ["2\n33\n", "2\n99\n", "2\n33\n", "2\n33\n", "2\n22\n", "2\n33\n", "2\n22\n", "2\n33\n"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
## A square of squares
You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks!
However, sometimes, you can't arrange them into a square. Ins... | {"functional": "_inputs = [[-1], [25], [26]]\n_outputs = [[False], [True], [False]]\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 Fa... | coding | 278 |
Solve the programming task below in a Python markdown code block.
A reversed arabic no is one whose digits have been written in the reversed order. However in this any trailing zeroes are omitted. The task at hand here is a simple one. You need to add two numbers which have been written in reversed arabic and return th... | {"inputs": ["1\n24 1"], "outputs": ["34"]} | coding | 185 |
Solve the programming task below in a Python markdown code block.
Ashish has an array $a$ of size $n$.
A subsequence of $a$ is defined as a sequence that can be obtained from $a$ by deleting some elements (possibly none), without changing the order of the remaining elements.
Consider a subsequence $s$ of $a$. He defi... | {"inputs": ["2 2\n5 10\n", "2 2\n5 10\n", "4 2\n1 2 3 4\n", "4 3\n1 2 3 4\n", "4 2\n1 3 3 4\n", "4 2\n1 2 3 4\n", "4 3\n1 2 3 4\n", "5 3\n5 3 4 2 6\n"], "outputs": ["5", "5\n", "1", "2", "1\n", "1\n", "2\n", "2"]} | coding | 624 |
Solve the programming task below in a Python markdown code block.
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings s and t to Vitaly. The... | {"inputs": ["y\nz\n", "a\nz\n", "q\nz\n", "x\nz\n", "a\nb\n", "w\nz\n", "p\nz\n", "b\nc\n"], "outputs": ["No such string", "b", "r", "y", "No such string", "x\n", "q\n", "No such string\n"]} | coding | 392 |
Solve the programming task below in a Python markdown code block.
Some new animals have arrived at the zoo. The zoo keeper is concerned that perhaps the animals do not have the right tails. To help her, you must correct the broken function to make sure that the second argument (tail), is the same as the last letter of ... | {"functional": "_inputs = [['Fox', 'x'], ['Rhino', 'o'], ['Meerkat', 't'], ['Emu', 't'], ['Badger', 's'], ['Giraffe', 'd']]\n_outputs = [[True], [True], [True], [False], [False], [False]]\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,... | coding | 126 |
Solve the programming task below in a Python markdown code block.
A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly $1$ meter in one of the four cardinal directions: north, south, west, and east. For the first step the robot can choose any of the four direction... | {"inputs": ["1\n", "2\n", "3\n", "8\n", "4\n", "5\n", "6\n", "7\n"], "outputs": ["4\n", "4\n", "12\n", "25\n", "9\n", "24\n", "16\n", "40\n"]} | coding | 317 |
Solve the programming task below in a Python markdown code block.
Vlad enjoys listening to music. He lives in Sam's Town. A few days ago he had a birthday, so his parents gave him a gift: MP3-player! Vlad was the happiest man in the world! Now he can listen his favorite songs whenever he wants!
Vlad built up his own pl... | {"inputs": ["3\n4\n1 3 4 2\n2\n5\n1 2 3 9 4\n5\n5\n1 2 3 9 4 \n2", "3\n4\n1 3 7 2\n1\n5\n1 2 0 9 4\n5\n5\n1 2 3 9 4 \n2", "3\n4\n1 3 4 2\n1\n5\n1 2 0 2 4\n5\n5\n1 2 3 9 4 \n2", "3\n4\n1 3 4 2\n2\n5\n1 2 3 9 8\n5\n5\n1 2 3 9 4 \n1", "3\n4\n1 3 4 2\n1\n5\n1 2 0 9 4\n5\n5\n1 2 3 1 4 \n2", "3\n4\n1 3 4 2\n0\n5\n1 2 3 9 4\n... | coding | 761 |
Solve the programming task below in a Python markdown code block.
You are given a chessboard of size NxN. There is a white knight and several black pawns located on the board. The knight can move similarly to the normal knight in the game of chess; however it can only move towards the right of the board (see the below ... | {"inputs": ["1\n5\nK....\n..P..\n.P...\n...P.\n....."], "outputs": ["2"]} | coding | 284 |
Solve the programming task below in a Python markdown code block.
While most devs know about [big/little-endianness](https://en.wikipedia.org/wiki/Endianness), only a selected few know the secret of real hard core coolness with mid-endians.
Your task is to take a number and return it in its mid-endian format, putting ... | {"functional": "_inputs = [[9999999], [0], [658188], [168496141], [43135012110]]\n_outputs = [['96987F'], ['00'], ['0B0A0C'], ['0D0B0A0C'], ['0D0B0A0C0E']]\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 ... | coding | 217 |
Solve the programming task below in a Python markdown code block.
Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.
Mike believes that the day will be successful in case exactly two different letters i... | {"inputs": ["2\nABABAB\nABC"], "outputs": ["YES\nNO"]} | coding | 331 |
Solve the programming task below in a Python markdown code block.
Chef wants to buy a stock whose price was S rupees when the market opened. He will buy the stock if and only if its price is in the range [A, B]. The price of the stock has changed by C\% by the time he was trying to buy the stock. Will he be able to buy... | {"inputs": ["3\n100 93 108 7\n100 94 100 -7\n183 152 172 -17"], "outputs": ["Yes\nNo\nNo"]} | coding | 469 |
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 tree $G$ with $N$ vertices numbered $1$ through $N$. It is guaranteed that $N$ is even.
For a positive integer $k$, let's define a g... | {"inputs": ["2\n2\n1 2\n6\n1 2\n1 3\n3 4\n3 5\n3 6"], "outputs": ["1\n1\n2\n2\n1 3 5\n2 4 6"]} | coding | 661 |
Solve the programming task below in a Python markdown code block.
Let's call a permutation $p$ of length $n$ anti-Fibonacci if the condition $p_{i-2} + p_{i-1} \ne p_i$ holds for all $i$ ($3 \le i \le n$). Recall that the permutation is the array of length $n$ which contains each integer from $1$ to $n$ exactly once.
... | {"inputs": ["2\n4\n3\n"], "outputs": ["1 4 3 2\n2 4 3 1\n3 4 2 1\n4 3 2 1\n1 3 2\n2 3 1\n3 2 1\n"]} | coding | 332 |
Solve the programming task below in a Python markdown code block.
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he ... | {"inputs": ["2\n2\n2\n1\n", "9\n2\n4\n1\n", "9\n2\n2\n1\n", "4\n2\n4\n2\n", "5\n3\n6\n4\n", "9\n2\n2\n1\n", "2\n2\n2\n1\n", "9\n2\n4\n1\n"], "outputs": ["1\n", "4\n", "8\n", "2\n", "1\n", "8\n", " 1\n", " ... | coding | 465 |
Solve the programming task below in a Python markdown code block.
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.
Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n ... | {"inputs": ["1 2\n1 0\n", "1 2\n5 0\n", "1 9\n9 0\n", "1 1\n1 0\n", "1 9\n9 1\n", "1 2\n2 1\n", "1 1\n1 0\n", "1 2\n5 0\n"], "outputs": ["0\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n", "0\n", "-1\n"]} | coding | 465 |
Solve the programming task below in a Python markdown code block.
Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation is transfo... | {"inputs": ["aa\naa\n1\n", "ab\nba\n0\n", "hi\nhi\n1\n", "ab\nba\n9\n", "aa\naa\n0\n", "ab\nab\n9\n", "ab\nca\n2\n", "ab\nbb\n2\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n"]} | coding | 453 |
Solve the programming task below in a Python markdown code block.
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration $\frac{a_{i}}{1000}$. Today, on the party in honour of Sergiy of Vancouver they decided to prepare ... | {"inputs": ["0 1\n0\n", "0 1\n0\n", "0 1\n1000\n", "0 1\n1000\n", "500 1\n1000\n", "500 1\n1000\n", "430 1\n1000\n", "50 2\n100 25\n"], "outputs": ["1\n", "1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "3\n"]} | coding | 606 |
Solve the programming task below in a Python markdown code block.
The educational program (AHK Education) of the Aiz Broadcasting Corporation broadcasts a program called "Play with Tsukuro" for children. Today is the time to make a box with drawing paper, but I would like to see if the rectangular drawing paper I prepa... | {"inputs": ["2 2\n2 3\n2 3\n2 3\n2 2\n5 2", "2 2\n2 3\n2 2\n2 3\n2 2\n2 2", "2 2\n2 3\n2 3\n2 2\n2 2\n5 2", "2 2\n2 3\n2 2\n2 3\n2 2\n2 3", "2 2\n2 3\n4 2\n2 3\n2 2\n2 3", "2 2\n2 3\n4 4\n2 3\n2 2\n2 3", "2 2\n2 3\n4 4\n2 3\n1 2\n2 3", "2 2\n2 3\n4 4\n2 3\n1 1\n2 3"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n",... | coding | 317 |
Solve the programming task below in a Python markdown code block.
Given an D-dimension array, where each axis is of length N, your goal is to find the sum of every index in the array starting from 0.
For Example if D=1 and N=10 then the answer would be 45 ([0,1,2,3,4,5,6,7,8,9])
If D=2 and N = 3 the answer is 18 which... | {"functional": "_inputs = [[2, 2], [2, 3], [3, 2], [3, 3], [1, 101], [10, 10], [10, 11], [11, 10], [11, 11], [15, 8], [19, 84], [17, 76]]\n_outputs = [[4], [18], [12], [81], [5050], [450000000000], [1296871230050], [4950000000000], [15692141883605], [1847179534663680], [2871495452512585452340652014195036913664], [60022... | coding | 310 |
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 tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer ... | {"inputs": ["1\n3\n1 2 4\n2 3 7\n1 5 10"], "outputs": ["1"]} | coding | 762 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of distinct strings words, return the minimal possible abbreviations for every word.
The following are the rules for a string abbreviation:
The initial abbreviation for each word is: the first characte... | {"functional": "def check(candidate):\n assert candidate(words = [\"like\", \"god\", \"internal\", \"me\", \"internet\", \"interval\", \"intension\", \"face\", \"intrusion\"]) == [\"l2e\",\"god\",\"internal\",\"me\",\"i6t\",\"interval\",\"inte4n\",\"f2e\",\"intr4n\"]\n assert candidate(words = [\"aa\",\"aaa\"]) =... | coding | 238 |
Solve the programming task below in a Python markdown code block.
The number 81 has a special property, a certain power of the sum of its digits is equal to 81 (nine squared). Eighty one (81), is the first number in having this property (not considering numbers of one digit).
The next one, is 512.
Let's see both cases... | {"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7]]\n_outputs = [[81], [512], [2401], [4913], [5832], [17576], [19683]]\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, tu... | coding | 226 |
Solve the programming task below in a Python markdown code block.
There is a game that uses numbers called "Fizz Buzz". In this game, multiple players count the numbers one by one, starting with 1, and each player says only one number after the previous player. At that time, you must say "Fizz" if it is divisible by 3,... | {"inputs": ["5 7\n1\n0\nFizz\n4\nBuzz\n6\n7\n3 5\n1\n2\n3\n4\n5\n0 0", "5 7\n1\n0\nFizz\n4\nBuzz\n6\n2\n3 5\n1\n2\n3\n4\n5\n0 0", "5 7\n1\n0\nFizz\n2\nBuzz\n6\n2\n3 5\n1\n2\n4\n4\n8\n0 0", "5 7\n1\n0\nFizz\n2\nzuzB\n6\n2\n3 5\n1\n2\n4\n4\n8\n0 0", "5 7\n1\n2\nFizz\n4\nBuzz\n6\n7\n3 5\n1\n1\n3\n4\n5\n0 0", "5 7\n1\n0\nF... | coding | 629 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.