task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
You need to handle two extraordinarily large integers. The good news is that you don't need to perform any arithmetic operation on them. You just need to compare them and see whether they are equal or one is greater than the other.
Given two strings x a... | {"inputs": ["27\n0!!!\n0\n1\n1!!!\n2!!!\n2\n3!!!\n999999999\n0!\n0\n11!\n40000000\n3!!\n721\n3\n2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n7!!!\n3!!!!\n0!\n2\n1\n2\n0\n0\n3!!!!\n4!!!!\n15!\n999999999\n999999999\n4!!\n7!!!\n5000!!\n40321\n8!\n3!\n5\n5!!\n3!!!\n7!\n3!!\n3!\n7\n6!\n719\n719!!\n6!!!\n6!\n721\n721!!!!\n6... | 218 | 655 |
coding | Solve the programming task below in a Python markdown code block.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exa... | {"inputs": ["10\n3\n111\n19\n8", "10\n52\n011\n3\n1", "10\n3\n010\n24\n9", "10\n3\n010\n19\n9", "10\n3\n011\n19\n9", "10\n3\n011\n19\n8", "10\n9\n100\n30\n95", "10\n9\n110\n30\n95"], "outputs": ["54\n", "42\n", "40\n", "40\n", "40\n", "40\n", "63\n", "65\n"]} | 155 | 168 |
coding | Solve the programming task below in a Python markdown code block.
For years you have been working hard in Santa's factory to manufacture gifts for kids in substandard work environments with no pay. You have finally managed to escape the factory and now you seek revenge. You are planning a heist with the Grinch to steal... | {"inputs": ["3\n4 9\n5 10\n42 9999999967"], "outputs": ["6\n1\n9999999966"]} | 313 | 48 |
coding | Solve the programming task below in a Python markdown code block.
Given a triangle of numbers where each number is equal to the sum of the three numbers on top of it, find the first even number in a row.
Explanatory Note:
The vertex of the triangle (at the top) is 1.
The structure of the triangle is shown below.
Eac... | {"inputs": ["2\n3\n4\n"], "outputs": ["2\n3\n"]} | 345 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different ... | {"inputs": ["1\n1 1 1\n1\n1 1 1\n", "1\n0 1 1\n1\n1 1 1\n", "1\n9 10 7\n1\n7 1 3\n", "1\n15 10 7\n1\n7 1 3\n", "1\n16 10 7\n1\n7 1 3\n", "1\n16 10 7\n1\n9 1 3\n", "1\n16 10 7\n1\n8 1 3\n", "1\n500 500 1\n1\n1 1 500\n"], "outputs": ["4\n", "2\n", "114\n", "150\n", "156\n", "156\n", "156\n", "1000000\n"]} | 645 | 213 |
coding | Solve the programming task below in a Python markdown code block.
Sereja has got an array, consisting of n integers, a_1, a_2, ..., a_{n}. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make v_{i}-th array element equal to x_{i}. In other words, p... | {"inputs": ["1 1\n1\n3 1\n", "1 1\n1\n3 1\n", "1 1\n2\n3 1\n", "1 1\n0\n3 1\n", "1 3\n1\n1 1 2\n2 1\n3 1\n", "1 3\n1\n1 1 2\n2 1\n3 1\n", "1 3\n1\n1 1 1\n2 1\n3 1\n", "4 4\n579010521 995684640 1830027497 63411296\n3 3\n3 1\n2 590\n1 1 856879574\n"], "outputs": ["1\n", "1\n", "2\n\n", "0\n\n", "3\n", "3\n", "2\n\n", "18... | 538 | 249 |
coding | Solve the programming task below in a Python markdown code block.
# Definition
A number is a **_Special Number_** *if it’s digits only consist 0, 1, 2, 3, 4 or 5*
**_Given_** a number *determine if it special number or not* .
# Warm-up (Highly recommended)
# [Playing With Numbers Series](https://www.codewars.c... | {"functional": "_inputs = [[2], [3], [5], [9], [7], [23], [79], [32], [39], [55], [11350224]]\n_outputs = [['Special!!'], ['Special!!'], ['Special!!'], ['NOT!!'], ['NOT!!'], ['Special!!'], ['NOT!!'], ['Special!!'], ['NOT!!'], ['Special!!'], ['Special!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | 509 | 238 |
coding | Solve the programming task below in a Python markdown code block.
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are n... | {"inputs": ["1\nB\n", "1\nB\n", "1\nC\n", "2\nBG\n", "2\nBB\n", "2\nBB\n", "2\nBG\n", "2\nGB\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "0\n"]} | 218 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.
You choose the starting player, i. The game proceeds as follows: player i passes the ball to player rece... | {"functional": "def check(candidate):\n assert candidate(receiver = [2,0,1], k = 4) == 6\n assert candidate(receiver = [1,1,1,2,3], k = 3) == 10\n\n\ncheck(Solution().getMaxFunctionValue)"} | 189 | 68 |
coding | Solve the programming task below in a Python markdown code block.
Three friends are going to meet each other. Initially, the first friend stays at the position $x = a$, the second friend stays at the position $x = b$ and the third friend stays at the position $x = c$ on the coordinate axis $Ox$.
In one minute each fri... | {"inputs": ["5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 2 2\n0 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 4 2\n0 3 3\n4 1 4\n10 5 8\n", "5\n1 1 1\n1 2 2\n3 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 4 0\n0 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 4 2\n0 3 3\n4 1 4\n10 8 8\n", "5\n1 1... | 586 | 382 |
coding | Solve the programming task below in a Python markdown code block.
There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i.
Takahashi will begin at (... | {"inputs": ["2 2 3\n1 0 3\n2 1 4\n1 2 5", "2 2 3\n1 0 3\n2 1 8\n1 2 5", "3 2 3\n1 0 5\n2 2 4\n1 2 5", "2 2 3\n1 0 5\n2 1 4\n1 2 5", "3 2 3\n1 0 5\n2 1 4\n1 2 5", "2 2 3\n1 1 3\n2 1 4\n1 2 5", "2 2 3\n1 1 3\n2 1 4\n1 2 5\n", "2 5 5\n1 1 3\n2 4 20\n2 2 1\n1 3 4\n1 4 2"], "outputs": ["5\n", "8\n", "9\n", "5\n", "5\n", "8"... | 559 | 252 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have some coins. The i-th coin has a probability prob[i] of facing heads when tossed.
Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.
Please compl... | {"functional": "def check(candidate):\n assert candidate(prob = [0.4], target = 1) == 0.40000\n assert candidate(prob = [0.5,0.5,0.5,0.5,0.5], target = 0) == 0.03125\n\n\ncheck(Solution().probabilityOfHeads)"} | 98 | 87 |
coding | Solve the programming task below in a Python markdown code block.
There is no single treatment that works for every phobia, but some people cure it by being gradually exposed to the phobic situation or object. In this kata we will try curing arachnophobia by drawing primitive spiders.
Our spiders will have legs, body... | {"functional": "_inputs = [[1, 1, 'W', 'o'], [2, 2, 'w', 'O'], [3, 3, 'w', '0']]\n_outputs = [['^(oWo)^'], ['/\\\\((OOwOO))/\\\\'], ['/\u2572(((0000w0000)))\u2571\\\\']]\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_... | 300 | 226 |
coding | Solve the programming task below in a Python markdown code block.
Implement a class/function, which should parse time expressed as `HH:MM:SS`, or `null/nil/None` otherwise.
Any extra characters, or minutes/seconds higher than 59 make the input invalid, and so should return `null/nil/None`.
Also feel free to reuse/exte... | {"functional": "_inputs = [['00:00:00'], ['01:02:03'], ['01:02:60'], ['01:60:03'], ['99:59:59'], ['0:00:00'], ['00:0:00'], ['00:00:0'], ['00:00:00\\n'], ['\\n00:00:00'], ['100:59:59'], ['09:059:59'], ['09:159:59'], ['09:59:059'], ['09:59:159']]\n_outputs = [[0], [3723], [None], [None], [359999], [None], [None], [None],... | 91 | 357 |
coding | Solve the programming task below in a Python markdown code block.
You will be given a list of integers, $\textbf{arr}$, and a single integer $\boldsymbol{\mbox{k}}$. You must create an array of length $\boldsymbol{\mbox{k}}$ from elements of $\textbf{arr}$ such that its unfairness is minimized. Call that array $arr'$.... | {"inputs": ["5\n2\n1\n2\n1\n2\n1\n", "7\n3\n10\n100\n300\n200\n1000\n20\n30\n", "10\n4\n1\n2\n3\n4\n10\n20\n30\n40\n100\n200\n"], "outputs": ["0\n", "20\n", "3\n"]} | 675 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Given two strings, the first being a random string and the second being the same as the first, but with three added characters somewhere in the string (three same characters),
Write a function that returns the added character
### E.g
```
string1 = "he... | {"functional": "_inputs = [['hello', 'checlclo'], ['aabbcc', 'aacccbbcc'], ['abcde', '2db2a2ec']]\n_outputs = [['c'], ['c'], ['2']]\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, ... | 283 | 189 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Mike is a network administrator in a university. One of his primary responsibilities in the job is to create an effective firewall so that the students are not able to visit ... | {"inputs": ["4\n- codeforces\n+ codechef\n- youtube\n+ google"], "outputs": ["2\ncodef\ny"]} | 561 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game. There are $n$ cells in a row. Initially each cell is either red or blue. Alice goes first.
On each turn, Alice chooses two neighbouring cells which contain at least one red cell, and paints that two cells white. Then, B... | {"inputs": ["8\n3\nBRB\n5\nRRBBB\n6\nRBRBRB\n8\nBBRRBRRB\n6\nBRRBRB\n12\nRBRBRBRBRRBB\n12\nRBRBRBRBBBRR\n4\nRBBR\n"], "outputs": ["Bob\nBob\nAlice\nAlice\nAlice\nAlice\nBob\nBob\n"]} | 676 | 89 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants you to distribute candies among $N$ kids who are sitting in a circle. However, he wants to make some kids jealous of others. Thus, he wants you to distribute candies in such a way that there is a difference of at least $K$ candies between two ... | {"inputs": ["1\n2 1"], "outputs": ["3"]} | 302 | 16 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a stack of n boxes, with widths wi, depths di, and heights hi. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in wi... | {"functional": "def check(candidate):\n assert candidate(box = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 6\n assert candidate(box = [[1, 1, 1], [2, 3, 4], [2, 6, 7], [3, 4, 5]]) == 10\n\n\ncheck(Solution().pileBox)"} | 148 | 101 |
coding | Solve the programming task below in a Python markdown code block.
You have N balls and K boxes. You want to divide the N balls into K boxes such that:
Each box contains ≥ 1 balls.
No two boxes contain the same number of balls.
Determine if it is possible to do so.
------ Input Format ------
- The first line contai... | {"inputs": ["4\n3 4\n30 3\n2 2\n1 1\n"], "outputs": ["NO\nYES\nNO\nYES\n"]} | 389 | 37 |
coding | Solve the programming task below in a Python markdown code block.
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had n buyers and each of them bought exact... | {"inputs": ["1 2\nhalfplus\n", "1 2\nhalfplus\n", "1 4\nhalfplus\n", "1 0\nhalfplus\n", "2 10\nhalf\nhalfplus\n", "2 12\nhalf\nhalfplus\n", "2 16\nhalf\nhalfplus\n", "2 10\nhalf\nhalfplus\n"], "outputs": ["1\n", "1\n", "2\n", "0\n", "15\n", "18\n", "24\n", "15\n"]} | 496 | 126 |
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 (0-indexed).
In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].
Return ... | {"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"aabc\",\"bc\"]) == True\n assert candidate(words = [\"ab\",\"a\"]) == False\n\n\ncheck(Solution().makeEqual)"} | 119 | 52 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the ith house.
Return the ma... | {"functional": "def check(candidate):\n assert candidate(colors = [1,1,1,6,1,1,1]) == 3\n assert candidate(colors = [1,8,3,8,3]) == 4\n assert candidate(colors = [0,1]) == 1\n\n\ncheck(Solution().maxDistance)"} | 130 | 77 |
coding | Solve the programming task below in a Python markdown code block.
VK gave a problem to Chef, but Chef is too lazy, so he asked you to solve the problem for him. The statement of the problem follows.
Consider an integer with $N$ digits (in decimal notation, without leading zeroes) $D_1, D_2, D_3, \dots, D_N$. Here, $D_1... | {"inputs": ["1\n2 3"], "outputs": ["6"]} | 527 | 16 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smalles... | {"inputs": ["5\n4 8\n2 0\n5 2\n25 331\n5594 361646\n", "5\n3 5\n4 6\n3 4\n69 696\n51217 654321\n", "5\n3 5\n2 0\n1 2\n69 696\n87131 654321\n", "5\n6 5\n2 0\n6 2\n39 696\n185099 29706\n", "5\n3 5\n2 0\n1 2\n36 696\n87131 654321\n", "5\n3 8\n2 0\n1 2\n36 696\n87131 654321\n", "5\n6 5\n2 0\n6 1\n39 974\n185099 29706\n", "... | 602 | 435 |
coding | Solve the programming task below in a Python markdown code block.
There is a hallway of length $N-1$ and you have $M$ workers to clean the floor. Each worker is responsible for segment $[L_{i}, R_{i}]$, i.e., the segment starting at $L_{i}$ and ending at $R_{i}$. The segments might overlap.
Every unit of length of th... | {"inputs": ["3\n10 3\n1 10\n1 5\n6 10\n10 1\n2 10\n10 2\n5 10\n1 5"], "outputs": ["3\n-1\n5"]} | 630 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Your colleagues have been good enough(?) to buy you a birthday gift. Even though it is your birthday and not theirs, they have decided to play pass the parcel with it so that everyone has an even chance of winning. There are multiple presents, and you wi... | {"functional": "_inputs = [['badpresent', 3], ['goodpresent', 9], ['crap', 10], ['bang', 27], ['dog', 23]]\n_outputs = [['Take this back!'], ['pxxmy{n|nw}'], ['acpr'], ['300'], ['pass out from excitement 23 times']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 266 | 217 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
Please complete the following python code precisely:
```python
class Soluti... | {"functional": "def check(candidate):\n assert candidate(s = \"aab\") == [[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]\n assert candidate(s = \"a\") == [[\"a\"]]\n\n\ncheck(Solution().partition)"} | 75 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Given a string S consisting of only 1s and 0s, find the number of substrings which start and end both in 1.
In this problem, a substring is defined as a sequence of continuous characters S_{i}... | {"inputs": ["2\n4\n1111\n5\n10001", "2\n4\n1111\n5\n10000", "2\n4\n1111\n5\n10100", "2\n4\n1011\n5\n10000", "2\n4\n1110\n5\n10100", "2\n4\n1001\n5\n10000", "2\n4\n1111\n5\n10011", "2\n4\n0001\n2\n10000"], "outputs": ["10\n3", "10\n1\n", "10\n3\n", "6\n1\n", "6\n3\n", "3\n1\n", "10\n6\n", "1\n1\n"]} | 346 | 201 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$. You have to determine whether it is possible to build the string $s$ out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order.
For exampl... | {"inputs": ["8\naaaabbb\nbbaaaaabbb\naaaaaa\nabab\na\nb\naaaab\nbbaaa\n", "1\nabababababababababababababababababababababababab\n"], "outputs": ["YES\nYES\nYES\nNO\nNO\nNO\nNO\nYES\n", "NO\n"]} | 348 | 88 |
coding | Solve the programming task below in a Python markdown code block.
A string $s$ of length $n$ can be encrypted by the following algorithm: iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position... | {"inputs": ["1\nz\n", "1\ny\n", "1\nx\n", "1\n{\n", "1\n|\n", "1\nz\n", "2\nir\n", "2\nir\n"], "outputs": ["z\n", "y\n", "x\n", "{\n", "|\n", "z\n", "ri\n", "ri\n"]} | 384 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Chef's favorite game is chess. Today, he invented a new piece and wants to see its strengths.
From a cell (X, Y), the new piece can move to any cell of the chessboard such that its color is different from that of (X, Y).
The new piece is currently loca... | {"inputs": ["3\n1 1 8 8\n5 7 5 8\n3 3 3 3\n"], "outputs": ["2\n1\n0\n"]} | 455 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Joisino wants to evaluate the formula "A op B".
Here, A and B are integers, and the binary operator op is either + or -.
Your task is to evaluate the formula instead of her.
-----Constraints-----
- 1≦A,B≦10^9
- op is either + or -.
-----Input-----
Th... | {"inputs": ["0 + 2", "1 - 1", "1 - 7", "2 - 7", "1 - 4", "3 - 7", "9 - 4", "0 - 7"], "outputs": ["2\n", "0\n", "-6\n", "-5\n", "-3\n", "-4\n", "5\n", "-7\n"]} | 141 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings, word1 and word2. You want to construct a string in the following manner:
Choose some non-empty subsequence subsequence1 from word1.
Choose some non-empty subsequence subsequence2 from word2... | {"functional": "def check(candidate):\n assert candidate(word1 = \"cacb\", word2 = \"cbba\") == 5\n assert candidate(word1 = \"ab\", word2 = \"ab\") == 3\n assert candidate(word1 = \"aa\", word2 = \"bb\") == 0\n\n\ncheck(Solution().longestPalindrome)"} | 200 | 79 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.
You will walk in a cl... | {"functional": "def check(candidate):\n assert candidate(rows = 1, cols = 4, rStart = 0, cStart = 0) == [[0,0],[0,1],[0,2],[0,3]]\n assert candidate(rows = 5, cols = 6, rStart = 1, cStart = 4) == [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,... | 184 | 215 |
coding | Solve the programming task below in a Python markdown code block.
*Debug* function `getSumOfDigits` that takes positive integer to calculate sum of it's digits. Assume that argument is an integer.
### Example
```
123 => 6
223 => 7
1337 => 15
```
Also feel free to reuse/extend the following starter code:
```python
... | {"functional": "_inputs = [[123], [223], [0]]\n_outputs = [[6], [7], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | 98 | 172 |
coding | Solve the programming task below in a Python markdown code block.
The aim of the kata is to try to show how difficult it can be to calculate decimals of an irrational number with a certain precision. We have chosen to get a few decimals of the number "pi" using
the following infinite series (Leibniz 1646–1716):
PI / ... | {"functional": "_inputs = [[0.1], [0.01], [0.001], [0.0001], [1e-05], [1e-06]]\n_outputs = [[[10, 3.0418396189]], [[100, 3.1315929036]], [[1000, 3.1405926538]], [[10000, 3.1414926536]], [[100001, 3.1416026535]], [[1000001, 3.1415936536]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isins... | 498 | 311 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
A permutation is an array consisting of $N$ distinct integers from $1$ to $N$ in arbitrary order.
Chef has two permutation arrays $A$ and $P$ of length $N$. ... | {"inputs": ["1\n 3\n 1 2 3\n 2 3 1\n 3\n 1\n 2 2 3\n 3 1"], "outputs": ["3"]} | 568 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Ezio can manipulate at most X number of guards with the apple of eden.
Given that there are Y number of guards, predict if he can safely manipulate all of them.
------ Input Format ------
- First line will contain T, number of test cases. Then the te... | {"inputs": ["3\n5 7\n6 6\n9 1"], "outputs": ["NO\nYES\nYES"]} | 342 | 28 |
coding | Solve the programming task below in a Python markdown code block.
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved.
There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on th... | {"inputs": ["1\n0\n", "6\n4 -4 1 -3 1 -3\n", "12\n-3 -3 -7 -7 -1 -7 3 3 -2 -1 0 -7\n"], "outputs": ["1", "5", "5"]} | 362 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Hemose was shopping with his friends Samez, AhmedZ, AshrafEzz, TheSawan and O_E in Germany. As you know, Hemose and his friends are problem solvers, so they are very clever. Therefore, they will go to all discount markets in Germany.
Hemose has an array... | {"inputs": ["4\n3 3\n3 2 1\n4 3\n1 2 3 4\n5 2\n5 1 2 3 4\n5 4\n1 2 3 4 4\n"], "outputs": ["NO\nYES\nYES\nYES\n"]} | 720 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.
Of c... | {"inputs": ["2\n0 5\n10 5\n2\n7 2\n6 1\n", "2\n0 5\n10 5\n2\n7 2\n0 1\n", "2\n0 5\n10 5\n2\n9 2\n0 1\n", "2\n0 5\n10 7\n2\n9 2\n0 1\n", "3\n1 1\n3 1\n-4 2\n1\n-4 -3\n", "3\n3 2\n7 1\n11 1\n4\n2 1\n6 0\n6 4\n11 2\n", "3\n3 2\n0 1\n11 1\n4\n2 1\n6 0\n6 4\n11 2\n", "3\n3 2\n0 1\n11 1\n4\n2 1\n6 0\n1 4\n11 2\n"], "outputs"... | 725 | 312 |
coding | Solve the programming task below in a Python markdown code block.
Sehr Sus is an infinite hexagonal grid as pictured below, controlled by MennaFadali, ZerooCool and Hosssam.
They love equilateral triangles and want to create $n$ equilateral triangles on the grid by adding some straight lines. The triangles must all be... | {"inputs": ["1\n1\n", "2\n10\n9\n", "2\n76\n15\n", "2\n2922\n2251\n", "4\n1\n2\n3\n4567\n", "1\n1000000000\n", "3\n390\n398\n285\n", "5\n66\n6666\n666666\n66666666\n666666666\n"], "outputs": ["2\n", "4\n4\n", "11\n5\n", "67\n59\n", "2\n2\n3\n83\n", "38730\n", "25\n25\n21\n", "10\n100\n1000\n10000\n31623\n"]} | 353 | 210 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Templat... | {"inputs": ["5\ninsert A\ninsert U\ninsert C\nfind G\nfind A", "5\ninsert B\ninsert T\ninsert C\nfind G\nfind A", "5\ninsert A\ninsert U\ninsert F\nfind F\nfind B", "5\ninsert A\ninsert U\ninsert D\nfind G\nfind A", "5\ninsert A\ninsert T\ninsert C\nfind G\nfind @", "5\ninsert A\ninsert U\ninsert D\nfind G\nfind B", "5... | 249 | 199 |
coding | Solve the programming task below in a Python markdown code block.
Chef has two ranges [A, B] and [C, D]. Chef needs to find the number of integers that belong to at least one of the ranges.
Note: A range [P, Q] contains all the integers \{P, P+1, P+2, \dots, Q-1, Q\}.
------ Input Format ------
- The first line of ... | {"inputs": ["4\n1 3 5 5\n3 8 2 5\n1 8 4 6\n5 5 5 5\n"], "outputs": ["4\n7\n8\n1\n"]} | 423 | 52 |
coding | Solve the programming task below in a Python markdown code block.
In Python, a string can be split on a delimiter.
Example:
>>> a = "this is a string"
>>> a = a.split(" ") # a is converted to a list of strings.
>>> print a
['this', 'is', 'a', 'string']
Joining a string is simple:
>>> a = "-".join(a)
>>> prin... | {"inputs": ["this is a string \n"], "outputs": ["this-is-a-string\n"]} | 198 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents:
positioni is the distance between t... | {"functional": "def check(candidate):\n assert candidate(cars = [[1,2],[2,1],[4,3],[7,2]]) == [1.00000,-1.00000,3.00000,-1.00000]\n assert candidate(cars = [[3,4],[5,4],[6,3],[9,1]]) == [2.00000,1.00000,1.50000,-1.00000]\n\n\ncheck(Solution().getCollisionTimes)"} | 268 | 136 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A series of highways connect n cities numbered from 0 to n - 1. You are given a 2D integer array highways where highways[i] = [city1i, city2i, tolli] indicates that there is a highway that connects city1i and city2i, ... | {"functional": "def check(candidate):\n assert candidate(n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], discounts = 1) == 9\n assert candidate(n = 4, highways = [[1,3,17],[1,2,7],[3,2,5],[0,1,6],[3,0,20]], discounts = 20) == 8\n assert candidate(n = 4, highways = [[0,1,3],[2,3,2]], discounts = 0... | 239 | 155 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the number of elements in the array.
You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you ca... | {"inputs": ["1 1\n1337\n", "1 1\n1337\n", "5 3\n1 2 2 4 5\n", "5 3\n1 2 3 4 5\n", "5 3\n1 2 3 3 3\n", "5 3\n1 2 4 4 5\n", "5 3\n1 2 1 4 5\n", "5 3\n1 3 3 3 3\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "0\n", "2\n", "1\n", "0\n"]} | 376 | 156 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary array nums (0-indexed).
We define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).
For example, if nums = [1,0,1], t... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,1]) == [True,False,False]\n assert candidate(nums = [1,1,1]) == [False,False,False]\n\n\ncheck(Solution().prefixesDivBy5)"} | 149 | 60 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two non-negative integers num1 and num2.
In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.
For example, if num1 = 5 and num2 = 4, subtract num2 from... | {"functional": "def check(candidate):\n assert candidate(num1 = 2, num2 = 3) == 3\n assert candidate(num1 = 10, num2 = 10) == 1\n\n\ncheck(Solution().countOperations)"} | 183 | 59 |
coding | Solve the programming task below in a Python markdown code block.
The chef was searching for his pen in the garage but he found his old machine with a display and some numbers on it. If some numbers entered then some different output occurs on the display. Chef wants to crack the algorithm that the machine is following... | {"inputs": ["1\n7"], "outputs": ["21"]} | 207 | 15 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:
i - k <= r <= i + k,
j - k <= c <= j + k, and
(r, c) is a valid position in the matr... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1) == [[12,21,16],[27,45,33],[24,39,28]]\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2) == [[45,45,45],[45,45,45],[45,45,45]]\n\n\ncheck(Solution().matrixBlockSum)"} | 126 | 140 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstruct and return the binar... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1]), tree_node([1,2,3,4,5,6,7]))\n\n\ncheck(Solution().constructFromPrePost)"} | 164 | 82 |
coding | Solve the programming task below in a Python markdown code block.
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.
How many grams of sand will the upper bulb contains after t seconds?
-----Constra... | {"inputs": ["3 0", "1 0", "2 0", "4 0", "48 0", "4 -2", "6 -2", "7 -4"], "outputs": ["3\n", "1\n", "2\n", "4\n", "48\n", "6\n", "8\n", "11\n"]} | 176 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides.
Print the answer in degrees, but do not print units.
Constraints
* 3 \leq N \leq 100
Input
Input is given from Standard Input in the following... | {"inputs": ["5", "9", "7", "2", "4", "8", "6", "3"], "outputs": ["540\n", "1260\n", "900\n", "0\n", "360\n", "1080\n", "720\n", "180"]} | 127 | 77 |
coding | Solve the programming task below in a Python markdown code block.
This is the easy version of this problem. The only difference between easy and hard versions is the constraints on $k$ and $m$ (in this version $k=2$ and $m=3$). Also, in this version of the problem, you DON'T NEED to output the answer by modulo.
You ar... | {"inputs": ["2\n2\n2 2\n1\n1\n", "2\n2\n2 2\n1\n1\n", "2\n2\n2 1\n1\n1\n", "3\n1\n1\n1\n1\n1\n1\n", "3\n1\n1\n1\n1\n1\n1\n", "2\n5\n1 1 1 1 1\n4\n1 1 1 1\n", "2\n5\n1 1 1 1 1\n4\n1 1 1 1\n", "2\n5\n1 1 2 1 1\n4\n1 1 1 1\n"], "outputs": ["0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n0\n", "0\n0\n0\n", "10\n4\n", "10\n4\n", "10\n... | 589 | 213 |
coding | Solve the programming task below in a Python markdown code block.
Xenia the beginner programmer has a sequence a, consisting of 2^{n} non-negative integers: a_1, a_2, ..., a_2^{n}. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a.
Namely, it ... | {"inputs": ["1 1\n1 1\n1 1\n", "1 1\n1 1\n1 1\n", "1 1\n2 1\n1 1\n", "2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2\n", "2 4\n1 6 3 2\n1 4\n3 4\n1 2\n1 2\n", "2 4\n1 6 4 2\n1 4\n3 4\n1 2\n1 4\n", "2 4\n1 6 2 2\n1 4\n3 4\n1 2\n1 2\n", "2 4\n1 6 3 2\n1 4\n3 5\n1 2\n1 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n3\n3\n3\n", "5\n0\n0\n0... | 634 | 260 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically... | {"functional": "def check(candidate):\n assert candidate(palindrome = \"abccba\") == \"aaccba\"\n assert candidate(palindrome = \"a\") == \"\"\n\n\ncheck(Solution().breakPalindrome)"} | 196 | 52 |
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.
A football competition has just finished. The players have been given points for scoring goals and points for committing fouls. Now, it is up to Alex... | {"inputs": ["2\n3\n40 30 50\n2 4 20\n1\n0\n10"], "outputs": ["800\n0"]} | 605 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky ... | {"inputs": ["4\n", "3\n", "8\n", "7\n", "2\n", "1\n", "5\n", "6\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 241 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array A of length N.
Let f(i) denote the sum A_{1} + A_{2} + \dots + A_{i} \, and let g(i) denote the sum A_{i} + A_{i + 1} + \dots + A_{N}.
Chef creates another array B of length N such that B_{i} = f(i) + g(i) for all 1 ≤ i ≤ N.
Now, Ch... | {"inputs": ["4\n1\n6\n3\n7 8 9\n4\n13 15 13 14\n2\n25 20\n"], "outputs": ["3 \n1 2 3 \n2 4 2 3 \n10 5 \n"]} | 678 | 71 |
coding | Solve the programming task below in a Python markdown code block.
An array is sorted if it has no inversions
A Young Boy
You are given an array of $n$ positive integers $a_1,a_2,\ldots,a_n$.
In one operation you do the following:
Choose any integer $x$.
For all $i$ such that $a_i = x$, do $a_i := 0$ (assign $0$ to... | {"inputs": ["5\n3\n3 3 2\n4\n1 3 1 3\n5\n4 1 5 3 2\n4\n2 4 1 2\n1\n1\n"], "outputs": ["1\n2\n4\n3\n0\n"]} | 425 | 66 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer arrays nums1 and nums2, both of length n.
You can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[l... | {"functional": "def check(candidate):\n assert candidate(nums1 = [60,60,60], nums2 = [10,90,10]) == 210\n assert candidate(nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]) == 220\n assert candidate(nums1 = [7,11,13], nums2 = [1,1,1]) == 31\n\n\ncheck(Solution().maximumsSplicedArray)"} | 292 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Each palindrome can be always created from the other palindromes, if a single character is also a palindrome. For example, the string "bobseesanna" can be created by some ways:
* bobseesanna = bob + sees + anna
* bobseesanna = bob + s + ee + s + anna
... | {"inputs": ["bobseesanna"], "outputs": ["18"]} | 228 | 16 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.
Please complete the following python code precisely:
```py... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,2,6,6,6,6,7,10]) == 6\n\n\ncheck(Solution().findSpecialInteger)"} | 84 | 49 |
coding | Solve the programming task below in a Python markdown code block.
Consider the string `"adfa"` and the following rules:
```Pearl
a) each character MUST be changed either to the one before or the one after in alphabet.
b) "a" can only be changed to "b" and "z" to "y".
```
From our string, we get:
```Pearl
"adfa" -> [... | {"functional": "_inputs = [['abba'], ['abaazaba'], ['abccba'], ['adfa'], ['ae'], ['abzy'], ['ababbaba'], ['sq'], ['kxbkwgyydkcbtjcosgikfdyhuuprubpwthgflucpyylbofvqxkkvqthmdnywpaunfihvupbwpruwfybdmgeuocltdaidyyewmbzm']]\n_outputs = [[True], [False], [True], [True], [False], [False], [True], [True], [True]]\nimport math\... | 298 | 265 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s.
A split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in ... | {"functional": "def check(candidate):\n assert candidate(s = \"aacaba\") == 2\n assert candidate(s = \"abcd\") == 1\n assert candidate(s = \"aaaaa\") == 4\n assert candidate(s = \"acbadbaada\") == 2\n\n\ncheck(Solution().numSplits)"} | 123 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Watson asks Sherlock:
Given a string S of N 0's and M 1's, how many unique permutations of this string start with 1?
Help Sherlock by printing the answer modulo (10^{9}+7).
Input Format
First line contains T, the number of test cases.
Each ... | {"inputs": ["2\n1 1\n2 3\n"], "outputs": ["1\n6\n"]} | 305 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats ... | {"inputs": ["1\nwdi\n", "1\nwdi\n", "1\nwci\n", "1\nwcj\n", "1\nwjc\n", "1\ncjw\n", "2\naa\na\n", "2\naa\na\n"], "outputs": ["wdi\n", "wdi\n", "wci\n", "wcj\n", "wjc\n", "cjw\n", "a\naa\n", "a\naa\n"]} | 440 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Farmer Bob have a big farm, where he growths chickens, rabbits and cows. It is very difficult to count the number of animals for each type manually, so he diceded to buy a system to do it. But he bought a cheap system that can count only total number of ... | {"functional": "_inputs = [[34, 11, 6], [154, 42, 10], [74, 20, 34], [152, 38, 34], [56, 17, 0]]\n_outputs = [[{'rabbits': 3, 'chickens': 5, 'cows': 3}], [{'rabbits': 30, 'chickens': 7, 'cows': 5}], [{'rabbits': 0, 'chickens': 3, 'cows': 17}], [{'rabbits': 21, 'chickens': 0, 'cows': 17}], [{'rabbits': 11, 'chickens': 6... | 499 | 327 |
coding | Solve the programming task below in a Python markdown code block.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one ... | {"inputs": ["5\n2\n7\n9\n6\n8\n10\n8\n7\n14\n18\n2\n17\n3\n1\n5\n19\n0", "5\n1\n7\n9\n6\n5\n10\n8\n7\n14\n18\n2\n11\n6\n1\n5\n19\n0", "5\n1\n7\n9\n6\n4\n0\n8\n7\n13\n18\n1\n11\n6\n16\n5\n19\n0", "5\n1\n7\n2\n6\n5\n10\n8\n7\n13\n18\n1\n3\n4\n17\n5\n19\n0", "5\n1\n7\n9\n3\n4\n10\n8\n7\n14\n18\n2\n11\n6\n4\n5\n19\n0", "5\... | 467 | 414 |
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 is playing a card game called Blackjack. He starts with a deck of $N$ cards (numbered $1$ through $N$), where for each valid $i$, the $i$-th car... | {"inputs": ["3\n3 4 5\n1 2 3\n3 3 4\n1 2 3\n2 20 30\n40 10"], "outputs": ["1\n0\n-1"]} | 636 | 55 |
coding | Solve the programming task below in a Python markdown code block.
A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly $n$ minutes. After a round ends, the next round starts immediately. This is repeated over and over again.
Each round has the same scenario. It is described by ... | {"inputs": ["1 1\n-1\n", "1 1\n-1\n", "1 2\n1 -1\n", "1 2\n-1 1\n", "1 2\n-1 1\n", "1 2\n1 -1\n", "2 2\n1 -1\n", "1 1\n-1000000\n"], "outputs": ["1\n", "1\n", "-1\n", "1\n", "1\n", "-1\n", "-1\n", "1\n"]} | 510 | 123 |
coding | Solve the programming task below in a Python markdown code block.
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of ... | {"inputs": ["u\n", "u\n", "v\n", "w\n", "zza\n", "abb\n", "zaz\n", "acc\n"], "outputs": ["u\n", "u\n", "v\n", "w\n", "zaz\n", "bab\n", "zaz\n", "cac\n"]} | 281 | 73 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ variables and $m$ requirements. Requirements are represented as $\left(x\leq y\right)$, meaning that the $x^{th}$ variable must be less than or equal to the $y^{th}$ variable.
Your task is to assign non-negative numbers smaller than $10$ ... | {"inputs": ["6 7\n1 3\n0 1\n2 4\n0 4\n2 5\n3 4\n0 2\n"], "outputs": ["1000\n"]} | 444 | 47 |
coding | Solve the programming task below in a Python markdown code block.
Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched ... | {"inputs": ["1 1\nY\n", "1 1\nN\n", "1 1\n?\n", "1 0\n?\n", "1 0\nN\n", "1 0\nY\n", "1 0\nY\n", "1 1\nY\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n"]} | 442 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, if 0 <= i <= (n / 2) - 1.
For example, if n = 4, then node 0 is the twin of node 3,... | {"functional": "def check(candidate):\n assert candidate(head = list_node([5,4,2,1])) == 6\n assert candidate(head = list_node([4,2,2,3])) == 7\n assert candidate(head = list_node([1,100000])) == 100001\n\n\ncheck(Solution().pairSum)"} | 228 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the fi... | {"inputs": ["2\n><\n5 5\n", "2\n>>\n1 1\n", "2\n><\n1 2\n", "2\n<>\n5 5\n", "2\n?>\n1 1\n", "2\n<>\n1 2\n", "2\n<>\n4 5\n", "2\n?>\n2 1\n"], "outputs": ["FINITE", "FINITE", "FINITE", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n"]} | 347 | 123 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has a string S of length N consisting of digits from 0 through 9.
He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integ... | {"inputs": ["4 3\n2919", "4 1\n2020", "4 3\n1541", "4 3\n3041", "4 2\n3041", "4 6\n1793", "4 4\n3041", "4 2\n1173"], "outputs": ["4\n", "10\n", "2\n", "3\n", "5\n", "1\n", "6\n", "0\n"]} | 400 | 119 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:
Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1] XOR .... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,1,3], maximumBit = 2) == [0,3,2,3]\n assert candidate(nums = [2,3,4,7], maximumBit = 3) == [5,2,6,5]\n assert candidate(nums = [0,1,2,2,5,7], maximumBit = 3) == [4,3,6,4,6,7]\n\n\ncheck(Solution().getMaximumXor)"} | 158 | 122 |
coding | Solve the programming task below in a Python markdown code block.
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thin... | {"inputs": ["1\n5\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n3\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n"]} | 566 | 86 |
coding | Solve the programming task below in a Python markdown code block.
You are given four integers $a$, $b$, $x$ and $y$. Initially, $a \ge x$ and $b \ge y$. You can do the following operation no more than $n$ times:
Choose either $a$ or $b$ and decrease it by one. However, as a result of this operation, value of $a$ can... | {"inputs": ["1\n10 10 8 5 3\n", "1\n10 10 8 5 3\n", "1\n10 10 8 1 3\n", "1\n10 10 0 1 3\n", "1\n10 10 10 5 3\n", "1\n10 10 10 5 4\n", "1\n10 20 10 5 3\n", "1\n10 10 10 5 0\n"], "outputs": ["70\n", "70\n", "70\n", "70\n", "70\n", "60\n", "170\n", "100\n"]} | 661 | 180 |
coding | Solve the programming task below in a Python markdown code block.
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. ... | {"inputs": ["1\n2 3 1\n2 3 1\n2\n", "1\n2 3 1\n2 3 1\n1\n", "2\n6 4 5 1 3 2\n6 1 3\n4 5 2\n6\n", "2\n2 3 4 5 6 1\n2 3 4\n5 6 1\n1\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n2\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n1\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n3\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n5\n"], "outputs": ["1 3\n", "2 3", "1 3 2 4 ... | 761 | 301 |
coding | Solve the programming task below in a Python markdown code block.
Time to win the lottery!
Given a lottery ticket (ticket), represented by an array of 2-value arrays, you must find out if you've won the jackpot. Example ticket:
To do this, you must first count the 'mini-wins' on your ticket. Each sub array has both... | {"functional": "_inputs = [[[['ABC', 65], ['HGR', 74], ['BYHT', 74]], 2], [[['ABC', 65], ['HGR', 74], ['BYHT', 74]], 1], [[['HGTYRE', 74], ['BE', 66], ['JKTY', 74]], 3]]\n_outputs = [['Loser!'], ['Winner!'], ['Loser!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 203 | 244 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square.
Please complete the following python c... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4) == 2\n assert candidate(mat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1) == 0\n\n\ncheck(Solution().maxSideLength)"} | 94 | 142 |
coding | Solve the programming task below in a Python markdown code block.
You are given $n$ points with integer coordinates on a coordinate axis $OX$. The coordinate of the $i$-th point is $x_i$. All points' coordinates are distinct and given in strictly increasing order.
For each point $i$, you can do the following operation... | {"inputs": ["1\n1\n29999\n", "5\n2\n1 4\n3\n1 2 3\n4\n1 2 3 7\n1\n1000000\n3\n2 5 6\n"], "outputs": ["YES\n", "YES\nYES\nNO\nYES\nYES\n"]} | 584 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Rahul and Rashi are off to the wedding of a close relative. This time they have to travel without their guardians. Rahul got very interested in the arrangement of seats insid... | {"inputs": ["3\n1\n5\n3"], "outputs": ["4LB\n2MB\n6UB"]} | 456 | 25 |
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 has a sequence $A_{1}, A_{2}, \ldots, A_{N}$. He needs to find the number of pairs $(i, j)$ ($1 ≤ i < j ≤ N$) such that $A_{i} + A_{j} = A_{i} \... | {"inputs": ["2\n3\n2 4 2\n3\n0 2 3"], "outputs": ["1\n0"]} | 385 | 30 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will create a function that converts a string with letters and numbers to the inverse of that string (with regards to Alpha and Numeric characters). So, e.g. the letter `a` will become `1` and number `1` will become `a`; `z` will become... | {"functional": "_inputs = [['25abcd26'], ['18zyz14'], ['a1b2c3d4'], ['5a8p17'], ['w6aa4ct24m5'], ['17dh'], ['25gj8sk6r17'], ['18zzz14'], ['y17kg5et11'], ['abcdefghijklmnopqrstuvwxyz'], ['1a2b3c4d5e6f7g8h9i10j11k12l13m14n15o16p17q18r19s20t21u22v23w24x25y26z'], ['h15q4pc6yw23nmx19y'], ['p16k11o25x7m6m20ct9'], ['nv15u19d5... | 257 | 887 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.
Note: You are not allowed to use any built-in function which evaluates strings as... | {"functional": "def check(candidate):\n assert candidate(s = \"1 + 1\") == 2\n assert candidate(s = \" 2-1 + 2 \") == 3\n assert candidate(s = \"(1+(4+5+2)-3)+(6+8)\") == 23\n\n\ncheck(Solution().calculate)"} | 94 | 79 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
Please complete the following python code precisely:
```python
class Solution:
def topKF... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,1,2,2,3], k = 2) == [1,2]\n assert candidate(nums = [1], k = 1) == [1]\n\n\ncheck(Solution().topKFrequent)"} | 80 | 68 |
coding | Solve the programming task below in a Python markdown code block.
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.
In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y... | {"inputs": ["`a\n", "a`\n", "aa\n", "aa`\n", "a`a\n", "aaa\n", "aabba\n", "bbaab\n"], "outputs": ["1\n", "1\n", "1\n", "4\n", "3\n", "5\n", "18\n", "18\n"]} | 338 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Kuro has just learned about permutations and he is really excited to create a new permutation type. He has chosen $n$ distinct positive integers and put all of them in a set $S$. Now he defines a magical permutation to be: A permutation of integers from ... | {"inputs": ["1\n1", "1\n20", "1\n7\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n8\n", "1\n3\n"], "outputs": ["1\n0 1", "0\n0", "0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n"]} | 578 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Like all minions Dave also like to eat bananas. So as to his obsession, he is eating banana, but this time in different way. There are N bananas in dish. Dave wants to eat all of them. He starts eating at speed 1 banana/second. He can increase or decreas... | {"inputs": ["2\n2\n4"], "outputs": ["2\n3"]} | 295 | 18 |
coding | Solve the programming task below in a Python markdown code block.
Your task in this Kata is to emulate text justify right in monospace font. You will be given a single-lined text and the expected justification width. The longest word will never be greater than this width.
Here are the rules:
- Use spaces to fill in t... | {"functional": "_inputs = [['abc def', 10], ['I take up the whole line', 24], ['Two lines, I am', 10]]\n_outputs = [[' abc def'], ['I take up the whole line'], ['Two lines,\\n I am']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a,... | 390 | 203 |
coding | Solve the programming task below in a Python markdown code block.
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i.
He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A.
In how many ways can he make his selectio... | {"inputs": ["3 8\n6 6 9\n", "4 8\n7 9 8 9\n", "8 5\n3 6 2 8 7 6 5 9\n", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n"], "outputs": ["0\n", "5\n", "19\n", "8589934591\n"]} | 331 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down a... | {"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n1\n", "1 1\n2\n", "1 2\n2\n", "1 2\n4\n", "1 3\n2\n", "1 3\n3\n"], "outputs": ["1\n", "2\n", "1\n", "2\n", "1\n", "2\n", "1\n", "1\n"]} | 472 | 102 |
coding | Solve the programming task below in a Python markdown code block.
There are n positive integers a_1, a_2, ..., a_n. For the one move you can choose any even value c and divide by two all elements that equal c.
For example, if a=[6,8,12,6,3,12] and you choose c=6, and a is transformed into a=[3,8,12,3,3,12] after the m... | {"inputs": ["4\n6\n22 3 32 3 20 1\n1\n94\n4\n3 4 8 30\n2\n3 1 7\n", "4\n6\n22 6 18 5 20 1\n1\n311\n4\n2 4 8 16\n3\n3 1 7\n", "4\n6\n22 4 18 5 20 1\n1\n311\n4\n2 4 8 16\n3\n3 1 7\n", "4\n6\n37 6 40 3 20 1\n1\n757\n4\n2 6 8 16\n3\n3 1 7\n", "4\n6\n37 6 40 3 20 1\n1\n757\n4\n2 6 8 20\n3\n3 1 7\n", "4\n6\n40 8 40 3 20 1\n1... | 582 | 454 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.