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.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so... | {"inputs": ["4 3\nijiem 6 578\ntaishn 6 1917\nshowa 62 3104\nheisfi 25 2431\n1126\n1917\n1988\n1 1\nuniwersalcemtury 170 2168\n3\n0 0", "4 3\nmeiji 4 18\ntaiohs 6 1917\nawohs 53 315\ngeisei 32 6266\n139\n1917\n1988\n1 1\nuniversalcentury 123 2168\n2611\n0 0", "4 3\nmeiji 10 704\ntaitho 6 1917\nasowh 62 1987\nheisei 33 ... | 739 | 869 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums and an integer k.
In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.
Return the maximum number of operations you can perfor... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], k = 5) == 2\n assert candidate(nums = [3,1,3,4,3], k = 6) == 1\n\n\ncheck(Solution().maxOperations)"} | 100 | 67 |
coding | Solve the programming task below in a Python markdown code block.
We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates.
For a non-empty subset T of S, let f(T) be the number of points contained in th... | {"inputs": ["3\n-2 3\n2 2\n3 0", "3\n-2 5\n2 2\n3 0", "3\n-1 3\n2 2\n3 -2", "3\n-1 3\n2 0\n3 -2", "3\n-1 5\n2 0\n3 -2", "3\n-2 5\n2 0\n3 -2", "3\n-1 3\n2 1\n3 -3", "3\n-2 3\n2 2\n3 -2"], "outputs": ["13", "13", "13", "13", "13", "13", "13", "13"]} | 577 | 166 |
coding | Solve the programming task below in a Python markdown code block.
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.
If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and ... | {"inputs": ["0 2 6", "3 1 0", "1 2 6", "0 0 7", "3 2 6", "3 1 3", "3 2 6\n", "3 1 3\n"], "outputs": ["4\n", "0\n", "3\n", "7\n", "1", "0", "1\n", "0\n"]} | 246 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Jigar got a sequence of n positive integers as his birthday present! He likes consecutive subsequences whose sum is divisible by k. He asks you to write a program to count them for him.
Input Format
The first line contains T, the number of testcases. ... | {"inputs": ["2\n5 3\n1 2 3 4 1\n6 2\n1 2 1 2 1 2\n"], "outputs": ["4\n9\n"]} | 350 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ throug... | {"inputs": ["2\n2 2 5\n2 3 7"], "outputs": ["14\n5"]} | 654 | 27 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a two-dimensional matrix A of dimensions N × M, (N rows and M columns).
He calls the matrix A beautiful if there exist an a×b submatrix, such that all of its eleme... | {"inputs": ["3 4\n1 8 3 4\n5 2 3 1\n3 6 2 2\n4\n1 1\n2 2\n2 3\n3 2"], "outputs": ["0\n4\n15\n9"]} | 663 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob went to a pet store. There are N animals in the store where the i^{th} animal is of type A_{i}.
Alice decides to buy some of these N animals. Bob decides that he will buy all the animals left in the store after Alice has made the purchase.... | {"inputs": ["4\n3\n4 4 4\n4\n2 3 3 2\n4\n1 2 2 3\n6\n5 5 1 5 1 5\n"], "outputs": ["NO\nYES\nNO\nYES\n"]} | 692 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outp... | {"inputs": ["1 2 1\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n7 4 2", "1 2 1\n2 3 2\n5 4 3\n7 3 2", "1 2 1\n2 3 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 1", "1 2 1\n2 4 3\n5 1 3\n7 3 1", "2 2 1\n2 4 3\n5 1 3\n7 3 1"], "outputs": ["5\n24\n7\n6\n", "5\n24\n7\n12\n", "5\n12\n7\n6\n", "5\... | 234 | 291 |
coding | Solve the programming task below in a Python markdown code block.
You are given two strings. In a single move, you can choose any of them, and delete the first (i.e. leftmost) character.
For Example:
* By applying a move to the string `"where"`, the result is the string `"here"`.
* By applying a move to the string `"... | {"functional": "_inputs = [['test', 'west'], ['test', 'yes'], ['b', 'ab'], ['abacabadabacaba', 'abacabadacaba'], ['aaabc', 'bc'], ['dark', 'd'], ['dadc', 'dddc'], ['nogkvcdldfpvlbkpedsecl', 'nogkvcdldfpvlbkpedsecl']]\n_outputs = [[2], [7], [1], [18], [3], [5], [4], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ... | 161 | 253 |
coding | Solve the programming task below in a Python markdown code block.
The "Western calendar" is a concept imported from the West, but in Japan there is a concept called the Japanese calendar, which identifies the "era name" by adding a year as a method of expressing the year on the calendar. For example, this year is 2016 ... | {"inputs": ["4 2", "3 1", "2 0", "3 2", "4 1", "1 0", "3 0", "4 0"], "outputs": ["1990\n", "1926\n", "1911\n", "1927\n", "1989\n", "1867\n", "1925\n", "1988\n"]} | 629 | 102 |
coding | Solve the programming task below in a Python markdown code block.
You are given a problemset consisting of $n$ problems. The difficulty of the $i$-th problem is $a_i$. It is guaranteed that all difficulties are distinct and are given in the increasing order.
You have to assemble the contest which consists of some prob... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 3\n", "2\n1 3\n", "2\n2 3\n", "2\n1 3\n", "2\n1 2\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "1\n", "2\n"]} | 747 | 98 |
coding | Solve the programming task below in a Python markdown code block.
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to... | {"inputs": ["3\n", "7\n", "4\n", "6\n", "1\n", "2\n", "5\n", "9\n"], "outputs": ["NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 307 | 70 |
coding | Solve the programming task below in a Python markdown code block.
You are a king and you are at war. If the enemy breaks through your frontline you lose.
Enemy can break the line only if the sum of morale of any $K$ continuous soldiers is strictly less than $M$. So, you being a motivational orator decides to boost thei... | {"inputs": ["6 2 5\n1 1 1 1 1 1"], "outputs": ["2"]} | 337 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Given the sum and gcd of two numbers, return those two numbers in ascending order. If the numbers do not exist, return `-1`, (or `NULL` in C, `tuple (-1,-1)` in C#, `pair (-1,-1)` in C++,`None` in Rust, `array {-1,-1} ` in Java and Golang).
```
For exam... | {"functional": "_inputs = [[6, 3], [8, 2], [10, 3], [12, 4], [12, 5], [50, 10], [50, 4], [10, 5], [100, 5], [1000, 5]]\n_outputs = [[[3, 3]], [[2, 6]], [-1], [[4, 8]], [-1], [[10, 40]], [-1], [[5, 5]], [[5, 95]], [[5, 995]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float... | 251 | 276 |
coding | Solve the programming task below in a Python markdown code block.
Chef owns an icecream shop in Chefland named scoORZ. There are only three types of coins in Chefland: Rs. 5, Rs. 10 and Rs. 15. An icecream costs Rs. 5.
There are $N$ people (numbered $1$ through $N$) standing in a queue to buy icecream from scoORZ. Each... | {"inputs": ["3\n2\n5 10\n2\n10 5\n2\n5 15\n"], "outputs": ["YES\nNO\nNO"]} | 615 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Poker Nim is another $2$-player game that's a simple variation on a Nim game. The rules of the games are as follows:
The game starts with $n$ piles of chips indexed from $\mbox{0}$ to $n-1$. Each pile $\boldsymbol{i}$ (where $0\leq i<n$) has $c_i$ chips... | {"inputs": ["2\n2 5\n1 2\n3 5\n2 1 3\n"], "outputs": ["First\nSecond\n"]} | 502 | 34 |
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 and an integer k. In an operation, you can choose an element and multiply it by 2.
Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] th... | {"functional": "def check(candidate):\n assert candidate(nums = [12,9], k = 1) == 30\n assert candidate(nums = [8,1,2], k = 2) == 35\n\n\ncheck(Solution().maximumOr)"} | 142 | 62 |
coding | Solve the programming task below in a Python markdown code block.
There are n cabs in a city numbered from 1 to n. The city has a rule that only one cab can run in the city at a time. Cab picks up the customer and drops him to his destination. Then the cab gets ready to pick next customer. There are m customers in sear... | {"inputs": ["1\n3 2\n1 3\n3 2\n3 5\n2 3 3 4\n5 3 4 1"], "outputs": ["1\n1"]} | 502 | 46 |
coding | Solve the programming task below in a Python markdown code block.
##Task:
You have to write a function **pattern** which creates the following pattern upto n number of rows. *If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.*
##Pattern:
(n)
(n)(n-1)
(n)(n-1)(n-2)
... | {"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['2\\n21'], ['5\\n54\\n543\\n5432\\n54321'], [''], ['']]\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, t... | 275 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Stack likes the number 3 a lot.
He has two non-negative integers A and B.
In one operation, Stack can do either of the following:
A:=|A-B| (change A to |A-B|)
B:=|A-B| (change B to |A-B|)
Note that |X| denotes absolute value of X. For example |-7| ... | {"inputs": ["2\n0 343\n1 1\n"], "outputs": ["0\n1\n"]} | 342 | 26 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n representing the number of nodes in a connected undirected graph containing exactly one cycle. The nodes are numbered from 0 to n - 1 (inclusive).
You are also given a 2D integer arr... | {"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[1,2],[2,4],[4,3],[3,1],[0,1],[5,2],[6,5]]) == [1,0,0,0,0,1,2]\n assert candidate(n = 9, edges = [[0,1],[1,2],[0,2],[2,6],[6,7],[6,8],[0,3],[3,4],[3,5]]) == [0,0,0,1,2,2,1,2,2]\n\n\ncheck(Solution().distanceToCycle)"} | 194 | 144 |
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 have a starting score of 0.
In one operation:
choose an index i such that 0 <= i < nums.length,
increase your score by nums[i], and
replace nums[i] w... | {"functional": "def check(candidate):\n assert candidate(nums = [10,10,10,10,10], k = 5) == 50\n assert candidate(nums = [1,10,3,3,3], k = 3) == 17\n\n\ncheck(Solution().maxKelements)"} | 149 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the i^{th} subject has c_{i} chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial p... | {"inputs": ["1 1\n1\n", "1 2\n1\n", "1 2\n2\n", "1 1\n1\n", "1 2\n2\n", "1 2\n1\n", "1 3\n1\n", "1 2\n0\n"], "outputs": ["1\n", "2\n", "4\n", "1\n", "4\n", "2\n", "3\n", "0\n"]} | 662 | 102 |
coding | Solve the programming task below in a Python markdown code block.
We have two bottles for holding water.
Bottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.
Bottle 2 contains C milliliters of water.
We will transfer water from Bottle 2 to Bottle 1 as much as possible.
How much am... | {"inputs": ["0 2 0", "0 4 0", "0 6 4", "1 4 0", "1 7 0", "6 4 0", "6 2 0", "9 0 7"], "outputs": ["2\n", "4\n", "10\n", "3\n", "6\n", "0\n", "0\n", "0\n"]} | 222 | 95 |
coding | Solve the programming task below in a Python markdown code block.
Given is a positive integer N. Consider repeatedly applying the operation below on N:
- First, choose a positive integer z satisfying all of the conditions below:
- z can be represented as z=p^e, where p is a prime number and e is a positive integer;
... | {"inputs": ["2", "4", "3", "5", "8", "6", "9", "1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "0"]} | 250 | 61 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.
You have to distribute the mon... | {"functional": "def check(candidate):\n assert candidate(money = 20, children = 3) == 1\n assert candidate(money = 16, children = 2) == 2\n\n\ncheck(Solution().distMoney)"} | 159 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the cod... | {"inputs": ["0 0 2 4\n1 2\n1 2\n", "0 0 2 3\n1 1\n1 3\n", "0 0 2 4\n1 1\n1 2\n", "0 0 2 3\n1 1\n1 2\n", "-140 -140 2 200\n1 0\n0 1\n", "-12 -34 5 200\n1 0\n2 0\n3 1\n10 3\n11 4\n", "0 0 5 101\n21 38\n43 42\n5 29\n69 3\n84 52\n", "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76\n"], "outputs": ["Anton\n", "Dasha\n", "Dasha\... | 498 | 259 |
coding | Solve the programming task below in a Python markdown code block.
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.
Some examples of beautiful numbers: ... | {"inputs": ["3\n", "1\n", "6\n", "9\n", "2\n", "5\n", "1\n", "5\n"], "outputs": ["1\n", "1\n", "6\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 268 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has a string S consisting of lowercase English letters.
Starting with this string, he will produce a new one in the procedure given as follows.
The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided... | {"inputs": ["y\n0\n1 1 x", "x\n0\n1 1 x", "y\n1\n2 1 y", "x\n1\n2 1 x", "y\n1\n2 1 z", "|\n0\n1 1 u", "x\n1\n2 1 y", "w\n0\n1 1 w"], "outputs": ["y\n", "x\n", "yy\n", "xx\n", "zy\n", "|\n", "yx\n", "w\n"]} | 447 | 118 |
coding | Solve the programming task below in a Python markdown code block.
The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items... | {"inputs": ["1 1\nC\n", "1 1\nZ\n", "2 2\nCC\nBB\n", "2 2\nAB\nCD\n", "2 2\nML\nWQ\n", "2 2\nAB\nDD\n", "2 4\nABAA\nABBB\n", "2 4\nAAAA\nABBB\n"], "outputs": ["1\n1 1\n", "1\n1 1\n", "2\n1 2\n", "4\n1 1\n", "4\n1 1\n", "3\n1 2\n", "2\n1 4\n", "3\n1 4\n"]} | 554 | 150 |
coding | Solve the programming task below in a Python markdown code block.
#Detail
[Countdown](https://en.wikipedia.org/wiki/Countdown_(game_show) is a British game show with number and word puzzles. The letters round consists of the contestant picking 9 shuffled letters - either picking from the vowel pile or the consonant pi... | {"functional": "_inputs = [[''], ['MKMKMKMKM'], ['IIIWUGEZI']]\n_outputs = [[None], [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 isinstance(a, (list, tuple)):\n if len(a) != l... | 309 | 174 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.
Please complete the followi... | {"functional": "def check(candidate):\n assert candidate(nums = [\"777\",\"7\",\"77\",\"77\"], target = \"7777\") == 4\n assert candidate(nums = [\"123\",\"4\",\"12\",\"34\"], target = \"1234\") == 2\n assert candidate(nums = [\"1\",\"1\",\"1\"], target = \"11\") == 6\n\n\ncheck(Solution().numOfPairs)"} | 99 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Sarthak has a set S of N distinct prime numbers. He grew very fond of that set, and now he only likes a positive integer X if all of its prime factors belong to S. Given the set and a positive integer M, can you find out how many integers he likes which ... | {"inputs": ["1\n2 10\n3 5\n"], "outputs": ["4"]} | 329 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Given a list of white pawns on a chessboard (any number of them, meaning from 0 to 64 and with the possibility to be positioned everywhere), determine how many of them have their backs covered by another.
Pawns attacking upwards since we have only white... | {"functional": "_inputs = [[['f7', 'b1', 'h1', 'c7', 'h7']], [['e5', 'b2', 'b4', 'g4', 'a1', 'a5']], [['a2', 'b1', 'c2']], [['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'e1... | 196 | 481 |
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 and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.
The path does not need to start or end at the root or a leaf, but it mu... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([10,5,-3,3,2,None,11,3,-2,None,1]), targetSum = 8) == 3\n assert candidate(root = tree_node([5,4,8,11,None,13,4,7,2,None,None,5,1]), targetSum = 22) == 3\n\n\ncheck(Solution().pathSum)"} | 172 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
For a positive, \textbf{even} integer N, we call a pair of arrays A and B to be interesting if they satisfy the following conditions :
|A| = |B| = N/2 i.e. the lengt... | {"inputs": ["2\n2\n4"], "outputs": ["NO\nYES\n1 4\n2 3"]} | 666 | 26 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an array of strings words, determine whether s is a prefix string of words.
A string s is a prefix string of words if s can be made by concatenating the first k strings in words for some positive ... | {"functional": "def check(candidate):\n assert candidate(s = \"iloveleetcode\", words = [\"i\",\"love\",\"leetcode\",\"apples\"]) == True\n assert candidate(s = \"iloveleetcode\", words = [\"apples\",\"i\",\"love\",\"leetcode\"]) == False\n\n\ncheck(Solution().isPrefixString)"} | 122 | 74 |
coding | Solve the programming task below in a Python markdown code block.
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and a_{i} is the length of i-th segment. No two seg... | {"inputs": ["1 1\n1\n", "1 2\n1\n", "1 6\n5\n", "1 5\n2\n", "1 3\n1\n", "1 7\n5\n", "1 1\n3\n", "1 3\n2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 422 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall.... | {"functional": "def check(candidate):\n assert candidate(maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]) == True\n assert candidate(maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]) == False\n asse... | 191 | 241 |
coding | Solve the programming task below in a Python markdown code block.
Problem Statement:
Nash, a high school student studies the concepts of Functions(Mathematics), for the first time.After learning the definitions of Domain and Range, he tries to find the number of functions possible,given the number of elements in domain... | {"inputs": ["5\n6 4\n4 6\n15 2\n2 85\n4 7", "47\n428 580\n692 254\n221 613\n14 794\n116 115\n926 200\n325 265\n517 290\n219 90\n947 543\n218 544\n149 976\n28 233\n879 494\n530 715\n853 618\n5 378\n369 781\n813 967\n880 841\n610 707\n205 655\n73 468\n187 715\n442 535\n413 765\n152 199\n72 58\n24 116\n900 962\n982 272\n6... | 294 | 897 |
coding | Solve the programming task below in a Python markdown code block.
Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has a_{i} coins.
Polycarpus and Vasily move in turns. Polycarpus moves first. During a move... | {"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n546\n", "1\n546\n", "1\n641\n", "1\n1151\n", "3\n1 2 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "3\n"]} | 447 | 100 |
coding | Solve the programming task below in a Python markdown code block.
January and February are usually very cold in ChefLand. The temperature may reach -20 and even -30 degrees Celsius. Because of that, many people seal up windows in their houses.
Sergey also lives in ChefLand. He wants to seal the window in his house. The... | {"inputs": ["1\n4\n0 0\n1000 0\n1000 2000\n0 2000\n2\n1000 10\n2000 15"], "outputs": ["50"]} | 767 | 61 |
coding | Solve the programming task below in a Python markdown code block.
You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some letter c of the English alphabet, such that this string i... | {"inputs": ["1 1\na\n10\n", "1 1\na\n10\n", "1 1\nb\n10\n", "1 2\nav\n10 10\n", "1 2\nav\n10 10\n", "1 2\naw\n10 10\n", "3 3\nabc\nada\nssa\n1 1 1\n1 1 1\n1 1 1\n", "3 3\nbac\nada\nssa\n1 1 1\n1 1 1\n1 1 1\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0", "0\n", "0\n", "0\n"]} | 521 | 171 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:
* Each of them simultaneously calculate the sum of the ... | {"inputs": ["2 2 3 1", "0 3 2 0", "2 3 3 1", "4 3 3 1", "9 6 3 2", "7 2 0 0", "1 2 3 1", "2 3 2 0"], "outputs": ["0\n", "-3\n", "1\n", "-1\n", "3\n", "5\n", "1", "-1"]} | 312 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Problem Statement:
Tom is collecting money for his birthday party, he is having 'a' coins today and his father gives him 'k' coins each day.
Since his birthday is on 'nth' day, he wants to know the amount of money he will have on his birthday.
Tom is... | {"inputs": ["100\n84 87 78\n16 94 36\n87 93 50\n22 63 28\n91 60 64\n27 41 27\n73 37 12\n69 68 30\n83 31 63\n24 68 36\n30 3 23\n59 70 68\n94 57 12\n43 30 74\n22 20 85\n38 99 25\n16 71 14\n27 92 81\n57 74 63\n71 97 82\n6 26 85\n28 37 6\n47 30 14\n58 25 96\n83 46 15\n68 35 65\n44 51 88\n9 77 79\n89 85 4\n52 55 100\n33 61 ... | 271 | 1,360 |
coding | Solve the programming task below in a Python markdown code block.
Chef is a big fan of Coldplay. Every Sunday, he will drive to a park taking M minutes to reach there, and during the ride he will play a single song on a loop. Today, he has got the latest song which is in total S minutes long. He is interested to know h... | {"inputs": ["3\n10 5\n10 6\n9 10"], "outputs": ["2\n1\n0"]} | 358 | 31 |
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 integer matrix matrix with the following two properties:
Each row is sorted in non-decreasing order.
The first integer of each row is greater than the last integer of the previous row.
Given a... | {"functional": "def check(candidate):\n assert candidate(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3) == True\n assert candidate(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13) == False\n\n\ncheck(Solution().searchMatrix)"} | 127 | 112 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i].
For example, if nums1 = [1,2,3,8], and nums2 = [5,6,7,4], you can swap the elemen... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,3,5,4], nums2 = [1,2,3,7]) == 1\n assert candidate(nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]) == 1\n\n\ncheck(Solution().minSwap)"} | 221 | 85 |
coding | Solve the programming task below in a Python markdown code block.
There is Chef and Chef’s Crush who are playing a game of numbers.
Chef’s crush has a number $A$ and Chef has a number $B$.
Now, Chef wants Chef’s crush to win the game always, since she is his crush. The game ends when the greatest value of A^B is reac... | {"inputs": ["1\n4 5"], "outputs": ["2 7"]} | 590 | 18 |
coding | Solve the programming task below in a Python markdown code block.
The Monty Hall problem is a probability puzzle base on the American TV show "Let's Make A Deal".
In this show, you would be presented with 3 doors: One with a prize behind it, and two without (represented with goats).
After choosing a door, the host wo... | {"functional": "_inputs = [[1, [1, 2, 2, 2, 3, 2, 1, 3, 1, 3]], [2, [2, 1, 2, 1, 2, 3, 1, 1, 2, 2, 3]], [3, [1, 1, 1, 2, 2, 3, 2, 2, 1, 3, 3, 2, 3, 1, 1, 2]]]\n_outputs = [[70], [55], [75]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ... | 267 | 283 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer 2D array nodes, your task is to determine if the given array represents the preorder traversal of some binary tree.
For each index i, nodes[i] = [id, parentId], where id is the id of the node... | {"functional": "def check(candidate):\n assert candidate(nodes = [[0,-1],[1,0],[2,0],[3,2],[4,2]]) == True\n assert candidate(nodes = [[0,-1],[1,0],[2,0],[3,1],[4,1]]) == False\n\n\ncheck(Solution().isPreorder)"} | 197 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game. They have an array of positive integers $a$ of size $n$.
Before starting the game, Alice chooses an integer $k \ge 0$. The game lasts for $k$ stages, the stages are numbered from $1$ to $k$. During the $i$-th stage, Ali... | {"inputs": ["7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "4\n3\n1 1 2\n4\n4 4 4 4\n1\n1\n5\n1 3 2 1 1\n", "13\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "13\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n"], "outputs": ... | 423 | 298 |
coding | Solve the programming task below in a Python markdown code block.
Kuroni is very angry at the other setters for using him as a theme! As a punishment, he forced them to solve the following problem:
You have an array $a$ consisting of $n$ positive integers. An operation consists of choosing an element and either adding... | {"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n3 1\n", "3\n6 2 4\n", "3\n6 3 4\n", "3\n6 2 4\n", "3\n12 4 4\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "0\n", "1\n", "0\n", "0\n"]} | 444 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one e... | {"inputs": ["1\n5\n", "1\n2\n", "1\n4\n", "1\n1\n", "1\n9\n", "1\n3\n", "1\n6\n", "1\n7\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n"]} | 319 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:
In each step, you will choose any 3 piles of coins (not necessarily consecutive).
Of your choice, Alice will pick... | {"functional": "def check(candidate):\n assert candidate(piles = [2,4,1,2,7,8]) == 9\n assert candidate(piles = [2,4,5]) == 4\n assert candidate(piles = [9,8,7,6,5,1,2,3,4]) == 18\n\n\ncheck(Solution().maxCoins)"} | 169 | 89 |
coding | Solve the programming task below in a Python markdown code block.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
- Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the large... | {"inputs": ["3 3 4\n4", "3 3 4\n0", "4 3 4\n0", "4 3 1\n0", "4 1 1\n0", "3 1 1\n0", "4 2 1\n0", "3 2 4\n2"], "outputs": ["70\n", "10\n", "11\n", "8\n", "6\n", "5\n", "7\n", "21\n"]} | 352 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
You are given two binary strings $A$ and $B$ with the same length.
You may perform the following operation any number of times (including zero): pi... | {"inputs": ["3\n100001\n110111\n1010\n1010\n000\n111"], "outputs": ["2\n0\n2"]} | 523 | 48 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.
The box is "Bulky" if:
Any of the dimensions ... | {"functional": "def check(candidate):\n assert candidate(length = 1000, width = 35, height = 700, mass = 300) == \"Heavy\"\n assert candidate(length = 200, width = 50, height = 800, mass = 50) == \"Neither\"\n\n\ncheck(Solution().categorizeBox)"} | 263 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Alice wants to send an email to Miku on her mobile phone.
The only buttons that can be used for input on mobile phones are number buttons. Therefore, in order to input characters, the number buttons are pressed several times to input characters. The fol... | {"inputs": ["5\n40\n0\n222220\n44033055505550666011011111090666077705550301110\n000555555550000330000444000080000200004440000", "5\n0\n20\n222220\n44033055505550666011011111090666077705550301110\n000555555550000330000444000080000200004440000", "5\n40\n30\n222220\n44033055505550666011011111090666077705550301110\n0005555... | 539 | 1,006 |
coding | Solve the programming task below in a Python markdown code block.
Recall that a permutation of length $n$ is an array where each element from $1$ to $n$ occurs exactly once.
For a fixed positive integer $d$, let's define the cost of the permutation $p$ of length $n$ as the number of indices $i$ $(1 \le i < n)$ such th... | {"inputs": ["2\n2\n3\n"], "outputs": ["2\n1 2 \n2\n1 2 3 \n"]} | 396 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Mr. E Ven only likes even length words.
Please create a translator so that he doesn't have to hear those pesky odd length words.
For some reason he also hates punctuation, he likes his sentences to flow.
Your translator should take in a string and outpu... | {"functional": "_inputs = [['I got a hole in 1!'], ['tHiS sEnTeNcE iS eVeN.'], ['underscore is not considered a word..in this case,'], ['hi. how are you? Bye!!'], ['lorem is so ipsum. why bother?'], ['_under the seA!']]\n_outputs = [['II gott aa hole in 11'], ['tHiS sEnTeNcE iS eVeN'], ['underscore is nott considered a... | 148 | 287 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string $s$ of length $n$.
Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{... | {"inputs": ["1\n2 1000000000\n01\n", "3\n4 0\n1010\n7 1\n0010100\n5 2\n00110\n"], "outputs": ["1\n", "21\n22\n12\n"]} | 565 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help.
## Task
You need to return a string that looks like a diamond shape when prin... | {"functional": "_inputs = [[3], [0], [2], [-1], [-2]]\n_outputs = [[' *\\n***\\n *\\n'], [None], [None], [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 isinstance(a, (list, tuple)):\n ... | 229 | 186 |
coding | Solve the programming task below in a Python markdown code block.
Hackerman wants to know who is the better player between Bob and Alice with the help of a game.
The game proceeds as follows:
First, Alice throws a die and gets the number A
Then, Bob throws a die and gets the number B
Alice wins the game if the sum on ... | {"inputs": ["3\n2 1\n1 1\n2 2\n"], "outputs": ["Alice\nAlice\nBob\n"]} | 389 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A web developer needs to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following re... | {"functional": "def check(candidate):\n assert candidate(area = 4) == [2,2]\n assert candidate(area = 37) == [37,1]\n assert candidate(area = 122122) == [427,286]\n\n\ncheck(Solution().constructRectangle)"} | 174 | 75 |
coding | Solve the programming task below in a Python markdown code block.
You have an empty sequence, and you will be given $N$ queries. Each query is one of these three types:
1 x -Push the element x into the stack.
2 -Delete the element present at the top of the stack.
3 -Print the maximum element in the stack.
Func... | {"inputs": ["STDIN Function\n----- --------\n10 operations[] size n = 10\n1 97 operations = ['1 97', '2', '1 20', ....]\n2\n1 20\n2\n1 26\n1 20\n2\n3\n1 91\n3\n"], "outputs": ["26\n91\n"]} | 286 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to calculate the number of arrays such that: each array contains $n$ elements; each element is an integer from $1$ to $m$; for each array, there is exactly one pair of equal elements; for each array $a$, there exists an index $i$ such th... | {"inputs": ["3 4\n", "3 5\n", "2 2\n", "3 3\n", "2 3\n", "3 3\n", "2 2\n", "2 3\n"], "outputs": ["6\n", "10\n", "0\n", "3\n", "0\n", "3\n", "0\n", "0\n"]} | 371 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Berland shop sells $n$ kinds of juices. Each juice has its price $c_i$. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vit... | {"inputs": ["2\n9 C\n3 B\n", "1\n100 ABC\n", "2\n9 C\n3 B\n", "1\n100 ABC\n", "2\n9 AB\n4 BC\n", "2\n9 AB\n4 BC\n", "2\n2 AB\n4 BC\n", "2\n6 AB\n5 BA\n"], "outputs": ["-1\n", "100\n", "-1", "100", "13\n", "13", "6\n", "-1\n"]} | 543 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is i... | {"inputs": ["6\n", "4\n", "5\n", "1\n", "9\n", "8\n", "7\n", "2\n"], "outputs": ["10 2\n1 2", "6 2\n1 2", "8 2\n1 2\n", "1 1\n1\n", "16 2\n1 2\n", "14 2\n1 2", "12 2\n1 2\n", "2 2\n1 2"]} | 573 | 116 |
coding | Solve the programming task below in a Python markdown code block.
In mathematics, the [degree] of polynomials in one variable is the highest power of the variable in the algebraic expression with non-zero coefficient.
Chef has a polynomial in one variable x with N terms. The polynomial looks like A_{0}\cdot x^{0} + A_... | {"inputs": ["4\n1\n5\n2\n-3 3\n3\n0 0 5\n4\n1 2 4 0\n"], "outputs": ["0\n1\n2\n2"]} | 629 | 48 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all ch... | {"functional": "def check(candidate):\n assert candidate(s = \"cczazcc\", repeatLimit = 3) == \"zzcccac\"\n assert candidate(s = \"aababab\", repeatLimit = 2) == \"bbabaa\"\n\n\ncheck(Solution().repeatLimitedString)"} | 181 | 67 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string, and you have to validate whether it's a valid Roman numeral. If it is valid, print True. Otherwise, print False. Try to create a regular expression for a valid Roman numeral.
Input Format
A single line of input containing a stri... | {"inputs": ["CDXXI\n"], "outputs": ["True\n"]} | 181 | 16 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1's in the resulting array. Return 0 if there is no such subarray.
Please complete ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,0,1]) == 3\n assert candidate(nums = [0,1,1,1,0,1,1,0,1]) == 5\n assert candidate(nums = [1,1,1]) == 2\n\n\ncheck(Solution().longestSubarray)"} | 94 | 83 |
coding | Solve the programming task below in a Python markdown code block.
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i.
You are choosing K among these N pieces to eat.
Your "satisfaction" here will be calculated as follows:
- The satisfaction is the sum of the "base... | {"inputs": ["1 1\n1 11\n", "4 3\n3 4\n2 8\n2 9\n3 1\n", "5 3\n1 9\n1 0\n2 6\n2 5\n3 1", "5 3\n1 9\n1 0\n2 6\n2 5\n3 2", "5 4\n1 9\n1 7\n2 6\n2 5\n3 1", "5 3\n1 3\n1 7\n2 6\n2 5\n3 1", "5 2\n1 9\n1 0\n2 6\n2 5\n3 2", "5 4\n2 9\n1 7\n2 3\n2 5\n3 1"], "outputs": ["12\n", "25\n", "25\n", "26\n", "32\n", "23\n", "19\n", "31... | 348 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Nexus 4.O is going to be organized by ASME, GLA University. Shubhanshu, Head of Finance Team is working for it. He has $N$ number of bills of different values as $a$$1$,$ a$$2$, $a$$3$…$a$$n$.
He is interested in a game in which one has to do the additio... | {"inputs": ["1\n8 3\n1 2 3 4 5 6 7 8\n2 3\n1 6\n5 8"], "outputs": ["5\n21\n26"]} | 700 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob received $n$ candies from their parents. Each candy weighs either 1 gram or 2 grams. Now they want to divide all candies among themselves fairly so that the total weight of Alice's candies is equal to the total weight of Bob's candies.
Che... | {"inputs": ["5\n2\n1 1\n2\n1 2\n4\n1 2 1 2\n3\n2 2 2\n3\n2 1 2\n"], "outputs": ["YES\nNO\nYES\nNO\nNO\n"]} | 462 | 60 |
coding | Solve the programming task below in a Python markdown code block.
You have been presented with a cipher, your goal is to re-create the cipher with little information. Use the examples provided to see if you can find a solution to how this cipher is made. You will be given no hints, only the handful of phrases that have... | {"functional": "_inputs = [['this will probably not be fun'], ['hopefully you will find satisfaction at least'], ['really this is very tedious'], ['if you made it this far you are a better programmer than i am']]\n_outputs = [['tiks zjop twrggfrf uwz kl pcx'], ['hprehxmoc ctx cmrs mqtl zjdqcqjnfsaa nh ztnhj'], ['rfclnb... | 141 | 273 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Sereja is playing a game called Winner Eats Sandwich with his friends. There are N persons in total, including Sereja. Sereja is allotted the number 1, while his friends are allotted numbers fro... | {"inputs": ["2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n0.5000 0.5000 0.5000\n0.5000 0.5000 0.5000", "2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n0.5000 0.5000 0.5000\n0.5000 0.5000 0.5000 ", "2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n1.2649803683768097 0.5000 0.5000\n0.5000 0.5000 0.5000", "2\n2 2\n1.0000 1.7642945663... | 565 | 896 |
coding | Solve the programming task below in a Python markdown code block.
Watson gives an integer $N$ to Sherlock and asks him: What is the number of divisors of $N$ that are divisible by 2?.
Input Format
First line contains $\mathbf{T}$, the number of testcases. This is followed by $\mathbf{T}$ lines each containing an... | {"inputs": ["2\n9\n8\n"], "outputs": ["0\n3\n"]} | 195 | 20 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The width of a sequence is the difference between the maximum and minimum elements in the sequence.
Given an array of integers nums, return the sum of the widths of all the non-empty subsequences of nums. Since the an... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,3]) == 6\n assert candidate(nums = [2]) == 0\n\n\ncheck(Solution().sumSubseqWidths)"} | 173 | 50 |
coding | Solve the programming task below in a Python markdown code block.
A permutation of length N is an array of N integers (P_{1},P_{2}, \dots,P_{N}) where every integer from 1 to N (inclusive) appears in it exactly once. The weight of a subsegment containing the elements (P_{l},P_{l+1}, \dots,P_{r}) is defined as follows: ... | {"inputs": ["4\n3 2\n3 5\n5 6\n4 10\n\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 618 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Makoto has a big blackboard with a positive integer $n$ written on it. He will perform the following action exactly $k$ times:
Suppose the number currently written on the blackboard is $v$. He will randomly pick one of the divisors of $v$ (possibly $1$ ... | {"inputs": ["6 1\n", "6 2\n", "2 4\n", "1 1\n", "2 4\n", "1 1\n", "2 6\n", "1 0\n"], "outputs": ["3\n", "875000008\n", "562500005\n", "1\n", "562500005\n", "1\n", "140625002\n", "1\n"]} | 507 | 118 |
coding | Solve the programming task below in a Python markdown code block.
This kata aims to show the vulnerabilities of hashing functions for short messages.
When provided with a SHA-256 hash, return the value that was hashed. You are also given the characters that make the expected value, but in alphabetical order.
The retu... | {"functional": "_inputs = [['b8c49d81cb795985c007d78379e98613a4dfc824381be472238dbd2f974e37ae', 'deGioOstu'], ['f58262c8005bb64b8f99ec6083faf050c502d099d9929ae37ffed2fe1bb954fb', 'abc']]\n_outputs = [['GoOutside'], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):... | 211 | 287 |
coding | Solve the programming task below in a Python markdown code block.
You are given an unsorted permutation P of size N. An operation is defined as:
Swap P_{i} and P_{i+K} for any i in the range [1,N-K].
Find the maximum value of K, such that, the permutation P can be sorted by applying any finite number of operations.
... | {"inputs": ["3\n4\n4 2 3 1\n5\n1 4 3 2 5\n2\n2 1\n"], "outputs": ["3\n2\n1\n"]} | 473 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the fi... | {"inputs": ["2\n><\n1 2\n", "2\n>>\n1 1\n", "2\n><\n5 5\n", "2\n>>\n1 1\n", "2\n><\n1 2\n", "2\n><\n5 5\n", "2\n><\n1 4\n", "2\n><\n5 6\n"], "outputs": ["FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n"]} | 355 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an integer k, return true if you can use all the characters in s to construct k palindrome strings or false otherwise.
Please complete the following python code precisely:
```python
class Soluti... | {"functional": "def check(candidate):\n assert candidate(s = \"annabelle\", k = 2) == True\n assert candidate(s = \"leetcode\", k = 3) == False\n assert candidate(s = \"True\", k = 4) == True\n assert candidate(s = \"yzyzyzyzyzyzyzy\", k = 2) == True\n assert candidate(s = \"cr\", k = 7) == False\n\n\nch... | 80 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants.
-----Input-----
The only line contains four integers $... | {"inputs": ["2 3 5 8\n", "1 1 2 1\n", "1 1 2 1\n", "2 3 5 8\n", "4 6 7 13\n", "4 1 5 15\n", "4 1 5 15\n", "4 2 5 15\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "4\n"]} | 248 | 122 |
coding | Solve the programming task below in a Python markdown code block.
You are given two positive integers ```a``` and ```b```.
You can perform the following operations on ```a``` so as to obtain ```b``` :
```
(a-1)/2 (if (a-1) is divisible by 2)
a/2 (if a is divisible by 2)
a*2
```
```b``` will always be a power o... | {"functional": "_inputs = [[1, 1], [2, 4], [3, 8], [4, 16], [4, 1], [1, 4]]\n_outputs = [[0], [1], [4], [2], [2], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ... | 223 | 202 |
coding | Solve the programming task below in a Python markdown code block.
When multiple master devices are connected to a single bus (https://en.wikipedia.org/wiki/System_bus), there needs to be an arbitration in order to choose which of them can have access to the bus (and 'talk' with a slave).
We implement here a very simpl... | {"functional": "_inputs = [['001000101', 9], ['000000101', 9], ['0000', 4]]\n_outputs = [['001000000'], ['000000100'], ['0000']]\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, tup... | 303 | 214 |
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 bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).
Please complete the following python code precisely:
``... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == [[15,7],[9,20],[3]]\n assert candidate(root = tree_node([1])) == [[1]]\n assert candidate(root = tree_node([])) == []\n\n\ncheck(Solution().levelOrderBottom)"} | 141 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Zaikia has $N$ sticks of distinct positive lengths $A_1,A_2,\dots,A_N$. For no good reason at all, he wants to know if there is a triplet of sticks which when connected end-to-end will form a non-trivial triangle. Here non-trivial refers to a triangle wi... | {"inputs": ["5\n4 2 10 3 5"], "outputs": ["YES\n5 4 3"]} | 418 | 29 |
coding | Solve the programming task below in a Python markdown code block.
We need a function ```prime_bef_aft()``` that gives the largest prime below a certain given value ```n```,
```befPrime or bef_prime``` (depending on the language),
and the smallest prime larger than this value,
```aftPrime/aft_prime``` (depending o... | {"functional": "_inputs = [[3], [4], [100], [97], [101], [120], [130]]\n_outputs = [[[2, 5]], [[3, 5]], [[97, 101]], [[89, 101]], [[97, 103]], [[113, 127]], [[127, 131]]]\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... | 275 | 241 |
coding | Solve the programming task below in a Python markdown code block.
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from 1 to n and then 3n times takes a random ... | {"inputs": ["5\n2 4 5 1 3\n"], "outputs": ["Petr\n"]} | 376 | 25 |
coding | Solve the programming task below in a Python markdown code block.
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the ... | {"inputs": ["3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n", "3\naaa\naaa\naaa\n", "3\naca\noec\nzba\n", "3\nxxx\naxa\nxax\n", "3\nxax\naxx\nxax\n", "3\nxax\naxa\nxxx\n", "3\nxax\nxxa\nxax\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 347 | 136 |
coding | Solve the programming task below in a Python markdown code block.
The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigne... | {"inputs": ["2 1\n1 0\n2 2\n3 1\n", "2 1\n1 0\n2 2\n6 1\n", "2 1\n1 0\n2 2\n3 1\n", "1 1\n3686 510\n-7485 5112\n", "1 1\n3686 4362\n-7485 5112\n", "1 1\n3686 4362\n-7485 5112\n", "3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2\n", "3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n3 2\n"], "outputs": ["No\n", "No\n", "No", "Yes\n", "Yes\n", "Yes", "... | 376 | 232 |
coding | Solve the programming task below in a Python markdown code block.
As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.
The «Two Paths» company, where Bob's brothe... | {"inputs": ["2\n2 1\n", "3\n1 3\n2 1\n", "3\n3 1\n1 2\n", "3\n2 3\n2 1\n", "3\n3 2\n1 2\n", "4\n3 2\n3 4\n1 4\n", "4\n2 3\n1 3\n2 4\n", "4\n4 2\n2 3\n2 1\n"], "outputs": ["0", "0", "0", "0\n", "0\n", "1", "1", "0"]} | 365 | 136 |
coding | Solve the programming task below in a Python markdown code block.
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourl... | {"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n-1\n", "1\n-2\n", "1\n-3\n"], "outputs": ["0\n", "1\n2001 ", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]} | 533 | 99 |
coding | Solve the programming task below in a Python markdown code block.
You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars) and then return the first value.
The returned value must be a string, and have `"***"` between each of its letters.
You ... | {"functional": "_inputs = [[['bitcoin', 'take', 'over', 'the', 'world', 'maybe', 'who', 'knows', 'perhaps']], [['turns', 'out', 'random', 'test', 'cases', 'are', 'easier', 'than', 'writing', 'out', 'basic', 'ones']], [['lets', 'talk', 'about', 'javascript', 'the', 'best', 'language']], [['i', 'want', 'to', 'travel', 't... | 101 | 344 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.
A continuous increasing subsequence is defined... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,4,7]) == 3\n assert candidate(nums = [2,2,2,2,2]) == 1\n\n\ncheck(Solution().findLengthOfLCIS)"} | 146 | 62 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.