task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
This time your assignment is really simple.
Calculate GCD(1, 1) * GCD(1, 2) * ... * GCD(1, M) * GCD(2, 1) * GCD(2, 2) * ... * GCD(2, M) * ... * GCD(N, 1) * GCD(N, 2) * ... * GCD(N, M).
where GCD is defined as the Greatest Common Divisor.
Input Format... | {"inputs": ["4 4\n"], "outputs": ["96\n"]} | 284 | 17 |
coding | Solve the programming task below in a Python markdown code block.
You are teaching a class of $N$ students. Today, during the morning prayer, all the students are standing in a line. You are given a string $s$ with length $N$; for each valid $i$, the $i$-th character of this string is 'b' if the $i$-th student in the l... | {"inputs": ["3\ngb\nbgg\nbbgg"], "outputs": ["1\n2\n6"]} | 576 | 25 |
coding | Solve the programming task below in a Python markdown code block.
Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows:
* x_{1,j} := a_j \quad (1 \leq j \leq N)
* x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i)
Find... | {"inputs": ["4\n21", "4\n32", "4\n13", "4\n21", "4\n44", "4\n12", "4\n11", "4\n22"], "outputs": ["1\n", "1\n", "2\n", "1\n", "0\n", "1\n", "0\n", "0\n"]} | 249 | 86 |
coding | 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"]} | 442 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5], requests = [[1,3],[0,1]]) == 19\n assert candidate(nums = [1,2,3,4,5,6], requests = [[0,1]]) == 11\n assert candidate(nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]) == 47\n\n\ncheck(Solution().maxSumRangeQuery)"} | 162 | 122 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian]
Chef is having a candlelit dinner with his girlfriend at his place. Currently, it is time $0$, Chef just managed to light a candle, but he is out of matchsticks.
Since Chef has an infinite supply of (unlit) candles,... | {"inputs": ["3\n1 1 1\n1 2 1\n2 2 1"], "outputs": ["1\n2\n2"]} | 691 | 34 |
coding | Solve the programming task below in a Python markdown code block.
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area sh... | {"inputs": ["6 5\n", "1 1\n", "2 1\n", "2 2\n", "5 5\n", "9 10\n", "8 10\n", "15 13\n"], "outputs": ["5 4\n", "1 1\n", "1 1", "2 2", "5 4", "8 10", "8 10\n", "10 8"]} | 249 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Due to the COVID pandemic, maintaining social distancing is of utmost importance. In this problem, you'd calculate how many days would it take to reach an apocalypse from an initial case if nobody maintains social distancing.
The Earth is flat (for this ... | {"inputs": ["2\n4 5\n2 1\n3 4\n1 1"], "outputs": ["5\n3"]} | 614 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII Minium
IV Vitriol
Misce ... | {"inputs": ["0 0 0 0 0\n", "1 1 2 7 4\n", "1 0 2 7 4\n", "1 1 2 6 4\n", "1 1 1 7 4\n", "1 2 2 7 4\n", "1 1 3 7 4\n", "1 1 2 6 4\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]} | 196 | 134 |
coding | Solve the programming task below in a Python markdown code block.
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can mo... | {"inputs": ["1 1\n1 1\n0 0\n.\n", "1 1\n1 1\n1 0\n.\n", "1 1\n1 1\n31 42\n.\n", "1 7\n1 1\n0 3\n.......\n", "1 7\n1 1\n0 0\n.......\n", "4 4\n3 2\n0 1\n....\n..*.\n....\n....\n", "4 4\n2 2\n0 1\n....\n..*.\n....\n....\n", "4 5\n3 2\n1 2\n.....\n..***\n...**\n*....\n"], "outputs": ["1", "1\n", "1", "4", "1\n", "7\n", "7... | 531 | 202 |
coding | Solve the programming task below in a Python markdown code block.
An array $a$ consisting of $k$ integers is strictly increasing if $a_1 < a_2 < \dots < a_k$. For example, the arrays $[1, 3, 5]$, $[1, 2, 3, 4]$, $[3, 5, 6]$ are strictly increasing; the arrays $[2, 2]$, $[3, 7, 5]$, $[7, 4, 3]$, $[1, 2, 2, 3]$ are not.
... | {"inputs": ["1\n4 6\n", "1\n5 6\n", "7\n5 9\n4 12\n3 3\n3 4\n4 4\n4 6\n8 11\n"], "outputs": ["1 3 4 5\n", "1 3 4 5 6\n", "1 3 6 7 8\n1 3 6 10\n1 2 3\n1 3 4\n1 2 3 4\n1 3 4 5\n1 3 6 7 8 9 10 11\n"]} | 509 | 145 |
coding | Solve the programming task below in a Python markdown code block.
You have an array of integers (initially empty).
You have to perform $q$ queries. Each query is of one of two types:
"$1$ $x$" — add the element $x$ to the end of the array;
"$2$ $x$ $y$" — replace all occurrences of $x$ in the array with $y$.
Find t... | {"inputs": ["1\n1 8\n", "1\n1 6\n", "1\n1 3\n", "1\n1 5\n", "1\n1 1\n", "1\n1 4\n", "1\n1 9\n", "1\n1 2\n"], "outputs": ["8", "6", "3", "5", "1", "4", "9", "2"]} | 674 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "6\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "3\n", "4\n", "5\n", "4"]} | 337 | 69 |
coding | Solve the programming task below in a Python markdown code block.
For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations:
* pushBack($x$): add element $x$ at the end of $A$
* randomAccess($p$):print element $a_p$
* popBack(): delete the last element of $A$
$A$ is a... | {"inputs": ["8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 1", "8\n0 0\n0 2\n0 3\n2\n1 0\n1 0\n1 1\n1 1", "8\n0 1\n0 2\n0 4\n2\n0 4\n1 0\n1 1\n1 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n0 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 0", "8\n0 0\n0 3\n0 3\n2\n0 0\n1 0\n1 1\n1 1", "8\n0 1... | 331 | 334 |
coding | Solve the programming task below in a Python markdown code block.
Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out.
**Example:**
Given an input string of:
```
apples, pears # and bananas
grapes
b... | {"functional": "_inputs = [['apples, pears # and bananas\\ngrapes\\nbananas !apples', ['#', '!']], ['a #b\\nc\\nd $e f g', ['#', '$']], ['apples, pears # and bananas\\ngrapes\\nbananas !#apples', ['#', '!']], ['apples, pears # and bananas\\ngrapes\\nbananas #!apples', ['#', '!']], ['apples, pears # and bananas\\ngrapes... | 181 | 452 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an exam which will start exactly M minutes from now. However, instead of preparing for his exam, Chef started watching Season-1 of Superchef. Season-1 has N episodes, and the duration of each episode is K minutes.
Will Chef be able to finish w... | {"inputs": ["3\n10 1 10\n25 2 10\n15 2 10"], "outputs": ["NO\nYES\nNO"]} | 520 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has a_{i} apples. This tree has a special property: the lengths of all paths from the root to any leaf have th... | {"inputs": ["3\n2 2 3\n1 1\n", "3\n1 2 3\n1 1\n", "3\n1 1 3\n1 1\n", "3\n2 2 3\n1 2\n", "3\n2 0 3\n1 2\n", "3\n2 0 1\n1 2\n", "3\n1 2 3\n1 1\n", "3\n2 2 3\n1 1\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]} | 739 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Given two arrays A and B each of length N.
Find the value \sum_{i=1}^N\sum_{j=1}^N \max(A_{i}\oplus B_{j},A_{i}\& B_{j}).
Here \oplus and \& denote the [bitwise XOR operation] and [bitwise AND operation] respectively.
------ Input Format ------
... | {"inputs": ["3\n2\n3 4\n1 2\n1\n0\n0\n3\n2 4 3\n1 2 1"], "outputs": ["15\n0\n30"]} | 729 | 48 |
coding | Solve the programming task below in a Python markdown code block.
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the b... | {"inputs": ["1 3\n5\n", "1 3\n5\n", "1 10\n4\n", "1 10\n4\n", "2 10\n6 4\n", "2 10\n6 4\n", "2 10\n6 6\n", "2 11\n6 6\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n"]} | 381 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.
To improve his division skills, Oleg came up with $t$ pairs of integers $p_i$ and $q_i$ and for each pair decided to find the greatest integer $x_i$, such... | {"inputs": ["1\n5 5\n", "1\n5 6\n", "1\n6 12\n", "1\n9 17\n", "1\n5 12\n", "1\n6 17\n", "1\n95775579 43432\n", "1\n95775579 67436\n"], "outputs": ["1\n", "5\n", "6\n", "9\n", "5\n", "6\n", "95775579\n", "95775579\n"]} | 513 | 142 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is no... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]) == [-1,0,0,1]\n assert candidate(nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]) == [-1,0,-1,0,0,0,-1]\n\n\ncheck(Solution().getCoprimes)"} | 284 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Dinesh is very fond of sweets recently his aunt Riya gifted him an array $a$ of sweets of size $N$. The ith sweet is of the type $a[i]$. His mother told him that he can choose one type of sweet in a day and eat at most 2 sweets of that type. Since he has... | {"inputs": ["3\n1 2 2"], "outputs": ["2"]} | 231 | 18 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers k, p_{a} and p_{b}.
You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability p_{a} / (p_{a} + p_{b}), add 'a' to the end of the... | {"inputs": ["1 1 1\n", "3 1 4\n", "1 1 2\n", "3 1 2\n", "3 1 1\n", "1 1 1\n", "3 1 4\n", "4 78149 46740\n"], "outputs": ["2\n", "370000006\n", "500000005", "722222231", "250000006", "2\n", "370000006\n", "604608981"]} | 471 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Sasha is a very happy guy, that's why he is always on the move. There are $n$ cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from $1$ to $n$ in increasing order. The distance bet... | {"inputs": ["4 2\n", "7 6\n", "9 5\n", "9 5\n", "5 5\n", "7 5\n", "4 1\n", "9 1\n"], "outputs": ["4\n", "6\n", "14\n", "14 \n", "4\n", "7\n", "6\n", "36\n"]} | 557 | 90 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters ... | {"functional": "def check(candidate):\n assert candidate(s = \"race a car\") == False\n assert candidate(s = \" \") == True\n\n\ncheck(Solution().isPalindrome)"} | 103 | 43 |
coding | Solve the programming task below in a Python markdown code block.
In this exercise, a string is passed to a method and a new string has to be returned with the first character of each word in the string.
For example:
```
"This Is A Test" ==> "TIAT"
```
Also feel free to reuse/extend the following starter code:
```pyt... | {"functional": "_inputs = [['sees eyes xray yoat'], ['brown eyes are nice'], ['cars are very nice'], ['kaks de gan has a big head']]\n_outputs = [['sexy'], ['bean'], ['cavn'], ['kdghabh']]\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... | 81 | 194 |
coding | Solve the programming task below in a Python markdown code block.
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y to... | {"inputs": ["3\n3 1 3", "3\n3 1 5", "3\n1 1 5", "3\n1 1 8", "3\n0 1 8", "3\n0 1 2", "3\n0 1 1", "3\n1 1 1"], "outputs": ["15\n", "23\n", "11\n", "17\n", "8\n", "2\n", "1\n", "3\n"]} | 360 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings ... | {"inputs": ["c\n", "a\n", "b\n", "z\n", "d\n", "`\n", "e\n", "{\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | 182 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Given are two sequences a=\{a_0,\ldots,a_{N-1}\} and b=\{b_0,\ldots,b_{N-1}\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\{a_0',\ldots,a_... | {"inputs": ["2\n1 2\n0 0\n", "3\n0 2 1\n2 0 3", "3\n0 2 1\n2 1 0", "3\n0 2 0\n1 3 3", "3\n1 0 1\n2 2 3", "3\n0 2 1\n0 1 3", "3\n0 0 1\n2 3 2", "3\n1 0 1\n2 3 2"], "outputs": ["", "0 2\n", "1 0\n", "1 3\n", "2 3\n", "2 1\n", "1 2\n", "0 3\n"]} | 528 | 167 |
coding | Solve the programming task below in a Python markdown code block.
Chef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. "abab" has a period P = 2, It als... | {"inputs": ["5\n3 1\n2 2\n3 3\n4 4\n6 3"], "outputs": ["impossible\nimpossible\naba\nabba\nabaaba"]} | 504 | 44 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N.
Construct a permutation P of length N such that
For all i (1 ≤ i ≤ N-1), i divides abs(P_{i+1}-P_{i}).
Recall that a permutation of length N is an array where every integer from 1 to N occurs exactly once.
It can be prove... | {"inputs": ["2\n2\n3\n"], "outputs": ["1 2\n2 1 3\n"]} | 437 | 26 |
coding | Solve the programming task below in a Python markdown code block.
When you divide the successive powers of `10` by `13` you get the following remainders of the integer divisions:
`1, 10, 9, 12, 3, 4`.
Then the whole pattern repeats.
Hence the following method:
Multiply the right most digit of the number with the ... | {"functional": "_inputs = [[8529], [85299258], [5634], [1111111111], [987654321]]\n_outputs = [[79], [31], [57], [71], [30]]\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))... | 413 | 213 |
coding | Solve the programming task below in a Python markdown code block.
You have to create a function named reverseIt.
Write your function so that in the case a string or a number is passed in as the data , you will return the data in reverse order. If the data is any other type, return it as it is.
Examples of inputs and... | {"functional": "_inputs = [['Hello'], [314159], ['314159'], [[]], [{}], [True], [[1, 2, 3]]]\n_outputs = [['olleH'], [951413], ['951413'], [[]], [{}], [True], [[1, 2, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab... | 138 | 221 |
coding | Solve the programming task below in a Python markdown code block.
Neo has a complex matrix script. The matrix script is a $N$ X $\mbox{M}$ grid of strings. It consists of alphanumeric characters, spaces and symbols (!,@,#,$,%,&).
To decode the script, Neo needs to read each column and select only the alphanumeric cha... | {"inputs": ["7 3\nTsi\nh%x\ni #\nsM \n$a \n#t%\nir!\n"], "outputs": ["This is Matrix# %!\n"]} | 341 | 45 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.
Return the rearranged number with minimal value.
Note that the sign of the number d... | {"functional": "def check(candidate):\n assert candidate(num = 310) == 103\n assert candidate(num = -7605) == -7650\n\n\ncheck(Solution().smallestNumber)"} | 100 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Tatyana is a big sports fan and she likes volleyball a lot! She writes down the final scores of the game after it has ended in her notebook.
If you are not familiar with the rules of volleyball, here's a brief:
2 teams play in total
During the course ... | {"inputs": ["3\n25\n", "24\n17\n"], "outputs": ["2925\n", "0\n"]} | 392 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Shohag has an integer sequence $a_1, a_2, \ldots, a_n$. He can perform the following operation any number of times (possibly, zero):
Select any positive integer $k$ (it can be different in different operations).
Choose any position in the sequence (pos... | {"inputs": ["4\n3\n1 3 4\n5\n1 2 5 7 4\n1\n1\n3\n69 6969 696969\n", "4\n3\n1 3 4\n5\n1 2 5 7 4\n1\n1\n3\n69 6969 718045\n", "4\n3\n1 3 4\n5\n1 2 5 7 1\n1\n1\n3\n69 6969 718045\n", "4\n3\n1 1 4\n5\n1 2 5 7 1\n1\n1\n3\n69 6969 718045\n", "4\n3\n1 3 4\n5\n1 2 5 7 4\n1\n1\n3\n69 6969 696969\n", "4\n3\n1 3 4\n5\n1 2 5 7 4\n... | 707 | 492 |
coding | Solve the programming task below in a Python markdown code block.
You are given a bracket sequence consisting of $n$ characters '(' and/or )'. You perform several operations with it.
During one operation, you choose the shortest prefix of this string (some amount of first characters of the string) that is good and rem... | {"inputs": ["1\n14\n()(((())((()))\n", "1\n15\n((((()))))(((((\n", "1\n16\n((((()))))((((((\n", "1\n18\n()()())(())(())(()\n", "5\n2\n()\n3\n())\n4\n((((\n5\n)((()\n6\n)((()(\n", "5\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n", "8\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n5\n))())\n1\n)\n2\n)(\n"], "... | 508 | 279 |
coding | Solve the programming task below in a Python markdown code block.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them contain... | {"inputs": ["5 3 2 3\n", "1 1 1 1\n", "1 2 1 2\n", "1 1 2 2\n", "1 2 1 2\n", "1 1 1 1\n", "1 1 2 2\n", "5 3 2 1\n"], "outputs": ["4\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "10\n"]} | 302 | 119 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
Please complete the following python code precisely:
```python
class Solution... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1]) == True\n assert candidate(nums = [1,2,3,4]) == False\n assert candidate(nums = [1,1,1,3,3,4,3,2,4,2]) == True\n\n\ncheck(Solution().containsDuplicate)"} | 76 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Chef recently realized that he needs a haircut, and went to his favorite hair salon. At the salon, he found N customers waiting for their haircuts. From his past experience, Chef knows that the salon takes M minutes per customer. Only one person can get ... | {"inputs": ["2\n2 15\n0 15\n"], "outputs": ["30\n0\n"]} | 349 | 27 |
coding | Solve the programming task below in a Python markdown code block.
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path ... | {"inputs": ["3\n2\n3\n1\n", "1\n2\n3\n5\n", "9\n9\n7\n5\n", "1\n2\n2\n1\n", "1\n1\n1\n1\n", "2\n1\n1\n3\n", "1\n3\n2\n1\n", "1\n5\n6\n1\n"], "outputs": ["3\n", "0\n", "42\n", "0\n", "0\n", "1\n", "0\n", "0\n"]} | 555 | 119 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string queryIP, return "IPv4" if IP is a valid IPv4 address, "IPv6" if IP is a valid IPv6 address or "Neither" if IP is not a correct IP of any type.
A valid IPv4 address is an IP in the form "x1.x2.x3.x4" whe... | {"functional": "def check(candidate):\n assert candidate(queryIP = \"172.16.254.1\") == \"IPv4\"\n assert candidate(queryIP = \"2001:0db8:85a3:0:0:8A2E:0370:7334\") == \"IPv6\"\n assert candidate(queryIP = \"256.256.256.256\") == \"Neither\"\n\n\ncheck(Solution().validIPAddress)"} | 457 | 119 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal.
Operation: Choose two integers i and j (possibly the sa... | {"inputs": ["3\n1 2 2\n5 2 2", "3\n1 2 2\n4 2 2", "3\n1 2 3\n4 2 2", "3\n0 2 3\n4 2 2", "3\n1 2 1\n4 2 2", "3\n0 2 2\n4 2 2", "3\n0 2 2\n7 2 2", "3\n0 0 2\n7 2 2"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | 302 | 158 |
coding | Solve the programming task below in a Python markdown code block.
The robot is placed in the top left corner of a grid, consisting of $n$ rows and $m$ columns, in a cell $(1, 1)$.
In one step, it can move into a cell, adjacent by a side to the current one:
$(x, y) \rightarrow (x, y + 1)$;
$(x, y) \rightarrow (x + 1,... | {"inputs": ["1\n2 3 1 3 0\n", "1\n2 3 1 3 1\n", "1\n776 123 5 7 3\n", "1\n1000 1000 99 99 2\n", "1\n1000 1000 99 9 21\n", "1\n1000 1000 10 10 0\n", "2\n2 3 1 3 0\n2 3 1 3 1\n", "2\n3 3 2 2 1\n5 5 3 3 1\n"], "outputs": ["3\n", "-1\n", "897\n", "1998\n", "1998\n", "1998\n", "3\n-1\n", "-1\n8\n"]} | 636 | 214 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tel... | {"inputs": ["1\n*\n1\na\n", "1\n*\n1\nz\n", "1\n*\n1\na\n", "1\n*\n1\nz\n", "1\n*\n1\ny\n", "1\n*\n1\nb\n", "1\n*\n2\na\nz\n", "2\n**\n1\naa\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n"]} | 717 | 121 |
coding | Solve the programming task below in a Python markdown code block.
Manipulating numbers is at the core of a programmer's job. To test how well you know their properties, you are asked to solve the following problem.
You are given $n$ non-negative integers $a_1$, $a_2$, ..., $a_n$. You want to know whether it's possible... | {"inputs": ["3\n1\n9\n3\n40 50 90\n2\n1 4\n"], "outputs": ["Yes\nYes\nNo\n"]} | 530 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Given N, count how many permutations of [1, 2, 3, ..., N] satisfy the following property.
Let P1, P2, ..., PN denote the permutation. The property we want to satisfy is that there exists an i between 2 and n-1 (inclusive) such that
- Pj > Pj + 1 ∀ ... | {"inputs": ["2\n2\n3"], "outputs": ["0\n2"]} | 281 | 18 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return true if it is a power of three. Otherwise, return false.
An integer n is a power of three, if there exists an integer x such that n == 3x.
Please complete the following python code precise... | {"functional": "def check(candidate):\n assert candidate(n = 27) == True\n assert candidate(n = 0) == False\n assert candidate(n = 9) == True\n assert candidate(n = 45) == False\n\n\ncheck(Solution().isPowerOfThree)"} | 92 | 67 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define the conversion array conver of an array arr as follows:
conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.
We also define the score of an array arr as... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,7,5,10]) == [4,10,24,36,56]\n assert candidate(nums = [1,1,2,4,8,16]) == [2,4,8,16,32,64]\n\n\ncheck(Solution().findPrefixScore)"} | 161 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Taking into consideration the [3.5 edition rules](http://www.dandwiki.com/wiki/SRD:Ability_Scores#Table:_Ability_Modifiers_and_Bonus_Spells), your goal is to build a function that takes an ability score (worry not about validation: it is always going to ... | {"functional": "_inputs = [[0], [1], [5], [10], [20]]\n_outputs = [[{'modifier': 0, 'maximum_spell_level': -1, 'extra_spells': []}], [{'modifier': -5, 'maximum_spell_level': -1, 'extra_spells': []}], [{'modifier': -3, 'maximum_spell_level': -1, 'extra_spells': []}], [{'modifier': 0, 'maximum_spell_level': 0, 'extra_spe... | 520 | 285 |
coding | Solve the programming task below in a Python markdown code block.
A circular array of length N is defined as follows: N integers A_{1},A_{2},…,A_{N} are placed in a circle in such a way that for each 1 ≤ i < N, A_{i} and A_{i+1} are adjacent, and A_{1} and A_{N} are also adjacent.
You are given a circular array A of l... | {"inputs": ["4\n6 1\n0 1 0 1 0 0\n3 0\n0 1 2\n8 2\n0 0 0 2 0 0 0 5\n3 10\n1 2 3"], "outputs": ["6\n3\n23\n66"]} | 702 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as many coins ... | {"inputs": ["2 1 1 1\n", "7 4 1 6\n", "4 4 2 2\n", "5 2 2 3\n", "5 3 2 1\n", "5 4 3 2\n", "1 1 1 1\n", "7 4 1 4\n"], "outputs": ["2", "-1", "1", "-1", "1", "-1", "-1", "-1"]} | 410 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Mobile Display Keystrokes
Do you remember the old mobile display keyboards? Do you also remember how inconvenient it was to write on it?
Well, here you have to calculate how much keystrokes you have to do for a specific word.
This is the layout:
Ret... | {"functional": "_inputs = [[''], ['123'], ['codewars'], ['zruf'], ['thisisasms'], ['longwordwhichdontreallymakessense']]\n_outputs = [[0], [3], [26], [16], [37], [107]]\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_t... | 177 | 204 |
coding | Solve the programming task below in a Python markdown code block.
A disease is spreading through ChefLand!
The disease spreads as follows:
At the end of day 0, a single person is infected with the disease.
During the next 10 days, the number of infected people doubles each day, until the disease has spread to all peop... | {"inputs": ["4\n100 3\n2000 10\n6000 11\n10 11"], "outputs": ["8\n1024\n3072\n10"]} | 631 | 53 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that accepts a string, and returns true if it is in the form of a phone number. Assume that any integer from 0-9 in any of the spots will produce a valid phone number.
Only worry about the following format:
(123) 456-7890 (don't forge... | {"functional": "_inputs = [['(123) 456-7890'], ['(1111)555 2345'], ['(098) 123 4567'], ['(123)456-7890'], ['abc(123)456-7890'], ['(123)456-7890abc'], ['abc(123)456-7890abc'], ['abc(123) 456-7890'], ['(123) 456-7890abc'], ['abc(123) 456-7890abc']]\n_outputs = [[True], [False], [False], [False], [False], [False], [False]... | 185 | 342 |
coding | Solve the programming task below in a Python markdown code block.
Find the union of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$.
Constraints
* $1 \leq n, m \leq 200,000$
* $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$
* $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$
Input
The inp... | {"inputs": ["3\n1 5 8\n2\n5 8", "3\n1 3 8\n2\n5 8", "3\n1 5 8\n2\n4 9", "3\n1 6 8\n2\n5 8", "3\n1 3 8\n2\n2 8", "3\n1 5 8\n2\n3 9", "3\n2 3 8\n2\n5 8", "3\n1 3 8\n2\n3 8"], "outputs": ["1\n5\n8\n", "1\n3\n5\n8\n", "1\n4\n5\n8\n9\n", "1\n5\n6\n8\n", "1\n2\n3\n8\n", "1\n3\n5\n8\n9\n", "2\n3\n5\n8\n", "1\n3\n8\n"]} | 273 | 206 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp bought a new expensive painting and decided to show it to his $n$ friends. He hung it in his room. $n$ of his friends entered and exited there one by one. At one moment there was no more than one person in the room. In other words, the first fri... | {"inputs": ["1\n??????????????????????????????\n", "8\n0\n1\n1110000\n?????\n1?1??0?0\n0?0???\n??11\n??0??\n"], "outputs": ["30\n", "1\n1\n2\n5\n4\n1\n1\n3\n"]} | 594 | 85 |
coding | Solve the programming task below in a Python markdown code block.
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented... | {"inputs": ["1\n2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n", "2\n2 2\n", "3\n1 2 1\n", "3\n2 1 2\n", "3\n1 1 1\n"], "outputs": ["1\n", "2\n", "2\n", "2\n", "2\n", "3\n", "3\n", "3\n"]} | 462 | 106 |
coding | Solve the programming task below in a Python markdown code block.
Chef is the financial incharge of Chefland and one of his duties is identifying if any company has gained a monopolistic advantage in the market.
There are exactly 3 companies in the market each of whose revenues are denoted by R_{1}, R_{2} and R_{3} re... | {"inputs": ["4\n1 1 1\n1 2 4\n2 10 3\n1 2 3\n"], "outputs": ["No\nYes\nYes\nNo\n"]} | 437 | 45 |
coding | 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 and an array queries of size k.
Find an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following pro... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]) == [5,8,1]\n assert candidate(grid = [[5,2,1],[1,1,2]], queries = [3]) == [0]\n\n\ncheck(Solution().maxPoints)"} | 215 | 89 |
coding | Solve the programming task below in a Python markdown code block.
------Read problems statements in Hindi,
Mandarin chinese
, Russian and Vietnamese as well. ------
At ShareChat, there are are plenty of interesting problems to solve. Here is one of them.
Given integers $A$, $B$ and $N$, you should calculate the [GCD... | {"inputs": ["2\n10 1 1\n9 1 5"], "outputs": ["1\n2"]} | 468 | 27 |
coding | Solve the programming task below in a Python markdown code block.
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $... | {"inputs": ["1\n2 2\n0 5\n", "1\n2 2\n0 5\n", "1\n2 2\n0 8\n", "1\n2 2\n0 0\n", "1\n2 2\n1 8\n", "1\n2 4\n0 0\n", "1\n2 1\n0 0\n", "1\n2 2\n-1 0\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 632 | 135 |
coding | Solve the programming task below in a Python markdown code block.
Chef likes to play with array elements. His teacher has given him an array problem. But now he is busy as Christmas is coming. So, he needs your help. Can you help him to solve this problem.
You are given an array $(A1,A2,A3……AN)$ of length $N$. You have... | {"inputs": ["2\n5\n2 4 5 7 9\n4\n5 4 2 3"], "outputs": ["6 11 14 4 2\n4 7 6 5"]} | 508 | 52 |
coding | Solve the programming task below in a Python markdown code block.
The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.
In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different ... | {"inputs": ["4\nrgbBRG\nRgbrBG\nbBrRgG\nrgRGBb\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 482 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of wo... | {"functional": "_inputs = [['AWUBBWUBC'], ['AWUBWUBWUBBWUBWUBWUBC'], ['WUBAWUBBWUBCWUB'], ['RWUBWUBWUBLWUB'], ['WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB'], ['WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB'], ['QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH'], ['WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTW... | 404 | 752 |
coding | Solve the programming task below in a Python markdown code block.
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time ... | {"inputs": ["2\n", "3\n", "4\n", "6\n", "9\n", "4\n", "3\n", "6\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "2\n", "2", "1", "3"]} | 368 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a sequence $b_1, b_2, b_3 \dots, b_{k - 1}, b_k$ almost increasing if $$\min(b_1, b_2) \le \min(b_2, b_3) \le \dots \le \min(b_{k - 1}, b_k).$$ In particular, any sequence with no more than two elements is almost increasing.
You are given a s... | {"inputs": ["3\n8\n1 2 7 3 2 1 2 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 3 2 1 2 5\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 6 2 1 1 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 1 2 1 1 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n", "3\n8\n1 2 7 6 2 1 4 4\n2\n2 1\n7\n7 3 3 2 6 3 7\n", "3\n8\n1 2 7 1 2 1 1 3\n2\n2 1\n7\n4 1 5 2 ... | 461 | 422 |
coding | Solve the programming task below in a Python markdown code block.
The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then ... | {"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n12\n3\n123\n45\n6\n1234\n567\n89\n10"]} | 207 | 49 |
coding | Solve the programming task below in a Python markdown code block.
There is an integer sequence A of length N whose values are unknown.
Given is an integer sequence B of length N-1 which is known to satisfy the following:
B_i \geq \max(A_i, A_{i+1})
Find the maximum possible sum of the elements of A.
-----Constraints... | {"inputs": ["2\n5", "2\n4", "2\n1", "2\n0", "2\n2", "2\n6", "2\n9", "2\n3"], "outputs": ["10\n", "8\n", "2\n", "0\n", "4\n", "12\n", "18\n", "6"]} | 236 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Given an integer, take the (mean) average of each pair of consecutive digits. Repeat this process until you have a single integer, then return that integer. e.g.
Note: if the average of two digits is not an integer, round the result **up** (e.g. the ave... | {"functional": "_inputs = [[246], [89], [2], [245], [345], [346], [3700]]\n_outputs = [[4], [9], [2], [4], [5], [5], [4]]\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... | 240 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given an array $A$ of size $N$. Find the maximum value of the expression $a * b + a - b$ where $a$ and $b$ are $2$ distinct elements of the array.
------ Inp... | {"inputs": ["2\n2 \n2 2\n3\n5 3 2"], "outputs": ["4\n17"]} | 461 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Beppa and her circle of geek friends keep up to date on a group chat in the instant messaging app SwerChat$^{\text{TM}}$.
The group has $n$ members, excluding Beppa. Each of those members has a unique ID between $1$ and $n$. When a user opens a group ch... | {"inputs": ["4\n5\n1 4 2 5 3\n4 5 1 2 3\n6\n1 2 3 4 5 6\n1 2 3 4 5 6\n8\n8 2 4 7 1 6 5 3\n5 6 1 4 8 2 7 3\n1\n1\n1\n"], "outputs": ["2\n0\n4\n0\n"]} | 762 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Write a function
```python
alternate_sort(l)
```
that combines the elements of an array by sorting the elements ascending by their **absolute value** and outputs negative and non-negative integers alternatingly (starting with the negative value, if any).... | {"functional": "_inputs = [[[5, 2, -3, -9, -4, 8]], [[5, -42, 2, -3, -4, 8, 9]], [[5, -42, 8, 2, -3, -4, 9]], [[5, -42, -8, 2, -3, -4, -9]], [[5, 2, 3, 4, 8, 9]], [[-5, -2, -3, -4, -8, -9]], [[-5, -2, 3, 4, -8, 0, -9]], [[-5, -2, 3, 9, 4, -2, -8, 0, 9, -9]]]\n_outputs = [[[-3, 2, -4, 5, -9, 8]], [[-3, 2, -4, 5, -42, 8,... | 265 | 502 |
coding | Solve the programming task below in a Python markdown code block.
A `bouncy number` is a positive integer whose digits neither increase nor decrease. For example, 1235 is an increasing number, 5321 is a decreasing number, and 2351 is a bouncy number. By definition, all numbers under 100 are non-bouncy, and 101 is the f... | {"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [6], [10], [20], [50]]\n_outputs = [[0], [0], [0], [525], [8325], [95046], [987048], [9999722967], [99999999999959940181], [99999999999999999999999999999999999999912040301674]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance... | 284 | 303 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order.... | {"inputs": ["2\n1\n", "2\n2\n", "2\n1\n", "2\n2\n", "3\n1 2\n", "3\n1 3\n", "3\n2 3\n", "3\n2 1\n"], "outputs": ["2\n", "1\n", " 2", " 1", "3\n", "2\n", "1\n", "3\n"]} | 249 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
There are N chairs placed in circular order. Some of the chairs are empty while others have a child sitting in it. You are required to change the places of the children so th... | {"inputs": ["1\n8\n10001010"], "outputs": ["2"]} | 531 | 23 |
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 non-empty subarrays with the leftmost element of the subarray not larger than other elements in the subarray.
A subarray is a contiguous part of an array.
Please com... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,2,5,3]) == 11\n assert candidate(nums = [3,2,1]) == 3\n assert candidate(nums = [2,2,2]) == 6\n\n\ncheck(Solution().validSubarrays)"} | 94 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Nold... | {"inputs": ["2 0\n", "4 7\n", "9 0\n", "2 9\n", "3 7\n", "8 0\n", "3 4\n", "3 0\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n"]} | 334 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef and his friend Chefu decided to go on a trip. The trip takes place over the next $N$ days (numbered 1 through $N$). There are $K$ different plac... | {"inputs": ["5\n5 3\n-1 -1 -1 -1 -1\n4 5\n1 2 3 5\n3 2\n1 -1 2\n4 2\n1 -1 -1 1\n6 4\n-1 -1 4 -1 2 -1"], "outputs": ["YES\n1 2 1 2 1\nYES\n1 2 3 5\nNO\nNO\nYES\n1 2 4 1 2 1"]} | 768 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in ... | {"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "1 2\n0 0\n", "2 1\n0\n0\n", "1 2\n0 1\n", "1 2\n0 0\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]} | 362 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Abhi and his friends (Shanky,Anku and Pandey) love to play with strings. Abhi invented a simple game. He will give a string S to his friends. Shanky and Anku will play the game while Pandey is just a spectator. Shanky will traverse the string from beginn... | {"inputs": ["3\ngoogle\nbreakraekb\naman"], "outputs": ["SHANKY\nPANDEY\nANKU"]} | 353 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Chef has to travel to another place. For this, he can avail any one of two cab services.
The first cab service charges X rupees.
The second cab service charges Y rupees.
Chef wants to spend the minimum amount of money. Which cab service should Chef take... | {"inputs": ["3\n30 65\n42 42\n90 50\n"], "outputs": ["FIRST\nANY\nSECOND\n"]} | 313 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to appear in a competitive exam. To take the exam, there are following requirements:
Minimum age limit is X (i.e. Age should be greater than or equal to X).
Age should be strictly less than Y.
Chef's current Age is A. Find whether he is curr... | {"inputs": ["5\n21 34 30\n25 31 31\n22 29 25\n20 40 15\n28 29 28\n"], "outputs": ["YES\nNO\nYES\nNO\nYES\n"]} | 523 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Number of tanka
Wishing to die in the spring under the flowers
This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases and thirt... | {"inputs": ["1\n2\n5\n390\n216\n442\n877438609014957\n0", "1\n2\n5\n390\n216\n763\n877438609014957\n0", "1\n2\n5\n390\n216\n442\n3724086920287233\n0", "1\n2\n5\n390\n216\n763\n1563679537664695\n0", "1\n3\n5\n390\n216\n763\n1563679537664695\n0", "1\n3\n6\n19\n216\n291\n34091156012094062\n0", "1\n3\n6\n19\n216\n291\n4542... | 537 | 878 |
coding | Solve the programming task below in a Python markdown code block.
You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t`
is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth
of seco... | {"functional": "_inputs = [[37], [45], [99], [85], [136], [52], [16], [127], [137], [14]]\n_outputs = [[10], [13], [28], [24], [39], [15], [5], [36], [39], [4]]\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)\... | 331 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Tanya wants to go on a journey across the cities of Berland. There are $n$ cities situated along the main railroad line of Berland, and these cities are numbered from $1$ to $n$.
Tanya plans her journey as follows. First of all, she will choose some ci... | {"inputs": ["2\n2 1\n", "2\n1 1\n", "3\n3 6 5\n", "3\n1 1 2\n", "1\n400000\n", "6\n1 1 1 2 3 4\n", "6\n1 1 1 1 1 2\n", "2\n399999 400000\n"], "outputs": ["2\n", "1\n", "8\n", "3\n", "400000\n", "10\n", "3\n", "799999\n"]} | 708 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Tunnel formula
One day while exploring an abandoned mine, you found a long formula S written in the mine. If you like large numbers, you decide to take out the choke and add `(` or `)` so that the result of the formula calculation is as large as possibl... | {"inputs": ["0-(2+3-4+5)", "0-(2+3-3+5)", "2-(2+3-4+5)", "1-(3+2-4+5)", "2-(2-3+4+5)", "0-(3+4-4+5)", "3+(2-4-4+5)", "2-(2+2-4+5)"], "outputs": ["4\n", "3\n", "6\n", "5\n", "12\n", "2\n", "10\n", "7\n"]} | 443 | 129 |
coding | Solve the programming task below in a Python markdown code block.
Write a method named `getExponent(n,p)` that returns the largest integer exponent `x` such that p^(x) evenly divides `n`. if `p<=1` the method should return `null`/`None` (throw an `ArgumentOutOfRange` exception in C#).
Also feel free to reuse/extend the... | {"functional": "_inputs = [[27, 3]]\n_outputs = [[3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_... | 97 | 159 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A_{1}, A_{2}, \dots, A_{N} of length N. You can perform the following operation any number of times (possibly 0 times) :
Choose any two indices i and j and replace either A_{i} or A_{j} with \gcd(A_{i},A_{j}).
Find the minimum pos... | {"inputs": ["2\n2\n5 10\n3\n2 2 6\n"], "outputs": ["10\n6\n"]} | 454 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Bears love candies and games involving eating them. Limak and Bob play the following game. Limak eats 1 candy, then Bob eats 2 candies, then Limak eats 3 candies, then Bob eats 4 candies, and so on. Once someone can't eat what he is supposed to eat, he l... | {"inputs": ["10\n3 2\n4 2\n1 1\n1 2\n1 3\n9 3\n9 11\n9 12\n9 1000\n8 11"], "outputs": ["Bob\nLimak\nLimak\nBob\nBob\nLimak\nLimak\nBob\nBob\nBob"]} | 629 | 81 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The diameter of a tree is the number of edges in the longest path in that tree.
There is an undirected tree of n nodes labeled from 0 to n - 1. You are given a 2D array edges where edges.length == n - 1 and edges[i] =... | {"functional": "def check(candidate):\n assert candidate(edges = [[0,1],[0,2]]) == 2\n assert candidate(edges = [[0,1],[1,2],[2,3],[1,4],[4,5]]) == 4\n\n\ncheck(Solution().treeDiameter)"} | 138 | 68 |
coding | Solve the programming task below in a Python markdown code block.
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) ... | {"inputs": ["1 0\n1\n", "1 1\n1\n", "1 2\n1\n", "1 4\n1\n", "1 7\n1\n", "1 3\n1\n", "2 1\n1\n2\n", "2 1\n2\n1\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]} | 157 | 106 |
coding | Solve the programming task below in a Python markdown code block.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy r... | {"inputs": ["9", "8", "3", "6", "5", "7", "1", "2"], "outputs": ["8\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 181 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You play your favourite game yet another time. You chose the character you didn't play before. It has $str$ points of strength and $int$ points of intelligence. Also, at start, the character has $exp$ free experience points you can invest either in stren... | {"inputs": ["4\n9 3 8\n2 1 1\n1 5 5\n4 0 4\n", "4\n1 4 8\n4 0 0\n1 5 5\n8 1 6\n", "4\n9 3 8\n2 1 1\n1 5 1\n4 0 4\n", "4\n8 4 8\n2 1 1\n1 5 5\n8 1 6\n", "4\n1 4 8\n4 0 0\n1 5 5\n8 1 1\n", "4\n1 4 8\n6 0 0\n1 5 5\n8 1 1\n", "4\n5 3 4\n2 1 0\n3 5 5\n4 10 6\n", "4\n5 3 4\n2 1 0\n1 5 5\n4 10 6\n"], "outputs": ["7\n1\n1\n4\n... | 456 | 312 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings words. Each element of words consists of two lowercase English letters.
Create the longest possible palindrome by selecting some elements from words and concatenating them in any orde... | {"functional": "def check(candidate):\n assert candidate(words = [\"lc\",\"cl\",\"gg\"]) == 6\n assert candidate(words = [\"ab\",\"ty\",\"yt\",\"lc\",\"cl\",\"ab\"]) == 8\n assert candidate(words = [\"cc\",\"ll\",\"xx\"]) == 2\n\n\ncheck(Solution().longestPalindrome)"} | 134 | 80 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, ... | {"inputs": ["m\nm\n", "m\nm\n", "td\nt\n", "aa\na\n", "td\nt\n", "aa\na\n", "dt\nt\n", "ct\nt\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 481 | 86 |
coding | Solve the programming task below in a Python markdown code block.
How can you tell an extrovert from an
introvert at NSA? Va gur ryringbef,
gur rkgebireg ybbxf ng gur BGURE thl'f fubrf.
I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it?
According to Wikipedia, ROT13 (http://en.wiki... | {"functional": "_inputs = [['EBG13 rknzcyr.'], [\"How can you tell an extrovert from an\\nintrovert at NSA? Va gur ryringbef,\\ngur rkgebireg ybbxf ng gur BGURE thl'f fubrf.\"], ['123'], ['Guvf vf npghnyyl gur svefg xngn V rire znqr. Gunaxf sbe svavfuvat vg! :)'], ['@[`{']]\n_outputs = [['ROT13 example.'], [\"Ubj pna l... | 215 | 341 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
Please complet... | {"functional": "def check(candidate):\n assert candidate(columnTitle = \"A\") == 1\n assert candidate(columnTitle = \"AB\") == 28\n assert candidate(columnTitle = \"ZY\") == 701\n\n\ncheck(Solution().titleToNumber)"} | 110 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length N consisting of ( and ). Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence.
Here, a correct bracket sequence is defined as follows:
- () is a correct bracket sequence.
- If X... | {"inputs": ["3\n)()", "3\n)))", "3\n))(", "3\n(()", "3\n())", "3\n())\n", "6\n)())))", "6\n())())"], "outputs": ["()()\n", "((()))\n", "(())()\n", "(())\n", "(())", "(())\n", "(((()())))\n", "((())())\n"]} | 254 | 93 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.