task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Write an algorithm to determine if a number n is happy.
A happy number is a number defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits.
Rep... | {"functional": "def check(candidate):\n assert candidate(n = 19) == True\n assert candidate(n = 2) == False\n\n\ncheck(Solution().isHappy)"} | 146 | 42 |
coding | Solve the programming task below in a Python markdown code block.
------Read problems statements in Hindi,
Mandarin chinese
, Russian and Vietnamese as well. ------
The structure of the company ShareChat can be described by a simple graph (without multiedges and self-loops) with $N$ vertices numbered $1$ through $N$ ... | {"inputs": ["2\n7 7\n1 2\n2 3\n3 4\n2 5\n3 5\n5 6\n6 7\n3 3\n1 2\n2 3\n3 1"], "outputs": ["6\n4\n6\n6\n6\n10\n6\n1\n1\n1"]} | 514 | 79 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M ... | {"functional": "def check(candidate):\n assert candidate(s = \"III\") == 3\n assert candidate(s = \"LVIII\") == 58\n assert candidate(s = \"MCMXCIV\") == 1994\n\n\ncheck(Solution().romanToInt)"} | 343 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".
Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna ac... | {"inputs": ["1 1\nI\n", "1 1\nD\n", "1 1\nM\n", "1 1\nA\n", "1 1\nD\n", "1 1\nM\n", "1 1\nA\n", "1 1\nI\n"], "outputs": ["Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n"]} | 675 | 126 |
coding | Solve the programming task below in a Python markdown code block.
# Task
John won the championship of a TV show. He can get some bonuses.
He needs to play a game to determine the amount of his bonus.
Here are `n` rows and `m` columns of cards were placed on the ground. A non-negative number is written on each card.
... | {"functional": "_inputs = [[[[1, 3, 9], [2, 8, 5], [5, 7, 4]]], [[[11, 72, 38], [80, 69, 65], [68, 96, 99]]], [[[1, 5, 1, 1], [1, 5, 5, 1], [5, 5, 5, 1], [1, 1, 5, 1]]], [[[0, 0, 2, 3, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 2, ... | 434 | 448 |
coding | Solve the programming task below in a Python markdown code block.
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows?
Every one of them has an integer sequences a and b of l... | {"inputs": ["3\n3 3 3\n1 1 1\n", "3\n1 1 1\n2 2 2\n", "3\n1 1 1\n2 2 2\n", "3\n1 2 0\n2 2 2\n", "3\n1 1 0\n2 2 2\n", "3\n3 3 6\n1 1 1\n", "3\n3 2 6\n1 1 1\n", "3\n0 2 0\n2 2 2\n"], "outputs": ["0\n", "0\n", "0", "4\n", "0\n", "0\n", "0\n", "4\n"]} | 556 | 165 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
You then do the following steps:
If original is found in nums, multiply... | {"functional": "def check(candidate):\n assert candidate(nums = [5,3,6,1,12], original = 3) == 24\n assert candidate(nums = [2,7,9], original = 4) == 4\n\n\ncheck(Solution().findFinalValue)"} | 142 | 68 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character.
A substring is a contiguous non-empty sequence of chara... | {"functional": "def check(candidate):\n assert candidate(s = \"abcba\") == 7\n assert candidate(s = \"abacad\") == 9\n assert candidate(s = \"a\") == 1\n\n\ncheck(Solution().numberOfSubstrings)"} | 96 | 58 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given integers height and width which specify the dimensions of a brick wall you are building. You are also given a 0-indexed array of unique integers bricks, where the ith brick has a height of 1 and a width ... | {"functional": "def check(candidate):\n assert candidate(height = 2, width = 3, bricks = [1,2]) == 2\n assert candidate(height = 1, width = 1, bricks = [5]) == 0\n\n\ncheck(Solution().buildWall)"} | 195 | 65 |
coding | Solve the programming task below in a Python markdown code block.
You should have done Product Partitions I to do this second part.
If you solved it, you should have notice that we try to obtain the multiplicative partitions with ```n ≤ 100 ```.
In this kata we will have more challenging values, our ```n ≤ 10000```. ... | {"functional": "_inputs = [[36, 3], [48, 5], [37, 2], [96, 5], [96, 6]]\n_outputs = [[[8, 3, [[2, 2, 9], [2, 3, 6], [3, 3, 4]]]], [[11, 1, [2, 2, 2, 2, 3]]], [[0, 0, []]], [[18, 2, [[2, 2, 2, 2, 6], [2, 2, 2, 3, 4]]]], [[18, 1, [2, 2, 2, 2, 2, 3]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, floa... | 625 | 314 |
coding | Solve the programming task below in a Python markdown code block.
William really likes the cellular automaton called "Game of Life" so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing $n$ cells, with each cell either being alive or dead.
Evolut... | {"inputs": ["1\n5 3017\n10011\n", "1\n5 42069\n11011\n", "1\n5 42069\n11011\n", "1\n5 45215\n01101\n", "1\n5 35184\n11011\n", "1\n5 21557\n11011\n", "1\n5 21557\n10011\n", "1\n5 55375\n11011\n"], "outputs": ["11111\n", "11011\n", "11011\n", "11101\n", "11011\n", "11011\n", "11111\n", "11011\n"]} | 670 | 213 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
Constraints
* 1000 \leq N \leq 9999
Input
Input is given from Standard Input in the following format:
N
Output... | {"inputs": ["0", "1", "2", "3", "95", "79", "89", "36"], "outputs": ["0\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 121 | 66 |
coding | Solve the programming task below in a Python markdown code block.
At the end of last year, Santa Claus forgot to give Christmas presents to the children in JOI village. Therefore, I decided to deliver the chocolate cake to the children as an apology. The day to deliver is approaching tomorrow, so it's time to come up w... | {"inputs": ["5 4\n3\n1 1\n3 4\n5 6", "6 4\n3\n1 1\n1 4\n5 6", "5 4\n3\n1 1\n3 4\n5 2", "5 4\n3\n1 1\n3 4\n7 6", "6 4\n3\n1 0\n1 4\n5 6", "6 4\n3\n0 1\n1 4\n5 0", "5 4\n3\n1 1\n3 3\n5 2", "5 4\n3\n0 1\n3 4\n7 6"], "outputs": ["13\n3 4\n", "12\n1 4\n", "11\n3 2\n", "16\n3 4\n", "14\n1 4\n", "13\n1 1\n", "9\n3 2\n", "18\n... | 680 | 229 |
coding | Solve the programming task below in a Python markdown code block.
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher ... | {"inputs": ["1\n1\n", "1\n6\n", "1\n0\n", "1\n3\n", "1\n3\n", "1\n1\n", "1\n6\n", "1\n0\n"], "outputs": ["0", "0", "0", "0", "0\n", "0\n", "0\n", "0\n"]} | 413 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes problems related to numbers a lot. He is generally quite good at solving these kinds of problems, but today he got stuck at one number theory problem, and so he ask... | {"inputs": ["6", "9939"], "outputs": ["1", "4"]} | 495 | 21 |
coding | Solve the programming task below in a Python markdown code block.
Chef has N candies. He has to distribute them to exactly M of his friends such that each friend gets equal number of candies and each friend gets even number of candies. Determine whether it is possible to do so.
NOTE: Chef will not take any candies him... | {"inputs": ["4\n9 3\n4 1\n4 2\n8 3"], "outputs": ["No\nYes\nYes\nNo"]} | 449 | 34 |
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": ["4 7\n", "1 9\n", "5 6\n", "1 2\n", "6 6\n", "3 4\n", "1 1\n", "4 8\n"], "outputs": ["25", "125", "14", "8", "7", "8\n", "4\n", "69\n"]} | 334 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Ma5termind is going through the Euler's book of knowledge when he finds the following function:
def function(L,R):
sum=0
for i in range(L,R+1): #[L,R]
for j in range(1,i+1): #[1,i]
cnt=0
if ... | {"inputs": ["2\n1 10\n2 5\n"], "outputs": ["9\n2\n"]} | 495 | 25 |
coding | Solve the programming task below in a Python markdown code block.
An array is a type of data structure that stores elements of the same type in a contiguous block of memory. In an array, $A$, of size $N$, each memory location has some unique index, $i$ (where $0\leq i<N$), that can be referenced as $A[i]$ or $A_i$.
Re... | {"inputs": ["4\n1 4 3 2\n"], "outputs": ["2 3 4 1\n"]} | 275 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it... | {"inputs": ["4\n", "2\n", "8\n", "3\n", "1\n", "7\n", "9\n", "6\n"], "outputs": ["0 1\n", "0 1\n", "0 3\n", "0 1\n", "0 0\n", "0 2\n", "0 3\n", "0 2\n"]} | 201 | 86 |
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.
We have N points in a two-dimensional plane.
The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i).
Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.
Here, ... | {"inputs": ["4 4\n1 4\n2 3\n6 2\n8 1", "4 4\n1 4\n2 3\n6 2\n8 0", "4 4\n0 4\n2 3\n6 2\n8 1", "4 4\n2 4\n3 3\n6 2\n8 1", "4 4\n1 4\n2 6\n6 2\n8 1", "4 2\n0 0\n1 1\n2 2\n3 3", "4 4\n1 4\n3 3\n6 2\n8 1", "4 4\n1 4\n3 3\n6 2\n8 1\n"], "outputs": ["21\n", "28\n", "24\n", "18\n", "35\n", "1", "21", "21\n"]} | 353 | 212 |
coding | Solve the programming task below in a Python markdown code block.
Finally, College has started calling students back to campus. There are so many students and thus due to some safety measures the college can’t call back all the students on the same day. It currently has the capacity of screening K students on a single ... | {"inputs": ["3\n3 3\n3 2\n4 3\n"], "outputs": ["1\n2\n2\n"]} | 475 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened.
Ori was very surprised, but Sein gave the ... | {"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "2 1\n1 1\n1 1\n", "2 2\n1 1\n1 1\n", "2 2\n1 1\n1 1\n", "2 1\n1 1\n1 1\n", "3 1\n1 1\n2 2\n3 3\n", "3 2\n1 1\n2 2\n3 3\n"], "outputs": ["1", "1\n", "2", "1", "1\n", "2\n", "3", "0"]} | 745 | 145 |
coding | Solve the programming task below in a Python markdown code block.
Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.
Magically, all the numbers were shuffled in arbitrary order while this note was passed t... | {"inputs": ["01\n0\n", "13\n3\n", "14\n4\n", "21\n2\n", "12\n2\n", "10\n0\n", "10\n0\n", "13\n3\n"], "outputs": ["0\n", "3\n", "4\n", "2\n", "2\n", "0\n", "0", "3"]} | 318 | 92 |
coding | Solve the programming task below in a Python markdown code block.
You are given several queries. In the i-th query you are given a single positive integer n_{i}. You are to represent n_{i} as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittin... | {"inputs": ["1\n4\n", "1\n12\n", "1\n12\n", "2\n6\n8\n", "2\n6\n4\n", "2\n8\n1\n", "2\n8\n4\n", "2\n6\n8\n"], "outputs": ["1\n", "3\n", "3\n", "1\n2\n", "1\n1\n", "2\n-1\n", "2\n1\n", "1\n2\n"]} | 352 | 109 |
coding | Solve the programming task below in a Python markdown code block.
Watson gives Sherlock an array of integers. Given the endpoints of an integer range, for all $M$ in that inclusive range, determine the minimum( abs(arr[i]-M) for all $1\leq i\leq|arr|$) ). Once that has been determined for all integers in the range, r... | {"inputs": ["3\n5 8 14\n4 9\n"], "outputs": ["4\n"]} | 674 | 25 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game. At the start of the game, there are N piles of stones, the i-th of which has A_{i} stones.
Alice and Bob alternate moves. On their move, a player does the following:
Choose one pile of stones, and discard the remaining ... | {"inputs": ["1\n3\n5 7 8"], "outputs": ["Alice"]} | 433 | 20 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is constraints.
Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtrans... | {"inputs": ["5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 0\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 1\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n", "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n"... | 671 | 292 |
coding | Solve the programming task below in a Python markdown code block.
A cricket match is going to be held. The field is represented by a 1D plane. A cricketer, Mr. X has $N$ favorite shots. Each shot has a particular range.
The range of the $i^{\mbox{th}}$ shot is from $\mbox{A}_{i}$ to $\mbox{B}_{i}$. That means his favo... | {"inputs": ["4 4 \n1 2 \n2 3\n4 5\n6 7\n1 5\n2 3\n4 7\n5 7 \n"], "outputs": ["9\n"]} | 610 | 53 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Russian] and [Bengali].
You are given two binary strings S and P. You need to convert S into P using the following operation any number of times (possibly zero):
Pick three binary values X, Y, and Z, such that at least one ... | {"inputs": ["2\n4\n1001\n0101\n3\n111\n000"], "outputs": ["YES\nNO"]} | 446 | 36 |
coding | Solve the programming task below in a Python markdown code block.
The number n is Evil if it has an even number of 1's in its binary representation.
The first few Evil numbers: 3, 5, 6, 9, 10, 12, 15, 17, 18, 20
The number n is Odious if it has an odd number of 1's in its binary representation.
The first few Odious num... | {"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[\"It's Odious!\"], [\"It's Odious!\"], [\"It's Evil!\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n i... | 205 | 182 |
coding | Solve the programming task below in a Python markdown code block.
Let f(X) denote the number of set bits in X.
Given integers N and K, construct an array A of length N such that:
0 ≤ A_{i} ≤ K for all (1 ≤ i ≤ N);
\sum_{i=1}^{N} A_{i} = K
Over all such possible arrays, find the maximum value of \sum_{i=1}^{N} f(A_{i}... | {"inputs": ["2\n1 7\n3 6\n"], "outputs": ["3\n4\n"]} | 443 | 24 |
coding | Solve the programming task below in a Python markdown code block.
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find th... | {"inputs": ["5 1\n", "3 2\n", "6 3\n", "5 3\n", "1 1\n", "2 1\n", "2 2\n", "1 1\n"], "outputs": ["10 10\n", "1 1\n", "3 6\n", "2 3\n", "0 0\n", "1 1\n", "0 0\n", "0 0\n"]} | 322 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Someone gave Alyona an array containing n positive integers a_1, a_2, ..., a_{n}. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat... | {"inputs": ["1\n1\n", "1\n2\n", "1\n2\n", "1\n1\n", "1\n3\n", "2\n2 1\n", "2\n1 1\n", "2\n1 3\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "3\n", "2\n", "3\n"]} | 444 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Mike likes strings. He is also interested in algorithms. A few days ago he discovered for himself a very nice problem:
You are given an AB-string S. You need to count the number of subs... | {"inputs": ["ABBCABA", "ABABBBA", "@BABBBA", "@BABCBA", "AB@BCAB", "BCABACB", "ABCBACB", "ABACBBA"], "outputs": ["2\n", "0\n", "1\n", "3\n", "4\n", "6\n", "5\n", "2\n"]} | 361 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Write function heron which calculates the area of a triangle with sides a, b, and c.
Heron's formula: sqrt (s \* (s - a) \* (s - b) \* (s - c)), where s = (a + b + c) / 2.
Output should have 2 digits precision.
Also feel free to reuse/extend the followi... | {"functional": "_inputs = [[3, 4, 5], [6, 8, 10]]\n_outputs = [[6], [24]]\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 ... | 107 | 175 |
coding | Solve the programming task below in a Python markdown code block.
You are given a secret message you need to decipher. Here are the things you need to know to decipher it:
For each word:
- the second and the last letter is switched (e.g. `Hello` becomes `Holle`)
- the first letter is replaced by its character code (e.... | {"functional": "_inputs = [['65 119esi 111dl 111lw 108dvei 105n 97n 111ka'], ['84eh 109ero 104e 115wa 116eh 108sse 104e 115eokp'], ['84eh 108sse 104e 115eokp 116eh 109ero 104e 104dare'], ['87yh 99na 119e 110to 97ll 98e 108eki 116tah 119esi 111dl 98dri'], ['84kanh 121uo 80roti 102ro 97ll 121ruo 104ple']]\n_outputs = [['... | 175 | 417 |
coding | Solve the programming task below in a Python markdown code block.
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these town... | {"inputs": ["4 3\n1 3\n2 3", "1 1\n3 2\n4 3", "1 2\n3 2\n4 3", "1 2\n2 2\n4 3", "3 2\n2 4\n1 4", "1 1\n3 2\n4 1", "1 4\n2 2\n4 3", "3 2\n3 4\n1 4"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n"]} | 303 | 142 |
coding | Solve the programming task below in a Python markdown code block.
A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them.
... | {"inputs": ["2 1\n0\n", "2 1\n5\n", "2 1\n0\n", "2 1\n5\n", "2 1\n8\n", "10 5\n0 0 1 0 2 0 0 1 0\n", "10 3\n1 1 1 1 2 1 1 1 1\n", "10 4\n0 0 6 2 7 1 6 4 0\n"], "outputs": ["0\n", "5\n", "0\n", "5\n", "8\n", "3\n", "3\n", "8\n"]} | 483 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Naman has two binary strings $s$ and $t$ of length $n$ (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert $s$ into $t$ using the following operation as few times as possible.
In one operation, he can cho... | {"inputs": ["3\n000\n000\n", "3\n000\n000\n", "3\n000\n001\n", "3\n100\n000\n", "3\n010\n000\n", "3\n010\n001\n", "3\n010\n100\n", "3\n010\n101\n"], "outputs": ["0", "0\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n"]} | 619 | 133 |
coding | Solve the programming task below in a Python markdown code block.
Complete the function that takes one argument, a list of words, and returns the length of the longest word in the list.
For example:
```python
['simple', 'is', 'better', 'than', 'complex'] ==> 7
```
Do not modify the input list.
Also feel free to reu... | {"functional": "_inputs = [[['simple', 'is', 'better', 'than', 'complex']], [['explicit', 'is', 'better', 'than', 'implicit']], [['beautiful', 'is', 'better', 'than', 'ugly']]]\n_outputs = [[7], [8], [9]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return m... | 93 | 205 |
coding | Solve the programming task below in a Python markdown code block.
Indian National Olympiad in Informatics 2016
Boing Inc, has N employees, numbered 1 ... N. Every employee other than Mr. Hojo (the head of the company) has a manager (P[i] denotes the manager of employee i). Thus an employee may manage any number of oth... | {"inputs": ["4 5 10 6 12 2 -1 4 2"], "outputs": ["6"]} | 637 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Chuck has lost count of how many asses he has kicked...
Chuck stopped counting at 100,000 because he prefers to kick things in the face instead of counting. That's just who he is.
To stop having to count like a mere mortal chuck developed his own speci... | {"functional": "_inputs = [['A6C2E5Z9A4.-F%8.08.'], ['PP P6A6T5F5S3.-Z%1.11.hgr'], ['A6A1E3A8M2.-Q%8.88.'], ['d G8H1E2O9N3.-W%8.56. f'], ['B4A1D1I8B4.-E%8.76.'], ['ffr65A C8K4D9U7V5.-Y%8.00.'], [' 76 B2L4D0A8C6.-T%8.90. lkd'], ['B2L4D0A8C6.-T%8.90'], ['B2L4D0AFC6.-T%8.90.'], ['B4A1D1I8B4'], ['B4A6666...'], ['... | 437 | 476 |
coding | Solve the programming task below in a Python markdown code block.
You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≤ i, j ≤ n). In other words, let's con... | {"inputs": ["1 1\n-4\n", "2 4\n2 0\n", "2 4\n2 1\n", "3 3\n1 1 2\n", "3 7\n5 4 3\n", "3 5\n1 1 2\n", "3 7\n5 0 3\n", "3 3\n3 1 5\n"], "outputs": ["-4 -4\n", "2 2\n", "2 2\n", "1 1\n", "5 3\n", "1 2\n", "5 0\n", "1 5\n"]} | 595 | 144 |
coding | Solve the programming task below in a Python markdown code block.
Apparently "Put A Pillow On Your Fridge Day is celebrated on the 29th of May each year, in Europe and the U.S. The day is all about prosperity, good fortune, and having bit of fun along the way."
All seems very weird to me.
Nevertheless, you will be gi... | {"functional": "_inputs = [[['EvH/KNikBiyxfeyK/miCMj', 'I/HwjnHlFLlahMOKNadps']], [['\\\\DjQ\\\\[zv]SpG]Z/[Qm\\\\eLL', 'amwZArsaGRmibriXBgTRZp']], [['n', 'B']], [['yF[CeAAiNihWEmKxJc/NRMVn', 'rMeIa\\\\KAfbjuLiTnAQxNw[XB']], [['inECnBMAA/u', 'ABAaIUOUx/M']]]\n_outputs = [[False], [False], [True], [True], [True]]\nimport... | 261 | 293 |
coding | Solve the programming task below in a Python markdown code block.
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her... | {"inputs": ["1\nm\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\nn\n", "1\nj\n", "1\nMiao.\n", "1\nLalA.\n"], "outputs": ["OMG>.< I don't know!\n", "OMG>.< I don't know!\n", "OMG>.< I don't know!\n", "OMG>.< I don't know!\n", "OMG>.< I don't know!\n", "OMG>.< I don't know!\n", "OMG>.< I don't know!\n", "OMG>.< I don't know!\n"]... | 357 | 155 |
coding | Solve the programming task below in a Python markdown code block.
A marine themed rival site to Codewars has started. Codwars is advertising their website all over the internet using subdomains to hide or obfuscate their domain to trick people into clicking on their site.
Your task is to write a function that accepts ... | {"functional": "_inputs = [['codwars.com'], ['http://codwars.com'], ['http://kcodwars.com'], ['https://www.codwars.com'], ['https://www.codwars.com/kata'], ['codewars.com.codwars.com'], ['https://www.codwars.com/kata?this=is&a=querystring'], ['https://this.is.an.unneccesarily.long.subdomain.codwars.com/katas.are.really... | 430 | 541 |
coding | Solve the programming task below in a Python markdown code block.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i.
Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or gr... | {"inputs": ["3 6\n1 7 3", "3 6\n1 5 2", "3 7\n1 5 0", "3 6\n1 7 2", "3 6\n1 5 0", "3 7\n0 5 0", "2 7\n0 6 0", "2 7\n0 3 0"], "outputs": ["2\n", "0\n", "3\n", "2\n", "1\n", "3\n", "2\n", "2\n"]} | 418 | 126 |
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 x.
Find the minimum absolute difference between two elements in the array that are at least x indices apart.
In other words, find two indices i and j such th... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,4], x = 2) == 0\n assert candidate(nums = [5,3,2,10,15], x = 1) == 1\n assert candidate(nums = [1,2,3,4], x = 3) == 3\n\n\ncheck(Solution().minAbsoluteDifference)"} | 139 | 93 |
coding | Solve the programming task below in a Python markdown code block.
During the Steam Summer Sale, Jim's $N-1$ friends have purchased $\mbox{M}$ games, which are numbered from $\mbox{1}$ to $\mbox{M}$. The games are multiplayer. Jim has invited his friends to his basement where they will play by making a LAN-Party.
Each... | {"inputs": ["5 2 4\n1 2 2 2 1\n1 2 \n2 3\n1 5\n4 5 \n"], "outputs": ["3\n4\n"]} | 669 | 48 |
coding | Solve the programming task below in a Python markdown code block.
Problem Statement
The Animal School is a primary school for animal children. You are a fox attending this school.
One day, you are given a problem called "Arithmetical Restorations" from the rabbit teacher, Hanako. Arithmetical Restorations are the pro... | {"inputs": ["3?4\n12?\n5?6\n?1?4\n5?7?\n?9?2\n?????\n?????\n?????\n0", "3?4\n12?\n6?5\n?2?4\n5?7?\n?9?2\n?????\n?????\n?????\n0", "3?4\n12?\n6?5\n?2?4\n5?7?\n2?9?\n?????\n?????\n?????\n0", "3?4\n?21\n6?5\n?2?4\n5?7?\n2?9?\n?????\n?????\n?????\n0", "34?\n?21\n6?5\n4?2?\n5?7?\n2?9?\n?????\n?????\n?????\n0", "3?4\n12?\n5?... | 654 | 453 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1].
We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After... | {"functional": "def check(candidate):\n assert candidate(arr = [4,3,2,1,0]) == 1\n assert candidate(arr = [1,0,2,3,4]) == 4\n\n\ncheck(Solution().maxChunksToSorted)"} | 125 | 61 |
coding | Solve the programming task below in a Python markdown code block.
There are two types of vehicles in Chefland.
Bus which has a capacity of 100 people.
Car which has a capacity of 4 people.
There are N people who want to travel from place A to place B. You know that a single bus emits X units of smoke while a single ca... | {"inputs": ["3\n9 40 8\n15 20 20\n105 80 10\n"], "outputs": ["24\n20\n100\n"]} | 488 | 48 |
coding | Solve the programming task below in a Python markdown code block.
You are given two arrays $a_1, a_2, \dots , a_n$ and $b_1, b_2, \dots , b_m$. Array $b$ is sorted in ascending order ($b_i < b_{i + 1}$ for each $i$ from $1$ to $m - 1$).
You have to divide the array $a$ into $m$ consecutive subarrays so that, for each ... | {"inputs": ["1 1\n1\n1\n", "1 1\n2\n1\n", "1 1\n3\n2\n", "1 1\n5\n3\n", "1 1\n1\n1\n", "1 1\n5\n3\n", "1 1\n2\n1\n", "1 1\n3\n2\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1", "0", "0", "0"]} | 613 | 114 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero.
Return true if and only if we can do this so that the resulting number is a power ... | {"functional": "def check(candidate):\n assert candidate(n = 1) == True\n assert candidate(n = 10) == False\n\n\ncheck(Solution().reorderedPowerOf2)"} | 99 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he dre... | {"inputs": ["1\n1\n", "1\n5\n", "1\n5\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n4\n", "1\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 350 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Vasya had three strings $a$, $b$ and $s$, which consist of lowercase English letters. The lengths of strings $a$ and $b$ are equal to $n$, the length of the string $s$ is equal to $m$.
Vasya decided to choose a substring of the string $a$, then choose ... | {"inputs": ["1 2\nt\nt\ntt\n", "1 2\nj\nj\njj\n", "1 2\nj\nj\njj\n", "1 2\nt\nt\ntt\n", "5 4\nazaza\nzazaz\nazaz\n", "5 4\nazaza\nzazaz\nazaz\n", "6 5\naabbaa\nbaaaab\naaaaa\n", "6 5\naabbaa\nbaaaab\naaaaa\n"], "outputs": ["1\n", "1\n", "1", "1", "11\n", "11", "4\n", "4"]} | 689 | 152 |
coding | Solve the programming task below in a Python markdown code block.
You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.
For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it i... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "3 3 2\nzyx\n", "3 2 3\nejt\n", "3 2 2\nzyx\n", "3 2 3\nzyx\n", "3 2 2\naaa\n"], "outputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\nzyx\n", "1\nejt\n", "-1\n", "1\nzyx\n", "-1\n"]} | 352 | 137 |
coding | Solve the programming task below in a Python markdown code block.
Everything was going well in Wasseypur until Ramadhir Singh found out that Sahid Khan plans to kill him someday and takeover his mine. To protect himself, he decided to take preemptive measures and kill Sahid Khan first. However, Sahid Khan also learnt o... | {"inputs": ["2\n4\n0000\n4\n0011"], "outputs": ["SAHID\nRAMADHIR"]} | 683 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Chanek gives you a sequence a indexed from 1 to n. Define f(a) as the number of indices where a_i = i.
You can pick an element from the current sequence and remove it, then concatenate the remaining elements together. For example, if you remove the... | {"inputs": ["1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n5\n", "1\n7\n", "1\n3\n", "1\n83\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 368 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensio... | {"inputs": ["5 1 5 2 5\n", "4 0 3 1 4\n", "5 4 0 5 1\n", "6 6 0 2 6\n", "5 4 0 5 2\n", "6 6 0 1 6\n", "2 0 1 2 0\n", "2 0 0 1 0\n"], "outputs": ["1\n", "2\n", "2\n", "10\n", "3\n", "11\n", "3\n", "1\n"]} | 316 | 136 |
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.
# Task
You are given two string `a` an `s`. Starting with an empty string we can do the following two operations:
```
append the given string a to the end of the current string.
erase one symbol of the current string.```
Your task is to find the least n... | {"functional": "_inputs = [['aba', 'abbabba'], ['aba', 'abaa'], ['aba', 'a'], ['a', 'a'], ['a', 'aaa'], ['abcdefgh', 'hgfedcba']]\n_outputs = [[9], [4], [3], [1], [3], [64]]\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, ... | 388 | 210 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on p... | {"inputs": ["1\na\n", "1\nk\n", "1\nH\n", "1\nk\n", "1\na\n", "1\nH\n", "1\nj\n", "1\nb\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]} | 376 | 86 |
coding | Solve the programming task below in a Python markdown code block.
A professor invented Cookie Breeding Machine for his students who like cookies very much.
When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie ... | {"inputs": ["3\n3 1\n4 4\n1 2", "3\n3 1\n4 50\n1 2", "3\n3 1\n4 75\n1 2", "3\n3 2\n2 98\n1 9", "3\n3 1\n4 75\n1 0", "3\n3 1\n4 64\n1 2", "3\n3 1\n4 37\n1 2", "3\n3 1\n4 89\n1 2"], "outputs": ["255\n504\n2\n", "255\n458\n2\n", "255\n433\n2\n", "256\n156\n9\n", "255\n433\n0\n", "255\n444\n2\n", "255\n471\n2\n", "255\n419... | 410 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal line... | {"inputs": ["4 3 1", "1 2 2", "1 5 1", "4 6 1", "1 9 1", "8 6 1", "1 9 2", "9 6 1"], "outputs": ["35\n", "1\n", "5\n", "12371\n", "34\n", "276953291\n", "21\n", "437876582\n"]} | 371 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Flatland is a country with a number of cities, some of which have space stations. Cities are numbered consecutively and each has a road of $1km$ length connecting it to the next city. It is not a circular route, so the first city doesn't connect with t... | {"inputs": ["5 2\n0 4\n", "6 6\n0 1 2 4 3 5\n"], "outputs": ["2\n", "0\n"]} | 660 | 42 |
coding | Solve the programming task below in a Python markdown code block.
In mathematics, a **pandigital number** is a number that in a given base has among its significant digits each digit used in the base at least once. For example, 1234567890 is a pandigital number in base 10.
For simplification, in this kata, we will con... | {"functional": "_inputs = [[0, 5], [5432160879, 3], [9876543000, 5], [9999999999, 1], [-123456789, 1], [-9999999999, 25]]\n_outputs = [[[1023456789, 1023456798, 1023456879, 1023456897, 1023456978]], [[5432160879, 5432160897, 5432160978]], [[9876543012, 9876543021, 9876543102, 9876543120, 9876543201]], [[]], [[102345678... | 347 | 699 |
coding | Solve the programming task below in a Python markdown code block.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the... | {"inputs": ["1\ne\n", "1\nA\n", "1\ne\n", "1\nA\n", "1\nf\n", "1\ng\n", "1\nd\n", "1\nc\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 217 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-nega... | {"inputs": ["3\n2 3 5\n", "3\n2 3 8\n", "3\n4 3 8\n", "3\n3 3 8\n", "3\n5 3 8\n", "3\n6 3 8\n", "3\n2 3 5\n", "3\n6 3 11\n"], "outputs": ["22 3", "37 3\n", "35 3\n", "34 3\n", "12 1\n", "37 3\n", "22 3", "52 3\n"]} | 700 | 141 |
coding | Solve the programming task below in a Python markdown code block.
Chef is standing at coordinate A while Chefina is standing at coordinate B.
In one step, Chef can increase or decrease his coordinate by at most K.
Determine the minimum number of steps required by Chef to reach Chefina.
------ Input Format ------
-... | {"inputs": ["4\n10 20 3\n36 36 5\n50 4 100\n30 4 2\n"], "outputs": ["4\n0\n1\n13\n"]} | 414 | 53 |
coding | Solve the programming task below in a Python markdown code block.
For given integer n, count the totatives of n, that is, the positive integers less than or equal to n that are relatively prime to n.
Input
n
An integer n (1 ≤ n ≤ 1000000000).
Output
The number of totatives in a line.
Examples
Input
6
Outp... | {"inputs": ["5", "2", "3", "6", "16", "31", "61", "59"], "outputs": ["4\n", "1\n", "2\n", "2", "8\n", "30\n", "60\n", "58\n"]} | 107 | 68 |
coding | Solve the programming task below in a Python markdown code block.
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher... | {"inputs": ["1\n(\n", "1\n(\n", "1\n)\n", "2\n((\n", "2\n((\n", "2\n()\n", "3\n(()\n", "3\n((*\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n", "-1\n", "-1\n"]} | 539 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Bob has got some injury in his leg and due to this he can take exactly M steps in one move.
Bob enters a square field of size NxN. The field is only having one gate(for both entrance and exit) at its one of the corners. Bob started walking along the per... | {"inputs": ["2\n1\n2"], "outputs": ["2\n8"]} | 471 | 18 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.
If there is more than one possible answer, return... | {"functional": "def check(candidate):\n assert candidate(words = [\"w\",\"wo\",\"wor\",\"worl\", \"world\"]) == \"world\"\n assert candidate(words = [\"a\", \"banana\", \"app\", \"appl\", \"ap\", \"apply\", \"apple\"]) == \"apple\"\n\n\ncheck(Solution().longestWord)"} | 138 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set.
Specifying the number of set ... | {"inputs": ["9 1 31\n2 3 3\n3 3 19\n16 10 3\n20 3 45\n20 8 19\n20 20 155\n3 6 6\n3 3 15\n0 0 0", "9 3 31\n2 3 3\n10 3 28\n16 6 87\n20 3 102\n20 8 19\n20 20 155\n3 6 6\n3 3 15\n0 0 0", "9 3 5\n9 1 22\n10 3 28\n16 10 107\n26 1 102\n20 10 21\n20 10 2\n3 4 3\n4 2 6\n0 0 0", "9 6 23\n2 3 3\n8 3 41\n16 10 87\n20 3 102\n20 2 ... | 458 | 786 |
coding | Solve the programming task below in a Python markdown code block.
Most of this problem is by the original author of [the harder kata](https://www.codewars.com/kata/556206664efbe6376700005c), I just made it simpler.
I read a book recently, titled "Things to Make and Do in the Fourth Dimension" by comedian and mathemati... | {"functional": "_inputs = [[1232], [123220], [0], [1], [141], [1234], [21234], [81352], [987654], [1020005], [9876545], [381654729], [1073741823]]\n_outputs = [[True], [False], [True], [True], [True], [False], [False], [False], [True], [True], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if... | 620 | 282 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a sequence good if the sum of all its elements is $0$.
You have a sequence of integers $A_1, A_2, \ldots, A_N$. You may perform any number of operations on this sequence (including zero). In one operation, you should choose a valid index $i$ a... | {"inputs": ["2\n1\n-1\n2\n1 2"], "outputs": ["NO\nYES"]} | 371 | 25 |
coding | Solve the programming task below in a Python markdown code block.
You are given $n$ chips on a number line. The $i$-th chip is placed at the integer coordinate $x_i$. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
Mov... | {"inputs": ["1\n1\n", "1\n5\n", "1\n2\n", "1\n2\n", "1\n5\n", "1\n1\n", "1\n3\n", "1\n0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 489 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Salmon received an array $A$ of size $N$ and an array $B$ of size $M$ for Christmas. He would like to move all the elements in $B$ to $A$ using a special method described below.
While $B$ is not empty, Salmon does the following operations in order:
* R... | {"inputs": ["5 3\n10 5 2 5 4\n3 1 2"], "outputs": ["5"]} | 574 | 31 |
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.
You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you c... | {"functional": "def check(candidate):\n assert candidate(nums = [1,-1,-2,4,-7,3], k = 2) == 7\n assert candidate(nums = [10,-5,-2,4,0,3], k = 3) == 17\n assert candidate(nums = [1,-5,-20,4,-1,3,-6,-3], k = 2) == 0\n\n\ncheck(Solution().maxResult)"} | 176 | 107 |
coding | Solve the programming task below in a Python markdown code block.
The marmots need to prepare k problems for HC^2 over n days. Each problem, once prepared, also has to be printed.
The preparation of a problem on day i (at most one per day) costs a_{i} CHF, and the printing of a problem on day i (also at most one per d... | {"inputs": ["1 1\n96\n86\n", "1 1\n96\n86\n", "1 1\n71\n86\n", "1 1\n50\n86\n", "1 1\n126\n86\n", "8 4\n3 8 7 9 9 4 6 8\n2 5 9 4 3 8 9 1\n", "8 4\n3 8 7 9 9 4 6 8\n2 5 9 4 3 8 9 0\n", "8 4\n3 3 7 9 9 4 6 8\n2 5 9 4 3 8 9 0\n"], "outputs": ["182", "182\n", "157\n", "136\n", "212\n", "32", "31\n", "26\n"]} | 489 | 224 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you... | {"functional": "def check(candidate):\n assert candidate(candies = [2,3,5,1,3], extraCandies = 3) == [True,True,True,False,True] \n assert candidate(candies = [4,2,1,1,2], extraCandies = 1) == [True,False,False,False,False] \n assert candidate(candies = [12,1,12], extraCandies = 10) == [True,False,True]\n\n\nc... | 167 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.
If the town judge exists, then:
The town judge trusts nobody.
Everybody (except for the town ju... | {"functional": "def check(candidate):\n assert candidate(n = 2, trust = [[1,2]]) == 2\n assert candidate(n = 3, trust = [[1,3],[2,3]]) == 3\n assert candidate(n = 3, trust = [[1,3],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().findJudge)"} | 195 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Doremy has $n$ buckets of paint which is represented by an array $a$ of length $n$. Bucket $i$ contains paint with color $a_i$.
Let $c(l,r)$ be the number of distinct elements in the subarray $[a_l,a_{l+1},\ldots,a_r]$. Choose $2$ integers $l$ and $r$ s... | {"inputs": ["7\n5\n1 3 2 2 4\n5\n1 2 3 4 5\n4\n2 1 2 1\n3\n2 3 3\n2\n2 2\n1\n1\n9\n9 8 5 2 1 1 2 3 3\n"], "outputs": ["1 5\n1 5\n1 4\n1 3\n1 2\n1 1\n1 9\n"]} | 693 | 112 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp likes arithmetic progressions. A sequence $[a_1, a_2, \dots, a_n]$ is called an arithmetic progression if for each $i$ ($1 \le i < n$) the value $a_{i+1} - a_i$ is the same. For example, the sequences $[42]$, $[5, 5, 5]$, $[2, 11, 20, 29]$ and $... | {"inputs": ["3\n1 2 1\n", "3\n2 1 2\n", "3\n5 9 5\n", "3\n3 1 2\n", "3\n1 9 4\n", "3\n2 1 3\n", "3\n9 3 6\n", "3\n2 1 2\n"], "outputs": ["1\n", "1\n", "-1\n", "2\n", "-1\n", "2\n", "-1\n", "1\n"]} | 708 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to calculate the sum (indicated by S) of all the k-balanced integers between [L, R]. An integer is called k-balanced when either of #1 or #2 below holds true.
The length of the integer <= k
Sum of the first k digits (with no leading ze... | {"inputs": ["9 23 1\n"], "outputs": ["42\n"]} | 203 | 20 |
coding | Solve the programming task below in a Python markdown code block.
The *beauty* value of an array is defined as the difference between the largest and second largest elements of the array. Note that the largest and second largest elements can have the same value in case of duplicates.
For example, *beauty* value of [2,... | {"inputs": ["4\n2\n1 1\n3\n4 2 1\n4\n8 1 7 2\n5\n6 9 4 2 1\n"], "outputs": ["1\n2\n4\n4\n"]} | 580 | 56 |
coding | Solve the programming task below in a Python markdown code block.
For an integer ```k``` rearrange all the elements of the given array in such way, that:
all elements that are less than ```k``` are placed before elements that are not less than ```k```;
all elements that are less than ```k``` remain in the same order w... | {"functional": "_inputs = [[5, [1, 3, 5, 7, 6, 4, 2]], [0, [5, 2, 7, 3, 2]], [6, [6, 4, 10, 10, 6]], [1, [3, 2, 8, 3, 2, 1]], [10, [9, 2, 4, 3, 4]]]\n_outputs = [[[1, 3, 4, 2, 5, 7, 6]], [[5, 2, 7, 3, 2]], [[4, 6, 10, 10, 6]], [[3, 2, 8, 3, 2, 1]], [[9, 2, 4, 3, 4]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if ... | 262 | 337 |
coding | Solve the programming task below in a Python markdown code block.
This is a hard version of the problem. In this version, there are two colors of the cards.
Alice has $n$ cards, each card is either black or white. The cards are stacked in a deck in such a way that the card colors alternate, starting from a white card.... | {"inputs": ["5\n10\n6\n17\n8\n1000000\n"], "outputs": ["3 2 2 3\n1 0 2 3\n6 4 3 4\n2 1 2 3\n250278 249924 249722 250076\n"]} | 458 | 90 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array arr consisting of n positive integers, and a positive integer k.
The array arr is called K-increasing if arr[i-k] <= arr[i] holds for every index i, where k <= i <= n-1.
For example, a... | {"functional": "def check(candidate):\n assert candidate(arr = [5,4,3,2,1], k = 1) == 4\n assert candidate(arr = [4,1,5,2,6,2], k = 2) == 0\n assert candidate(arr = [4,1,5,2,6,2], k = 3) == 2\n\n\ncheck(Solution().kIncreasing)"} | 283 | 98 |
coding | Solve the programming task below in a Python markdown code block.
In Aramic language words can only represent objects.
Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $x$ of a word $... | {"inputs": ["3\namer arem mrea\n", "3\namer mera mrea\n", "3\nrema mera mrea\n", "3\nrema mera erma\n", "3\nrema arem erma\n", "3\nrema aerm erma\n", "3\namer arem mrea\n", "5\na aa aaa ab abb\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2"]} | 373 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Adilbek was assigned to a special project. For Adilbek it means that he has $n$ days to run a special program and provide its results. But there is a problem: the program needs to run for $d$ days to calculate the results.
Fortunately, Adilbek can optim... | {"inputs": ["1\n7 16\n", "1\n7 16\n", "1\n4 16\n", "1\n17 81\n", "1\n17 81\n", "1\n23 28\n", "1\n11 81\n", "1\n40 28\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n"]} | 563 | 115 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal.
For example, if nums = [6,1,7,4,1]:
Choosi... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,6,4]) == 1\n assert candidate(nums = [1,1,1]) == 3\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().waysToMakeFair)"} | 205 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that
* s(a) ≥ n,
* s(b) ≥ n,
* s(a + b) ≤ m.
Input
The only line of input contain two integers n ... | {"inputs": ["4 1\n", "1 1\n", "9 1\n", "4 3\n", "3 1\n", "2 1\n", "7 1\n", "4 2\n"], "outputs": ["1111\n8889", "1\n9", "111111111\n888888889", "1111\n8889", "111\n889", "11\n89", "1111111\n8888889", "1111\n8889"]} | 244 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow)
-----Input-----
Input will start with an integer T the count of test cases, each case will hav... | {"inputs": ["1\n10"], "outputs": ["10"]} | 160 | 16 |
coding | Solve the programming task below in a Python markdown code block.
There is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.)
For every integer K satisfying 1 \leq K \leq 2^N-1, solve the following problem:
- Let i and j be integers. Find the maximum value of A_i + A_j ... | {"inputs": ["2\n1 2 3 2", "2\n0 2 3 2", "2\n1 2 3 1", "2\n1 2 3 1\n", "3\n3 210 47 33 0 9 17 82", "3\n3 312 47 33 0 9 17 82", "3\n3 312 59 33 0 9 17 82", "3\n2 312 59 33 0 9 17 82"], "outputs": ["3\n4\n5\n", "2\n3\n5\n", "3\n4\n5", "3\n4\n5\n", "213\n213\n257\n257\n257\n257\n292\n", "315\n315\n359\n359\n359\n359\n394\n... | 432 | 302 |
coding | Solve the programming task below in a Python markdown code block.
There is a girl named ''Akansha''. She is very fond of eating chocolates but she has a weak immune system due to which she gets cold after eating chocolate during morning, evening and night and can only eat at most $x$ number of chocolate each afternoon.... | {"inputs": ["3\n3\n5\n4 1 2\n5\n2\n4 4 3 2 2\n5\n1\n4 2 3 1 1"], "outputs": ["Impossible\nPossible\nImpossible"]} | 628 | 54 |
coding | Solve the programming task below in a Python markdown code block.
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me?
— Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night?
At this point the Smart Beaver got rushing. Everything should be ... | {"inputs": ["2\n0 0\n", "3\n1 1 1\n", "2\n-1 -1\n", "3\n2 1 1\n", "3\n2 2 1\n", "3\n0 -1 0\n", "3\n0 0 -1\n", "3\n-1 0 -1\n"], "outputs": ["0 0\n", "3 0\n", "-2 0\n", "2 1\n1\n", "4 1\n3\n", "0 1\n2 ", "0 1\n3\n", "-2 0\n"]} | 535 | 139 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.