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.
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organiz... | {"inputs": ["2\n5 7\n", "2\n2 1\n", "2\n1 2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 3\n", "2\n2 0\n", "2\n2 7\n"], "outputs": ["2 5\n", "1 1\n", "2 1\n", "2 1\n", "1 1\n", "2 1\n", "1 0\n", "2 2\n"]} | 322 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Count the number of divisors of a positive integer `n`.
Random tests go up to `n = 500000`.
## Examples
```python
divisors(4) == 3 # 1, 2, 4
divisors(5) == 2 # 1, 5
divisors(12) == 6 # 1, 2, 3, 4, 6, 12
divisors(30) == 8 # 1, 2, 3, 5, 6, 10, 15, ... | {"functional": "_inputs = [[1], [4], [5], [12], [25], [30], [4096]]\n_outputs = [[1], [3], [2], [6], [3], [8], [13]]\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 ... | 176 | 197 |
coding | Solve the programming task below in a Python markdown code block.
We have the numbers with different colours with the sequence: ['red', 'yellow', 'blue'].
That sequence colours the numbers in the following way:
1 2 3 4 5 6 7 8 9 10 11 12 13 .....
We have got the following recursive function:... | {"functional": "_inputs = [[3, 3, 'blue'], [100, 4, 'red'], [250, 6, 'yellow'], [1000, 7, 'red']]\n_outputs = [[[6, 15, 21]], [[136, 190, 253, 325]], [[]], [[1081, 1225, 1378, 1540, 1711, 1891, 2080]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math... | 537 | 268 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights w_{i} kilograms.
Vasya needs... | {"inputs": ["2 3 4 5 6\n1 2\n", "2 3 4 5 6\n1 2\n", "2 6 4 5 6\n1 2\n", "4 7 2 3 9\n1 2 3 4\n", "4 7 2 3 9\n0 2 3 4\n", "4 7 2 3 9\n0 2 6 4\n", "4 7 4 3 9\n1 2 3 4\n", "4 7 2 3 9\n1 2 3 4\n"], "outputs": ["11\n", "11\n", "14\n", "34\n", "27\n", "33\n", "49\n", "34\n"]} | 608 | 194 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has $N$ [6-sided standard dice]. Each die has dimensions $1 \times 1 \times 1$. Since Chef is bored during the quarantine, he decides to stack dice for f... | {"inputs": ["1\n1"], "outputs": ["20"]} | 509 | 15 |
coding | Solve the programming task below in a Python markdown code block.
A total of $n$ depots are located on a number line. Depot $i$ lies at the point $x_i$ for $1 \le i \le n$.
You are a salesman with $n$ bags of goods, attempting to deliver one bag to each of the $n$ depots. You and the $n$ bags are initially at the orig... | {"inputs": ["4\n5 1\n1 2 3 4 5\n9 3\n-5 -10 -15 6 5 8 3 7 4\n5 3\n2 2 3 3 3\n4 2\n1000000000 1000000000 1000000000 1000000000\n"], "outputs": ["25\n41\n7\n3000000000\n"]} | 739 | 132 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.
A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to t... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1],[1,0]]) == 2\n assert candidate(grid = [[0,0,0],[1,1,0],[1,1,0]]) == 4\n assert candidate(grid = [[1,0,0],[1,1,0],[1,1,0]]) == -1\n\n\ncheck(Solution().shortestPathBinaryMatrix)"} | 187 | 96 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers.
You can choose any non-negative integer $D$ (i.e. $D \ge 0$), and for each $a_i$ you can:
add $D$ (only once), i. e. perform $a_i := a_i + D$, or subtract $D$ (only once), i... | {"inputs": ["2\n2 8\n", "1\n100\n", "2\n1 1\n", "2\n2 7\n", "2\n5 8\n", "2\n3 1\n", "2\n2 5\n", "2\n3 8\n"], "outputs": ["3\n", "0\n", "0\n", "5\n", "3\n", "1\n", "3\n", "5\n"]} | 556 | 102 |
coding | Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.
A message is a sequence of n integers a1, a2... | {"inputs": ["3 1 5\n1 2 5\n4\n", "3 1 5\n1 2 3\n4\n", "5 2 7\n0 0 1 2 4\n3 5\n", "5 2 7\n0 0 1 2 4\n3 0\n", "4 3 2\n1 1 1 1\n1 1 2\n", "4 3 2\n1 1 1 1\n0 1 2\n", "4 3 2\n1 2 1 1\n0 1 2\n", "4 3 2\n1 1 1 1\n0 1 1\n"], "outputs": ["0 1 4\n", "0 1 2 \n", "3 1 2 3 2 \n", "3 3 4 5 4\n", "0 1 0 1\n", "1 0 0 1\n", "1 1 0 1\n"... | 580 | 252 |
coding | Solve the programming task below in a Python markdown code block.
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.
He will receive a headline which contains one of the strings S_1,...,S_n tomorrow.
He is excited and already thinking of what string... | {"inputs": ["3\na\naa\na", "3\na\naa\nb", "3\na\naa\nb\n", "3\ncaaa\ndaacc\nacacac", "3\ncaaa\nd`acc\nacacac", "3\naaca\nbdb`c\nacacac", "3\ncaca\ncca`d\nacacac", "3\nacba\nda`cb\nacacbc"], "outputs": ["a\n", "", "\n", "aac\n", "ac\n", "c\n", "acc\n", "abc\n"]} | 348 | 131 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has his favourite number $n$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $d_1, d_2, \ldots, d_k$, such that $1 \leq d_i \leq 9$ for all $i$ and $d_1 + d_2 + \ldots + d_k = n$.
Vasya likes beauty in ... | {"inputs": ["1\n", "4\n", "2\n", "3\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n1 ", "4\n1 1 1 1 ", "2\n1 1 ", "3\n1 1 1 ", "5\n1 1 1 1 1 ", "6\n1 1 1 1 1 1 ", "7\n1 1 1 1 1 1 1 ", "8\n1 1 1 1 1 1 1 1 "]} | 535 | 135 |
coding | Solve the programming task below in a Python markdown code block.
"Don't Drink and Drive, but when you do, Better Call Saul."
Once Jesse and Walter were fighting over extra cash, and Saul decided to settle it with a game of stone piles whose winner gets the extra money. The game is described as follows :
There are N$N$... | {"inputs": ["2\n5 3\n4 4 4 3 4\n7 4\n3 3 1 1 1 2 4"], "outputs": ["Jesse\nWalter"]} | 618 | 48 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.
You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirec... | {"functional": "def check(candidate):\n assert candidate(n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]) == 43\n assert candidate(n = 5, roads = [[0,3],[2,4],[1,3]]) == 20\n\n\ncheck(Solution().maximumImportance)"} | 180 | 88 |
coding | Solve the programming task below in a Python markdown code block.
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one... | {"inputs": ["1\n1\n5\n", "1\n1\n8\n", "1\n1\n2\n", "1\n1\n78\n", "1\n1\n46\n", "1\n1\n16\n", "1\n1\n37\n", "1\n1\n87\n"], "outputs": ["2\n", "3\n", "1\n", "26\n", "16\n", "6\n", "13\n", "29\n"]} | 597 | 111 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ with $n$ integers. You can perform the following operation at most $k$ times:
Choose two indices $i$ and $j$, in which $i \,mod\, k = j \,mod\, k$ ($1 \le i < j \le n$).
Swap $a_i$ and $a_j$.
After performing all operations,... | {"inputs": ["1\n1 1\n0\n", "1\n2 2\n123456 123456\n", "5\n3 2\n5 6 0\n1 1\n7\n5 3\n7 0 4 0 4\n4 2\n2 7 3 4\n3 3\n1000000000 1000000000 999999997\n"], "outputs": ["0\n", "246912\n", "11\n7\n15\n10\n2999999997\n"]} | 495 | 157 |
coding | Solve the programming task below in a Python markdown code block.
You are given $n$ integers $a_1, a_2, \ldots, a_n$. You choose any subset of the given numbers (possibly, none or all numbers) and negate these numbers (i. e. change $x \to (-x)$). What is the maximum number of different values in the array you can achie... | {"inputs": ["1\n2\n-100 100\n", "1\n4\n100 -100 99 -99\n", "3\n4\n1 1 2 2\n3\n1 2 3\n2\n0 0\n", "4\n3\n100 -100 100\n4\n100 0 0 0\n5\n0 0 0 0 0\n7\n100 3 -2 0 -100 4 5\n", "1\n30\n1 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\n"], "outputs": ["2\n", "4\n", "4\n3\n1\n", "2\n2\n1\n7\n",... | 354 | 250 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. In one operation, you can:
Choose an index i in the range 0 <= i < nums.length
Set nums[i] to nums[i] + 1 or nums[i] - 1
Return the minimum number of operations to make ... | {"functional": "def check(candidate):\n assert candidate(nums = [3,2,4,5,0]) == 4\n assert candidate(nums = [2,2,3,4]) == 0\n assert candidate(nums = [0]) == 0\n\n\ncheck(Solution().convertArray)"} | 118 | 69 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of $n$ positive integers.
You can use the following operation as many times as you like: select any integer $1 \le k \le n$ and do one of two things: decrement by one $k$ of the first elements of the array. decrement by one... | {"inputs": ["4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n1 3 1 3 1\n4\n5 2 1 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 1 3 1\n4\n5 2 1 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 1 3 2\n4\n5 2 1 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 1 3 2\n4\n5 2 0 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 0 3 2\n4\n5 2 0 10\n", "4\n3\n1 2 2\n5\n1... | 518 | 462 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,4,2,3], x = 5) == 2\n assert candidate(nums = [5,6,7,8,9], x = 4) == -1\n assert candidate(nums = [3,2,20,1,1,3], x = 10) == 5\n\n\ncheck(Solution().minOperations)"} | 125 | 98 |
coding | Solve the programming task below in a Python markdown code block.
In HackerLand, they have a very strange monetary system.
Each gold coin has an integer number 'N' written on it.
A coin N can be split into any number of coins.
For example {11} can be split into {5,6} or {2,4,5} or any other possible way.
You are offer... | {"inputs": ["30\n1\n8566\n6308\n41\n5680\n4427\n2739\n77\n6274\n3601\n7506\n8951\n5345\n3\n9621\n9300\n23\n720\n2151\n7854\n3607\n256\n6076\n9369\n1729\n8229\n205\n980\n4197\n1460"], "outputs": ["1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n2\n1\n3\n1\n1\n2\n1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"]} | 314 | 206 |
coding | Solve the programming task below in a Python markdown code block.
Leonardo loves primes and created ${q}$ queries where each query takes the form of an integer, $n$. For each $n$, count the maximum number of distinct prime factors of any number in the inclusive range $[1,n]$.
Note: Recall that a prime number is only d... | {"inputs": ["6\n1\n2\n3\n500\n5000\n10000000000\n"], "outputs": ["0\n1\n1\n4\n5\n10\n"]} | 443 | 52 |
coding | Solve the programming task below in a Python markdown code block.
You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, th... | {"inputs": ["1\n", "a\n", ".\n", ";\n", ";\n", ".\n", "0\n", "b\n"], "outputs": ["\"1\"\n-\n", "-\n\"a\"\n", "-\n\".\"\n", "-\n\",\"\n", "-\n\",\"\n", "-\n\".\"\n", "\"0\"\n-\n", "-\n\"b\"\n"]} | 475 | 99 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers $a \le b \le c$.
In one move, you can add $+1$ or $-1$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this op... | {"inputs": ["1\n3 6 10000\n", "1\n1 100 940\n", "1\n3 6 10000\n", "1\n1 100 940\n", "1\n1 6 10000\n", "1\n1 110 940\n", "1\n1 73 10000\n", "1\n5 76 10000\n"], "outputs": ["2\n3 6 10002\n", "6\n1 94 940\n", "2\n3 6 10002\n", "6\n1 94 940\n", "1\n1 5 10000\n", "10\n1 104 936\n", "1\n1 73 10001\n", "4\n5 80 10000\n"]} | 496 | 233 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Today is Chef's birthday. His mom gifted him a truly lovable gift, a permutation of first N positive integers.
She placed the permutation on a very long table in front of Chef and left it for ... | {"inputs": ["2\n5 2\n3 5\n5 1\n1", "2\n5 2\n3 5\n7 1\n1", "2\n5 2\n3 3\n7 1\n1", "2\n6 2\n1 3\n7 1\n2", "2\n6 0\n1 3\n7 0\n1", "2\n5 2\n3 3\n7 0\n1", "2\n5 2\n1 3\n7 0\n1", "2\n6 2\n1 3\n7 0\n1"], "outputs": ["Mom\nChef", "Mom\nChef\n", "Chef\nChef\n", "Chef\nMom\n", "Mom\nMom\n", "Chef\nChef\n", "Chef\nChef\n", "Chef\... | 739 | 189 |
coding | Solve the programming task below in a Python markdown code block.
There is an array of strings. All strings contains similar _letters_ except one. Try to find it!
```python
find_uniq([ 'Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a' ]) # => 'BbBb'
find_uniq([ 'abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba' ]) # =>... | {"functional": "_inputs = [[['Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a']], [['abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba']], [['silvia', 'vasili', 'victor']], [['Tom Marvolo Riddle', 'I am Lord Voldemort', 'Harry Potter']], [['', '', '', 'a', '', '']], [[' ', ' ', ' ', 'a', ' ', '']], [['foobar', 'barfo... | 276 | 313 |
coding | Solve the programming task below in a Python markdown code block.
For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent a_{i} minutes building the i-th ball in the tree.
Jacob's teacher will evaluate his model and grade Jacob based on... | {"inputs": ["2 1\n1 100000\n2 1\n", "2 1\n1 100000\n2 1\n", "2 1\n2 100000\n2 1\n", "2 2\n2 100000\n2 1\n", "2 1\n1 100100\n2 1\n", "2 1\n2 101000\n2 1\n", "2 1\n0 101001\n2 1\n", "2 1\n3 001000\n2 1\n"], "outputs": ["100000\n", "100000\n", "100000\n", "2\n", "100100\n", "101000\n", "101001\n", "1000\n"]} | 659 | 223 |
coding | Solve the programming task below in a Python markdown code block.
Given an undirected tree, let the distance between vertices u and v be the number of edges on the simple path from u to v. The diameter of a tree is the maximum among the distances between any two vertices. We will call a tree good if and only if its dia... | {"inputs": ["6 1\n1 2\n3 2\n4 2\n1 6\n5 6", "6 7\n1 2\n3 2\n4 2\n1 6\n5 6", "6 2\n1 2\n3 2\n4 2\n1 6\n5 2", "6 2\n1 3\n3 2\n4 2\n1 6\n5 6", "6 2\n0 3\n3 2\n4 2\n1 6\n5 6", "6 0\n1 3\n6 2\n4 2\n1 6\n5 6", "6 7\n1 2\n3 4\n4 2\n1 6\n5 6", "6 5\n1 3\n3 2\n4 2\n1 6\n5 6"], "outputs": ["4\n", "0\n", "1\n", "3\n", "2\n", "5\n... | 354 | 238 |
coding | Solve the programming task below in a Python markdown code block.
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper... | {"inputs": ["3\n1 1000 1\n", "6\n3 2 1 2 3 3\n"], "outputs": ["0\n", "8\n"]} | 549 | 43 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai an... | {"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[0,2],[1,3],[1,4],[2,5]], values = [2,8,3,6,2,5]) == 24\n assert candidate(n = 3, edges = [[0,1],[1,2]], values = [4,6,1]) == 0\n\n\ncheck(Solution().maxXor)"} | 253 | 103 |
coding | Solve the programming task below in a Python markdown code block.
The Bitlandians are quite weird people. They have very peculiar customs.
As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.
The kids are excited because just as is cus... | {"inputs": ["1\n1 23\n", "1\n0 23\n", "1\n0 28\n", "1\n0 48\n", "1\n0 19\n", "1\n1 999\n", "1\n1 999\n", "1\n1 397\n"], "outputs": ["A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n"]} | 545 | 113 |
coding | Solve the programming task below in a Python markdown code block.
Switch/Case - Bug Fixing #6
Oh no! Timmy's evalObject function doesn't work. He uses Switch/Cases to evaluate the given properties of an object, can you fix timmy's function?
Also feel free to reuse/extend the following starter code:
```python
def eval_... | {"functional": "_inputs = [[{'a': 1, 'b': 1, 'operation': '+'}], [{'a': 1, 'b': 1, 'operation': '-'}], [{'a': 1, 'b': 1, 'operation': '/'}], [{'a': 1, 'b': 1, 'operation': '*'}], [{'a': 1, 'b': 1, 'operation': '%'}], [{'a': 1, 'b': 1, 'operation': '**'}]]\n_outputs = [[2], [0], [1], [1], [0], [1]]\nimport math\ndef _de... | 79 | 274 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes that course prevCoursej... | {"functional": "def check(candidate):\n assert candidate(n = 3, relations = [[1,3],[2,3]], time = [3,2,5]) == 8\n assert candidate(n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]) == 12\n\n\ncheck(Solution().minimumTime)"} | 245 | 100 |
coding | Solve the programming task below in a Python markdown code block.
In graph theory, a graph is a collection of nodes with connections between them.
Any node can be connected to any other node exactly once, and can be connected to no nodes, to some nodes, or to every other node.
Nodes cannot be connected to themselves
A ... | {"functional": "_inputs = [[[[], []]], [[[1], [0]]], [[[1, 2], [0, 2], [0, 1]]], [[[1, 2, 3], [0, 2], [1, 2], [0]]], [[[1, 2, 3], [0], [0], [0, 4], [3]]], [[[1, 2, 3], [0], [0], [0, 4], [3], []]], [[[1], [0, 2], [1, 3, 5], [2, 4], [3, 5], [4, 2]]], [[[1], [0, 2, 3, 4], [1], [1], [1]]], [[[1], [0, 2, 3], [1], [1], [5], ... | 392 | 465 |
coding | Solve the programming task below in a Python markdown code block.
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of... | {"inputs": ["1 1\n1 1\n", "1 0\n1 1\n", "178279081 0\n", "4 2\n1 2\n2 0\n", "6 2\n1 3\n4 1\n", "5 2\n1 1\n2 2\n", "8 2\n1 2\n2 0\n", "8 2\n1 2\n2 1\n"], "outputs": ["1", "1", "1", "1", "1", "1", "1", "1"]} | 566 | 134 |
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 s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.
Each letter in the alp... | {"functional": "def check(candidate):\n assert candidate(s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) == True\n assert candidate(s = \"aa\", distance = [1,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]) == False\n\n\ncheck(Solution().checkDistances)"} | 202 | 154 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
Given an integer n, return true if n is an ugly number.
Please complete the following python code precisely:
```python
class Solut... | {"functional": "def check(candidate):\n assert candidate(n = 6) == True\n assert candidate(n = 1) == True\n assert candidate(n = 14) == False\n\n\ncheck(Solution().isUgly)"} | 85 | 54 |
coding | Solve the programming task below in a Python markdown code block.
There is a $n \times m$ grid. You are standing at cell $(1, 1)$ and your goal is to finish at cell $(n, m)$.
You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell $(x, y)$. You can:
move right to t... | {"inputs": ["6\n1 1 0\n2 2 2\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\n", "6\n1 1 0\n2 2 4\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\n", "6\n1 1 0\n2 2 4\n2 2 3\n2 2 4\n1 4 2\n100 100 10000\n", "6\n1 1 0\n2 2 4\n3 2 3\n2 2 4\n1 4 3\n100 100 10000\n", "6\n1 1 0\n2 2 4\n2 2 2\n2 2 4\n1 4 2\n100 100 10000\n", "6\n1 1 1\n2 2 4\n2 2 2... | 548 | 502 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to make a purchase. For this, he needs X gold coins, but he has none at the moment.
Chef has N fixed deposits, the i^{th} of which is worth A_{i} coins. He wants to open the minimum number of these deposits so that he has at least X coins.
Y... | {"inputs": ["4\n4 6\n4 3 5 1\n3 15\n1 5 3\n2 5\n10 3\n4 7\n1 2 3 4"], "outputs": ["2\n-1\n1\n2"]} | 609 | 63 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.
The bombs are represented by a... | {"functional": "def check(candidate):\n assert candidate(bombs = [[2,1,3],[6,1,4]]) == 2\n assert candidate(bombs = [[1,1,5],[10,10,5]]) == 1\n assert candidate(bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]) == 5\n\n\ncheck(Solution().maximumDetonation)"} | 220 | 109 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.
Return the length of the shortest pa... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,2,3],[0],[0],[0]]) == 4\n assert candidate(graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]) == 4\n\n\ncheck(Solution().shortestPathLength)"} | 130 | 73 |
coding | Solve the programming task below in a Python markdown code block.
A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like.
-----Co... | {"inputs": ["cofgee", "sjppvv", "uuppis", "ephoni", "cofgef", "uvppis", "eohoni", "fegfoc"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 169 | 78 |
coding | Solve the programming task below in a Python markdown code block.
You are given a positive integer $n$.
Let $S(x)$ be sum of digits in base 10 representation of $x$, for example, $S(123) = 1 + 2 + 3 = 6$, $S(0) = 0$.
Your task is to find two integers $a, b$, such that $0 \leq a, b \leq n$, $a + b = n$ and $S(a) + S(b... | {"inputs": ["1\n", "8\n", "9\n", "5\n", "5\n", "1\n", "8\n", "9\n"], "outputs": ["1\n", "8\n", "9\n", "5\n", "5\n", "1\n", "8\n", "9\n"]} | 405 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.
Return the larg... | {"functional": "def check(candidate):\n assert candidate(arr = [1,15,7,9,2,5,10], k = 3) == 84\n assert candidate(arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4) == 83\n assert candidate(arr = [1], k = 1) == 1\n\n\ncheck(Solution().maxSumAfterPartitioning)"} | 127 | 109 |
coding | Solve the programming task below in a Python markdown code block.
Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'!
To compose a story, Stephen wrote out $n$ words consisting of the first $5$ lowercase letters of the Latin alphabet. He wants to select t... | {"inputs": ["6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nab\nab\nc\nbc\n5\ncbdca\nd\na\nd\ne\n3\nb\nc\nca\n", "6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nba\nab\nc\nbc\n5\ncbdca\nd\na\nd\ne\n3\nb\nc\nca\n", "6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nab\naa\nc\nbc\n5\ncbdc... | 743 | 617 |
coding | Solve the programming task below in a Python markdown code block.
Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.
-----Input-----
The first line of input contains T - number of test cases.
Each of the n... | {"inputs": ["3\n1 2 0 3\n1 2 4 -1\n1 2 3 4"], "outputs": ["Yes\nYes\nNo"]} | 237 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Define a function that removes duplicates from an array of numbers and returns it as a result.
The order of the sequence has to stay the same.
Also feel free to reuse/extend the following starter code:
```python
def distinct(seq):
``` | {"functional": "_inputs = [[[1]], [[1, 2]], [[1, 1, 2]], [[1, 1, 1, 2, 3, 4, 5]], [[1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 7, 7]]]\n_outputs = [[[1]], [[1, 2]], [[1, 2]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5, 6, 7]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ... | 62 | 274 |
coding | Solve the programming task below in a Python markdown code block.
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbe... | {"inputs": ["6\n", "9\n", "8\n", "4\n", "5\n", "7\n", "2\n", "3\n"], "outputs": ["2 4 1 5 4 ", "2 4 7 2 7 4 2 1 ", "2 4 7 3 8 6 5 ", "2 4 3 ", "2 4 2 1 ", "2 4 7 4 2 1 ", "2 ", "2 1 "]} | 433 | 119 |
coding | Solve the programming task below in a Python markdown code block.
# Definition
**_Jumping number_** is the number that *All adjacent digits in it differ by 1*.
____
# Task
**_Given_** a number, **_Find if it is Jumping or not_** .
____
# Warm-up (Highly recommended)
# [Playing With Numbers Series](https://www.co... | {"functional": "_inputs = [[1], [7], [9], [23], [32], [79], [98], [987654322]]\n_outputs = [['Jumping!!'], ['Jumping!!'], ['Jumping!!'], ['Jumping!!'], ['Jumping!!'], ['Not!!'], ['Jumping!!'], ['Not!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma... | 602 | 223 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D.
Find out maximum possible sum of all good disjoint pairs that... | {"inputs": ["3\n3 3\n3 5 8\n3 3\n5 8 20 0\n5 3\n3 3 8 17 9", "3\n3 3\n3 5 8\n4 3\n5 1 0 20\n5 6\n3 1 8 14 15", "3\n3 3\n3 5 8\n4 3\n5 1 0 20\n5 6\n3 1 5 14 15", "3\n3 3\n0 2 8\n4 3\n5 8 36 8\n1 3\n3 2 8 17 15", "3\n3 3\n3 5 8\n4 3\n5 2 0 20\n5 6\n3 1 5 14 15", "3\n3 3\n3 5 8\n4 3\n3 8 10 5\n5 3\n3 2 3 15 15", "3\n2 1\n... | 361 | 416 |
coding | Solve the programming task below in a Python markdown code block.
You are given a tree with $N$ vertices (numbered $1$ through $N$) and a sequence of integers $A_1, A_2, \ldots, A_N$. You may choose an arbitrary permutation $p_1, p_2, \ldots, p_N$ of the integers $1$ through $N$. Then, for each vertex $i$, you should a... | {"inputs": ["2\n4\n1 2 3 4\n1 2\n2 3\n2 4\n5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5"], "outputs": ["24\n15"]} | 591 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Pushpa has entered Chefland and wants to establish Pushpa-Raj here too.
Chefland has N towers where the height of the i^{th} tower is H_{i}. To establish Pushpa-Raj, Pushpa does the following:
Initially, Pushpa chooses any tower i (1≤ i ≤ N) and lands ... | {"inputs": ["2\n4\n1 2 1 3\n1\n2"], "outputs": ["3\n2"]} | 557 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given an integer N and a digit D. Find the minimum non-negetive integer you should add to N such that the final value of N does not contain the digit ... | {"inputs": ["5\n21 5\n8 8\n100 0\n5925 9\n434356 3\n"], "outputs": ["0\n1\n11\n75\n5644\n"]} | 467 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X.
Constraints
* 1 \leq N \leq 3000
* 1 \leq X \leq 2N
* N and X are integers.
Input
Input is given from St... | {"inputs": ["5 3", "1 6", "5 1", "1 1", "0 2", "3 6", "5 2", "4 2"], "outputs": ["47\n", "3\n", "32\n", "2\n", "1\n", "26\n", "6\n", "5\n"]} | 212 | 81 |
coding | Solve the programming task below in a Python markdown code block.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, ... | {"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "1 1 1\n1\n2\n", "1 1 3\n5\n15\n", "1 1 4\n5\n15\n", "1 1 2\n5\n15\n", "1 1 2\n5\n13\n", "1 1 10\n5\n15\n"], "outputs": ["0\n", "0", "2\n", "22\n", "21\n", "23\n", "19\n", "15\n"]} | 517 | 144 |
coding | Solve the programming task below in a Python markdown code block.
Let's define a multiplication operation between a string $a$ and a positive integer $x$: $a \cdot x$ is the string that is a result of writing $x$ copies of $a$ one after another. For example, "abc" $\cdot~2~=$ "abcabc", "a" $\cdot~5~=$ "aaaaa".
A strin... | {"inputs": ["1\nabababababbb\nab\n", "1\nabababababbb\nab\n", "1\nabababababbb\naa\n", "1\nabababacabbb\naa\n", "1\nabababacabbb\nba\n", "1\nabababacabbb\nab\n", "1\nbbbacabababa\naa\n", "1\nbbbacbbababa\naa\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 459 | 141 |
coding | Solve the programming task below in a Python markdown code block.
For a given array whose element values are randomly picked from single-digit integers `0` to `9`, return an array with the same digit order but all `0`'s paired. Paring two `0`'s generates one `0` at the location of the first.
Ex:
```python
pair_zeros([... | {"functional": "_inputs = [[[]], [[1]], [[1, 2, 3]], [[0]], [[0, 0]], [[1, 0, 1, 0, 2, 0, 0]], [[0, 0, 0]], [[1, 0, 1, 0, 2, 0, 0, 3, 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_outputs = [[[]], [[1]], [[1, 2, 3]], [[0]], [[0]], [[1, 0, 1, 2, 0]], [[0, 0]], [[1, 0, 1, 2, 0,... | 404 | 406 |
coding | Solve the programming task below in a Python markdown code block.
### Longest Palindrome
Find the length of the longest substring in the given string `s` that is the same in reverse.
As an example, if the input was “I like racecars that go fast”, the substring (`racecar`) length would be `7`.
If the length ... | {"functional": "_inputs = [['a'], ['aa'], ['baa'], ['aab'], ['baabcd'], ['baablkj12345432133d'], ['I like racecars that go fast'], ['abcdefghba'], [''], ['FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinag... | 156 | 580 |
coding | Solve the programming task below in a Python markdown code block.
There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a_1, a_2, ..., a_{n}. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all bu... | {"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n0 2\n", "2\n1 6\n", "2\n9 3\n", "2\n1 3\n", "2\n9 2\n", "2\n7 9\n"], "outputs": ["1 1\n", "1 1\n", "2 1 ", "5 1 ", "6 1 ", "2 1 ", "7 1 ", "2 1 "]} | 365 | 113 |
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.
As usual, Tom and Jerry are fighting. Tom has strength $TS$ and Jerry has strength $JS$. You are given $TS$ and your task is to find the number of po... | {"inputs": ["2\n1\n11"], "outputs": ["0\n5"]} | 506 | 19 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.
Return the number of consistent stri... | {"functional": "def check(candidate):\n assert candidate(allowed = \"ab\", words = [\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]) == 2\n assert candidate(allowed = \"abc\", words = [\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]) == 7\n assert candidate(allowed = \"cad\", words = [\"cc\",\"acd\",\"b\",\"ba\",\"b... | 98 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Vietnamese], and [Russian] as well.
Chef has an array A of length N.
Since Chef's favorite number is 3, he wants to make all numbers in the array a multiple of 3.
Chef can do the following operation:
Select any ... | {"inputs": ["3\n3\n1 2 3\n4\n6 3 9 12\n2\n4 3\n"], "outputs": ["1\n0\n-1\n"]} | 455 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n_1 balls and second player's box contains exactly n_2 balls. In one move first player can take from 1 to k_1 balls from his box and throw ... | {"inputs": ["2 2 1 2\n", "2 1 1 1\n", "5 7 4 1\n", "5 7 1 4\n", "1 1 1 1\n", "5 7 1 4\n", "5 7 4 1\n", "1 1 1 1\n"], "outputs": ["Second\n", "First\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n"]} | 310 | 118 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:
* Append one of the following at ... | {"inputs": ["dre`merer", "dre`meqer", "reqem`erd", "reqem`erc", "cre`meqer", "bre`meqer", "cre`mdqer", "cre`mdqeq"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 171 | 91 |
coding | Solve the programming task below in a Python markdown code block.
The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range.
For n points on a plane, report a set of points which are within in a given range. Note that you do not need to consider i... | {"inputs": ["6\n2 1\n2 2\n4 2\n6 2\n3 6\n5 4\n2\n2 4 0 4\n4 10 2 5", "6\n2 1\n2 2\n4 2\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n2 1\n2 2\n5 1\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n0 1\n2 2\n5 1\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n0 1\n2 2\n5 1\n6 4\n3 2\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n0 1\n2 2\n5 1\n6 4\... | 433 | 482 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you have to correctly return who is the "survivor", ie: the last element of a Josephus permutation.
Basically you have to assume that n people are put into a circle and that they are eliminated in steps of k elements, like this:
```
joseph... | {"functional": "_inputs = [[7, 3], [11, 19], [40, 3], [14, 2], [100, 1], [1, 300], [2, 300], [5, 300], [7, 300], [300, 300]]\n_outputs = [[4], [10], [28], [13], [100], [1], [1], [1], [7], [265]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclos... | 346 | 268 |
coding | Solve the programming task below in a Python markdown code block.
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of t... | {"inputs": ["1 1\nf\n1 1\n", "1 1\nf\n1 1\n", "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n1 3\n6 4\n", "6 6\nxzyacc\n1 2\n3 1\n2 3\n5 4\n1 3\n6 4\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n"], "outputs": ["... | 482 | 246 |
coding | Solve the programming task below in a Python markdown code block.
It's been a tough week at work and you are stuggling to get out of bed in the morning.
While waiting at the bus stop you realise that if you could time your arrival to the nearest minute you could get valuable extra minutes in bed.
There is a bus that ... | {"functional": "_inputs = [['10:00'], ['10:45'], ['15:05'], ['06:10'], ['05:10'], ['04:50'], ['05:55'], ['23:57'], ['00:00'], ['23:55']]\n_outputs = [[10], [10], [5], [0], [45], [65], [0], [358], [355], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | 291 | 256 |
coding | Solve the programming task below in a Python markdown code block.
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.
The appointed Judg... | {"inputs": ["3 1\n", "7 3\n", "4 1\n", "5 2\n", "5 2\n", "1 1\n", "2 1\n", "3 1\n"], "outputs": ["3\n1 2\n2 3\n3 1\n", "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3\n", "4\n1 2\n2 3\n3 4\n4 1\n", "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2\n", "10... | 406 | 293 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two string arrays creators and ids, and an integer array views, all of length n. The ith video on a platform was created by creators[i], has an id of ids[i], and has views[i] views.
The popularity of a c... | {"functional": "def check(candidate):\n assert candidate(creators = [\"alice\",\"bob\",\"alice\",\"chris\"], ids = [\"one\",\"two\",\"three\",\"four\"], views = [5,10,5,4]) == [[\"alice\",\"one\"],[\"bob\",\"two\"]]\n assert candidate(creators = [\"alice\",\"alice\",\"alice\"], ids = [\"a\",\"b\",\"c\"], views = ... | 271 | 124 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i].
Return any permutation of nums1 that max... | {"functional": "def check(candidate):\n assert candidate(nums1 = [2,7,11,15], nums2 = [1,10,4,11]) == [2,11,7,15]\n assert candidate(nums1 = [12,24,8,32], nums2 = [13,25,32,11]) == [24,32,8,12]\n\n\ncheck(Solution().advantageCount)"} | 117 | 112 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the tree. Return the minimum time in seconds you have to s... | {"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [False,False,True,False,True,True,False]) == 8 \n assert candidate(n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [False,False,True,False,False,True,False]) == 6\n assert ... | 200 | 173 |
coding | Solve the programming task below in a Python markdown code block.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets th... | {"inputs": ["4 45 8", "1 45 8", "1 57 8", "77 1 1", "77 1 2", "4 30 8", "1 45 5", "4 24 20"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "Yes\n"]} | 231 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.
```python
move_zeros([False,1,0,1,2,0,1,3,"a"]) # returns[False,1,1,2,1,3,"a",0,0]
```
Also feel free to reuse/extend the following... | {"functional": "_inputs = [[[1, 2, 0, 1, 0, 1, 0, 3, 0, 1]], [[9, 0.0, 0, 9, 1, 2, 0, 1, 0, 1, 0.0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [['a', 0, 0, 'b', 'c', 'd', 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [['a', 0, 0, 'b', None, 'c', 'd', 0, 1, False, 0, 1, 0, 3, [], 0, 1, 9, 0, 0, {}, 0, 0, 9]], [[0, 1, None, 2, False, 1,... | 106 | 662 |
coding | Solve the programming task below in a Python markdown code block.
You must have tried to solve the Rubik’s cube. You might even have succeeded at it. Rubik’s cube is a 3x3x3 cube which has 6 different color for each face.The Rubik’s cube is made from 26 smaller pieces which are called cubies. There are 6 cubies at the ... | {"inputs": ["1\n3\n3\n3"], "outputs": ["12"]} | 403 | 19 |
coding | Solve the programming task below in a Python markdown code block.
You need to play around with the provided string (s).
Move consonants forward 9 places through the alphabet.
If they pass 'z', start again at 'a'.
Move vowels back 5 places through the alphabet.
If they pass 'a', start again at 'z'.
For our Polish frie... | {"functional": "_inputs = [['testcase'], ['codewars'], ['exampletesthere'], ['returnofthespacecamel'], ['bringonthebootcamp'], ['weneedanofficedog']]\n_outputs = [['tabtbvba'], ['bnaafvab'], ['agvvyuatabtqaaa'], ['aatpawnftqabyvbabvvau'], ['kaiwpnwtqaknntbvvy'], ['fawaaavwnffibaanp']]\nimport math\ndef _deep_eq(a, b, t... | 195 | 244 |
coding | Solve the programming task below in a Python markdown code block.
JJ has a binary string S of length N. JJ can perform the following operation on S:
Select an i such that 1 ≤ i ≤ N, and flip S_{i} (i.e. change 0 to 1 and 1 to 0)
JJ wants to minimize the number of inversions in S by performing the above operation at mo... | {"inputs": ["3\n8 3\n00010111\n5 1\n10100\n6 2\n111000\n"], "outputs": ["0\n2\n3\n"]} | 564 | 52 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You start with an initial power of power, an initial score of 0, and a bag of tokens given as an integer array tokens, where each tokens[i] denotes the value of tokeni.
Your goal is to maximize the total score by stra... | {"functional": "def check(candidate):\n assert candidate(tokens = [100], power = 50) == 0\n assert candidate(tokens = [200,100], power = 150) == 1\n assert candidate(tokens = [100,200,300,400], power = 200) == 2\n\n\ncheck(Solution().bagOfTokensScore)"} | 210 | 99 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer $k$. Find the largest integer $x$, where $1 \le x < k$, such that $x! + (x - 1)!^\dagger$ is a multiple of $^\ddagger$ $k$, or determine that no such $x$ exists.
$^\dagger$ $y!$ denotes the factorial of $y$, which is defined rec... | {"inputs": ["4\n3\n6\n8\n10\n", "10\n595\n358\n784\n542\n361\n368\n108\n860\n116\n391\n", "100\n44\n71\n96\n94\n37\n44\n79\n61\n60\n35\n75\n51\n97\n90\n31\n30\n98\n15\n16\n11\n53\n17\n71\n75\n99\n57\n95\n12\n84\n74\n98\n73\n80\n47\n72\n36\n30\n63\n90\n78\n68\n35\n89\n44\n33\n81\n45\n56\n19\n93\n26\n94\n50\n43\n28\n92\n... | 447 | 725 |
coding | Solve the programming task below in a Python markdown code block.
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b.
Dima put the chessboard in front of Inna an... | {"inputs": ["5 7 1 3 2 2\n", "5 5 2 3 1 1\n", "1 1 1 1 1 1\n", "5 7 1 3 1 2\n", "5 4 2 3 2 2\n", "5 4 2 3 1 1\n", "5 5 1 3 1 2\n", "5 5 4 3 1 2\n"], "outputs": ["2\n", "Poor Inna and pony!\n", "0\n", "2\n", "Poor Inna and pony!\n", "1\n", "Poor Inna and pony!\n", "1\n"]} | 670 | 165 |
coding | Solve the programming task below in a Python markdown code block.
Chef is learning linear algebra. Recently, he learnt that for a square matrix $M$, $\mathop{\rm trace}(M)$ is defined as the sum of all elements on the main diagonal of $M$ (an element lies on the main diagonal if its row index and column index are equal... | {"inputs": ["1\n3\n1 2 5\n6 3 4\n2 7 1"], "outputs": ["13"]} | 553 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Chef categorises an instagram account as *spam*, if, the *following* count of the account is more than 10 times the count of *followers*.
Given the *following* and *follower* count of an account as X and Y respectively, find whether it is a *spam* acco... | {"inputs": ["4\n1 10\n10 1\n11 1\n97 7\n"], "outputs": ["NO\nNO\nYES\nYES\n"]} | 437 | 40 |
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 blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the ith block. The characters 'W' and 'B' denote the colors white and black, respectively.
You are a... | {"functional": "def check(candidate):\n assert candidate(blocks = \"WBBWWBBWBW\", k = 7) == 3\n assert candidate(blocks = \"WBWBBBW\", k = 2) == 0\n\n\ncheck(Solution().minimumRecolors)"} | 163 | 62 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.
If you burst the ith balloon, you will get nums[i -... | {"functional": "def check(candidate):\n assert candidate(nums = [3,1,5,8]) == 167\n assert candidate(nums = [1,5]) == 10\n\n\ncheck(Solution().maxCoins)"} | 165 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Given an integer `n` return `"odd"` if the number of its divisors is odd. Otherwise return `"even"`.
**Note**: big inputs will be tested.
## Examples:
All prime numbers have exactly two divisors (hence `"even"`).
For `n = 12` the divisors are `[1, 2,... | {"functional": "_inputs = [[1], [5], [16], [27], [121]]\n_outputs = [['odd'], ['even'], ['odd'], ['even'], ['odd']]\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 ... | 150 | 183 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily dis... | {"inputs": ["1\n2\n1 1\n", "1\n2\n1 1\n", "1\n2\n2 1\n", "1\n2\n2 2\n", "1\n2\n0 1\n", "1\n2\n2 3\n", "1\n2\n1 2\n", "1\n2\n0 2\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n"]} | 616 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].
Given two sentences sentence1 and sentence2 each ... | {"functional": "def check(candidate):\n assert candidate(sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"good\"],[\"fine\",\"good\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]) == True\n assert candidate(sentence1 = [\"I\",\"love\",\"le... | 253 | 209 |
coding | Solve the programming task below in a Python markdown code block.
Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is a_{i}, and after a week of discounts its price will be b_{i}.
Not all of sellers are honest, ... | {"inputs": ["1 0\n9\n8\n", "1 0\n9\n8\n", "2 0\n4 10\n1 2\n", "2 0\n4 10\n1 2\n", "2 1\n4 10\n1 2\n", "2 1\n4 10\n1 4\n", "2 0\n4 14\n1 2\n", "2 1\n3 10\n1 4\n"], "outputs": ["8\n", "8\n", "3\n", "3\n", "6\n", "8\n", "3\n", "7\n"]} | 522 | 148 |
coding | Solve the programming task below in a Python markdown code block.
[BasE91](http://base91.sourceforge.net/) is a method for encoding binary as ASCII characters. It is more efficient than Base64 and needs 91 characters to represent the encoded data.
The following ASCII charakters are used:
'ABCDEFGHIJKLMNOPQRSTUVWX... | {"functional": "_inputs = [['fPNKd'], ['>OwJh>Io0Tv!8PE']]\n_outputs = [['test'], ['Hello World!']]\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) != l... | 232 | 178 |
coding | Solve the programming task below in a Python markdown code block.
We have N balls. The i-th ball has an integer A_i written on it.
For each k=1, 2, ..., N, solve the following problem and print the answer.
- Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the ... | {"inputs": ["4\n2 2 3 4", "4\n1 2 2 4", "4\n2 2 2 4", "4\n2 2 3 2", "4\n0 2 3 2", "4\n1 2 3 4", "4\n1 2 3 4\n", "5\n0 1 2 1 2"], "outputs": ["0\n0\n1\n1\n", "1\n0\n0\n1\n", "1\n1\n1\n3\n", "1\n1\n3\n1\n", "1\n0\n1\n0\n", "0\n0\n0\n0", "0\n0\n0\n0\n", "2\n1\n1\n1\n1\n"]} | 274 | 178 |
coding | Solve the programming task below in a Python markdown code block.
Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.
He has very high awareness of safety, and decides to buy two bells, one for each hand.
The store sells three kinds of bells for the price of ... | {"inputs": ["6 1 66", "0 1 66", "1 1 34", "2 1 73", "0 0 25", "-2 0 3", "-4 1 6", "-5 4 1"], "outputs": ["7\n", "1\n", "2\n", "3\n", "0\n", "-2\n", "-3\n", "-4\n"]} | 276 | 99 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows:
'a' maps to ".-",
'b' maps to "-...",
'c' maps to "-.-.", and so on.
For convenience, the ... | {"functional": "def check(candidate):\n assert candidate(words = [\"a\"]) == 1\n\n\ncheck(Solution().uniqueMorseRepresentations)"} | 264 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Khalkhoul, an amazing teacher, likes to answer questions sent by his students via e-mail, but he often doesn't have the time to answer all of them. In this kata you will help him by making a program that finds
some of the answers.
You are given a `q... | {"functional": "_inputs = [['is khalkhoul dumb', ['no he is NOT', 'i guess so']]]\n_outputs = [['no he is NOT']]\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 i... | 232 | 173 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number $6$... | {"inputs": ["1\n4\n", "1\n4\n", "1\n7\n", "1\n9\n", "1\n2\n", "1\n1\n", "1\n8\n", "1\n6\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 665 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s, which contains stars *.
In one operation, you can:
Choose a star in s.
Remove the closest non-star character to its left, as well as remove the star itself.
Return the string after all star... | {"functional": "def check(candidate):\n assert candidate(s = \"leet**cod*e\") == \"lecoe\"\n assert candidate(s = \"erase*****\") == \"\"\n\n\ncheck(Solution().removeStars)"} | 128 | 49 |
coding | Solve the programming task below in a Python markdown code block.
There is "7 rows" in the game using playing cards. Here we consider a game that simplifies it. Arrange 7 using 13 cards with numbers 1 to 13 written on each. In the match, the game progresses as follows with only two players.
1. Place 7 cards in the "fi... | {"inputs": ["5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 3 5 10 5\n1 3 3 6 9 11", "5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 4 5 10 11\n1 3 2 6 9 5", "5\n1 2 3 4 8 5\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 4 5 10 11\n1 2 3 6 9 2", "5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 6 5 10 11\n1 3 2 6 9 5", "5\n1 2 3 4 5 6\n1 3... | 504 | 622 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.
Please complete the following python code precisely:
```python
class Solution:
... | {"functional": "def check(candidate):\n assert candidate(s = \"(()\") == 2\n assert candidate(s = \")()())\") == 4\n assert candidate(s = \"\") == 0\n\n\ncheck(Solution().longestValidParentheses)"} | 74 | 59 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:
0 represents a wall that you cannot pass through.
1 repres... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3) == [[0,1],[1,1],[2,1]]\n assert candidate(grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2) == [[2,1],[1,2]]\n assert candidate(grid = [[1,1,1],[0... | 372 | 202 |
coding | Solve the programming task below in a Python markdown code block.
This function should test if the `factor` is a factor of `base`.
Return `true` if it is a factor or `false` if it is not.
## About factors
Factors are numbers you can multiply together to get another number.
2 and 3 are factors of 6 because: `2 * 3 = ... | {"functional": "_inputs = [[10, 2], [63, 7], [2450, 5], [24612, 3], [9, 2], [653, 7], [2453, 5], [24617, 3]]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ... | 190 | 239 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n matrix, return all elements of the matrix in spiral order.
Please complete the following python code precisely:
```python
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int... | {"functional": "def check(candidate):\n assert candidate(matrix = [[1,2,3],[4,5,6],[7,8,9]]) == [1,2,3,6,9,8,7,4,5]\n assert candidate(matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]) == [1,2,3,4,8,12,11,10,9,5,6,7]\n\n\ncheck(Solution().spiralOrder)"} | 67 | 128 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him t_{j} minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the... | {"inputs": ["1 1 0\n2\n", "1 1 1\n1\n", "2 1 0\n2\n", "1 1 0\n4\n", "1 1 0\n5\n", "1 1 3\n5\n", "1 1 3\n5\n", "1 1 0\n5\n"], "outputs": ["0\n", "2\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 476 | 118 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.