task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
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.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: `2332, 110011, 54322345`
For a given number ```num```, write a function which returns an array of al... | {"functional": "_inputs = [[2], [34322122], [10015885], [4444], [1002001], [141221001], [1551], [13598], ['ACCDDCCA'], ['1551'], [-4505]]\n_outputs = [['No palindromes found'], [[22, 212, 343, 22122]], [[88, 1001, 5885]], [[44, 444, 4444]], [[1002001]], [[22, 141, 1001, 1221]], [[55, 1551]], ['No palindromes found'], [... | 407 | 348 |
coding | Solve the programming task below in a Python markdown code block.
It is a simplified version of problem F2. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is ca... | {"inputs": ["1\n4320 2\n", "1\n9319 2\n", "1\n5952 2\n", "1\n7778 2\n", "1\n5878 2\n", "1\n4025 2\n", "1\n89258 1\n", "1\n76353 2\n"], "outputs": ["4333\n", "9333\n", "5955\n", "7778\n", "5885\n", "4040\n", "99999\n", "76666\n"]} | 373 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Compute:
floor[1*e] + floor[2*e] + floor[3*e] + ... + floor[n*e],
where floor[x] is the largest integer that is not greater than x, and e is Euler's number: 2.7182818284...
... | {"inputs": ["3"], "outputs": ["15"]} | 296 | 13 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones, respectively.
Alice and Bob alternately perform the following operation, starting from Alice:
- Take 2i ston... | {"inputs": ["1 0", "6 0", "2 0", "1 8", "4 0", "1 5", "3 0", "0 7"], "outputs": ["Brown\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n"]} | 281 | 78 |
coding | Solve the programming task below in a Python markdown code block.
There is BMI (Body Mass Index) as an index showing the degree of obesity. The BMI value is calculated using the following formula.
BMI = weight (kg) / (height (m)) 2
The closer the BMI value is to the standard value, the more "ideal body shape" is cons... | {"inputs": ["6\n4 179 10\n0 657 0\n4 24 36\n11 2 75\n1 13 111\n10 336 74\n3\n2 15 4\n-1 76 6\n2 139 34\n0", "6\n4 216 10\n0 657 0\n4 24 36\n11 2 68\n1 13 011\n10 336 74\n3\n2 15 4\n0 76 12\n1 139 34\n0", "6\n2 58 11\n1 178 30\n3 78 72\n4 42 65\n7 101 62\n6 47 50\n3\n-1 147 129\n1 3 14\n0 80 24\n0", "6\n2 32 66\n1 178 1... | 441 | 727 |
coding | Solve the programming task below in a Python markdown code block.
Description
Lets imagine a yoga classroom as a Square 2D Array of Integers ```classroom```, with each integer representing a person, and the value representing their skill level.
```
classroom = [
[3,2,1,3],
[1,3,2,1],
... | {"functional": "_inputs = [[[[0, 0], [0, 0]], [1, 1, 0, 1, 2, 3, 0, 1, 5]], [[], [1, 3, 4]], [[[0, 0], [0, 0]], []], [[], []]]\n_outputs = [[8], [0], [0], [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... | 365 | 229 |
coding | Solve the programming task below in a Python markdown code block.
## Task
You have to write three functions namely - `PNum, GPNum and SPNum` (JS, Coffee), `p_num, g_p_num and s_p_num` (Python and Ruby), `pNum, gpNum and spNum` (Java, C#), `p-num, gp-num and sp-num` (Clojure) - to check whether a given argument `n` is ... | {"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [100]]\n_outputs = [[False], [True], [False], [False], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (... | 528 | 192 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Let's consider a table consisting of `n` rows and `n` columns. The cell located at the intersection of the i-th row and the j-th column contains number i × j. The rows and columns are numbered starting from 1.
You are given a positive integer `... | {"functional": "_inputs = [[5, 5], [10, 5], [6, 12], [6, 169], [100000, 1000000000]]\n_outputs = [[2], [2], [4], [0], [16]]\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)):... | 489 | 212 |
coding | Solve the programming task below in a Python markdown code block.
Assume `"#"` is like a backspace in string. This means that string `"a#bc#d"` actually is `"bd"`
Your task is to process a string with `"#"` symbols.
## Examples
```
"abc#d##c" ==> "ac"
"abc##d######" ==> ""
"#######" ==> ""
"" ... | {"functional": "_inputs = [['abjd####jfk#'], ['gfh#jds###d#dsd####dasdaskhj###dhkjs####df##s##d##'], ['831####jns###s#cas/*####-5##s##6+yqw87e##hfklsd-=-28##fds##'], ['######831###dhkj####jd#dsfsdnjkf###d####dasns'], [''], ['#######'], ['####gfdsgf##hhs#dg####fjhsd###dbs########afns#######sdanfl##db#####s#a'], ['#hskjd... | 118 | 350 |
coding | Solve the programming task below in a Python markdown code block.
a is an array of n positive integers, all of which are not greater than n.
You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap ... | {"inputs": ["3\n1 1 1\n3\n1 1\n2 1\n1 1\n", "3\n1 1 1\n3\n2 1\n2 1\n1 1\n", "3\n2 1 1\n3\n1 1\n2 1\n1 1\n", "3\n1 1 2\n3\n2 1\n2 1\n1 1\n", "3\n1 1 1\n3\n2 2\n2 1\n1 1\n", "3\n1 1 0\n3\n2 1\n2 1\n1 1\n", "3\n1 1 1\n3\n1 1\n2 1\n3 1\n", "10\n3 5 4 3 7 8 6 7 2 3\n10\n4 5\n2 10\n4 3\n9 9\n9 2\n5 1\n6 4\n1 1\n5 6\n6 4\n"],... | 280 | 321 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return the preorder traversal of its nodes' values.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,None,2,3])) == [1,2,3]\n assert candidate(root = tree_node([])) == []\n assert candidate(root = tree_node([1])) == [1]\n assert candidate(root = tree_node([1,2])) == [1,2]\n assert candidate(root = tree_node([1,None,2])) == [1,2... | 119 | 111 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you will be given a sequence of the dimensions of rectangles ( sequence with width and length ) and circles ( radius - just a number ).
Your task is to return a new sequence of dimensions, sorted ascending by area.
For example,
```python... | {"functional": "_inputs = [[[]]]\n_outputs = [[[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq... | 224 | 155 |
coding | Solve the programming task below in a Python markdown code block.
**Debug** a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "\*", or "/", the function will return the result of the corresponding mathematical functio... | {"functional": "_inputs = [[2, '+', 4], [6, '-', 1.5], [-4, '*', 8], [49, '/', -7], [8, 'm', 2], [4, '/', 0], [3.2, '+', 8], [3.2, '-', 8], [3.2, '/', 8], [3.2, '*', 8], [-3, '+', 0], [-3, '-', 0], [-3, '/', 0], [-2, '/', -2], [-2, 'codewars', -2], [-3, '*', 0], [0, '*', 0], [0, '**', 0], [-3, 'w', 0], [0, '/', 0]]\n_o... | 277 | 384 |
coding | Solve the programming task below in a Python markdown code block.
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vecto... | {"inputs": ["2\n", "1\n", "3\n", "0\n", "4\n", "2\n", "4\n", "1\n"], "outputs": ["++++\n+*+*\n++**\n+**+\n", "++\n+*\n", "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*\n", "+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\... | 721 | 468 |
coding | Solve the programming task below in a Python markdown code block.
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of the vertices, except the root, has a directed edge coming from its parent. Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each o... | {"inputs": ["3 1\n1 2\n2 3\n2 3", "3 1\n1 2\n1 3\n2 3", "6 3\n2 1\n2 3\n4 1\n4 2\n6 1\n2 6\n3 6\n6 5", "6 3\n2 1\n2 3\n4 1\n4 2\n6 1\n2 6\n3 6\n4 5", "6 3\n3 1\n4 3\n4 1\n4 2\n6 1\n4 6\n3 6\n4 5", "6 3\n2 1\n2 3\n4 1\n4 2\n6 1\n2 6\n3 6\n1 5", "6 3\n2 1\n2 3\n4 1\n4 2\n6 1\n2 6\n3 6\n3 5", "6 3\n3 1\n4 3\n4 1\n4 2\n6 2... | 466 | 361 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array... | {"inputs": ["1 0\n1\n", "1 1\n1\n", "1 4\n7\n", "1 6\n5\n", "1 2\n5\n", "1 6\n5\n", "1 2\n5\n", "1 4\n7\n"], "outputs": ["1\n", "1\n", "28\n", "30\n", "10\n", "30", "10", "28"]} | 476 | 105 |
coding | Solve the programming task below in a Python markdown code block.
You are the gym teacher in the school.
There are $n$ students in the row. And there are two rivalling students among them. The first one is in position $a$, the second in position $b$. Positions are numbered from $1$ to $n$ from left to right.
Since th... | {"inputs": ["1\n5 2 3 2\n", "1\n5 2 3 2\n", "1\n7 2 3 2\n", "1\n7 0 3 2\n", "1\n7 1 3 2\n", "1\n3 1 1 2\n", "1\n5 2 1 2\n", "1\n6 1 3 2\n"], "outputs": ["3\n", "3\n", "3\n", "1\n", "2\n", "2\n", "3\n", "2\n"]} | 422 | 134 |
coding | Solve the programming task below in a Python markdown code block.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:
* 232
* 110011
* 54322345
Complete the function to test if the given number (`num`) **can be rearr... | {"functional": "_inputs = [[5], [1212], ['ololo'], [1331], [194], [111222], ['Hello world!'], [3357665], ['357665'], [-42]]\n_outputs = [[False], [True], ['Not valid'], [True], [False], [False], ['Not valid'], [True], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)... | 256 | 241 |
coding | Solve the programming task below in a Python markdown code block.
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is repres... | {"inputs": ["3\n1 2 3\n3 2\n2\n", "3\n1 2 3\n3 2\n2\n", "3\n2 2 3\n3 2\n2\n", "3\n2 1 3\n3 2\n2\n", "3\n2 2 3\n3 2\n3\n", "3\n84 7 9\n9 84\n9\n", "3\n84 30 9\n9 84\n9\n", "3\n84 30 9\n9 84\n9\n"], "outputs": ["1\n3\n", "1\n3\n", "2\n3\n", "1\n3\n", "2\n2\n", "7\n84\n", "30\n84\n", "30\n84\n"]} | 563 | 195 |
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 buses of length n, where buses[i] represents the departure time of the ith bus. You are also given a 0-indexed integer array passengers of length m, where passengers[j] represen... | {"functional": "def check(candidate):\n assert candidate(buses = [10,20], passengers = [2,17,18,19], capacity = 2) == 16\n assert candidate(buses = [20,30,10], passengers = [19,13,26,4,25,11,21], capacity = 2) == 20\n\n\ncheck(Solution().latestTimeCatchTheBus)"} | 295 | 108 |
coding | Solve the programming task below in a Python markdown code block.
In ChefLand, human brain speed is measured in bits per second (bps). Chef has a threshold limit of X bits per second above which his calculations are prone to errors. If Chef is currently working at Y bits per second, is he prone to errors?
If Chef is p... | {"inputs": ["7 9\n", "6 6\n", "53 8\n", "31 53\n"], "outputs": ["YES", "NO", "NO", "YES\n"]} | 413 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move.... | {"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n6\n", "1\n3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 194 | 86 |
coding | Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game i... | {"inputs": ["4\n1 0 0 2\n", "4\n0 0 0 1\n", "4\n1 0 0 1\n", "4\n1 0 1 2\n", "5\n4 1 4 7 6\n", "5\n2 1 4 7 6\n", "5\n2 1 4 4 6\n", "5\n2 1 4 1 6\n"], "outputs": ["1\n1\n2\n", "0\n0\n0\n", "1\n1\n2\n", "1\n1\n3\n", "4\n5\n9\n17\n", "2\n3\n7\n15\n", "2\n3\n7\n12\n", "2\n3\n7\n9\n"]} | 583 | 185 |
coding | Solve the programming task below in a Python markdown code block.
You're given an array $b$ of length $n$. Let's define another array $a$, also of length $n$, for which $a_i = 2^{b_i}$ ($1 \leq i \leq n$).
Valerii says that every two non-intersecting subarrays of $a$ have different sums of elements. You want to deter... | {"inputs": ["1\n3\n1 1 2\n", "1\n3\n1 1 1\n", "1\n3\n1 2 3\n", "1\n3\n1 2 3\n", "1\n3\n1 1 1\n", "1\n3\n1 1 2\n", "1\n3\n1 2 2\n", "1\n3\n0 2 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n"]} | 605 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Given A, B, and C as the sides of a triangle, find whether the triangle is *scalene*.
Note:
A triangle is said to be *scalene* if all three sides of the triangle are distinct.
It is guaranteed that the sides represent a valid triangle.
------ Input For... | {"inputs": ["4\n2 3 4\n1 2 2\n2 2 2\n3 5 6\n"], "outputs": ["YES\nNO\nNO\nYES"]} | 428 | 43 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer arrays nums1 and nums2, of equal length n.
In one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices.
Find the mini... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5]) == 10\n assert candidate(nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3]) == 10\n assert candidate(nums1 = [1,2,2], nums2 = [1,2,2]) == -1\n\n\ncheck(Solution().minimumTotalCost)"} | 176 | 119 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x): change ai to x.
Note that the initial values of ai (i = 0, 1, . . ... | {"inputs": ["1 3\n1 0 1\n0 0 5\n0 0 0", "1 3\n1 0 0\n0 0 5\n1 0 0", "1 3\n1 -1 0\n0 0 5\n1 0 0", "1 3\n1 -1 0\n0 0 9\n1 0 0", "1 3\n1 -1 0\n0 0 5\n0 0 0", "1 3\n1 -1 0\n0 0 4\n1 0 0", "1 3\n1 -1 0\n1 0 9\n1 0 0", "1 3\n1 -1 1\n0 0 5\n0 0 0"], "outputs": ["2147483647\n", "2147483647\n5", "2147483647\n5\n", "2147483647\n... | 375 | 323 |
coding | Solve the programming task below in a Python markdown code block.
Akash is stuck in a N \times N grid, where N is odd. The rows of the grid are numbered 1 to N from top to bottom, and the columns are numbered 1 to N from left to right. The cell at the intersection of the i-th row and j-th column will be denoted (i, j).... | {"inputs": ["2\n3 2 1\n5 3 1"], "outputs": ["1\n0\n"]} | 669 | 27 |
coding | Solve the programming task below in a Python markdown code block.
You're given a string of dominos. For each slot, there are 3 options:
* "|" represents a standing domino
* "/" represents a knocked over domino
* " " represents a space where there is no domino
For example:
```python
"||| ||||//| |/"
```
Wha... | {"functional": "_inputs = [['||| ||||//| |/'], ['|||||'], [' ///'], [''], [' '], [' |'], ['||||| |||'], ['|||||/|||']]\n_outputs = [['/// ||||//| |/'], ['/////'], [' ///'], [''], [' '], [' |'], ['///// |||'], ['//////|||']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float)... | 200 | 219 |
coding | Solve the programming task below in a Python markdown code block.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car... | {"inputs": ["3 2 1 1\n", "5 4 3 1\n", "4 3 2 1\n", "98 2 1 1\n", "27 3 2 3\n", "13 7 6 2\n", "15 6 4 5\n", "21 3 1 3\n"], "outputs": ["4\n3\n1\n", "-1\n", "4\n3\n2\n", "98\n3\n1\n", "-1\n", "-1\n", "15\n11\n5\n", "-1\n"]} | 429 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that accepts two parameters, i) a string (containing a list of words) and ii) an integer (n). The function should alphabetize the list based on the nth letter of each word.
The letters should be compared case-insensitive. If both lette... | {"functional": "_inputs = [['bill, bell, ball, bull', 2], ['words, wordz, wordy, wording', 5], ['he, hi, ha, ho', 2], ['zephyr, yellow, wax, a, ba, cat', 1], ['hello, how, are, you, doing, today', 3]]\n_outputs = [['ball, bell, bill, bull'], ['wording, words, wordy, wordz'], ['ha, he, hi, ho'], ['a, ba, cat, wax, yello... | 220 | 278 |
coding | Solve the programming task below in a Python markdown code block.
Parsa has a humongous tree on $n$ vertices.
On each vertex $v$ he has written two integers $l_v$ and $r_v$.
To make Parsa's tree look even more majestic, Nima wants to assign a number $a_v$ ($l_v \le a_v \le r_v$) to each vertex $v$ such that the beaut... | {"inputs": ["3\n2\n1 7\n3 8\n1 2\n3\n1 3\n10 6\n7 9\n1 2\n2 3\n6\n3 1\n12 20\n6 19\n3 16\n5 17\n3 17\n3 3\n6 5\n1 5\n2 6\n4 6\n", "3\n2\n0 6\n3 8\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n12 21\n12 19\n3 12\n11 0\n3 0\n3 5\n6 5\n1 5\n2 6\n4 6\n", "3\n2\n1 6\n3 2\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n8 20\n12 19\n... | 619 | 826 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums, you start with an initial positive value startValue.
In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).
Return the minimum ... | {"functional": "def check(candidate):\n assert candidate(nums = [-3,2,-3,4,2]) == 5\n assert candidate(nums = [1,2]) == 1\n assert candidate(nums = [1,-2,-3]) == 5\n\n\ncheck(Solution().minStartValue)"} | 116 | 70 |
coding | Solve the programming task below in a Python markdown code block.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number.
For each i = 1, 2, ..., N, let the median of X_1,... | {"inputs": ["2\n1 2\n", "4\n2 4 4 3\n", "6\n5 5 4 4 3 3\n"], "outputs": ["2\n1\n", "4\n3\n3\n4\n", "4\n4\n4\n4\n4\n4\n"]} | 396 | 72 |
coding | Solve the programming task below in a Python markdown code block.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at ... | {"inputs": ["3 1\n1\n", "1 1\n1\n", "1 1\n1\n", "5 1\n1\n", "4 1\n1\n", "3 1\n1\n", "4 2\n1 4\n", "4 2\n1 3\n"], "outputs": ["1\n", "1\n", "1", "1\n", "1\n", "1", "2\n", "2\n"]} | 317 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Alice guesses the strings that Bob made for her.
At first, Bob came up with the secret string $a$ consisting of lowercase English letters. The string $a$ has a length of $2$ or more characters. Then, from string $a$ he builds a new string $b$ and offers... | {"inputs": ["1\nassaad\n", "1\nassaad\n", "1\nbssaad\n", "1\ndaassb\n", "2\nabbaac\nac\n", "2\nabbaac\nac\n", "2\nabbaad\nac\n", "2\nabbaad\nca\n"], "outputs": ["asad\n", "asad\n", "bsad\n", "dasb\n", "abac\nac\n", "abac\nac\n", "abad\nac\n", "abad\nca\n"]} | 558 | 120 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer array $a$ of length $n$.
Does there exist an array $b$ consisting of $n+1$ positive integers such that $a_i=\gcd (b_i,b_{i+1})$ for all $i$ ($1 \leq i \leq n$)?
Note that $\gcd(x, y)$ denotes the greatest common divisor (GCD) o... | {"inputs": ["1\n3\n6 3 2\n", "1\n3\n6 9 2\n", "1\n3\n12 4 3\n", "1\n3\n10 5 4\n", "1\n3\n35 7 5\n", "1\n3\n96 64 3\n", "1\n3\n22 11 18\n", "1\n3\n101 1 101\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 423 | 146 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ non-negative integers. It is guaranteed that $a$ is sorted from small to large.
For each operation, we generate a new array $b_i=a_{i+1}-a_{i}$ for $1 \le i < n$. Then we sort $b$ from small to large, replace... | {"inputs": ["1\n4\n1 145 10441 497785\n", "1\n4\n1 143 10297 497785\n", "5\n3\n1 10 100\n4\n4 8 9 13\n5\n0 0 0 8 13\n6\n2 4 8 16 32 64\n7\n0 0 0 0 0 0 0\n", "1\n104\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 ... | 666 | 1,642 |
coding | Solve the programming task below in a Python markdown code block.
We all know how to calculate $a^{b}$ using $\boldsymbol{b}$ operations by multiplying $1$ by $\boldsymbol{a}$ a total of $\boldsymbol{b}$ times. The drawback to this method is that $\boldsymbol{b}$ can be large, which makes exponentiation very slow.
The... | {"inputs": ["3\n2 0 9 1000\n0 1 5 10\n8 2 10 1000000000\n"], "outputs": ["512 0\n0 1\n880332800 927506432\n"]} | 554 | 80 |
coding | Solve the programming task below in a Python markdown code block.
In a coding contest, there are prizes for the top rankers. The prize scheme is as follows:
Top 10 participants receive rupees X each.
Participants with rank 11 to 100 (both inclusive) receive rupees Y each.
Find the total prize money over all the conte... | {"inputs": ["4\n1000 100\n1000 1000\n80 1\n400 30\n"], "outputs": ["19000\n100000\n890\n6700\n"]} | 543 | 65 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is playing a game with his friend Misha. They have a pile containg N coins. Players take alternate turns, removing some coins from the pile. On each turn, a player can r... | {"inputs": ["2\n1\n8", "2\n0\n8", "2\n0\n6", "2\n0\n1", "2\n0\n0", "2\n1\n0", "2\n1\n1", "2\n0\n2"], "outputs": ["Chef\nChef", "Misha\nChef\n", "Misha\nMisha\n", "Misha\nChef\n", "Misha\nMisha\n", "Chef\nMisha\n", "Chef\nChef\n", "Misha\nChef\n"]} | 417 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Chef usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Chef's friend Dustin gave him binary strings $S$ and $R$, each with length $N$, and told him to make them identical. However, unlike ... | {"inputs": ["2\n5\n11000\n01001\n3\n110\n001"], "outputs": ["YES\nNO"]} | 478 | 38 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two sparse matrices mat1 of size m x k and mat2 of size k x n, return the result of mat1 x mat2. You may assume that multiplication is always possible.
Please complete the following python code precisely:
```p... | {"functional": "def check(candidate):\n assert candidate(mat1 = [[1,0,0],[-1,0,3]], mat2 = [[7,0,0],[0,0,0],[0,0,1]]) == [[7,0,0],[-7,0,3]]\n assert candidate(mat1 = [[0]], mat2 = [[0]]) == [[0]]\n\n\ncheck(Solution().multiply)"} | 97 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Given a string, s, return a new string that orders the characters in order of frequency.
The returned string should have the same number of characters as the original string.
Make your transformation stable, meaning characters that compare equal shou... | {"functional": "_inputs = [['Hello world'], [''], ['wubz dermatoglyphics'], ['Four score and seven years ago'], ['Hello He worldwrd']]\n_outputs = [['lllooHe wrd'], [''], ['wubz dermatoglyphics'], [' eeeeorsorasarsaonnFucdvyg'], ['lllHeo He wordwrd']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | 305 | 222 |
coding | Solve the programming task below in a Python markdown code block.
We have 3 equations with 3 unknowns x, y, and z and we are to solve for these unknowns.
Equations 4x -3y +z = -10, 2x +y +3z = 0, and -x +2y -5z = 17 will be passed in as an array of [[4, -3, 1, -10], [2, 1, 3, 0], [-1, 2, -5, 17]] and the result should ... | {"functional": "_inputs = [[[[4, -3, 1, -10], [2, 1, 3, 0], [-1, 2, -5, 17]]], [[[2, 1, 3, 10], [-3, -2, 7, 5], [3, 3, -4, 7]]], [[[3, 2, 0, 7], [-4, 0, 3, -6], [0, -2, -6, -10]]], [[[4, 2, -5, -21], [2, -2, 1, 7], [4, 3, -1, -1]]]]\n_outputs = [[[1, 4, -2]], [[-1, 6, 2]], [[3, -1, 2]], [[1, 0, 5]]]\nimport math\ndef _... | 215 | 340 |
coding | Solve the programming task below in a Python markdown code block.
#### Background:
A linear regression line has an equation in the form `$Y = a + bX$`, where `$X$` is the explanatory variable and `$Y$` is the dependent variable. The parameter `$b$` represents the *slope* of the line, while `$a$` is called the *inte... | {"functional": "_inputs = [[[25, 30, 35, 40, 45, 50], [78, 70, 65, 58, 48, 42]], [[56, 42, 72, 36, 63, 47, 55, 49, 38, 42, 68, 60], [147, 125, 160, 118, 149, 128, 150, 145, 115, 140, 152, 155]], [[0, 10, 20, 30, 40], [0.51, 0.55, 0.57, 0.59, 0.63]]]\n_outputs = [[[114.381, -1.4457]], [[80.7777, 1.138]], [[0.514, 0.0028... | 574 | 402 |
coding | Solve the programming task below in a Python markdown code block.
Final kata of the series (highly recommended to compute [layers](https://www.codewars.com/kata/progressive-spiral-number-position/) and [branch](https://www.codewars.com/kata/progressive-spiral-number-branch/) first to get a good idea), this is a blatant... | {"functional": "_inputs = [[1], [5], [25], [30], [96], [50], [66], [306], [307], [308]]\n_outputs = [[0], [2], [4], [5], [5], [7], [7], [17], [18], [17]]\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... | 414 | 221 |
coding | Solve the programming task below in a Python markdown code block.
Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word.
To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position.
Write a ... | {"functional": "_inputs = [['dog', 'car'], ['dog', 'god'], ['dog', 'cog'], ['dog', 'cod'], ['dog', 'bog'], ['dog', 'dog'], ['abcde', 'abcde'], ['same', 'same'], ['z', 'z']]\n_outputs = [[0], [1], [2], [1], [2], [3], [5], [4], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b,... | 431 | 234 |
coding | Solve the programming task below in a Python markdown code block.
There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)
What is the area of ... | {"inputs": ["6 7", "2 1", "0 2", "0 4", "9 2", "2 4", "0 0", "7 2"], "outputs": ["30\n", "0\n", "-1\n", "-3\n", "8\n", "3\n", "1\n", "6\n"]} | 192 | 79 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright:
numsleft has all the elements of nums between index... | {"functional": "def check(candidate):\n assert candidate(nums = [0,0,1,0]) == [2,4]\n assert candidate(nums = [0,0,0]) == [3]\n assert candidate(nums = [1,1]) == [0]\n\n\ncheck(Solution().maxScoreIndices)"} | 227 | 73 |
coding | Solve the programming task below in a Python markdown code block.
You are given two arrays $a$ and $b$, both of length $n$. All elements of both arrays are from $0$ to $n-1$.
You can reorder elements of the array $b$ (if you want, you may leave the order of elements as it is). After that, let array $c$ be the array of... | {"inputs": ["1\n0\n0\n", "1\n0\n0\n", "2\n0 0\n1 1\n", "2\n1 1\n0 1\n", "2\n1 1\n0 1\n", "2\n0 0\n1 1\n", "2\n0 1\n0 1\n", "2\n1 0\n1 1\n"], "outputs": ["0 \n", "0 ", "1 1 \n", "0 1 \n", "0 1 ", "1 1 ", "0 0\n", "0 1\n"]} | 533 | 138 |
coding | Solve the programming task below in a Python markdown code block.
One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a.
For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence ... | {"inputs": ["4 4\n2 5 2 5", "4 2\n2 5 3 5", "4 4\n2 5 2 1", "4 2\n4 5 2 5", "4 2\n2 8 2 5", "4 2\n2 5 2 5", "8 4\n9 1 8 2 7 5 6 6", "8 4\n9 1 8 2 7 8 6 6"], "outputs": ["6\n", "13\n", "2\n", "9\n", "12\n", "12", "32\n", "33\n"]} | 300 | 162 |
coding | Solve the programming task below in a Python markdown code block.
An array $[b_1, b_2, \ldots, b_m]$ is a palindrome, if $b_i = b_{m+1-i}$ for each $i$ from $1$ to $m$. Empty array is also a palindrome.
An array is called kalindrome, if the following condition holds:
It's possible to select some integer $x$ and delet... | {"inputs": ["4\n1\n1\n2\n1 2\n3\n1 2 3\n5\n1 4 4 1 4\n"], "outputs": ["YES\nYES\nNO\nYES\n"]} | 659 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Monk visits the land of Islands. There are a total of N islands numbered from 1 to N. Some pairs of islands are connected to each other by Bidirectional bridges running over water.
Monk hates to cross these bridges as they require a lot of efforts. He ... | {"inputs": ["2\n3 2\n1 2\n2 3\n4 5\n1 2\n2 3\n3 4\n4 2\n1 3"], "outputs": ["2\n2"]} | 259 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Bhallaladeva was an evil king who ruled the kingdom of Maahishmati. He wanted to erect a 100ft golden statue of himself and he looted gold from several places for this. He even looted his own people, by using the following unfair strategy:
There are N ho... | {"inputs": ["4\n3 2 1 4\n2\n0\n2"], "outputs": ["10\n3"]} | 736 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X ... | {"inputs": ["5 3\n20 11 18 2 13\n1 3\n3 5\n2 4"], "outputs": ["2147483629\n2147483645\n2147483645"]} | 417 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Assume that you started to store items in progressively expanding square location, like this for the first 9 numbers:
```
05 04 03
06 01 02
07 08 09
```
And like this for the expanding to include up to the first 25 numbers:
```
17 16 15 14 13
18 05 04... | {"functional": "_inputs = [[1], [5], [25], [30], [50]]\n_outputs = [[1], [2], [3], [4], [5]]\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): ... | 430 | 180 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A set of real numbers can be represented as the union of several disjoint intervals, where each interval is in the form [a, b). A real number x is in the set if one of its intervals [a, b) contains x (i.e. a <= x < b)... | {"functional": "def check(candidate):\n assert candidate(intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]) == [[0,1],[6,7]]\n assert candidate(intervals = [[0,5]], toBeRemoved = [2,3]) == [[0,2],[3,5]]\n assert candidate(intervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4]) == [[-5,-4],[-3... | 221 | 149 |
coding | Solve the programming task below in a Python markdown code block.
Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i... | {"inputs": ["5\n4\n0 2 1 7\n5 12 29 8\n4\n1 1 0 2\n5 3 33 20\n4\n4 3 9 1\n0 9 5 2\n2\n1 1\n0 2\n1\n1\n666\n", "5\n4\n0 2 1 7\n5 12 29 8\n4\n2 1 0 2\n5 3 33 20\n4\n4 3 9 1\n0 9 5 2\n2\n1 1\n0 2\n1\n1\n666\n", "5\n4\n1 3 0 4\n5 9 15 20\n4\n1 2 2 2\n6 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n2 1\n5 9\n1\n1\n25\n", "5\n4\n1 3 1 ... | 741 | 772 |
coding | Solve the programming task below in a Python markdown code block.
A binary string is called a self-destructing string if it can reduced to an empty string by performing the following operation some number of times (possibly zero): Choose a valid integer $i$ such that the $i$-th character of the current string is differ... | {"inputs": ["3\n001101\n1101\n110"], "outputs": ["0\n1\n-1"]} | 564 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Two players A and B have a list of $n$ integers each. They both want to maximize the subtraction between their score and their opponent's score.
In one turn, a player can either add to his score any element from his list (assuming his list is not empty... | {"inputs": ["2\n1 4\n5 1\n", "2\n2 1\n5 6\n", "2\n2 1\n5 2\n", "2\n1 4\n5 1\n", "2\n2 1\n5 6\n", "3\n100 100 100\n100 100 100\n", "3\n100 100 100\n100 100 101\n", "3\n100 100 100\n100 100 100\n"], "outputs": ["0", "-3", "0\n", "0\n", "-3\n", "0", "0\n", "0\n"]} | 678 | 179 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.
The following rules define a valid string:
Any left parenthesis '(' must have a corresponding right parenthesis... | {"functional": "def check(candidate):\n assert candidate(s = \"()\") == True\n assert candidate(s = \"(*)\") == True\n assert candidate(s = \"(*))\") == True\n\n\ncheck(Solution().checkValidString)"} | 138 | 54 |
coding | Solve the programming task below in a Python markdown code block.
There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times:
* Choose 1 \leq i \leq N and multiply the value of A_i by -2.
Notice that he multiplies it by minus two.
He would ... | {"inputs": ["4\n2 1 4 1", "4\n3 1 4 4", "4\n2 1 5 1", "4\n2 1 4 2", "4\n3 1 4 2", "4\n3 1 4 8", "4\n2 1 4 8", "4\n2 1 1 2"], "outputs": ["3\n", "1\n", "5\n", "3\n", "3\n", "1\n", "1\n", "1\n"]} | 312 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:
0 <= i, j, k, l < n
nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
Please complete the ... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]) == 2\n assert candidate(nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]) == 1\n\n\ncheck(Solution().fourSumCount)"} | 141 | 90 |
coding | Solve the programming task below in a Python markdown code block.
# Task
**_Given_** a **_list of digits_**, *return the **_smallest number_** that could be formed from these digits, using the digits only once (ignore duplicates).*
___
# Notes:
* Only **_positive integers_** *will be passed to the function (> 0 ), ... | {"functional": "_inputs = [[[1, 3, 1]], [[4, 7, 5, 7]], [[4, 8, 1, 4]], [[5, 7, 9, 5, 7]], [[6, 7, 8, 7, 6, 6]], [[5, 6, 9, 9, 7, 6, 4]], [[1, 9, 1, 3, 7, 4, 6, 6, 7]], [[3, 6, 5, 5, 9, 8, 7, 6, 3, 5, 9]]]\n_outputs = [[13], [457], [148], [579], [678], [45679], [134679], [356789]]\nimport math\ndef _deep_eq(a, b, tol=1... | 472 | 342 |
coding | Solve the programming task below in a Python markdown code block.
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store:
The store has an infinite number of items of every product.
... | {"inputs": ["1\n8 2\n", "1\n8 2\n", "1\n8 4\n", "1\n8 1\n", "1\n6 1\n", "1\n4 1\n", "1\n16 1\n", "2\n7 7\n1 4\n"], "outputs": ["10\n", "10\n", "12\n", "9\n", "7\n", "5\n", "17\n", "14\n"]} | 710 | 112 |
coding | Solve the programming task below in a Python markdown code block.
Alice has recently started playing Chess. Her current rating is X. She noticed that when she wins a game, her rating increases by 8 points.
Can you help Alice in finding out the minimum number of games she needs to win in order to make her rating greate... | {"inputs": ["4\n10 10\n10 17\n10 18\n10 19\n"], "outputs": ["0\n1\n1\n2"]} | 476 | 43 |
coding | Solve the programming task below in a Python markdown code block.
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has ... | {"inputs": ["8 6 4 5\n", "8 6 4 6\n", "4 2 1 4\n", "1 1 1 1\n", "3 1 1 1\n", "4 2 1 6\n", "5 5 4 4\n", "3 2 1 1\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n"]} | 524 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).
Return the largest possible value of num after any number of swaps.
Plea... | {"functional": "def check(candidate):\n assert candidate(num = 1234) == 3412\n assert candidate(num = 65875) == 87655\n\n\ncheck(Solution().largestInteger)"} | 93 | 58 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.
In the ith move, you can choose one of the fol... | {"functional": "def check(candidate):\n assert candidate(moves = \"L_RL__R\") == 3\n assert candidate(moves = \"_R__LL_\") == 5\n assert candidate(moves = \"_______\") == 7\n\n\ncheck(Solution().furthestDistanceFromOrigin)"} | 159 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Create a function `sierpinski` to generate an ASCII representation of a Sierpinski triangle of order **N**.
Seperate each line with `\n`. You don't have to check the input value.
The output should look like this:
sierpinski(4)
... | {"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[' * \\n* *'], [' * \\n * * \\n * * \\n* * * *'], [' * \\n * * \\n * * \\n * * * * \\n * * \\n * * * * \\n * * * * \\n* * * * * * * *']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstan... | 235 | 249 |
coding | Solve the programming task below in a Python markdown code block.
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equa... | {"inputs": ["1\n1 1 1 1\n", "1\n1 1 1 0\n", "1\n1 1 1 -1\n", "3\n0 1 4 1\n1 4 1 2\n0 3 2 3\n", "3\n0 1 2 1\n1 6 1 2\n0 3 3 3\n", "3\n0 1 2 1\n1 2 1 2\n0 3 3 3\n", "3\n0 1 2 1\n1 6 1 2\n0 3 2 3\n", "3\n1 1 2 1\n1 6 1 2\n0 3 3 3\n"], "outputs": ["1", "2\n", "3\n", "10\n", "11\n", "8\n", "10\n", "10\n"]} | 395 | 217 |
coding | Solve the programming task below in a Python markdown code block.
Imagine if there were no order of operations. Instead, you would do the problem from left to right. For example, the equation `$a +b *c /d$` would become `$(((a+b)*c)//d)$` (`Math.floor(((a+b)*c)/d)` in JS). Return `None`/`null` (depending on your langu... | {"functional": "_inputs = [['2 + 3- 4*1 ^ 3'], ['7 * 3 - 3/ 10 0'], ['1 20% 0 + 9'], ['6 9* 2+6 / 0']]\n_outputs = [[1], [0], [None], [None]]\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 isin... | 449 | 220 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.
You examine the typed characters of the keyboard. ... | {"functional": "def check(candidate):\n assert candidate(name = \"alex\", typed = \"aaleex\") == True\n assert candidate(name = \"saeed\", typed = \"ssaaedd\") == False\n\n\ncheck(Solution().isLongPressedName)"} | 123 | 59 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.
For example, in s = "110100010" the longest... | {"functional": "def check(candidate):\n assert candidate(s = \"1101\") == True\n assert candidate(s = \"111000\") == False\n assert candidate(s = \"110100010\") == False\n\n\ncheck(Solution().checkZeroOnes)"} | 169 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that finds the [integral](https://en.wikipedia.org/wiki/Integral) of the expression passed.
In order to find the integral all you need to do is add one to the `exponent` (the second argument), and divide the `coefficient` (the first ar... | {"functional": "_inputs = [[3, 2], [12, 5], [20, 1], [40, 3], [90, 2]]\n_outputs = [['1x^3'], ['2x^6'], ['10x^2'], ['10x^4'], ['30x^3']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (l... | 238 | 215 |
coding | Solve the programming task below in a Python markdown code block.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integ... | {"inputs": ["4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 1 0 1\n0 0 0 1 0\n0 0 0 1 0", "3 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 -1 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 -1\n0 0 0 1 0", ... | 214 | 397 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:
event1 = [startTime1, endTime1] and
event2 = [startTime2, endTime2].
Event times are v... | {"functional": "def check(candidate):\n assert candidate(event1 = [\"01:15\",\"02:00\"], event2 = [\"02:00\",\"03:00\"]) == True\n assert candidate(event1 = [\"01:00\",\"02:00\"], event2 = [\"01:20\",\"03:00\"]) == True\n assert candidate(event1 = [\"10:00\",\"11:00\"], event2 = [\"14:00\",\"15:00\"]) == False... | 160 | 145 |
coding | Solve the programming task below in a Python markdown code block.
Integers in Python can be as big as the bytes in your machine's memory. There is no limit in size as there is: $2^{31}-1$ (c++ int) or $2^{63}-1$ (C++ long long int).
As we know, the result of $a^{b}$ grows really fast with increasing $\boldsymbol{b... | {"inputs": ["9\n29\n7\n27\n"], "outputs": ["4710194409608608369201743232 \n"]} | 361 | 51 |
coding | Solve the programming task below in a Python markdown code block.
Ash is on his way to becoming the Pokemon Master. His pokemon can perform the following moves:
- Tackle - Deal damage worth $X$ points
- Grow - Increase damage by $Y$ points i.e. $X$ = $X$ + $Y$
But, it can only perform Grow first (0 or more times) ... | {"inputs": ["2\n101 10 10\n11 3 3"], "outputs": ["6\n-1"]} | 525 | 32 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are some prizes on the X-axis. You are given an integer array prizePositions that is sorted in non-decreasing order, where prizePositions[i] is the position of the ith prize. There could be different prizes at t... | {"functional": "def check(candidate):\n assert candidate(prizePositions = [1,1,2,2,3,3,5], k = 2) == 7\n assert candidate(prizePositions = [1,2,3,4], k = 0) == 2\n\n\ncheck(Solution().maximizeWin)"} | 239 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
You are given an integer N. Consider the sequence containing the integers 1, 2, \ldots, N in increasing order (each exactly once). Find the maximum length of its cont... | {"inputs": ["3\n3\n4\n5"], "outputs": ["3\n4\n4"]} | 318 | 22 |
coding | Solve the programming task below in a Python markdown code block.
problem
There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $).
$ M (x, y) $ represents an animal that came out by putting ani... | {"inputs": ["3\nF S T", "3\nF R T", "3\nG S T", "3\nG R T", "3\nH R T", "3\nF U T", "3\nE S T", "3\nE T T"], "outputs": ["T\n", "T\n", "T\n", "T\n", "T\n", "T\n", "T\n", "T\n"]} | 245 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
- A is a sequence of N positive integers.
- 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us d... | {"inputs": ["10 10 1\n1 10 9 1", "10 10 1\n1 10 9 1\n", "10 10 1\n1 10 12 1", "3 4 3\n2 3 3 100\n1 2 2 10\n2 3 2 10", "3 4 3\n1 1 3 100\n1 2 2 10\n2 3 2 10", "3 4 2\n2 3 1 100\n1 2 2 10\n2 3 2 14", "3 4 2\n2 3 3 101\n1 2 2 16\n2 3 2 14", "3 4 3\n1 3 3 100\n1 2 2 10\n2 3 2 10"], "outputs": ["1", "1\n", "0\n", "100\n", "... | 462 | 276 |
coding | Solve the programming task below in a Python markdown code block.
In this kata, your task is to create a function that takes a single list as an argument and returns a flattened list. The input list will have a maximum of one level of nesting (list(s) inside of a list).
```python
# no nesting
[1, 2, 3]
# one level of... | {"functional": "_inputs = [[[1, [2, 3], 4]], [[['a', 'b'], 'c', ['d']]], [['!', '?']]]\n_outputs = [[[1, 2, 3, 4]], [['a', 'b', 'c', 'd']], [['!', '?']]]\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... | 228 | 209 |
coding | Solve the programming task below in a Python markdown code block.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your... | {"inputs": ["####\n.#..\n####\n....\n", "####\n....\n####\n....\n", "....\n....\n....\n....\n", "###.\n...#\n###.\n...#\n", ".##.\n#..#\n.##.\n#..#\n", ".#.#\n#.#.\n.#.#\n#.#.\n", "##..\n..##\n##..\n..##\n", "#.#.\n#.#.\n.#.#\n.#.#\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 345 | 162 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:
1 which means go to the cell to the right. (i.e go fr... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]) == 3\n assert candidate(grid = [[1,1,3],[3,2,2],[1,1,4]]) == 0\n assert candidate(grid = [[1,2],[4,3]]) == 1\n assert candidate(grid = [[2,2,2],[2,2,2]]) == 3\n assert candidate(grid = [[4]]) == 0\n... | 340 | 141 |
coding | Solve the programming task below in a Python markdown code block.
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinser... | {"inputs": ["0000", "0010", "0110", "0111", "0011", "0001", "110011", "110010"], "outputs": ["4\n", "8\n", "11\n", "10\n", "9\n", "8", "24\n", "25\n"]} | 296 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Sebi likes solving Rubik's cube a lot. He spends a lot of time in getting expertize in solving not only the 3 * 3 * 3 cube, but also the cubes of higher dimensions like 4 * 4... | {"inputs": ["2\n2 5\n2 2"], "outputs": ["YES\nNO"]} | 615 | 22 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$, consisting only of characters '0' or '1'. Let $|s|$ be the length of $s$.
You are asked to choose some integer $k$ ($k > 0$) and find a sequence $a$ of length $k$ such that:
$1 \le a_1 < a_2 < \dots < a_k \le |s|$;
$a_{i-1}... | {"inputs": ["9\n11\n11\n11\n11\n11\n11\n11\n11\n11\n", "9\n11\n11\n11\n11\n11\n11\n11\n11\n11\n", "5\n10101011011\n0000\n11111\n110\n1100\n", "5\n10101011011\n1000\n11111\n110\n1100\n", "5\n10101011011\n1000\n11111\n110\n0100\n", "5\n10101011001\n1000\n11111\n110\n0101\n", "5\n10101011001\n1001\n11111\n110\n1100\n", "5... | 595 | 396 |
coding | Solve the programming task below in a Python markdown code block.
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to $120^{\circ}$. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There... | {"inputs": ["1 1 1 1 1 1\n", "1 2 1 2 1 2\n", "2 4 5 3 3 6\n", "7 5 4 8 4 5\n", "3 2 1 4 1 2\n", "7 1 7 3 5 3\n", "9 2 9 3 8 3\n", "1 6 1 5 2 5\n"], "outputs": ["6\n", "13\n", "83\n", "175\n", "25\n", "102\n", "174\n", "58\n"]} | 352 | 160 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their positions ... | {"inputs": ["5 1 3\n1\n3\n", "1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "2 1 1\n1\n1\n", "2 1 2\n1\n1\n", "3 1 2\n1\n1\n", "5 1 3\n1\n2\n", "5 1 2\n1\n1\n"], "outputs": ["1\n", "1\n", "1\n", "-1\n", "1\n", "-1\n", "-1\n", "-1\n"]} | 484 | 134 |
coding | Solve the programming task below in a Python markdown code block.
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it i... | {"inputs": ["1\n", "9\n", "4\n", "1\n", "4\n", "9\n", "8\n", "2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 202 | 70 |
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 number of ways to partition nums is the number of pivot indices that satisfy both conditions:
1 <= pivot < n
nums[0] + nums[1] + ... + nums[pivot - 1] == ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,-1,2], k = 3) == 1\n assert candidate(nums = [0,0,0], k = 1) == 2\n assert candidate(nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33) == 4\n\n\ncheck(Solution().waysToPartition)"} | 184 | 114 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n binary matrix matrix.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa).
Return the maximum num... | {"functional": "def check(candidate):\n assert candidate(matrix = [[0,1],[1,1]]) == 1\n assert candidate(matrix = [[0,1],[1,0]]) == 2\n assert candidate(matrix = [[0,0,0],[0,0,1],[1,1,0]]) == 2\n\n\ncheck(Solution().maxEqualRowsAfterFlips)"} | 118 | 87 |
coding | Solve the programming task below in a Python markdown code block.
# MOD 256 without the MOD operator
The MOD-operator % (aka mod/modulus/remainder):
```
Returns the remainder of a division operation.
The sign of the result is the same as the sign of the first operand.
(Different behavior in Python!)
```
The short unb... | {"functional": "_inputs = [[254], [256], [258], [-254], [-256], [-258]]\n_outputs = [[254], [0], [2], [2], [0], [254]]\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 ... | 437 | 204 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.
Given an integer n, return the largest number that is less than or equal to n with monotone increasing digi... | {"functional": "def check(candidate):\n assert candidate(n = 10) == 9\n assert candidate(n = 1234) == 1234\n assert candidate(n = 332) == 299\n\n\ncheck(Solution().monotoneIncreasingDigits)"} | 96 | 69 |
coding | Solve the programming task below in a Python markdown code block.
One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.
A positive integer a is initially on the screen. The player can put a coin into the machine and then add 1 to or subtract 1 from any tw... | {"inputs": ["2\n28\n94\n", "2\n99\n11\n", "2\n37\n97\n", "2\n85\n96\n", "2\n64\n97\n", "2\n37\n94\n", "2\n19\n97\n", "2\n54\n96\n"], "outputs": ["-1\n", "8\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n", "-1\n", "1\n1 1\n", "3\n1 1\n1 1\n1 1\n", "-1\n", "-1\n", "-1\n"]} | 629 | 167 |
coding | Solve the programming task below in a Python markdown code block.
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then t... | {"inputs": ["2\n2\n4"], "outputs": ["2\n21\n210\n21\n2\n4\n43\n432\n4321\n43210\n4321\n432\n43\n4"]} | 220 | 62 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.