task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \le a_i \le 1$. You can hack this problem only if you solve and lock both problems.
Christmas is coming, and our protagonist, Bob, is preparing a spectacular present f... | {"inputs": ["1\n1\n", "1\n1\n", "3\n1 0 1\n", "3\n0 0 1\n", "3\n0 0 1\n", "3\n0 1 0\n", "3\n1 1 1\n", "3\n0 1 1\n"], "outputs": ["-1\n", "-1", "2\n", "-1\n", "-1", "-1\n", "2\n", "1\n"]} | 514 | 109 |
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 of length n.
A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.
... | {"functional": "def check(candidate):\n assert candidate(nums = [4,7,8,15,3,5]) == 2\n assert candidate(nums = [4,7,15,8,3,5]) == -1\n\n\ncheck(Solution().findValidSplit)"} | 255 | 66 |
coding | Solve the programming task below in a Python markdown code block.
> If you've finished this kata, you can try the [more difficult version](https://www.codewars.com/kata/5b256145a454c8a6990000b5).
## Taking a walk
A promenade is a way of uniquely representing a fraction by a succession of “left or right” choices.
Fo... | {"functional": "_inputs = [[''], ['L'], ['R'], ['LRLL'], ['LLRLR'], ['RRRLRRR'], ['LLLLRLLLL'], ['LLLLLLLLLL'], ['RLRLRLRRLRLL'], ['LLRRLRRLRLLL'], ['LRRLLRLLRLRR'], ['LRRLRLLLLRLL'], ['LLLRRRLLLRLL'], ['RRLRRRLLRLRR'], ['RRRRLLRLLRLR'], ['LLRLRLLRLLRL'], ['LRLLRRRRLLRR'], ['RLRRLRRRRRRR']]\n_outputs = [[[1, 1]], [[1, ... | 641 | 414 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.
In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of... | {"functional": "def check(candidate):\n assert candidate(pressedKeys = \"22233\") == 8\n assert candidate(pressedKeys = \"222222222222222222222222222222222222\") == 82876089\n\n\ncheck(Solution().countTexts)"} | 259 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to cross a hallway of N doors. These N doors are represented as a string. Each door is initially either open or close, represented by 1 or 0 respectively. Chef is required to go through all the doors one by one in the order that they appear, s... | {"inputs": ["3\n111\n010\n10011"], "outputs": ["0\n3\n2"]} | 522 | 30 |
coding | Solve the programming task below in a Python markdown code block.
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuf... | {"inputs": ["3\nnoe\n", "3\nnoe\n", "3\none\n", "3\neon\n", "3\nneo\n", "3\neno\n", "3\noen\n", "4\nezor\n"], "outputs": ["1 \n", "1\n", "1 ", "1 ", "1 ", "1 ", "1 ", "0 \n"]} | 312 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Two's company, three's a crowd!
It's been one year since Chef met his brother. Last year, his younger brother came to visit him during this time of the year. This year, the Chef is planning to go visit his brother. Chef's brother has planned to throw a "... | {"inputs": ["2\n3\n4"], "outputs": ["1\n3"]} | 430 | 18 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Teams $A$ and $B$ are having a penalty shoot-out to decide the winner of their football match. Each team gets to take a shot $N$ times, and the team... | {"inputs": ["2\n3\n101011\n3\n100001"], "outputs": ["4\n6"]} | 767 | 32 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer, $N$. Write a program to determine if $N$ is an element of the Fibonacci sequence.
The first few elements of the Fibonacci sequence are $0,1,1,2,3,5,8,13,\cdots$. A Fibonacci sequence is one where every element is a sum of the... | {"inputs": ["3\n5\n7\n8\n"], "outputs": ["IsFibo\nIsNotFibo\nIsFibo\n"]} | 401 | 31 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return true if it is a power of three. Otherwise, return false.
An integer n is a power of three, if there exists an integer x such that n == 3x.
Please complete the following python code precise... | {"functional": "def check(candidate):\n assert candidate(n = 27) == True\n assert candidate(n = 0) == False\n assert candidate(n = 9) == True\n assert candidate(n = 45) == False\n\n\ncheck(Solution().isPowerOfThree)"} | 92 | 67 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer sequence $A_1, A_2, \ldots, A_N$ and an integer $X$. Consider a $N \times N$ matrix $B$, where $B_{i,j} = A_i + A_j$ for each valid $i$ and $j$.
You need to find the number of square submatrices of $B$ such that the sum of their ... | {"inputs": ["2\n5 36\n1 2 3 1 12\n4 54\n3 3 3 3"], "outputs": ["6\n4"]} | 499 | 43 |
coding | Solve the programming task below in a Python markdown code block.
#Permutation position
In this kata you will have to permutate through a string of lowercase letters, each permutation will start at ```a``` and you must calculate how many iterations it takes to reach the current permutation.
##examples
```
input: 'a'
... | {"functional": "_inputs = [['a'], ['z'], ['aaa'], ['aaab'], ['foo']]\n_outputs = [[1], [26], [1], [2], [3759]]\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 ... | 154 | 184 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded. Each encoded[i] = [v... | {"functional": "def check(candidate):\n assert candidate(encoded1 = [[1,3],[2,3]], encoded2 = [[6,3],[3,3]]) == [[6,6]]\n assert candidate(encoded1 = [[1,3],[2,1],[3,2]], encoded2 = [[2,3],[3,3]]) == [[2,3],[6,1],[9,2]]\n\n\ncheck(Solution().findRLEArray)"} | 381 | 103 |
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.
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills:
There is a s... | {"inputs": ["2\n10\nabcdefghij\n7\nbcadage"], "outputs": ["hgfeabcdij\ngacbade"]} | 452 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Chef has two integers X and S. He is interested in sequences of non-negative integers such that the sum of their elements is S and the [bitwise OR] of their elements is X. Chef would like to know the shortest possible length such a sequence can have.
Fo... | {"inputs": ["3\n13 23\n6 13\n1 25\n"], "outputs": ["3\n-1\n25\n"]} | 483 | 36 |
coding | Solve the programming task below in a Python markdown code block.
The purpose of this series is developing understanding of stastical problems in AS and A level maths. Let's get started with a simple concept in statistics: Mutually exclusive events.
The probability of an OR event is calculated by the following rule:
... | {"functional": "_inputs = [[[[3, 0.4], [4, 0.1], [1, 0.01], [2, 0.09], [5, 0.2], [6, 0.1]], 1, 6], [[[1, 0.1], [2, 0.14], [3, 0.16], [4, 0.2], [5, 0.15], [6, 0.25]], 1, 4], [[[1, 0.6], [2, 0.1001], [3, 0.0999], [4, 0.1], [5, 0.05], [6, 0.05]], 3, 4], [[[6, 0.25], [1, 0.1], [3, 0.16], [2, 0.14], [5, 0.15], [4, 0.2]], 1,... | 601 | 468 |
coding | Solve the programming task below in a Python markdown code block.
For a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$.
If any such permutation of the elem... | {"inputs": ["3\naaaabccc\naabbcc\nppppmmnnoooopp"], "outputs": ["Dynamic\nNot\nDynamic"]} | 517 | 32 |
coding | Solve the programming task below in a Python markdown code block.
So you've found a meeting room - phew! You arrive there ready to present, and find that someone has taken one or more of the chairs!! You need to find some quick.... check all the other meeting rooms to see if all of the chairs are in use.
Your meeting ... | {"functional": "_inputs = [[[['XXX', 3], ['XXXXX', 6], ['XXXXXX', 9]], 4], [[['XXX', 1], ['XXXXXX', 6], ['X', 2], ['XXXXXX', 8], ['X', 3], ['XXX', 1]], 5], [[['XX', 2], ['XXXX', 6], ['XXXXX', 4]], 0], [[['XX', 2], ['XXXX', 6], ['XXXXX', 4]], 8], [[['XX', 2], ['XXXX', 6], ['XXXXX', 4]], 2]]\n_outputs = [[[0, 1, 3]], [[0... | 486 | 322 |
coding | Solve the programming task below in a Python markdown code block.
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions: the length of... | {"inputs": ["4 3\n", "6 6\n", "5 2\n", "3 2\n", "3 3\n", "6 3\n", "6 2\n", "4 2\n"], "outputs": ["abca\n", "abcdef\n", "ababa\n", "aba\n", "abc\n", "abcabc\n", "ababab\n", "abab\n"]} | 386 | 92 |
coding | Solve the programming task below in a Python markdown code block.
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.
T... | {"inputs": ["5\n2 1 8 15 3\n", "5\n0 1 8 15 3\n", "5\n1 1 8 15 3\n", "5\n1 2 8 15 3\n", "5\n1 2 9 15 3\n", "5\n1 2 9 15 4\n", "5\n0 2 9 15 4\n", "5\n15 1 8 15 3\n"], "outputs": ["0 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "3 -1 1 0 -1 "]} | 438 | 216 |
coding | Solve the programming task below in a Python markdown code block.
The polar bears are going fishing. They plan to sail from (s_{x}, s_{y}) to (e_{x}, e_{y}). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x... | {"inputs": ["1 5 5 5 6\nE\n", "1 5 5 5 6\nE\n", "1 5 3 5 6\nE\n", "1 5 8 5 6\nE\n", "1 0 0 0 -1\nS\n", "1 0 0 0 -1\nS\n", "1 5 3 5 12\nE\n", "1 -2 0 0 0\nS\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "-1\n"]} | 489 | 152 |
coding | Solve the programming task below in a Python markdown code block.
Given a string consisting of only numbers from 0 to 9, consider the operation of creating a new string from that string according to the following rules. Read the given string one character at a time from the left end. Go, if the same number a continues ... | {"inputs": ["5\n6\n5\n1\n0", "5\n4\n3\n1\n0", "5\n7\n5\n1\n0", "5\n4\n0\n1\n0", "5\n9\n5\n8\n0", "5\n7\n4\n1\n0", "5\n3\n4\n1\n0", "5\n3\n8\n1\n0"], "outputs": ["1113122116\n312211\n", "1113122114\n1211\n", "1113122117\n312211\n", "1113122114\n", "1113122119\n1113122118\n", "1113122117\n111221\n", "1113122113\n111221\n... | 418 | 257 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation p_1, p_2, …, p_n.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer... | {"inputs": ["1\n1\n", "3\n3 2 1\n", "3\n2 3 1\n", "3\n3 1 2\n", "3\n2 1 3\n", "3\n1 3 2\n", "3\n1 2 3\n", "5\n5 4 3 1 2\n"], "outputs": ["0\n", "0 1 3\n", "0 2 2\n", "0 0 2\n", "0 1 1\n", "0 1 1\n", "0 0 0\n", "0 0 2 5 9\n"]} | 325 | 150 |
coding | Solve the programming task below in a Python markdown code block.
When provided with a String, capitalize all vowels
For example:
Input : "Hello World!"
Output : "HEllO WOrld!"
Note: Y is not a vowel in this kata.
Also feel free to reuse/extend the following starter code:
```python
def swap(st):
``` | {"functional": "_inputs = [['HelloWorld!'], ['Sunday'], ['Codewars'], ['Monday'], ['Friday'], ['abracadabra']]\n_outputs = [['HEllOWOrld!'], ['SUndAy'], ['COdEwArs'], ['MOndAy'], ['FrIdAy'], ['AbrAcAdAbrA']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | 73 | 210 |
coding | Solve the programming task below in a Python markdown code block.
The re.sub() tool (sub stands for substitution) evaluates a pattern and, for each valid match, it calls a method (or lambda).
The method is called for all matches and can be used to modify strings in different ways.
The re.sub() method returns the mo... | {"inputs": ["11\na = 1;\nb = input();\n\nif a + b > 0 && a - b < 0:\n start()\nelif a*b > 10 || a/b < 1:\n stop()\nprint set(list(a)) | set(list(b)) \n#Note do not change &&& or ||| or & or |\n#Only change those '&&' which have space on both sides.\n#Only change those '|| which have space on both sides.\n"], "out... | 648 | 229 |
coding | Solve the programming task below in a Python markdown code block.
In Conway's Game of Life, cells in a grid are used to simulate biological cells.
Each cell is considered to be either alive or dead.
At each step of the simulation
each cell's current status and number of living neighbors is used to determine the status
... | {"inputs": ["4\n00011101\n000\n000001\n11110", "4\n00011101\n100\n000001\n11110", "4\n00010101\n100\n000101\n11110", "4\n00010101\n100\n010101\n11110", "4\n00010101\n000\n011111\n11110", "4\n00010101\n000\n011111\n11100", "4\n00000101\n000\n011111\n11100", "4\n00000101\n000\n010101\n11100"], "outputs": ["01100101\nMult... | 505 | 421 |
coding | Solve the programming task below in a Python markdown code block.
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer $p$ (which may be positive, negative, or zero). To combine their tastes, they invented $p$-binary numbers... | {"inputs": ["1 1\n", "1 0\n", "5 2\n", "9 8\n", "3 2\n", "2 1\n", "9 4\n", "1 0\n"], "outputs": ["-1\n", "1\n", "-1\n", "1\n", "1\n", "1\n", "-1\n", "1\n"]} | 670 | 87 |
coding | Solve the programming task below in a Python markdown code block.
This kata is based on a [variation](https://www.codewars.com/kata/happy-numbers-5) of *Happy Numbers* by TySlothrop. It is advisable to complete it first to grasp the idea and then move on to this one.
___
Hello, my dear friend, and welcome to another ... | {"functional": "_inputs = [[10], [50], [100]]\n_outputs = [[[1, 7, 10]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math... | 443 | 294 |
coding | Solve the programming task below in a Python markdown code block.
You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly... | {"inputs": ["1 4 2\n", "5 5 5\n", "0 2 0\n", "0 0 0\n", "1 1 1\n", "1 2 1\n", "1 2 2\n", "2 2 2\n"], "outputs": ["6\n", "14\n", "0\n", "0\n", "2\n", "4\n", "4\n", "6\n"]} | 409 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Lately, Chef has been inspired by the "pawri" meme. Therefore, he decided to take a string $S$ and change each of its substrings that spells "party" to "pawr... | {"inputs": ["3\npart\npartypartiparty\nyemaihuyemericarhaiauryahapartyhorahihai"], "outputs": ["part\npawripartipawri\nyemaihuyemericarhaiauryahapawrihorahihai"]} | 335 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
The *MEX* (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:
The MEX of [2, 2, 1] is 0, bec... | {"inputs": ["4\n0\n1\n2\n5\n"], "outputs": ["1\n2\n2\n4\n"]} | 478 | 28 |
coding | Solve the programming task below in a Python markdown code block.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characte... | {"inputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "20\n", "10\n", "12\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "20\n", "01\n", "12\n"]} | 495 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function do... | {"inputs": ["1\n1\n", "1\n0\n", "2\n2 1\n", "2\n1 1\n", "2\n2 4\n", "2\n1 3\n", "2\n4 1\n", "2\n1 0\n"], "outputs": ["1\n1 1\n", "0\n", "2\n1 1\n1 2\n", "1\n1 2\n", "4\n2 2\n2 2\n1 2\n1 2\n", "3\n2 2\n2 2\n1 2\n", "4\n1 1\n1 1\n1 1\n1 2\n", "1\n1 1\n"]} | 565 | 162 |
coding | Solve the programming task below in a Python markdown code block.
You are given a square grid with $n$ rows and $n$ columns, where each cell has a non-negative integer written in it. There is a chip initially placed at the top left cell (the cell with coordinates $(1, 1)$). You need to move the chip to the bottom right... | {"inputs": ["2\n1 2\n3 4\n", "3\n10 10 10\n10 0 10\n10 10 10\n", "3\n0 0 1000000000\n0 1000000000 0\n1000000000 0 0\n", "3\n167301 677798 614819\n732414 586919 7990\n768516 777873 977915\n", "4\n0 0 0 1000000000\n0 0 1000000000 0\n0 1000000000 0 0\n1000000000 0 0 0\n", "3\n1000000000 1000000000 1\n1000000000 1 10000000... | 501 | 596 |
coding | Solve the programming task below in a Python markdown code block.
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to co... | {"inputs": ["1\n2\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n1\n", "1\n7\n", "1\n3\n", "1\n6\n"], "outputs": ["98\n", "98\n", "9998\n", "99988\n", "8\n", "9999988\n", "998\n", "999988\n"]} | 675 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Aureole the Techno-cultural fest of JEC thought of conducting a workshop on big data, as the topic is hot everyone wants to take part but due to limited seats in the Jashan Auditorium there is a selection criteria, a problem is given.
the problem states ... | {"inputs": ["1\naaabb"], "outputs": ["-40"]} | 336 | 17 |
coding | Solve the programming task below in a Python markdown code block.
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
-----Input-----
A single line with a positive integer $k$ ($... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "7\n", "9\n", "7\n"], "outputs": ["19\n", "28\n", "37\n", "46\n", "55\n", "73\n", "91\n", "73"]} | 151 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value.
Example
$arr=[1,2,2,3]$
Delete the $2$ elements $1$ and $3$ leaving $arr=[2,2]$. If both twos plus either the $1$ or the $3$ are ... | {"inputs": ["STDIN Function\n----- --------\n5 arr[] size n = 5\n3 3 2 1 3 arr = [3, 3, 2, 1, 3]\n"], "outputs": ["2 \n"]} | 368 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a_1, a_2, ..., a_{n}.
While Vasya wa... | {"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "3 1 2\n1 2 3\n3 1 2\n", "3 1 2\n1 2 5\n3 1 2\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n", "4 3 4\n1 2 3 4\n2 1 3 4\n", "4 2 2\n2 1 2 2\n1 2 2 2\n"], "outputs": ["TRUTH\n", "TRUTH\n", "LIE\n", "LIE\n", "LIE\n", "TRUTH\n", "LIE\n", "LIE\n"]} | 709 | 202 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string of length $n$ (i. e. a string consisting of $n$ characters '0' and '1').
In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given on... | {"inputs": ["1\n2 1\n00\n", "1\n2 1\n00\n", "2\n8 5\n11011010\n7 9\n1111100\n", "2\n8 5\n11011010\n7 9\n1111100\n", "2\n8 5\n11011010\n7 9\n1011100\n", "2\n8 5\n01011010\n7 9\n1011100\n", "2\n8 1\n01011010\n7 9\n1011100\n", "2\n8 5\n11011010\n7 9\n1111101\n"], "outputs": ["00\n", "00\n", "01011110\n0101111\n", "0101111... | 540 | 326 |
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 is given an array A consisting of N positive integers. Chef shuffles the array A and creates a new array B of length N, where B_{i} = (A_{i} + i) \bmod 2... | {"inputs": ["3\n3\n1 2 3\n3\n2 4 5\n2\n2 4\n"], "outputs": ["2\n3\n1"]} | 591 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Ivan has got an array of n non-negative integers a_1, a_2, ..., a_{n}. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2^{a}_1, 2^{a}_2, ..., 2^{a}_{n} on a piece of paper. Now he wonders, what minimum number of... | {"inputs": ["1\n3\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n"], "outputs": ["3\n", "0\n", "1\n", "0\n", "1\n", "2\n", "4\n", "8\n"]} | 334 | 86 |
coding | Solve the programming task below in a Python markdown code block.
# Task
**_Given_** *a number* , **_Return_** **_The Maximum number _** *could be formed from the digits of the number given* .
___
# Notes
* **_Only Natural numbers_** *passed to the function , numbers Contain digits [0:9] inclusive*
* **_Digit ... | {"functional": "_inputs = [[213], [7389], [63792], [566797], [1000000]]\n_outputs = [[321], [9873], [97632], [977665], [1000000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tu... | 606 | 218 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
There are three friends; let's call them A, B, C. They made the following statements:
A: "I have $x$ Rupees more than B."
B: "I have $y$ rupees more than C."... | {"inputs": ["2\n1 2 1\n1 1 1"], "outputs": ["yes\nno"]} | 512 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Due to the COVID pandemic, there has been an increase in the number of cases if a hospital. The management has decided to clear a large square area for the patients and arrange for beds. But the beds can't be too near to each other.
The area is of dimens... | {"inputs": ["2\n4\n1 0 1 0\n0 0 0 1\n0 1 0 0\n1 0 0 1\n4\n1 0 1 0\n0 0 0 0\n1 0 1 1\n0 1 0 0"], "outputs": ["SAFE\nUNSAFE"]} | 505 | 83 |
coding | Solve the programming task below in a Python markdown code block.
There is a tree with N vertices numbered 1 through N.
The i-th edge connects Vertex x_i and y_i.
Each vertex is painted white or black.
The initial color of Vertex i is represented by a letter c_i.
c_i = W represents the vertex is white; c_i = B represen... | {"inputs": ["1\nB", "1\nB\n", "5\n1 2\n0 3\n2 4\n4 5\nWBBWW", "5\n1 2\n2 3\n2 5\n4 5\nWBBWW", "5\n1 2\n1 3\n2 4\n4 5\nWBBWW", "5\n1 3\n2 3\n2 5\n4 5\nWBBWW", "5\n1 2\n1 3\n3 4\n4 5\nWBBWW", "5\n1 2\n2 3\n2 4\n4 5\nWBBWW"], "outputs": ["0", "0\n", "5\n", "5\n", "5\n", "7\n", "5\n", "5"]} | 435 | 185 |
coding | Solve the programming task below in a Python markdown code block.
F: Tea Party
Yun decided to hold a tea party at the company.
The shop sells $ N $ sets of bread, each containing $ A_1, A_2, A_3, \ dots, A_N $.
Yun decided to make a sandwich by combining two breads into a pair.
Yun-san is very careful, so I want to... | {"inputs": ["5\n4 3 5 6 7", "5\n2 3 3 6 7", "5\n6 2 5 0 3", "5\n9 2 2 0 6", "5\n0 0 7 6 0", "5\n0 0 7 1 0", "5\n0 9 2 0 2", "5\n0 0 7 0 0"], "outputs": ["11\n", "9\n", "8\n", "5\n", "3\n", "4\n", "2\n", "0\n"]} | 359 | 143 |
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.
Let next(x) be the minimum lucky n... | {"inputs": ["3 4\n", "1 2\n", "5 6\n", "1 1\n", "4 7\n", "1 9\n", "6 6\n", "6 9\n"], "outputs": ["8\n", "8\n", "14\n", "4\n", "25\n", "125\n", "7\n", "102\n"]} | 334 | 92 |
coding | Solve the programming task below in a Python markdown code block.
You're given an integer N. Write a program to calculate the sum of all the digits of N.
-----Input-----
The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N.
-----Output-----
For e... | {"inputs": ["3 \n595\n1\n8", "3 \n595\n1\n1", "3 \n831\n1\n1", "3 \n831\n1\n2", "3 \n831\n1\n0", "3 \n290\n39\n8", "3 \n562\n39\n8", "3 \n595\n39\n8"], "outputs": ["19\n1\n8\n", "19\n1\n1\n", "12\n1\n1\n", "12\n1\n2\n", "12\n1\n0\n", "11\n12\n8\n", "13\n12\n8\n", "19\n12\n8\n"]} | 152 | 180 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese .
Given an array of n non-negative integers: A_{1}, A_{2}, …, A_{N}. Your mission is finding a pair of integers A_{u}, A_{v} (1 ≤ u < v ≤ N) such that (A_{u} and A_{v}) is as large as possible.
And is a bit... | {"inputs": ["4\n2\n4\n0\n8", "4\n2\n4\n2\n7", "4\n1\n8\n7\n5", "4\n2\n3\n3\n7", "4\n7\n7\n3\n1", "4\n2\n4\n2\n8", "4\n2\n4\n0\n3", "4\n2\n4\n0\n0"], "outputs": ["0\n", "4\n", "5\n", "3\n", "7\n", "2\n", "2\n", "0\n"]} | 321 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Eac... | {"inputs": ["7 6 0\n5\n4\n0\n0\n2\n5\n0 0 0", "7 3 0\n5\n4\n0\n0\n2\n5\n0 0 0", "7 3 1\n5\n4\n0\n0\n2\n5\n0 0 0", "10 6 8\n5\n4\n1\n6\n2\n5\n0 0 0", "10 6 8\n5\n4\n0\n0\n2\n5\n0 0 0", "10 6 8\n5\n4\n0\n0\n2\n7\n0 0 0", "10 6 8\n5\n1\n8\n6\n2\n5\n0 0 0", "10 3 8\n5\n4\n0\n6\n2\n5\n0 0 0"], "outputs": ["OK\nNA\nNA\nNA\nO... | 294 | 307 |
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 and an integer k.
A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
Return the length of the longest possible ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,3,1,3], k = 3) == 3\n assert candidate(nums = [1,1,2,2,1,1], k = 2) == 4\n\n\ncheck(Solution().longestEqualSubarray)"} | 131 | 76 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence a_1, a_2, ..., a_n, consisting of integers.
You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning, or to the end of a. Note that you have to move a... | {"inputs": ["3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 4 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 5 8 8\n7\n4 2 5 2 6 4... | 711 | 502 |
coding | Solve the programming task below in a Python markdown code block.
In the pet store on sale there are:
$a$ packs of dog food;
$b$ packs of cat food;
$c$ packs of universal food (such food is suitable for both dogs and cats).
Polycarp has $x$ dogs and $y$ cats. Is it possible that he will be able to buy food for all ... | {"inputs": ["1\n0 0 0 0 1\n", "1\n114514 1 1 1 1\n", "1\n114515 1 1 114515 2\n", "1\n114515 0 0 114514 0\n", "2\n2 3 5 4 4\n2 3 5 4 4\n", "2\n2 3 4 4 4\n2 3 4 4 4\n", "1\n55555 55555 55555 55555 55555\n", "1\n114514 114514 114514 114514 114514\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\nYES\n", "YES\nYES\... | 419 | 244 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.
Please complete the following python code precisely:
```python
class Solution:
def toLowerCase(self, s: ... | {"functional": "def check(candidate):\n assert candidate(s = \"Hello\") == \"hello\"\n assert candidate(s = \"here\") == \"here\"\n assert candidate(s = \"LOVELY\") == \"lovely\"\n\n\ncheck(Solution().toLowerCase)"} | 66 | 60 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An array is squareful if the sum of every pair of adjacent elements is a perfect square.
Given an integer array nums, return the number of permutations of nums that are squareful.
Two permutations perm1 and perm2 are ... | {"functional": "def check(candidate):\n assert candidate([1,17,8]) == 2\n assert candidate([2,2,2]) == 1\n\n\ncheck(Solution().numSquarefulPerms)"} | 114 | 51 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. A perfectly straight street is represented by a number line ranging from 0 to n - 1. You are given a 2D integer array lights representing the street lamp(s) on the street. Each lights[i] = ... | {"functional": "def check(candidate):\n assert candidate(n = 5, lights = [[0,1],[2,1],[3,2]], requirement = [0,2,1,4,1]) == 4\n assert candidate(n = 1, lights = [[0,1]], requirement = [2]) == 0\n\n\ncheck(Solution().meetRequirement)"} | 238 | 83 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.
Initially, you are facing directly east fro... | {"functional": "def check(candidate):\n assert candidate(points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]) == 3\n assert candidate(points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]) == 4\n assert candidate(points = [[1,0],[2,1]], angle = 13, location = [1,1]) == 1\n\n\ncheck(Solution()... | 302 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Math geeks and computer nerds love to anthropomorphize numbers and assign emotions and personalities to them. Thus there is defined the concept of a "happy" number. A happy number is defined as an integer in which the following sequence ends with the num... | {"functional": "_inputs = [[10], [50], [100]]\n_outputs = [[[1, 7, 10]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math... | 539 | 293 |
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 of length n.
The sum score of nums at an index i where 0 <= i < n is the maximum of:
The sum of the first i + 1 elements of nums.
The sum of the last n - i elements of num... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,-2,5]) == 10\n assert candidate(nums = [-3,-5]) == -3\n\n\ncheck(Solution().maximumSumScore)"} | 121 | 53 |
coding | Solve the programming task below in a Python markdown code block.
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a bl... | {"inputs": ["4 3 2 1\n2\n", "0 0 0 0\n1\n", "1 2 3 4\n4\n", "1 2 3 4\n4\n", "4 3 2 1\n2\n", "0 0 0 0\n1\n", "0 2 3 4\n4\n", "0 3 2 1\n2\n"], "outputs": ["3\n", "0\n", "4\n", "4\n", "3\n", "0\n", "4\n", "3\n"]} | 361 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The power of the string is the maximum length of a non-empty substring that contains only one unique character.
Given a string s, return the power of s.
Please complete the following python code precisely:
```python... | {"functional": "def check(candidate):\n assert candidate(s = \"leetcode\") == 2\n assert candidate(s = \"abbcccddddeeeeedcba\") == 5\n\n\ncheck(Solution().maxPower)"} | 79 | 49 |
coding | Solve the programming task below in a Python markdown code block.
Shivani is interning at HackerEarth. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and may have distributed the chocolates unequally. One of the program managers gets to know this and orders Shivani to... | {"inputs": ["1\n4\n2 2 3 7"], "outputs": ["2"]} | 403 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Make a function that receives a value, ```val``` and outputs the smallest higher number than the given value, and this number belong to a set of positive integers that have the following properties:
- their digits occur only once
- they are odd
- they... | {"functional": "_inputs = [[12], [13], [99], [999999], [9999999999]]\n_outputs = [[15], [15], [105], [1023459], ['There is no possible number that fulfills those requirements']]\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=t... | 187 | 215 |
coding | Solve the programming task below in a Python markdown code block.
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civil... | {"inputs": ["1\n654 61\n", "2\n6 5\n5 6\n", "1\n139 252\n", "1\n139 252\n", "1\n139 361\n", "1\n220 361\n", "1\n340 361\n", "1\n654 361\n"], "outputs": ["0", "1\n", "0\n", "0\n", "0", "0", "0", "0"]} | 744 | 128 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array consisting of $n$ integers $a_1$, $a_2$, ..., $a_n$. Initially $a_x = 1$, all other elements are equal to $0$.
You have to perform $m$ operations. During the $i$-th operation, you choose two indices $c$ and $d$ such that $l_i \le ... | {"inputs": ["1\n16 771 1\n2 146\n", "1\n152 771 0\n3 282\n", "1\n65 1380 0\n3 282\n", "1\n13 1380 0\n3 282\n", "1\n152 771 1\n2 146\n", "1\n152 771 0\n13 15\n", "1\n239 771 0\n3 282\n", "1\n65 2224 0\n3 282\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 556 | 197 |
coding | Solve the programming task below in a Python markdown code block.
A string is called *boring* if all the characters of the string are same.
You are given a string S of length N, consisting of lowercase english alphabets. Find the length of the longest *boring* substring of S which occurs more than once.
Note that if ... | {"inputs": ["4\n3\naaa\n3\nabc\n5\nbcaca\n6\ncaabaa\n"], "outputs": ["2\n0\n1\n2\n"]} | 498 | 39 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integers m and n, which represent the dimensions of a matrix.
You are also given the head of a linked list of integers.
Generate an m x n matrix that contains the integers in the linked list presente... | {"functional": "def check(candidate):\n assert candidate(m = 3, n = 5, head = list_node([3,0,2,6,8,1,7,9,4,2,5,5,0])) == [[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]\n assert candidate(m = 1, n = 4, head = list_node([0,1,2])) == [[0,1,2,-1]]\n\n\ncheck(Solution().spiralMatrix)"} | 178 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.
You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, a... | {"inputs": ["2", "4", "3", "6", "7", "5", "8", "1"], "outputs": ["ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n"]} | 168 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each s... | {"inputs": ["8\n1\n2\n", "5\n3\n4\n", "6\n4\n2\n", "1\n1\n1\n", "3\n1\n2\n", "3\n2\n1\n", "8\n3\n5\n", "5\n4\n2\n"], "outputs": ["1\n", "6\n", "4\n", "6\n", "3\n", "4\n", "3\n", "5\n"]} | 351 | 102 |
coding | Solve the programming task below in a Python markdown code block.
A chess tournament will be held soon, where $n$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.
... | {"inputs": ["3\n3\n111\n1\n1\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n", "3\n3\n111\n2\n12\n4\n2122\n", "3\n3\n111\n2\n11\n4\n2122\n", "3\n3\n111\n2\n22\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n"], "outputs": ["YES\nX==\n=X=\n==X\nYES\nX\nYES\nX=+-\n=X==\n-=X+\n+=-X\n", "YES\nX==\n=X=\n==... | 500 | 411 |
coding | Solve the programming task below in a Python markdown code block.
There are N bikes and M cars on the road.
Each bike has 2 tyres.
Each car has 4 tyres.
Find the total number of tyres on the road.
------ Input Format ------
- The first line will contain T - the number of test cases. Then the test cases follow.
- T... | {"inputs": ["2\n2 1\n3 0\n"], "outputs": ["8\n6\n"]} | 346 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Problem
Given the string S, which consists of lowercase letters and numbers. Follow the steps below to compress the length of string S.
1. Change the order of the characters in the character string to any order.
Example: "0ig3he12fz99"-> "efghiz012399"... | {"inputs": ["2", "90", "111", "011", "010", "001", "101", "000"], "outputs": ["1\n", "2\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | 337 | 75 |
coding | Solve the programming task below in a Python markdown code block.
A string with length $L$ is called rich if $L \ge 3$ and there is a character which occurs in this string strictly more than $L/2$ times.
You are given a string $S$ and you should answer $Q$ queries on this string. In each query, you are given a substrin... | {"inputs": ["1\n10 2\nhelloworld\n1 3\n1 10"], "outputs": ["NO\nYES"]} | 338 | 31 |
coding | Solve the programming task below in a Python markdown code block.
There are 100 questions in a paper. Each question carries +3 marks for correct answer, -1 marks for incorrect answer and 0 marks for unattempted question.
It is given that Chef received exactly X (0 ≤ X ≤ 100) marks. Determine the minimum number of prob... | {"inputs": ["4\n0\n100\n32\n18\n"], "outputs": ["0\n2\n1\n0\n"]} | 318 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants.... | {"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n-1\n", "1 1\n555\n", "1 1\n-24\n", "4 2\n7 1 0 -7\n", "4 2\n7 0 0 -7\n", "2 2\n-742 -187\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "24\n", "7\n", "7\n", "929\n"]} | 268 | 129 |
coding | Solve the programming task below in a Python markdown code block.
Tom is very fond of adding values , so what he does whenever he gets a value he adds all its digits and forms a new value and checks it whether it has become a single digit or not and if it does not even becomes a single digit he apply the operation agai... | {"inputs": ["72\n147\n1009\n994\n5564\n9999\n1547\n18894\n1475\n5554\n8457\n32254\n14562\n18995\n5624\n65412\n1235\n2356\n1113\n1555\n4631\n8641\n2945\n8466\n3214\n4412\n6594\n3120\n55\n964\n1584\n6645\n3472\n12\n6642\n34454\n4851\n6524\n6314\n7516\n9547\n8714\n8214\n6425\n7132\n5621\n1203\n2350\n563\n1223\n4584\n6424\... | 242 | 516 |
coding | Solve the programming task below in a Python markdown code block.
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid.
Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero)... | {"inputs": ["1\n1\n1\n1\n", "1\n1\n1\n1\n", "1\n1\n0\n1\n", "1\n3\n1 2 1\n2 1 2\n", "1\n3\n8 9 8\n9 8 9\n", "1\n3\n4 5 4\n5 4 5\n", "1\n3\n3 7 3\n7 3 7\n", "1\n3\n1 2 1\n1 1 2\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 718 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a binary tree. The binary tree consists of 1 or more nodes. Each node has a unique integer id. Each node has up to 2 children, which are identified by their ids, and each node is the child of at most 1 other node. A node X is considered to be an... | {"inputs": ["2\n1\n4 0\n6\n1 5\n2 0\n3 0\n4 0\n5 5\n6 5", "2\n1\n4 0\n6\n1 8\n2 0\n3 0\n4 0\n5 5\n6 5", "2\n1\n4 0\n6\n0 8\n2 0\n3 0\n4 0\n5 5\n6 5", "2\n1\n4 0\n6\n1 8\n2 0\n3 0\n4 0\n5 5\n6 4", "2\n1\n4 0\n6\n1 8\n2 0\n3 0\n4 0\n5 5\n6 7", "2\n1\n0 0\n6\n1 8\n2 0\n3 0\n4 0\n5 5\n6 4", "2\n1\n4 0\n6\n1 5\n2 1\n3 0\n4 ... | 497 | 333 |
coding | Solve the programming task below in a Python markdown code block.
The BFS algorithm is defined as follows. Consider an undirected graph with vertices numbered from $1$ to $n$. Initialize $q$ as a new queue containing only vertex $1$, mark the vertex $1$ as used. Extract a vertex $v$ from the head of the queue $q$. P... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n2 1\n", "2\n2 1\n1 2\n", "2\n2 1\n2 1\n", "2\n1 2\n2 1\n", "2\n2 1\n1 2\n", "2\n2 1\n2 1\n"], "outputs": ["Yes", "Yes\n", "No", "Yes", "No", "No\n", "Yes\n", "No\n"]} | 562 | 118 |
coding | Solve the programming task below in a Python markdown code block.
N integers 1, 2, 3, \ldots N are placed on a circle in clockwise order such that i and (i+1) are adjacent for all 1 ≤ i ≤ N - 1, and 1 and N are also adjacent.
Given an integer K, Ashish repeatedly removes integers from the circle until only one integer... | {"inputs": ["4\n4 1\n3 3\n9 1\n3489601027782 8104267"], "outputs": ["EVEN\nEVEN\nODD\nEVEN"]} | 699 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Range Minimum Query is a well-known problem: given an array of distinct integers with size $n=2^k$ and $m$ queries, find the minimum element on subsegment $[L_i,R_i]$.
One of the most efficient and famous solutions to this problem is a segment tree. A s... | {"inputs": ["2\n1 1 1\n", "4\n3 1 3 1 2 4 1\n"], "outputs": ["NO \n", "YES\n1 1 3 1 2 3 4 \n"]} | 709 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Vishesh has gone to watch the new Spider-Man movie, but he is having troubles choosing which Popcorn-and-Coke combo to buy.
There are three combos A, B, and C available at the counter. You are given the time (in minute) for which each Popcorn bucket and... | {"inputs": ["3\n3 6\n5 10\n8 7\n99 1\n55 55\n33 51\n54 146\n5436 627\n1527 5421\n"], "outputs": ["15\n110\n6948\n"]} | 623 | 80 |
coding | Solve the programming task below in a Python markdown code block.
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic tea... | {"inputs": ["1\n9876\n", "1\n1234\n", "1\n2771\n", "1\n2705\n", "2\n2004\n1000\n", "2\n9988\n8899\n", "2\n2037\n2025\n", "2\n2099\n1000\n"], "outputs": ["1876\n", "1034\n", "1771\n", "1705\n", "1004\n1004\n", "No solution", "1037\n2005\n", "1099\n1100\n"]} | 654 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must mak... | {"inputs": ["1\n5\n", "1\n0\n", "1\n0\n", "1\n5\n", "2\n0 0\n", "2\n0 5\n", "2\n0 5\n", "2\n0 0\n"], "outputs": ["-1\n", "0\n", "0\n", "-1\n", "0\n", "0\n", "0\n", "0\n"]} | 336 | 95 |
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 | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers.
Let's call a pair of indices $i$, $j$ good if $1 \le i < j \le n$ and $\gcd(a_i, 2a_j) > 1$ (where $\gcd(x, y)$ is the greatest common divisor of $x$ and $y$).
Find the maximum number of good index... | {"inputs": ["3\n4\n3 6 5 3\n2\n1 7\n5\n1 4 2 4 1\n", "1\n211\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 391 | 480 |
coding | Solve the programming task below in a Python markdown code block.
There are N blocks, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Block i has a weight of w_i, a solidness of s_i and a value of v_i.
Taro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order... | {"inputs": ["3\n2 2 20\n2 1 7\n3 1 40", "3\n2 3 20\n2 1 7\n3 1 40", "3\n3 5 20\n1 1 7\n3 1 40", "3\n2 2 20\n2 1 30\n3 1 47", "3\n2 2 20\n2 1 30\n3 2 47", "3\n2 2 20\n2 1 29\n3 2 47", "3\n2 2 20\n2 1 29\n3 4 47", "3\n4 2 20\n2 1 35\n3 0 71"], "outputs": ["40\n", "60\n", "67\n", "50\n", "77\n", "76\n", "96\n", "71\n"]} | 505 | 235 |
coding | Solve the programming task below in a Python markdown code block.
After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem.
Given a bitstring $y \in \{0,1\}^n$ find out the number of different $k$ ($0 \leq k < n$) such that there e... | {"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "2\n00\n", "2\n10\n", "2\n01\n", "2\n11\n"], "outputs": ["1\n", "0\n", "1", "0", "2\n", "0\n", "0\n", "1\n"]} | 431 | 88 |
coding | Solve the programming task below in a Python markdown code block.
You are organizing a boxing tournament, where $n$ boxers will participate ($n$ is a power of $2$), and your friend is one of them. All boxers have different strength from $1$ to $n$, and boxer $i$ wins in the match against boxer $j$ if and only if $i$ is... | {"inputs": ["4\n3 9 1 -1\n", "4\n1 -1 1 1\n", "4\n1 -1 1 1\n", "4\n3 9 0 -1\n", "4\n0 9 0 -1\n", "4\n3 9 1 -1\n", "2\n-1 1000000000\n", "2\n1000000000 -1\n"], "outputs": ["0", "1", "1\n", "0\n", "0\n", "0", "1000000000", "0"]} | 665 | 149 |
coding | Solve the programming task below in a Python markdown code block.
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for ... | {"inputs": ["...\nX.X\n...\n", "X..\nX..\nX..\n", "...\nXXX\nXXX\n", "...\nX.X\nX..\n", "..X\nX..\n..X\n", "...\n...\n..X\n", "X..\n...\n...\n", "...\nX..\n...\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 362 | 113 |
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 true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.
Please complete the following python code precisely:... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1], k = 3) == True\n assert candidate(nums = [1,0,1,1], k = 1) == True\n assert candidate(nums = [1,2,3,1,2,3], k = 2) == False\n\n\ncheck(Solution().containsNearbyDuplicate)"} | 96 | 91 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given an array of numbers in which two numbers occur once and the rest occur only twice. Your task will be to return the sum of the numbers that occur only once.
For example, `repeats([4,5,7,5,4,8]) = 15` because only the numb... | {"functional": "_inputs = [[[4, 5, 7, 5, 4, 8]], [[9, 10, 19, 13, 19, 13]], [[16, 0, 11, 4, 8, 16, 0, 11]], [[5, 17, 18, 11, 13, 18, 11, 13]], [[5, 10, 19, 13, 10, 13]]]\n_outputs = [[15], [19], [12], [22], [24]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 341 | 291 |
coding | Solve the programming task below in a Python markdown code block.
# Task
A media access control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment.
The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six gr... | {"functional": "_inputs = [['00-1B-63-84-45-E6'], ['Z1-1B-63-84-45-E6'], ['not a MAC-48 address'], ['FF-FF-FF-FF-FF-FF'], ['00-00-00-00-00-00'], ['G0-00-00-00-00-00'], ['12-34-56-78-9A-BC'], ['02-03-04-05-06-07-'], ['02-03-04-05'], ['02-03-04-FF-00-F0']]\n_outputs = [[True], [False], [False], [True], [True], [False], [... | 268 | 346 |
coding | Solve the programming task below in a Python markdown code block.
On an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers.
There are unpaved roads between every pair of points for which either the x coordinates are equal and the difference ... | {"inputs": ["2 2\n3\n6\n2\n7", "2 2\n3\n9\n2\n7", "2 2\n3\n9\n0\n7", "2 2\n3\n9\n1\n7", "2 2\n1\n8\n1\n7", "2 2\n3\n5\n2\n7", "2 2\n3\n16\n2\n7", "2 2\n3\n32\n2\n7"], "outputs": ["31\n", "35\n", "29\n", "32\n", "27\n", "29", "42\n", "58\n"]} | 392 | 151 |
coding | Solve the programming task below in a Python markdown code block.
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studi... | {"inputs": ["4 3\n", "1 1\n", "5 3\n", "1 4\n", "5 4\n", "9 7\n", "2 3\n", "6 7\n"], "outputs": ["6\n", "1\n", "6\n", "1\n", "24\n", "5040\n", "2\n", "720\n"]} | 409 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Chef is the manager of the Code cinemas and after a long break, the theatres are now open to the public again. To compensate for the loss in revenue due to Covid-19, Mr. Chef wants to maximize the profits for every show from now on and at the same ti... | {"inputs": ["3\n1 5\n3 3\n4 4"], "outputs": ["3\n4\n4"]} | 484 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Positive integer $x$ is called divisor of positive integer $y$, if $y$ is divisible by $x$ without remainder. For example, $1$ is a divisor of $7$ and $3$ is not divisor of $8$.
We gave you an integer $d$ and asked you to find the smallest positive inte... | {"inputs": ["2\n1\n2\n", "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n1\n4\n", "2\n2\n1\n"], "outputs": ["6\n15\n", "15\n15\n", "15\n55\n", "55\n55\n", "91\n55\n", "91\n91\n", "6\n55\n", "15\n6\n"]} | 400 | 131 |
coding | Solve the programming task below in a Python markdown code block.
Write a simple parser that will parse and run Deadfish.
Deadfish has 4 commands, each 1 character long:
* `i` increments the value (initially `0`)
* `d` decrements the value
* `s` squares the value
* `o` outputs the value into the return array
Invali... | {"functional": "_inputs = [['ooo'], ['ioioio'], ['idoiido'], ['isoisoiso'], ['codewars']]\n_outputs = [[[0, 0, 0]], [[1, 2, 3]], [[0, 1]], [[1, 4, 25]], [[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... | 128 | 207 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.