task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers distance.
You start at the point (0, 0) on an X-Y plane, and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[... | {"functional": "def check(candidate):\n assert candidate(distance = [2,1,1,2]) == True\n assert candidate(distance = [1,2,3,4]) == False\n assert candidate(distance = [1,1,1,1]) == True\n\n\ncheck(Solution().isSelfCrossing)"} | 149 | 72 |
coding | Solve the programming task below in a Python markdown code block.
Program the function distance(p1, p2) which returns the distance between the points p1 and p2 in n-dimensional space. p1 and p2 will be given as arrays.
Your program should work for all lengths of arrays, and should return -1 if the arrays aren't of the... | {"functional": "_inputs = [[[], []], [[1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]]\n_outputs = [[-1], [-1]]\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... | 136 | 188 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
- Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
- Type 2: answer the num... | {"inputs": ["7\nabcdbbd\n6\n2 3 6\n1 5 y\n2 1 1\n1 4 a\n1 7 d\n2 1 7", "7\nabccbbd\n6\n2 3 6\n1 5 y\n2 1 1\n1 4 a\n1 7 d\n2 0 7", "7\nabdcbbd\n6\n2 3 6\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 0 7", "7\nabcdbbd\n6\n2 3 0\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 1 7", "7\nabccbbd\n6\n2 3 5\n1 5 z\n2 1 1\n1 5 a\n1 7 d\n2 0 7", "7\nabcdbbd\n... | 489 | 409 |
coding | Solve the programming task below in a Python markdown code block.
You are given the equation $\tan\alpha=\frac{p}{q}$ and a positive integer, $n$. Calculate $\tan n\alpha$. There are $\mathbf{T}$ test cases.
Input Format
The first line contains $\mathbf{T}$, the number of test cases.
The next $\mathbf{T}$ lines con... | {"inputs": ["2\n2 1 2\n5 6 7\n"], "outputs": ["666666670\n237627959\n"]} | 425 | 44 |
coding | Solve the programming task below in a Python markdown code block.
# Description
Given a number `n`, you should find a set of numbers for which the sum equals `n`. This set must consist exclusively of values that are a power of `2` (eg: `2^0 => 1, 2^1 => 2, 2^2 => 4, ...`).
The function `powers` takes a single paramet... | {"functional": "_inputs = [[1], [2], [4], [32], [128], [512], [6], [14], [688], [8197], [1966], [9007199254740991]]\n_outputs = [[[1]], [[2]], [[4]], [[32]], [[128]], [[512]], [[2, 4]], [[2, 4, 8]], [[16, 32, 128, 512]], [[1, 4, 8192]], [[2, 4, 8, 32, 128, 256, 512, 1024]], [[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024... | 294 | 864 |
coding | Solve the programming task below in a Python markdown code block.
Since due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and give him the... | {"inputs": ["2\n4\n16\n2 4 6 10\n4\n20\n2 8 12 10"], "outputs": ["2\n2"]} | 365 | 43 |
coding | Solve the programming task below in a Python markdown code block.
You have an array $a$ of size $n$ consisting only of zeroes and ones and an integer $k$. In one operation you can do one of the following:
Select $2$ consecutive elements of $a$ and replace them with their minimum (that is, let $a := [a_{1}, a_{2}, \ldo... | {"inputs": ["1\n32 32\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "7\n3 2\n0 1 0\n5 3\n1 0 1 1 0\n2 2\n1 1\n4 4\n0 0 0 0\n6 3\n0 0 1 0 0 1\n7 5\n1 1 1 1 1 1 1\n5 3\n0 0 1 0 0\n"], "outputs": ["NO\n", "YES\nYES\nYES\nNO\nYES\nYES\nYES\n"]} | 749 | 196 |
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 | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.
k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is n... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 2), list_node([2,1,4,3,5]))\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 3), list_node([3,2,1,4,5]))\n\n\ncheck(Solution().reverseKGroup)"} | 185 | 102 |
coding | Solve the programming task below in a Python markdown code block.
problem
JOI decided to make a signboard for the store.
There are N old signboards with letters written at equal intervals. JOI makes a sign by erasing some letters from the old sign. I want the remaining characters to be the name of the store, and the ... | {"inputs": ["4\nbar\nabracadabra\nbear\nbar\nbbraxbara", "4\nrab\nabracadabra\nbear\nbar\nbbraxbara", "4\nrab\nabracadabra\nbear\nbar\narabxarbb", "4\nqab\nabracadabra\nbear\nbar\narabxarbb", "4\nqab\nabracadabra\nbear\nbra\narabxarbb", "4\nqab\nabrbcadaara\nbear\nbra\narabxarbb", "4\nqab\nabrbcadaara\nbear\nbra\narbbx... | 586 | 202 |
coding | Solve the programming task below in a Python markdown code block.
problem
JOI took six subjects: physics, chemistry, biology, earth science, history, and geography. Each test was scored on a 100-point scale.
JOI chooses 3 subjects from 4 subjects of physics, chemistry, biology, and earth science, and 1 subject from 2... | {"inputs": ["100\n0\n3\n2\n0\n-4", "100\n4\n41\n96\n1\n0", "100\n4\n68\n96\n1\n0", "100\n0\n55\n30\n0\n0", "100\n0\n55\n41\n0\n0", "100\n0\n34\n41\n0\n0", "100\n2\n50\n41\n0\n0", "100\n2\n50\n4\n-1\n0"], "outputs": ["105\n", "238\n", "265\n", "185\n", "196\n", "175\n", "191\n", "154\n"]} | 614 | 189 |
coding | Solve the programming task below in a Python markdown code block.
Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given n days from Petya's live and you have to determine what happened with his flower in the end.
The flower grows as follows:
* If the flower... | {"inputs": ["1\n7\n1 0 1 1 0 0 1 0 0 0\n", "1\n7\n0 0 1 1 0 0 1 0 0 0\n", "1\n7\n0 0 2 1 0 0 1 0 0 0\n", "1\n3\n0 0 2 1 0 0 1 0 0 0\n", "1\n3\n0 0 2 1 0 0 2 0 0 0\n", "1\n7\n0 0 1 1 0 0 1 1 0 0\n", "1\n7\n0 0 2 1 1 0 1 0 0 0\n", "1\n3\n0 0 2 1 1 0 1 0 0 0\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n",... | 395 | 247 |
coding | Solve the programming task below in a Python markdown code block.
# Bubblesort Algorithm
## Overview
The Bubblesort Algorithm is one of many algorithms used to sort a list of similar items (e.g. all numbers or all letters) into either ascending order or descending order. Given a list (e.g.):
```python
[9, 7, 5, 3, ... | {"functional": "_inputs = [[[9, 7, 5, 3, 1, 2, 4, 6, 8]], [[1, 2]], [[2, 1]], [[1, 3]], [[3, 1]], [[24, 57]], [[89, 36]], [[1, 2, 3]], [[2, 4, 1]], [[17, 5, 11]], [[25, 16, 9]], [[103, 87, 113]], [[1032, 3192, 2864]], [[1, 2, 3, 4]], [[2, 3, 4, 1]], [[3, 4, 1, 2]], [[4, 1, 2, 3]], [[7, 5, 3, 1]], [[5, 3, 7, 7]], [[3, 1... | 387 | 796 |
coding | Solve the programming task below in a Python markdown code block.
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
* the final tourname... | {"inputs": ["2\na\nA\nA-a 2:1\n", "2\na\nA\nA-a 1:2\n", "2\na\nA\na-A 1:2\n", "2\na\nA\na-A 2:1\n", "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 0:1\nB-D 0:3\nC-D 0:3\n", "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 0:1\nB-D 0:3\nD-C 0:3\n", "4\nA\nB\nC\nD\nA-B 1:1\nA-D 2:2\nD-A 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n", "... | 583 | 322 |
coding | Solve the programming task below in a Python markdown code block.
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t.
-----Constraints-----
- 1 ≤ ... | {"inputs": ["4 7 4", "1 7 4", "5 7 5", "2 7 4", "7 7 5", "9 6 5", "1 7 1", "1 7 0"], "outputs": ["2\n", "0\n", "3\n", "1\n", "5\n", "7\n", "0\n", "0\n"]} | 232 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer a_{i} — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginn... | {"inputs": ["1 4 1\n1\n", "1 4 1\n1\n", "2 2 2\n1 3\n", "2 3 1\n1 2\n", "2 3 1\n1 2\n", "2 2 2\n2 3\n", "2 2 2\n1 3\n", "3 3 2\n3 5 1\n"], "outputs": ["1\n", "1\n", "0\n", "2\n", "2\n", "1\n", "0\n", "1\n"]} | 496 | 132 |
coding | Solve the programming task below in a Python markdown code block.
problem
Given the sequence $ A $ of length $ N $. The $ i $ item in $ A $ is $ A_i $. You can do the following for this sequence:
* $ 1 \ leq i \ leq N --Choose the integer i that is 1 $. Swap the value of $ A_i $ with the value of $ A_ {i + 1} $.
F... | {"inputs": ["5\n0 2 3 4 5", "5\n1 2 1 4 5", "5\n0 2 3 4 8", "5\n0 1 3 4 5", "5\n0 2 3 4 2", "5\n0 2 3 8 2", "5\n0 4 3 9 4", "5\n1 5 3 1 8"], "outputs": ["2\n", "1\n", "2\n", "2\n", "1\n", "1\n", "0\n", "1\n"]} | 308 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.
The treasure map can be represented as a rectangle n × m in size. Each c... | {"inputs": ["3 3\n###\n#A#\n###\n1\nN 1\n", "3 3\n###\n#A#\n###\n1\nN 0\n", "3 4\n####\n#-A#\n####\n2\nW 1\nN 2\n", "3 4\n####\n#-A#\n####\n2\nW 2\nN 2\n", "3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n", "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nW 3\n", "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nS 1\n", "4... | 650 | 254 |
coding | Solve the programming task below in a Python markdown code block.
Given a $6\times6$ 2D Array, $\textbf{arr}$:
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
An hourglass in $\mbox{A}$ is a subset of values with indices falling in this pattern in $\textbf{arr}$'s graphical representation:
a... | {"inputs": ["1 1 1 0 0 0\n0 1 0 0 0 0\n1 1 1 0 0 0\n0 0 2 4 4 0\n0 0 0 2 0 0\n0 0 1 2 4 0\n"], "outputs": ["19\n"]} | 727 | 85 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A maximum tree is a tree where every node has a value greater than any other value in its subtree.
You are given the root of a maximum binary tree and an integer val.
Just as in the previous problem, the given tree wa... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,1,3,None,None,2]), val = 5), tree_node([5,4,None,1,3,None,None,2]))\n assert is_same_tree(candidate(root = tree_node([5,2,4,None,1]), val = 3), tree_node([5,2,4,None,1,None,3]))\n assert is_same_tree(candidate(root = tree... | 311 | 148 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has N sticks.
The length of the i-th stick is l_i.
Snuke is making a snake toy by joining K of the sticks together.
The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the to... | {"inputs": ["5 5\n1 2 3 4 5", "5 5\n2 2 3 4 5", "5 3\n2 2 3 4 5", "5 5\n1 2 2 4 5", "5 5\n3 2 3 4 5", "5 5\n1 4 2 4 0", "0 3\n1 1 4 8 0", "5 5\n3 2 3 4 7"], "outputs": ["15\n", "16\n", "12\n", "14\n", "17\n", "11\n", "13\n", "19\n"]} | 212 | 166 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:
You should build the array arr which has the following properties:
arr has exac... | {"functional": "def check(candidate):\n assert candidate(n = 2, m = 3, k = 1) == 6\n assert candidate(n = 5, m = 2, k = 3) == 0\n assert candidate(n = 9, m = 1, k = 1) == 1\n\n\ncheck(Solution().numOfArrays)"} | 168 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Your car starts at position 0 and speed +1 on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions 'A' (accelerate) and 'R' (reverse):... | {"functional": "def check(candidate):\n assert candidate(target = 3) == 2\n assert candidate(target = 6) == 5\n\n\ncheck(Solution().racecar)"} | 221 | 43 |
coding | Solve the programming task below in a Python markdown code block.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
-----Constraints-----
- 1000 ≤ N ≤ 9999
- N is an integer.
-----Input-----
Input is given fro... | {"inputs": ["860", "374", "425", "647", "317", "943", "308", "164"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 139 | 78 |
coding | Solve the programming task below in a Python markdown code block.
You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4).
Return:
* `0` if the elements can form such a sequence, and no ... | {"functional": "_inputs = [['1 2 3 5'], ['1 5'], [''], ['1 2 3 4 5'], ['2 3 4 5'], ['2 6 4 5 3'], ['_______'], ['2 1 4 3 a'], ['1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 ... | 336 | 536 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The red-green-blue color "#AABBCC" can be written as "#ABC" in shorthand.
For example, "#15c" is shorthand for the color "#1155cc".
The similarity between the two colors "#ABCDEF" and "#UVWXYZ" is -(AB - UV)2 - (CD ... | {"functional": "def check(candidate):\n assert candidate(color = \"#09f166\") == \"#11ee66\"\n assert candidate(color = \"#4e3fe1\") == \"#5544dd\"\n\n\ncheck(Solution().similarRGB)"} | 184 | 66 |
coding | Solve the programming task below in a Python markdown code block.
There is a right triangle ABC with ∠ABC=90°.
Given the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.
It is guaranteed that the area of the triangle ABC is an integer.
-----Constraints-----
- 1 \leq |AB|,|BC|,|... | {"inputs": ["3 3 5", "0 3 5", "1 2 7", "7 2 2", "3 4 5", "3 4 5\n", "1 10 1", "1 6 13"], "outputs": ["4\n", "0\n", "1\n", "7\n", "6", "6\n", "5\n", "3\n"]} | 177 | 96 |
coding | Solve the programming task below in a Python markdown code block.
At the end of a busy day, The Chef and his assistants play a game together. The game is not just for fun but also used to decide who will have to clean the kitchen. The Chef is a Game Master, so his concern is how to manage the game but not how to win th... | {"inputs": ["1\n5 2 3\n1 4\n3 5\n1 5", "1\n5 2 3\n1 4\n3 5\n0 5", "1\n5 2 3\n1 3\n3 5\n1 5", "1\n5 2 3\n2 4\n3 5\n0 5", "1\n5 2 3\n2 4\n2 5\n0 5", "1\n5 2 3\n2 4\n2 8\n0 5", "1\n4 2 3\n1 6\n3 9\n1 5", "1\n5 2 3\n5 4\n2 5\n0 3"], "outputs": ["1", "0\n", "4\n", "1\n", "2\n", "6\n", "7\n", "5\n"]} | 608 | 205 |
coding | Solve the programming task below in a Python markdown code block.
You have an award-winning garden and everyday the plants need exactly 40mm of water. You created a great piece of JavaScript to calculate the amount of water your plants will need when you have taken into consideration the amount of rain water that is fo... | {"functional": "_inputs = [[100], [40], [39], [5], [0]]\n_outputs = [['Your plant has had more than enough water for today!'], ['Your plant has had more than enough water for today!'], ['You need to give your plant 1mm of water'], ['You need to give your plant 35mm of water'], ['You need to give your plant 40mm of wate... | 114 | 235 |
coding | Solve the programming task below in a Python markdown code block.
Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia.
The game is played by two people taking turns, where Mr. Chanek takes... | {"inputs": ["2\n5\n6\n", "2\n6\n6\n", "2\n3\n6\n", "2\n4\n6\n", "2\n1\n6\n", "2\n7\n3\n", "2\n8\n3\n", "2\n5\n1\n"], "outputs": ["2\n4\n", "4\n4\n", "2\n4\n", "3\n4\n", "1\n4\n", "3\n2\n", "5\n2\n", "2\n1\n"]} | 394 | 118 |
coding | Solve the programming task below in a Python markdown code block.
A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.
In the festival m fireworks will be launched. The i-th ... | {"inputs": ["10 2 1\n1 1000 4\n9 1000 4\n", "10 2 1\n1 1000 4\n9 1000 4\n", "50 3 1\n49 1 1\n26 1 4\n6 1 6\n", "50 3 1\n49 1 1\n26 1 4\n8 1 6\n", "50 3 1\n49 1 1\n26 1 4\n4 1 6\n", "50 3 2\n49 1 1\n26 1 4\n6 1 6\n", "50 3 2\n49 1 1\n26 1 4\n4 1 6\n", "65 3 0\n49 1 1\n26 1 2\n4 1 6\n"], "outputs": ["1992\n", " ... | 500 | 280 |
coding | Solve the programming task below in a Python markdown code block.
We have five variables x_1, x_2, x_3, x_4, and x_5.
The variable x_i was initially assigned a value of i.
Snuke chose one of these variables and assigned it 0.
You are given the values of the five variables after this assignment.
Find out which variable ... | {"inputs": ["0 2 3 4 5\n", "1 2 0 4 5\n", "1 0 3 4 5\n", "1 2 3 0 5\n", "1 2 3 4 0\n"], "outputs": ["1\n", "3\n", "2\n", "4\n", "5\n"]} | 223 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a special keyboard with all keys in a single row.
Given a string keyboard of length 26 indicating the layout of the keyboard (indexed from 0 to 25). Initially, your finger is at index 0. To type a character, ... | {"functional": "def check(candidate):\n assert candidate(keyboard = \"abcdefghijklmnopqrstuvwxyz\", word = \"cba\") == 4\n assert candidate(keyboard = \"pqrstuvwxyzabcdefghijklmno\", word = \"leetcode\") == 73\n\n\ncheck(Solution().calculateTime)"} | 162 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Two red beads are placed between every two blue beads. There are N blue beads. After looking at the arrangement below work out the number of red beads.
@
@@
@
@@
@
@@
@
@@
@
@@
@
Implement count_red_beads(n) (in PHP count_red_beads($n); in Java, Javasc... | {"functional": "_inputs = [[0], [1], [3], [5]]\n_outputs = [[0], [0], [4], [8]]\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\... | 144 | 175 |
coding | Solve the programming task below in a Python markdown code block.
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for... | {"inputs": ["1 1\n2 1\n", "1 2\n2 1\n", "1 2\n3 1\n", "1 2\n3 2\n", "1 1\n2 1\n", "1 29\n2 8\n", "1 1\n1 10\n", "1 2\n2 10\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "8\n", "10\n", "10\n"]} | 383 | 123 |
coding | Solve the programming task below in a Python markdown code block.
Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
... | {"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "2\n1 1\n", "2\n1 1\n", "2\n1 0\n", "1\n1000\n", "1\n1000\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | 284 | 98 |
coding | Solve the programming task below in a Python markdown code block.
On a planet called RUIZ LAND, which is ruled by the queen, Erika Ruiz. Each person on that planet has a strength value (strength value >0).
That planet has a special rule made by the queen that a boy and a girl will form a couple if their Hate value is a... | {"inputs": ["2\n10 16"], "outputs": ["8 18"]} | 363 | 21 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string num of length n consisting of digits.
Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.
Please complete the fo... | {"functional": "def check(candidate):\n assert candidate(num = \"1210\") == True\n assert candidate(num = \"030\") == False\n\n\ncheck(Solution().digitCount)"} | 96 | 46 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes... | {"inputs": ["4\n4\n0 0 0 1\n2\n1 1\n6\n1 2 3 4 5 6\n4\n2 28 3 22\n"], "outputs": ["1\n0\n4\n3\n"]} | 747 | 62 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n.
Please complete the following python code precisely:
```python
class S... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 5\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().numTrees)"} | 80 | 43 |
coding | Solve the programming task below in a Python markdown code block.
For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that l... | {"inputs": ["4 6\n", "1 2\n", "1 4\n", "2 2\n", "6 7\n", "5 7\n", "3 7\n", "1 1\n"], "outputs": ["20\n", "14\n", "20\n", "14\n", "18\n", "20\n", "20\n", "8\n"]} | 362 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good n... | {"inputs": ["1 3 3\n", "7 8 2\n", "6 9 1\n", "6 9 1\n", "7 8 2\n", "7 8 1\n", "3 8 2\n", "1 4 3\n"], "outputs": ["1\n", "0\n", "2\n", "2\n", "0\n", "2\n", "0\n", "0\n"]} | 302 | 102 |
coding | Solve the programming task below in a Python markdown code block.
π (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name π is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίμετρος (perime... | {"inputs": ["0.15\n0.05\n0.0", "1.052205526162189\n0.05\n0.0", "0.15\n0.892857233308306\n0.0", "0.15\n0.897940711549928\n0.0", "1.0557371636651482\n0.05\n0.0", "0.4926473169582818\n0.05\n0.0", "0.5656950408067312\n0.05\n0.0", "1.0653255099845902\n0.05\n0.0"], "outputs": ["3/1\n19/6", "3/1\n19/6\n", "3/1\n3/1\n", "3/1\n... | 488 | 306 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you will create a function that takes in a list and returns a list with the reverse order.
### Examples
```python
reverse_list([1,2,3,4]) == [4,3,2,1]
reverse_list([3,1,5,4]) == [4,5,1,3]
```
Also feel free to reuse/extend the following st... | {"functional": "_inputs = [[[1, 2, 3, 4]], [[3, 1, 5, 4]], [[3, 6, 9, 2]], [[1]]]\n_outputs = [[[4, 3, 2, 1]], [[4, 5, 1, 3]], [[2, 9, 6, 3]], [[1]]]\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 isi... | 106 | 226 |
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 elements that have both a strictly smaller and a strictly greater element appear in nums.
Please complete the following python code precisely:
```python
class Soluti... | {"functional": "def check(candidate):\n assert candidate(nums = [11,7,2,15]) == 2\n assert candidate(nums = [-3,3,3,90]) == 2\n\n\ncheck(Solution().countElements)"} | 74 | 58 |
coding | Solve the programming task below in a Python markdown code block.
In some countries of former Soviet Union there was a belief about lucky tickets. A transport ticket of any sort was believed to posess luck if sum of digits on the left half of its number was equal to the sum of digits on the right half. Here are example... | {"functional": "_inputs = [['5555'], ['003111'], ['543970707'], ['439924'], ['943294329932'], ['000000'], ['454319'], ['1233499943'], ['935336']]\n_outputs = [[True], [True], [False], [False], [False], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstan... | 292 | 259 |
coding | Solve the programming task below in a Python markdown code block.
DestinyLand is a really fun place for kids. It is composed of N islands, numbered from 1 to N. The company is planning to divide these N islands into exactly M area, such that, each island will belong to one of the M areas, and each area will contain at ... | {"inputs": ["3\n3 2 1 1000003\n3 1 2 1234567891\n3 1 1 314159\n"], "outputs": ["6\n9\n6\n"]} | 388 | 62 |
coding | Solve the programming task below in a Python markdown code block.
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the f... | {"inputs": ["1\n5\n", "1\n5\n", "1\n2\n", "2\n0 1\n", "2\n0 5\n", "2\n0 5\n", "2\n0 1\n", "3\n1 1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 351 | 98 |
coding | Solve the programming task below in a Python markdown code block.
Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.
In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.
Du will chat in the group for n days.... | {"inputs": ["1 1 0\n0\n", "1 1 1\n2\n", "1 1 1\n0\n", "1 1 0\n2\n", "1 1 1\n1\n", "1 0 1\n0\n", "5 3 3\n8 5 5 1 14\n", "5 3 3\n8 5 5 2 14\n"], "outputs": ["0\n", "2\n", "0\n", "2\n", "1\n", "0\n", "22\n", "22\n"]} | 558 | 138 |
coding | Solve the programming task below in a Python markdown code block.
There are N towns in the State of Atcoder, connected by M bidirectional roads.
The i-th road connects Town A_i and B_i and has a length of C_i.
Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).
She will fly to the ... | {"inputs": ["5 3 2\n1 3\n2 3 2\n1 3 6\n1 2 2", "5 3 2\n1 3\n2 3 2\n1 3 6\n1 1 2", "3 3 2\n1 3\n2 3 0\n0 3 6\n1 2 2", "6 3 2\n1 3\n2 3 2\n1 3 9\n0 1 2", "6 3 2\n1 4\n4 3 2\n1 3 9\n0 1 2", "5 3 2\n2 2\n2 3 0\n1 5 8\n1 2 2", "6 3 2\n1 3\n2 3 2\n1 3 6\n1 1 2", "6 3 2\n1 3\n2 3 2\n1 3 7\n1 1 2"], "outputs": ["4\n", "6\n", "... | 425 | 271 |
coding | Solve the programming task below in a Python markdown code block.
C: Skewering
problem
One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura.
There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of... | {"inputs": ["2 1 1", "2 1 2", "4 1 2", "2 1 0", "4 1 3", "2 2 0", "0 1 2", "7 1 3"], "outputs": ["Hom\n", "Tem\n", "Tem\n", "Tem\n", "Hom\n", "Tem\n", "Tem\n", "Hom\n"]} | 476 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed ... | {"inputs": ["2\n3\n5 6 2\n1.0 0.0 0.5\n4\n2 2 2 2\n0.5 0.5 0.5 0.5"], "outputs": ["6.000000000000000\n1.000000000000000"]} | 682 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that returns the index of the first occurence of the word "Wally". "Wally" must not be part of another word, but it can be directly followed by a punctuation mark. If no such "Wally" exists, return -1.
Examples:
"Wally" => 0
"Where... | {"functional": "_inputs = [[''], ['WAlly'], ['wAlly'], ['DWally'], ['.Wally'], ['Wallyd'], [\"wally mollyWally Wallybrolly 'Wally\"], ['Walley ,Wally -Wally ;Wally +Wally :Wally'], ['Walley Wally, Wally- Wally: Wally+ Wally:'], ['12Wally Wally01 W.ally'], [\"Where's Waldo\"], ['Wally'], ['Wally Wally'], ['W ally Wally'... | 174 | 369 |
coding | Solve the programming task below in a Python markdown code block.
There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login in this si... | {"inputs": ["2\n3527\n47269"], "outputs": ["1305\n25047"]} | 280 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berl... | {"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n2\n", "2\n2 1\n", "2\n2 1\n", "2\n2 0\n"], "outputs": ["1 ", "0 ", "1 ", "0 ", "2 ", ":(\n", ":(", "1 1 "]} | 623 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Problem description.
Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the string with mini... | {"inputs": ["1\n9"], "outputs": ["XXXDDD"]} | 242 | 15 |
coding | Solve the programming task below in a Python markdown code block.
# Definition
An **_element is leader_** *if it is greater than The Sum all the elements to its right side*.
____
# Task
**_Given_** an *array/list [] of integers* , **_Find_** *all the **_LEADERS_** in the array*.
___
# Notes
* **_Array/list_** siz... | {"functional": "_inputs = [[[1, 2, 3, 4, 0]], [[16, 17, 4, 3, 5, 2]], [[-1, -29, -26, -2]], [[-36, -12, -27]], [[5, 2]], [[0, -1, -29, 3, 2]]]\n_outputs = [[[4]], [[17, 5, 2]], [[-1]], [[-36, -12]], [[5, 2]], [[0, -1, 3, 2]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, floa... | 647 | 278 |
coding | Solve the programming task below in a Python markdown code block.
A rabbit is playing a role-playing game. Just before entering the castle, he was ambushed by an enemy!
It was a battle between one hero operated by a rabbit and n enemies. Each character has four stats, health hi, attack power ai, defense power di, and ... | {"inputs": ["2\n10 3 1 2\n2 4 1 3\n1 2 1 1", "2\n10 3 1 2\n2 4 1 3\n1 3 1 1", "2\n10 3 1 2\n3 4 1 3\n1 3 1 1", "2\n10 3 2 2\n3 4 1 3\n1 3 1 1", "2\n10 3 2 2\n3 8 1 3\n1 3 1 1", "2\n10 3 2 2\n3 8 1 3\n1 6 1 1", "2\n10 2 2 2\n3 8 1 3\n1 6 1 1", "2\n10 2 2 2\n3 5 1 3\n1 6 1 1"], "outputs": ["4\n", "5\n", "9\n", "6\n", "-1... | 366 | 262 |
coding | Solve the programming task below in a Python markdown code block.
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N.
We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M).
AtCoDeer the deer is going to perform the following operation... | {"inputs": ["3 2\n3 2 1\n1 2\n2 3\n", "5 1\n1 2 3 4 5\n1 5\n", "5 2\n5 3 1 4 2\n1 3\n5 4\n", "10 8\n5 3 6 8 7 10 9 1 2 4\n3 1\n4 1\n5 9\n2 5\n6 5\n3 5\n8 9\n7 9\n"], "outputs": ["3\n", "5\n", "2\n", "8\n"]} | 387 | 146 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In this problem, a tree is an undirected graph that is connected and has no cycles.
You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two... | {"functional": "def check(candidate):\n assert candidate(edges = [[1,2],[1,3],[2,3]]) == [2,3]\n assert candidate(edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]) == [1,4]\n\n\ncheck(Solution().findRedundantConnection)"} | 192 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Chef bought car insurance. The policy of the insurance is:
The maximum rebatable amount for any damage is Rs X lakhs.
If the amount required for repairing the damage is ≤ X lakhs, that amount is rebated in full.
Chef's car meets an accident and require... | {"inputs": ["4\n5 3\n5 8\n4 4\n15 12\n"], "outputs": ["3\n5\n4\n12\n"]} | 373 | 39 |
coding | Solve the programming task below in a Python markdown code block.
There are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. The particles keep collecting in the chamber 0. However if at any time, there are more than N particles in a chamber, a reaction will cause 1 particle to... | {"inputs": ["3 1 3", "3 1 1", "3 1 5", "1 1 3", "6 1 5", "1 2 2", "0 2 2", "0 2 4"], "outputs": ["1 1 0", "1\n", "1 1 0 0 0\n", "1 0 0\n", "0 1 1 0 0\n", "1 0\n", "0 0\n", "0 0 0 0\n"]} | 475 | 127 |
coding | Solve the programming task below in a Python markdown code block.
Vasya trains to compose crossword puzzles. He can only compose crosswords of a very simplе type so far. All of them consist of exactly six words; the words can be read only from top to bottom vertically and from the left to the right horizontally. The wo... | {"inputs": ["ABA\nABA\nABA\nABA\nGIP\nOII\n", "ABA\nCABA\nDABA\nCABA\nGIP\nTOII\n", "AAA\nAAA\nAAAAA\nAAA\nAAA\nAAAAA\n", "NOD\nBAA\nYARD\nAIRWAY\nNEWTON\nBURN\n", "NOD\nBAAA\nYARD\nAIRWAY\nNWWWON\nBURN\n", "NOD\nBAA\nYARD\nAIRWAY\nNEWWON\nBURNN\n", "NOD\nBAAA\nDRAY\nAIRWAY\nNWWWON\nBURN\n", "AFZIF\nELO\nAOZOPMME\nITA\... | 478 | 258 |
coding | Solve the programming task below in a Python markdown code block.
Ted$Ted$ loves prime numbers. One day he is playing a game called legendary$legendary$ with his girlfriend Robin$Robin$. Ted$Ted$ writes a number N$N$ on a table and the number is in the form of :
N = P1A1 * P2A2 * ……….. * PnAn
Ted$Ted$ asks Robin$Robin... | {"inputs": ["1\n3\n2 3 5\n2 1 2\n1 1 1"], "outputs": ["540"]} | 635 | 34 |
coding | Solve the programming task below in a Python markdown code block.
On the great island of Baltia, there live N people, numbered from 1 to N. There are exactly M pairs of people that are friends with each other. The people of Baltia want to organize a successful party, but they have very strict rules on what a party is a... | {"inputs": ["5 0\n", "6 3\n1 4\n1 3\n5 1\n", "6 3\n1 2\n4 2\n5 2\n", "6 3\n1 4\n4 2\n5 1\n", "6 3\n1 4\n5 2\n5 4\n", "6 3\n1 2\n4 2\n5 1\n", "6 3\n1 4\n4 3\n5 1\n", "6 3\n1 5\n4 2\n5 4\n"], "outputs": ["1 2 3 4 5\n", "2 3 4 5 6\n", "1 3 4 5 6\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 426 | 194 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network as... | {"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n8\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 481 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
Given an integer n, return the number of distinct solutions to the n-queens puzzle.
Please com... | {"functional": "def check(candidate):\n assert candidate(n = 4) == 2\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().totalNQueens)"} | 98 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Vasya is reading a e-book. The file of the book consists of $n$ pages, numbered from $1$ to $n$. The screen is currently displaying the contents of page $x$, and Vasya wants to read the page $y$. There are two buttons on the book which allow Vasya to scr... | {"inputs": ["1\n11 0 0 9\n", "1\n7 0 0 22\n", "1\n11 0 11 9\n", "1\n11 0 0 18\n", "1\n11 0 0 22\n", "1\n5 0 -1 22\n", "1\n7 0 -1 22\n", "1\n11 11 11 9\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "0\n", "-1\n", "-1\n", "0\n"]} | 498 | 147 |
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 N integers. In each step you can choose some K of the remaining numbers and delete them, if the following condition holds: Let the K numbers you've chosen be a_... | {"inputs": ["2\n6 3 2\n4 1 2 2 3 1\n6 3 2\n1 2 2 1 4 4"], "outputs": ["1\n2"]} | 464 | 50 |
coding | Solve the programming task below in a Python markdown code block.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not alway... | {"inputs": ["4 6 2\n", "3 6 1\n", "3 3 3\n", "1 1 1\n", "3 3 3\n", "1 1 1\n", "3 8 3\n", "3 6 1\n"], "outputs": ["2\n", "3\n", "1\n", "1\n", "1\n", "1\n", "3\n", "3\n"]} | 378 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Farmer Feb has three fields with potatoes planted in them. He harvested x potatoes from the first field, y potatoes from the second field and is yet to harvest potatoes from the third field. Feb is very superstitious and believes that if the sum of potat... | {"inputs": ["2\n1 3\n4 3", "2\n1 3\n3 3", "2\n1 3\n1 6", "2\n1 3\n2 6", "2\n1 3\n3 6", "2\n1 4\n4 3", "2\n2 3\n3 3", "2\n1 4\n2 3"], "outputs": ["1\n4", "1\n1\n", "1\n4\n", "1\n3\n", "1\n2\n", "2\n4\n", "2\n1\n", "2\n2\n"]} | 328 | 141 |
coding | Solve the programming task below in a Python markdown code block.
You are given a dataset consisting of $N$ items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not.
We want to use this dataset for training our latest machine learning model. Thus we want to choose some su... | {"inputs": ["3\n3\nabc 0\nabc 1\nefg 1\n7\nfck 1\nfck 0\nfck 1\nbody 0\nbody 0\nbody 0\nram 0\n5\nvv 1\nvv 0\nvv 0\nvv 1\nvv 1\n"], "outputs": ["2\n6\n3"]} | 583 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a positive integer extremely round if it has only one non-zero digit. For example, $5000$, $4$, $1$, $10$, $200$ are extremely round integers; $42$, $13$, $666$, $77$, $101$ are not.
You are given an integer $n$. You have to calculate the num... | {"inputs": ["1\n1\n", "1\n69\n", "1\n912\n", "2\n1\n1\n", "1\n9123\n", "1\n9999\n", "1\n9998\n", "1\n9997\n"], "outputs": ["1\n", "15\n", "27\n", "1\n1\n", "36\n", "36\n", "36\n", "36\n"]} | 277 | 111 |
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 string s with length n. You should find a permutation P of numbers 1 through n such that if you apply this permutation on the string s, you will get a palindr... | {"inputs": ["4\naa\nbaa\nabc\nabab"], "outputs": ["1 2\n2 1 3\n-1\n1 2 4 3"]} | 596 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his newly desi... | {"inputs": ["3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -", "3\n4\ntilak +\ntilak +\ntilak -\ntilaj +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -", "3\n4\ntilak +\nkalit +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -... | 615 | 580 |
coding | Solve the programming task below in a Python markdown code block.
# Task
You are given a function that should insert an asterisk (`*`) between every pair of **even digits** in the given input, and return it as a string. If the input is a sequence, concat the elements first as a string.
## Input
The input can be an... | {"functional": "_inputs = [[5312708], [9682135], [2222], [1111], [9999], ['0000'], [8], [2], [0], [[1, 4, 64, 68, 67, 23, 1]]]\n_outputs = [['531270*8'], ['96*8*2135'], ['2*2*2*2'], ['1111'], ['9999'], ['0*0*0*0'], ['8'], ['2'], ['0'], ['14*6*4*6*8*67231']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance... | 187 | 304 |
coding | Solve the programming task below in a Python markdown code block.
Fans of The Wire will appreciate this one.
For those that haven't seen the show, the Barksdale Organization has a simple method for encoding telephone numbers exchanged via pagers: "Jump to the other side of the 5 on the keypad, and swap 5's and 0's."
... | {"functional": "_inputs = [['4103432323'], ['4103438970'], ['4104305768'], ['4102204351'], ['4107056043']]\n_outputs = [['6957678787'], ['6957672135'], ['6956750342'], ['6958856709'], ['6953504567']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | 279 | 268 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent... | {"functional": "def check(candidate):\n assert candidate(parent = [-1,0,0,1,1,2], s = \"acaabc\") == 8\n assert candidate(parent = [-1,0,0,0,0], s = \"aaaaa\") == 10\n\n\ncheck(Solution().countPalindromePaths)"} | 224 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinates he can'... | {"inputs": ["3\n2 1\n3 3\n10 5"], "outputs": ["2\n1\n252"]} | 221 | 31 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.
You are g... | {"functional": "def check(candidate):\n assert candidate(edges = [[1,2],[2,3],[4,2]]) == 2\n assert candidate(edges = [[1,2],[5,1],[1,3],[1,4]]) == 1\n\n\ncheck(Solution().findCenter)"} | 139 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Kristina has two arrays $a$ and $b$, each containing $n$ non-negative integers. She can perform the following operation on array $a$ any number of times:
apply a decrement to each non-zero element of the array, that is, replace the value of each element... | {"inputs": ["1\n1\n372\n200\n", "1\n2\n1456 5324\n1455 5323\n", "1\n4\n372 372 1 8\n372 372 1 8\n", "1\n4\n8293 8293 1 8\n8293 8293 1 8\n", "6\n4\n3 5 4 1\n1 3 2 0\n3\n1 2 1\n0 1 0\n4\n5 3 7 2\n1 1 1 1\n5\n1 2 3 4 5\n1 2 3 4 6\n1\n8\n0\n1\n4\n6\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\nYES\nNO\nNO\nYES... | 733 | 228 |
coding | Solve the programming task below in a Python markdown code block.
The goal of this Kata is to remind/show you, how Z-algorithm works and test your implementation.
For a string str[0..n-1], Z array is of same length as string. An element Z[i] of Z array stores length of the longest substring starting from str[i] which ... | {"functional": "_inputs = [['ababcaba'], [''], ['aaaaaaaa'], ['ababababab'], ['aaaa$aaaa'], ['abracadabra']]\n_outputs = [[[8, 0, 2, 0, 0, 3, 0, 1]], [[]], [[8, 7, 6, 5, 4, 3, 2, 1]], [[10, 0, 8, 0, 6, 0, 4, 0, 2, 0]], [[9, 3, 2, 1, 0, 4, 3, 2, 1]], [[11, 0, 0, 1, 0, 1, 0, 4, 0, 0, 1]]]\nimport math\ndef _deep_eq(a, b,... | 345 | 318 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 2D grid of size m x n, you should find the matrix answer of size m x n.
The cell answer[r][c] is calculated by looking at the diagonal values of the cell grid[r][c]:
Let leftAbove[r][c] be the number of disti... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,2,3],[3,1,5],[3,2,1]]) == [[1,1,0],[1,0,1],[0,1,1]]\n assert candidate(grid = [[1]]) == [[0]]\n\n\ncheck(Solution().differenceOfDistinctValues)"} | 290 | 81 |
coding | Solve the programming task below in a Python markdown code block.
For the first place at the competition, Alex won many arrays of integers and was assured that these arrays are very expensive. After the award ceremony Alex decided to sell them. There is a rule in arrays pawnshop: you can sell array only if it can be co... | {"inputs": ["1\n1\n1\n", "1\n5\n1 3 1 3 0\n", "1\n5\n0 1000000000 999999999 999999998 999999997\n", "6\n6\n1 9 17 6 14 3\n3\n4 2 2\n3\n7 3 4\n3\n2 2 4\n5\n0 1000000000 0 1000000000 0\n2\n1 1\n"], "outputs": ["0\n", "-1\n", "1000000001 1000000000\n", "19 8\n-1\n-1\n-1\n2000000000 1000000000\n0\n"]} | 654 | 231 |
coding | Solve the programming task below in a Python markdown code block.
There are N balls in a row. Initially, the i-th ball from the left has the integer A_i written on it.
When Snuke cast a spell, the following happens:
* Let the current number of balls be k. All the balls with k written on them disappear at the same tim... | {"inputs": ["5 3\n1 1 5 4 5\n1 2\n2 5\n5 4", "5 3\n1 1 3 1 5\n1 2\n2 5\n5 4", "5 3\n0 1 5 1 5\n1 2\n2 5\n5 4", "5 3\n1 2 3 4 5\n1 2\n2 5\n5 4", "5 3\n1 1 5 4 5\n2 2\n2 5\n1 4", "5 3\n0 1 5 1 3\n1 4\n2 4\n5 4", "5 3\n1 2 3 4 5\n1 2\n1 5\n5 2", "5 3\n1 1 5 4 5\n1 2\n2 0\n5 4"], "outputs": ["1\n1\n1\n", "1\n0\n0\n", "1\n0... | 562 | 286 |
coding | Solve the programming task below in a Python markdown code block.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the di... | {"inputs": ["1\nz\n", "1\nz\n", "1\ny\n", "1\n{\n", "1\n|\n", "1\n}\n", "1\n~\n", "1\n\u007f\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 398 | 91 |
coding | Solve the programming task below in a Python markdown code block.
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), th... | {"inputs": ["6\n", "7\n", "4\n", "5\n", "3\n", "8\n", "9\n", "1\n"], "outputs": ["6 1 2 3 4 5\n", "7 1 2 3 4 5 6\n", "4 1 2 3\n", "5 1 2 3 4\n", "3 1 2\n", "8 1 2 3 4 5 6 7 ", "9 1 2 3 4 5 6 7 8 ", "1\n"]} | 286 | 138 |
coding | Solve the programming task below in a Python markdown code block.
Let's say take 2 strings, A and B, and define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings `abc` and `abd` is 2, while the similarity of strings `aaa` and `aaab` is 3.... | {"functional": "_inputs = [['aa'], ['abc'], ['ababaa'], ['aaaa'], ['aaaaa'], ['aaaaaa'], ['mnsomn'], ['apple'], ['a'], ['pippi']]\n_outputs = [[3], [3], [11], [10], [15], [21], [8], [5], [1], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | 286 | 220 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef Chick loves to jump a lot. Once, it realised that it was on an infinitely long road, and decided to travel along this road by jumping.
Let's v... | {"inputs": ["1\n2\n2 3"], "outputs": ["2"]} | 569 | 18 |
coding | Solve the programming task below in a Python markdown code block.
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Ali... | {"inputs": ["2\n1 2\n", "2\n6 2\n", "2\n4 6\n", "2\n2 6\n", "2\n8 2\n", "2\n3 6\n", "2\n7 3\n", "2\n2 1\n"], "outputs": ["Bob\n", "Alice\n", "Alice\n", "Alice\n", "Bob\n", "Bob\n", "Alice\n", "Bob\n"]} | 361 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.
For every i and j where 0 <= i < j < arr.length, we consider the frac... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,5], k = 3) == [2,5]\n assert candidate(arr = [1,7], k = 1) == [1,7]\n\n\ncheck(Solution().kthSmallestPrimeFraction)"} | 155 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way.
In total there are n piles of boxes, arranged in a line, from left to right, i-th pile (1 ≤ i ≤ n) containing ai boxes. Luckily, m student... | {"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n3\n", "2 1\n2 1\n", "2 1\n1 1\n", "3 2\n1 0 4\n", "3 2\n1 0 3\n", "3 2\n1 0 2\n"], "outputs": [" 2", "3\n", "4\n", "5\n", " 4", "6\n", "5\n", " ... | 617 | 121 |
coding | Solve the programming task below in a Python markdown code block.
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
for i = 1 to A.length-1
key = A[i]
/* insert A[i] into the sorted sequence A[0,...,j-1] */
j = i - 1... | {"inputs": ["3\n2 2 3", "3\n2 4 3", "3\n2 4 5", "3\n2 4 8", "3\n2 6 8", "3\n4 6 8", "3\n4 2 8", "3\n6 2 8"], "outputs": ["2 2 3\n2 2 3\n2 2 3\n", "2 4 3\n2 4 3\n2 3 4\n", "2 4 5\n2 4 5\n2 4 5\n", "2 4 8\n2 4 8\n2 4 8\n", "2 6 8\n2 6 8\n2 6 8\n", "4 6 8\n4 6 8\n4 6 8\n", "4 2 8\n2 4 8\n2 4 8\n", "6 2 8\n2 6 8\n2 6 8\n"]... | 353 | 238 |
coding | Solve the programming task below in a Python markdown code block.
This is the harder version of the problem. In this version, $1 \le n \le 10^6$ and $0 \leq a_i \leq 10^6$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems
Christmas is coming, and our pr... | {"inputs": ["1\n1\n", "1\n1\n", "1\n25\n", "1\n835\n", "1\n2103\n", "1\n2103\n", "1\n2140\n", "3\n4 8 5\n"], "outputs": ["-1\n", "-1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "9\n"]} | 678 | 103 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.
Each number in candidates may only be used once ... | {"functional": "def check(candidate):\n assert candidate(candidates = [10,1,2,7,6,1,5], target = 8) == [\n[1,1,6],\n[1,2,5],\n[1,7],\n[2,6]\n]\n assert candidate(candidates = [2,5,2,1,2], target = 5) == [\n[1,2,2],\n[5]\n]\n\n\ncheck(Solution().combinationSum2)"} | 112 | 123 |
coding | Solve the programming task below in a Python markdown code block.
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input
The first input line contains the string.... | {"inputs": ["a\n", "b\n", "`\n", "yy\n", "fg\n", "xy\n", "gf\n", "yx\n"], "outputs": ["0", "0\n", "0\n", "1", "0", "0\n", "0\n", "0\n"]} | 145 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk... | {"inputs": ["5 2 2\n", "5 4 7\n", "6 2 3\n", "2 1 2\n", "2 1 3\n", "2 1 3\n", "2 1 2\n", "5 1 2\n"], "outputs": ["2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "3\n"]} | 420 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Set
Given the sequence a_1, a_2, .., a_N.
How many values are there in this sequence?
input
N
a_1 a_2 ... a_N
output
Output the number of types of values in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Inp... | {"inputs": ["6\n8 5 9 1 2 1", "6\n8 5 9 0 2 1", "6\n1 2 9 0 2 0", "6\n1 5 9 0 2 1", "6\n1 5 9 0 2 0", "6\n8 6 9 1 2 1", "6\n1 2 15 0 2 0", "6\n-1 1 0 0 7 1"], "outputs": ["5\n", "6\n", "4\n", "5\n", "5\n", "5", "4\n", "4\n"]} | 149 | 159 |
coding | Solve the programming task below in a Python markdown code block.
There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.
Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.
Recently, they learned the operation called xor (exclusive OR).What is xor?
For n non-negative int... | {"inputs": ["4\n1 2 0 49", "4\n2 2 0 49", "4\n2 0 0 49", "4\n2 0 1 49", "4\n0 0 1 49", "4\n1 0 1 49", "4\n1 0 2 49", "4\n1 0 3 49"], "outputs": ["51 48 50 3\n", "51 51 49 0\n", "49 51 51 2\n", "48 50 51 3\n", "48 48 49 1\n", "48 49 48 0\n", "51 50 48 3\n", "50 51 48 2\n"]} | 666 | 206 |
coding | Solve the programming task below in a Python markdown code block.
You are given an HTML code snippet of $N$ lines.
Your task is to detect and print all the HTML tags, attributes and attribute values.
Print the detected items in the following format:
Tag1
Tag2
-> Attribute2[0] > Attribute_value2[0]
-> Attribute2[1] >... | {"inputs": ["9\n<head>\n<title>HTML</title>\n</head>\n<object type=\"application/x-flash\" \n data=\"your-file.swf\" \n width=\"0\" height=\"0\">\n <!-- <param name=\"movie\" value=\"your-file.swf\" /> -->\n <param name=\"quality\" value=\"high\"/>\n</object>\n"], "outputs": ["head\ntitle\nobject\n-> type > applica... | 522 | 137 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.