task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes.
Given an a... | {"functional": "def check(candidate):\n assert candidate(n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]) == [False,True]\n assert candidate(n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]) == [True,False]\n\n\ncheck(Solution().distanceLimited... | 207 | 140 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted.
Return the number of ways to color the grid with n... | {"functional": "def check(candidate):\n assert candidate(m = 1, n = 1) == 3\n assert candidate(m = 1, n = 2) == 6\n assert candidate(m = 5, n = 5) == 580986\n\n\ncheck(Solution().colorTheGrid)"} | 130 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
To... | {"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n2 1\n", "2\n1 3\n", "2\n0 1\n", "2\n0 2\n", "2\n0 4\n", "2\n0 7\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 390 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to pla... | {"inputs": ["1 4\n", "2 2\n", "3 2\n", "2 1\n", "5 3\n", "5 2\n", "8 5\n", "1 3\n"], "outputs": ["3B\n", "Impossible\n", "1A1B\n", "1A\n", "1A1B1A\n", "2A1B\n", "1A1B1A1B\n", "2B\n"]} | 671 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$.
Chef expects $N$ customers to come buy s... | {"inputs": ["1\n5 3\n1 2 3\n2 6 3\n2 10 7\n2 50 3\n1 10 5\n1 7 4"], "outputs": ["33\n2 2 3 1 3"]} | 660 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Today s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is ... | {"inputs": ["2 33\n2 5 1 2 14\n1 3 11\n", "2 33\n2 1 3 10 3\n1 11 3\n", "2 6\n3 1 2 2 1 1 2\n3 2 1 1 2 2 1\n", "2 5\n3 2 1 1 1 2 1\n3 1 1 2 1 1 2\n", "2 5\n3 2 1 1 1 2 1\n3 1 2 2 1 1 1\n", "2 166755\n2 733 187 362 82\n3 813 147 565 57 557 27\n", "5 33\n2 1 3 3 10\n1 11 3\n2 5 3 3 6\n2 3 1 10 3\n2 6 3 3 5\n", "3 228385\... | 575 | 382 |
coding | Solve the programming task below in a Python markdown code block.
A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting
transmission errors, validating document contents, and... | {"functional": "_inputs = [['ACM'], ['MID CENTRAL'], ['BBC'], ['???'], ['axg '], ['234 234 WEF ASDF AAA 554211 ???? '], ['A C M'], ['ABCDEFGHIJKLMNOPQRSTUVWXYZ'], ['A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'], ['ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ... | 333 | 460 |
coding | Solve the programming task below in a Python markdown code block.
## The Riddle
The King of a small country invites 1000 senators to his annual party. As a tradition, each senator brings the King a bottle of wine. Soon after, the Queen discovers that one of the senators is trying to assassinate the King by giving him ... | {"functional": "_inputs = [[[0]], [[1]], [[2]], [[3]], [[4]], [[5]], [[6]], [[7]], [[8]], [[9]], [[3, 5, 6, 7, 8, 9]], [[0, 3, 5, 4, 9, 8]], [[0, 1, 9, 3, 5]], [[0, 1, 2, 3, 4, 6]], [[0, 1, 3, 4]]]\n_outputs = [[1], [2], [4], [8], [16], [32], [64], [128], [256], [512], [1000], [825], [555], [95], [27]]\nimport math\nde... | 304 | 321 |
coding | Solve the programming task below in a Python markdown code block.
Format any integer provided into a string with "," (commas) in the correct places.
**Example:**
``` csharp
Kata.NumberFormat(100000); // return "100,000"
Kata.NumberFormat(5678545); // return "5,678,545"
Kata.NumberFormat(-420902); // return "-420,902"
... | {"functional": "_inputs = [[100000], [5678545], [-420902], [-3], [-1003]]\n_outputs = [['100,000'], ['5,678,545'], ['-420,902'], ['-3'], ['-1,003']]\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... | 489 | 221 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Today, Chef was trying to solve a problem he found pretty hard: Given an integer N and a triple of integers (a, b, c), compute the number of triples of positive integers (x, ... | {"inputs": ["3\n100 8 23 11\n497296800 1000000 1000000 1000000\n1 1 2 3"], "outputs": ["10\n97800\n1"]} | 499 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Imagine that you are given two sticks. You want to end up with three sticks of equal length. You are allowed to cut either or both of the sticks to accomplish this, and can throw away leftover pieces.
Write a function, maxlen, that takes the lengths of ... | {"functional": "_inputs = [[5, 12], [12, 5], [5, 17], [17, 5], [7, 12], [12, 7]]\n_outputs = [[5], [5], [5.666666666666667], [5.666666666666667], [6.0], [6.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... | 117 | 244 |
coding | Solve the programming task below in a Python markdown code block.
Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend ... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n2 1\n2 2\n", "2\n2 1\n2 2\n", "2\n4 1\n2 2\n", "3\n3 1\n3 2\n3 3\n", "3\n3 1\n3 2\n3 3\n", "3\n5 1\n3 2\n3 3\n"], "outputs": ["1\n", "1\n", "0\n1\n", "0\n1\n", "0\n1\n", "0\n2\n1\n", "0\n2\n1\n", "0\n2\n1\n"]} | 514 | 156 |
coding | Solve the programming task below in a Python markdown code block.
I need to save some money to buy a gift. I think I can do something like that:
First week (W0) I save nothing on Sunday, 1 on Monday, 2 on Tuesday... 6 on Saturday,
second week (W1) 2 on Monday... 7 on Saturday and so on according to the table below whe... | {"functional": "_inputs = [[5], [6], [8], [15], [100], [365], [730], [999], [2000], [4000], [5000]]\n_outputs = [[105], [168], [360], [2040], [515100], [24513765], [195308580], [499999500], [4006002000], [32024004000], [62537505000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance... | 469 | 298 |
coding | Solve the programming task below in a Python markdown code block.
A certain type of steel is graded according to the following conditions.
1. Hardness of the steel must be greater than 50
2. Carbon content of the steel must be less than 0.7
3. Tensile strength must be greater than 5600
The grades awarded are as follo... | {"inputs": ["3 \n67 0.6 5602\n45 0 4500\n0 0 0", "3 \n67 0.6 5602\n78 0 4500\n0 0 0", "3 \n53 0.6 5602\n45 0 4500\n0 0 0", "3 \n103 0.6 5602\n78 0 4500\n0 0 0", "3 \n103 0.6 5602\n78 0 4466\n0 0 0", "3 \n103 0.6 7770\n78 0 4466\n0 0 0", "3 \n53 0.6 5602\n45 0 4500\n0 0 0 \n", "3 \n103 0.6 7770\n78 -1 4466\n0 0 0"], "ou... | 349 | 340 |
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 sequence $A$ consisting of $N$ positive integers.
He is playing a game with this sequence. The goal of the game is to maximize the greatest common divisor of all... | {"inputs": ["2\n2\n1 25\n5\n27 3 15 1024 15"], "outputs": ["1\n6"]} | 384 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Sumit and Dhiraj are roommates in a hostel of NIT Jamshedpur,One day after completing there boring assignments of Artificial Intelligence, they decided to play a game as it was dhiraj,s idea to play a game so he started explaining the rules of the game t... | {"inputs": ["2\n4\n5"], "outputs": ["YES\nNO"]} | 360 | 18 |
coding | Solve the programming task below in a Python markdown code block.
Chef has provided with a sequence of integers of length $N$ arranged in an unsorted fashion.
The elements of the sequence are ordered as ${A1,A2,A3.....A'N}$
The task of the chef is to identify the highest and lowest value among the given sequence. It is... | {"inputs": ["5\n3 2 7 9 4"], "outputs": ["9 2"]} | 260 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Even if it's a really easy question, she won't be able to answer it
— Perfect Memento in Strict Sense
Cirno's perfect bitmasks classroom has just started!
Cirno gave her students a positive integer $x$. As an assignment, her students need to find the ... | {"inputs": ["1\n1073741824\n", "7\n1\n2\n5\n9\n16\n114514\n1000000\n"], "outputs": ["1073741825\n", "3\n3\n1\n1\n17\n2\n64\n"]} | 369 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Welcome
This kata is inspired by This Kata
We have a string s
We have a number n
Here is a function that takes your string, concatenates the even-indexed chars to the front, odd-indexed chars to the back.
Examples
s = "Wow Example!"
result... | {"functional": "_inputs = [['Such Wow!', 1], ['better example', 2], ['qwertyuio', 2], ['Greetings', 8], ['I like it!', 1234], ['codingisfornerdsyounerd', 10101010], ['this_test_will_hurt_you', 12345678987654321]]\n_outputs = [['Sc o!uhWw'], ['bexltept merae'], ['qtorieuwy'], ['Gtsegenri'], ['Iiei t kl!'], ['criyinodeds... | 293 | 298 |
coding | Solve the programming task below in a Python markdown code block.
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands. Each service connects two islan... | {"inputs": ["3 2\n1 2\n0 3", "3 2\n1 2\n2 3", "4 3\n1 3\n2 3\n3 4", "4 3\n1 3\n3 3\n3 4", "4 3\n1 1\n2 3\n3 4", "4 2\n1 3\n2 3\n3 4", "4 3\n1 1\n2 5\n3 4", "4 2\n1 3\n2 3\n0 4"], "outputs": ["IMPOSSIBLE\n", "POSSIBLE", "POSSIBLE\n", "POSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n"]} | 403 | 186 |
coding | Solve the programming task below in a Python markdown code block.
Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from ... | {"inputs": ["3\nAAA\nBABA\nAABBBABBBB\n", "3\nAAA\nAABA\nAABBBABBBB\n", "3\nAAB\nBABA\nAABBBABBBB\n", "3\nAAB\nBABA\nBBBBABBBAA\n", "3\nAAB\nBAAA\nBBBBABBBAA\n", "3\nAAA\nBABB\nAABBBABBBB\n", "3\nAAB\nABAB\nBBBBABBBAA\n", "3\nBAA\nBAAA\nBBBBABBBAA\n"], "outputs": ["3\n2\n0\n", "3\n2\n0\n", "1\n2\n0\n", "1\n2\n2\n", "1\... | 438 | 195 |
coding | Solve the programming task below in a Python markdown code block.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that th... | {"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n1 3\n", "1\n0 3\n", "1\n0 1\n", "1\n0 2\n", "1\n0 6\n", "1\n1 6\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "0 1\n", "0 1\n", "0 1\n", "0 1\n", "1 1\n"]} | 382 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Charlie and Johnny play a game. For every integer $\mbox{X}$ Charlie gives, Johnny has to find the smallest positive integer $\mathbf{Y}$ such that $X\times Y$ ($\mbox{X}$ multiplied by $\mathbf{Y}$) contains only 4s and 0s and starts with one or more 4s... | {"inputs": ["3\n4\n5\n80\n"], "outputs": ["2\n3\n4\n"]} | 463 | 25 |
coding | Solve the programming task below in a Python markdown code block.
William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of cryptocurrencies.
The conference has $n$ participants, ... | {"inputs": ["2 1\n1 2\n", "3 1\n2 3\n", "4 1\n2 4\n", "3 2\n1 3\n3 1\n", "4 2\n2 4\n3 4\n", "4 3\n2 1\n4 1\n1 2\n", "7 6\n1 2\n3 4\n2 4\n7 6\n6 5\n1 7\n", "10 8\n1 2\n2 3\n3 4\n1 4\n6 7\n8 9\n8 10\n1 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n2\n", "1\n2\n", "1\n2\n3\n", "1\n1\n3\n3\n3\n6\n", "1\n2\n3\n4\n5\n5\n6\n8\n... | 645 | 216 |
coding | Solve the programming task below in a Python markdown code block.
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than... | {"inputs": ["5 2 7 4\n0 1\n1 2\n0 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n0 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n0 2\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 2\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 1\n", "7 2 10 4\n1 1\n1 1\n1 4\n0 1\n", "7 3 17 4\n1 1\n1 1\n1 4\n0 1\n"], "outputs": ["4 1\n5 1\n4 1\n5 1\n", ... | 699 | 367 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. Chef wants you to handle $Q$ queries. There are two types of queries:
1 L R X: for each $i$ ($L ≤ i ≤ R$), add $(... | {"inputs": ["5 4\n1 10 3 6 5\n1 1 3 5\n2 3\n1 4 5 7\n2 5"], "outputs": ["52\n69"]} | 527 | 53 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n binary matrix grid.
Let us call a non-empty subset of rows good if the sum of each column of the subset is at most half of the length of the subset.
More formally, if the length of the ... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1,0],[0,0,0,1],[1,1,1,1]]) == [0,1]\n assert candidate(grid = [[0]]) == [0]\n assert candidate(grid = [[1,1,1],[1,1,1]]) == []\n\n\ncheck(Solution().goodSubsetofBinaryMatrix)"} | 200 | 94 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards.
Given an integer array hand where hand[i] is the va... | {"functional": "def check(candidate):\n assert candidate(hand = [1,2,3,6,2,3,4,7,8], groupSize = 3) == True\n assert candidate(hand = [1,2,3,4,5], groupSize = 4) == False\n\n\ncheck(Solution().isNStraightHand)"} | 127 | 80 |
coding | Solve the programming task below in a Python markdown code block.
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a squa... | {"inputs": ["1 1\n1\n", "2 1\n2\n", "2 1\n1\n", "2 1\n2\n", "1 1\n1\n", "2 1\n1\n", "2 2\n2 2\n", "4 2\n1 2\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n"]} | 412 | 106 |
coding | Solve the programming task below in a Python markdown code block.
The chef is trying to decode 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 ... | {"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n12\n3\n123\n45\n6\n1234\n567\n89\n10"]} | 207 | 49 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of non-empty subarrays with the leftmost element of the subarray not larger than other elements in the subarray.
A subarray is a contiguous part of an array.
Please com... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,2,5,3]) == 11\n assert candidate(nums = [3,2,1]) == 3\n assert candidate(nums = [2,2,2]) == 6\n\n\ncheck(Solution().validSubarrays)"} | 94 | 73 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the least number of perfect square numbers that sum to n.
A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For ... | {"functional": "def check(candidate):\n assert candidate(n = 12) == 3 \n assert candidate(n = 13) == 2\n\n\ncheck(Solution().numSquares)"} | 123 | 47 |
coding | Solve the programming task below in a Python markdown code block.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0.
Constrai... | {"inputs": ["3 6\n1 2 3", "3 3\n1 2 3", "3 7\n1 2 3", "3 10\n1 2 3", "3 10\n0 2 3", "3 15\n1 2 3", "3 10\n1 2 0", "6 4\n1 2 0 2 3 2"], "outputs": ["3\n", "1\n", "0", "0\n", "0\n", "0\n", "0\n", "2\n"]} | 241 | 135 |
coding | Solve the programming task below in a Python markdown code block.
You are given a N * N matrix, U. You have to choose 2 sub-matrices A and B made of only 1s of U, such that, they have at least 1 cell in common, and each matrix is not completely engulfed by the other, i.e.,
If U is of the form
and A is of the form
... | {"inputs": ["4\n0010\n0001\n1010\n1110\n"], "outputs": ["10\n"]} | 512 | 35 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp loves geometric progressions — he collects them. However, as such progressions occur very rarely, he also loves the sequences of numbers where it is enough to delete a single element to get a geometric progression.
In this task we shall define ... | {"inputs": ["1\n2\n", "1\n0\n", "1\n1\n", "1\n3\n", "1\n4\n", "1\n-1\n", "1\n-2\n", "1\n-4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 370 | 89 |
coding | Solve the programming task below in a Python markdown code block.
Each army fighting the world war Z is denoted with a word consisting any combination of 26 alphabets. An army is a match for his/her opponent if and only if his name is an anagram of his/her opponent. Your job as a programmer is to help find whether two ... | {"inputs": ["3\nman app\na b\nabcde edcba"], "outputs": ["No\nNo\nYes"]} | 236 | 27 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you should simply determine, whether a given year is a leap year or not. In case you don't know the rules, here they are:
* years divisible by 4 are leap years
* but years divisible by 100 are **not** leap years
* but years divisible by 400... | {"functional": "_inputs = [[1984], [2000], [2004], [8], [0], [1234], [1100], [1194]]\n_outputs = [[True], [True], [True], [True], [True], [False], [False], [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=t... | 139 | 215 |
coding | Solve the programming task below in a Python markdown code block.
You recently received a bag of chocolate sticks for Halloween. To prevent you from compulsively eating all the chocolate sticks in one go, your dietician devises the following fun game.
In each move, you choose one of the sticks from your bag. Then, you... | {"inputs": ["1\n6\n", "3\n1 7 24\n"], "outputs": ["10\n", "55\n"]} | 507 | 33 |
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.
You are given two arrays of integers $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$.
Let's define a transformation of the array $a$:
Choose any non-negative integer $k$ such that $0 \le k \le n$.
Choose $k$ distinct array indices $1 \le i_1 < i_2... | {"inputs": ["1\n1\n2\n1\n", "1\n1\n3\n2\n", "1\n1\n1\n2\n", "1\n1\n3\n1\n", "1\n1\n5\n4\n", "1\n1\n4\n3\n", "1\n1\n1\n0\n", "1\n1\n2\n3\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]} | 606 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied... | {"inputs": ["3\n0 1\n0 10\n0 100\n", "4\n2 1\n0 0\n1 5\n1 3\n", "4\n2 0\n0 0\n1 5\n2 3\n", "4\n2 1\n0 0\n1 5\n2 3\n", "4\n2 1\n0 0\n1 5\n4 3\n", "4\n2 1\n1 0\n1 5\n4 3\n", "4\n2 1\n1 0\n1 5\n2 3\n", "4\n2 0\n1 0\n1 5\n2 3\n"], "outputs": ["111", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "0\n"]} | 293 | 198 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
You are given a tree of $N$ nodes rooted at node $1$. Each node $u$ initially has a positive value $a_{u}$ associated with it.
You randomly choose one node i... | {"inputs": ["3\n1\n1\n4\n1 2\n2 3\n2 4\n1 1 1 2\n7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n1 2 3 4 1 2 1\n"], "outputs": ["1\n4\n14\n"]} | 716 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Everybody is worried about Rakesh as the boy does not have much knowledge about the real world. He can not go from one place to another on his own. It's high time he learned to explore the city. He is going to a relative's house situated on the other sid... | {"inputs": ["2\n20 20\n4 5\n13\nLLUUUUURRRRRR\n10 10\n3 4\n7\nUDUDDRR"], "outputs": ["Case 1: REACHED\nCase 2: DANGER"]} | 744 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$. Each character is either 0 or 1.
You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100... | {"inputs": ["2\n01010\n0\n", "2\n01010\n0\n", "2\n01110\n0\n", "2\n01011\n1\n", "2\n10011\n1\n", "2\n01110\n1\n", "2\n01111\n1\n", "2\n11011\n1\n"], "outputs": ["1\n0\n", "1\n0\n", "0\n0\n", "1\n0\n", "2\n0\n", "0\n0\n", "0\n0\n", "1\n0\n"]} | 356 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Given an array, return the difference between the count of even numbers and the count of odd numbers. `0` will be considered an even number.
```
For example:
solve([0,1,2,3]) = 0 because there are two even numbers and two odd numbers. Even - Odd = 2 - ... | {"functional": "_inputs = [[[0, 1, 2, 3]], [[0, 1, 2, 3, 'a', 'b']], [[0, 15, 'z', 16, 'm', 13, 14, 'c', 9, 10, 13, 'u', 4, 3]], [[13, 6, 8, 15, 4, 8, 13]], [[1, 'a', 17, 8, 'e', 3, 'i', 12, 1]], [[5, 15, 16, 10, 6, 4, 16, 't', 13, 'n', 14, 'k', 'n', 0, 'q', 'd', 7, 9]]]\n_outputs = [[0], [0], [0], [1], [-2], [2]]\nimp... | 307 | 357 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth.
Return the number of '*'... | {"functional": "def check(candidate):\n assert candidate(s = \"l|*e*et|c**o|*de|\") == 2\n assert candidate(s = \"iamprogrammer\") == 0\n assert candidate(s = \"yo|uar|e**|b|e***au|tifu|l\") == 5\n\n\ncheck(Solution().countAsterisks)"} | 131 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Rng is going to a festival.
The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.
Here, assume that the name of "a festival of s" is... | {"inputs": ["CODEFESTIVAM", "CPDEFESTIVAM", "BPDEFDSTIVBM", "MBVITSDFEDPB", "MBWITSDFEDPB", "BPCEFDSTIWBM", "CPCEFDSTJWBM", "WPCEFDSTJCAM"], "outputs": ["CODE\n", "CPDE\n", "BPDE\n", "MBVI\n", "MBWI\n", "BPCE\n", "CPCE\n", "WPCE\n"]} | 228 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
On the occasion of the birthday, Chef bought a large circular cake and decorated it with k candles placed equally spaced around the circumference of the cake, i.e. the leng... | {"inputs": ["3\n6 1 3\n6 1 4\n10 1 5"], "outputs": ["1\n0\n3"]} | 407 | 35 |
coding | Solve the programming task below in a Python markdown code block.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
- For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
- There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the proble... | {"inputs": ["4 1 3", "7 3 4", "9 2 4", "3 2 3", "5 1 4", "4 1 2", "8 4 5", "6 1 3"], "outputs": ["4\n2\n0\n", "6\n5\n4\n3\n2\n1\n", "9\n8\n6\n5\n4\n3\n1\n0\n", "2\n1\n", "5\n4\n1\n0\n", "3\n2\n1\n", "7\n6\n5\n4\n3\n2\n1\n", "6\n4\n3\n2\n0\n"]} | 463 | 154 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a bookstore owner that has a store open for n minutes. You are given an integer array customers of length n where customers[i] is the number of the customers that enter the store at the start of the ith minut... | {"functional": "def check(candidate):\n assert candidate(customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3) == 16\n assert candidate(customers = [1], grumpy = [0], minutes = 1) == 1\n\n\ncheck(Solution().maxSatisfied)"} | 225 | 97 |
coding | Solve the programming task below in a Python markdown code block.
Do you have in mind the good old TicTacToe?
Assuming that you get all the data in one array, you put a space around each value, `|` as a columns separator and multiple `-` as rows separator, with something like `["O", "X", " ", " ", "X", " ", "X", "O", ... | {"functional": "_inputs = [[['O', 'X', 'X', 'O'], 2], [['O', 'X', ' ', ' ', 'X', ' ', 'X', 'O', ' '], 3], [['O', 'X', ' ', ' ', 'X', ' ', 'X', 'O', ' ', 'O'], 5], [['O', 'X', ' ', ' ', 'X', ' ', 'X', 'O', ' ', 'O'], 2], [['1', '2', '3', '4', '5', '1', '2', '3', '4', '5', '1', '2', '3', '4', '5', '1', '2', '3', '4', '5'... | 299 | 602 |
coding | Solve the programming task below in a Python markdown code block.
In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (blank, newl... | {"inputs": ["2\nThis is a sample piece of text to illustrate this\nproblem."], "outputs": ["10\na\nillustrate\nis\nof\npiece\nproblem\nsample\ntext\nthis\nto"]} | 374 | 50 |
coding | Solve the programming task below in a Python markdown code block.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ ... | {"inputs": ["40", "41", "000", "010", "110", "111", "011", "581"], "outputs": ["3\n", "4\n", "0\n", "1\n", "5\n", "6\n", "2\n", "25\n"]} | 136 | 77 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.
You can place cuboid i on cuboid j if widthi <= w... | {"functional": "def check(candidate):\n assert candidate(cuboids = [[50,45,20],[95,37,53],[45,23,12]]) == 190\n assert candidate(cuboids = [[38,25,45],[76,35,3]]) == 76\n assert candidate(cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]) == 102\n\n\ncheck(Solution().maxHeight)"} | 154 | 152 |
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.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Chef is participating in an ICPC regional contest, in which there is a total of $N$ problems (numbered $1$ through $N$) with varying difficulties. For each va... | {"inputs": ["3\n7\n1 2 3 4 5 7 6\n8\n8 7 6 5 4 3 2 1\n9\n7 4 3 5 6 1 8 2 9"], "outputs": ["7\n8\n8"]} | 548 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Given an array $a$ of length $n$, you can do at most $k$ operations of the following type on it:
choose $2$ different elements in the array, add $1$ to the first, and subtract $1$ from the second. However, all the elements of $a$ have to remain non-nega... | {"inputs": ["1\n3 1\n1 8 9\n", "1\n3 1\n3 1 9\n", "1\n3 1\n1 0 1\n", "2\n3 1\n3 1 4\n2 10\n1 0\n"], "outputs": ["0 8 10 \n", "2 1 10 \n", "0 0 2 \n", "2 1 5 \n0 1 \n"]} | 438 | 114 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.
Please complete the following python code precisely:
```python
class Solution:
def findDiagonalOrder(sel... | {"functional": "def check(candidate):\n assert candidate(nums = [[1,2,3],[4,5,6],[7,8,9]]) == [1,4,2,7,5,3,8,6,9]\n assert candidate(nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]) == [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]\n assert candidate(nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]) == [1,4,2,5,... | 76 | 243 |
coding | Solve the programming task below in a Python markdown code block.
Chef recently realized that he needs a haircut, and went to his favorite hair salon. At the salon, he found N customers waiting for their haircuts. From his past experience, Chef knows that the salon takes M minutes per customer. Only one person can get ... | {"inputs": ["2\n2 15\n0 15\n"], "outputs": ["30\n0\n"]} | 349 | 27 |
coding | Solve the programming task below in a Python markdown code block.
Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid,
B potions of blue liquid, and G potions of green liquid.
-
The red liquid potions have liquid amounts given ... | {"inputs": ["3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n2\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8", "3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n3\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8", "3\n1 1 1 1\n1\n4\n5\n1 1 1 1\n3\n4\n6\n3 2 2 2\n2 2 3\n2 7\n6 8", "3\n1 1 1 1\n1\n4\n5\n1 1 1 2\n3\n4\n6\n3 2 2 2\n2 2 3\n2 7\n6 8", "3\n2 1 1 1\n1\n4\n5\n1 1 1 2\n3\n4\n6\n... | 591 | 493 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays nums1 and nums2 of length n, count the pairs of indices (i, j) such that i < j and nums1[i] + nums1[j] > nums2[i] + nums2[j].
Return the number of pairs satisfying the condition.
Please comp... | {"functional": "def check(candidate):\n assert candidate(nums1 = [2,1,2,1], nums2 = [1,2,1,2]) == 1\n assert candidate(nums1 = [1,10,6,2], nums2 = [1,4,1,5]) == 5\n\n\ncheck(Solution().countPairs)"} | 112 | 82 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array restaurants where restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters.
The veganFriendly filter will be either true (meaning you ... | {"functional": "def check(candidate):\n assert candidate(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10) == [3,1,5] \n assert candidate(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganF... | 227 | 301 |
coding | Solve the programming task below in a Python markdown code block.
Complete the function that returns an array of length `n`, starting with the given number `x` and the squares of the previous number. If `n` is negative or zero, return an empty array/list.
## Examples
```
2, 5 --> [2, 4, 16, 256, 65536]
3, 3 --> [... | {"functional": "_inputs = [[2, 5], [3, 3], [5, 3], [10, 4], [2, 0], [2, -4]]\n_outputs = [[[2, 4, 16, 256, 65536]], [[3, 9, 81]], [[5, 25, 625]], [[10, 100, 10000, 100000000]], [[]], [[]]]\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... | 131 | 260 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied:
The greatest common divisor of an... | {"functional": "def check(candidate):\n assert candidate(n = 4) == 184\n assert candidate(n = 2) == 22\n\n\ncheck(Solution().distinctSequences)"} | 188 | 47 |
coding | Solve the programming task below in a Python markdown code block.
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic perform... | {"inputs": ["1\n5\n3\n", "1\n1\n2\n", "1\n1\n1\n", "1\n1\n1\n", "1\n1\n2\n", "1\n1\n3\n", "1\n2\n3\n", "1\n2\n4\n"], "outputs": ["-1\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 505 | 103 |
coding | Solve the programming task below in a Python markdown code block.
A format for expressing an ordered list of integers is to use a comma separated list of either
* individual integers
* or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. The range includes ... | {"functional": "_inputs = [[[-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]], [[-3, -2, -1, 2, 10, 15, 16, 18, 19, 20]], [[1, 2, 3, 4, 5]]]\n_outputs = [['-6,-3-1,3-5,7-11,14,15,17-20'], ['-3--1,2,10,15,16,18-20'], ['1-5']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float... | 379 | 324 |
coding | Solve the programming task below in a Python markdown code block.
Codex is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into sec... | {"inputs": ["19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19"], "outputs": ["4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916"]} | 367 | 169 |
coding | Solve the programming task below in a Python markdown code block.
Two people are playing a game with a string $s$, consisting of lowercase latin letters.
On a player's turn, he should choose two consecutive equal letters in the string and delete them.
For example, if the string is equal to "xaax" than there is only... | {"inputs": ["a\n", "a\n", "`\n", "_\n", "aa\n", "aa\n", "`a\n", "a`\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n"]} | 266 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth $A$ billion dollars and have no liabilities. He aims t... | {"inputs": ["3\n100 200 10\n111 199 11\n190 200 10"], "outputs": ["10\n8\n1"]} | 552 | 50 |
coding | Solve the programming task below in a Python markdown code block.
In a class of N students, a class test was held. The i^{th} student scored A_{i} marks. It is also known that the scores of all students were distinct.
A student passes the test if their score is strictly greater than the passing mark.
Given that exact... | {"inputs": ["3\n2 2\n5 1\n4 1\n5 1 7 4\n4 3\n15 70 100 31\n"], "outputs": ["0\n6\n30\n"]} | 486 | 56 |
coding | Solve the programming task below in a Python markdown code block.
DestinyLand is a really fun place for kids. It is composed of N islands, numbered from 1 to N. The company is planning to divide these N islands into exactly M area, such that, each island will belong to one of the M areas, and each area will contain at ... | {"inputs": ["3\n3 2 1 1000003\n3 1 2 1234567891\n3 1 1 314159\n"], "outputs": ["6\n9\n6\n"]} | 388 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You have a statistic of price changes for one product represented as an array of $n$ positive integers $p_0, p_1, \dots, p_{n - 1}$, where $p_0$ is the initial price of the product and $p_i$ is how the price was increased during the $i$-th month.
Using ... | {"inputs": ["1\n3 3\n7 2 3\n", "1\n3 3\n7 2 6\n", "1\n3 3\n97 2 2\n", "1\n3 3\n97 2 2\n", "1\n3 3\n17 2 2\n", "1\n3 2\n25 2 2\n", "1\n3 1\n94 2 2\n", "1\n3 2\n25 2 4\n"], "outputs": ["91\n", "191\n", "0\n", "0\n", "50\n", "75\n", "106\n", "173\n"]} | 690 | 165 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Russian here
Chef has a special affection for sets of binary strings of equal length which have same numbers of 1's. Given three integers n, k and m, your task is to find the the lexicographically m^{th} smallest string amon... | {"inputs": ["1\n3 2 2", "1\n3 2 3", "1\n3 3 3", "1\n6 3 3", "1\n6 4 3", "1\n6 4 6", "1\n3 1 3", "1\n9 3 3"], "outputs": ["101", "110\n", "-1\n", "001101\n", "011011\n", "100111\n", "100\n", "000001101\n"]} | 323 | 138 |
coding | Solve the programming task below in a Python markdown code block.
For a given two numbers your mission is to derive a function that evaluates whether two given numbers are **abundant**, **deficient** or **perfect** and whether together they are **amicable**.
### Abundant Numbers
An abundant number or excessive numbe... | {"functional": "_inputs = [[220, 284], [220, 280], [1184, 1210], [220221, 282224], [10744, 10856], [299920, 9284], [999220, 2849], [139815, 122265], [496, 28], [8128, 8128]]\n_outputs = [['abundant deficient amicable'], ['abundant abundant not amicable'], ['abundant deficient amicable'], ['deficient abundant not amicab... | 741 | 363 |
coding | Solve the programming task below in a Python markdown code block.
The integers 14 and 15, are contiguous (1 the difference between them, obvious) and have the same number of divisors.
```python
14 ----> 1, 2, 7, 14 (4 divisors)
15 ----> 1, 3, 5, 15 (4 divisors)
```
The next pair of contiguous integers with this propert... | {"functional": "_inputs = [[1, 50], [3, 100], [3, 200], [6, 350], [6, 1000], [7, 1500], [7, 2500], [7, 3000], [9, 4000], [9, 5000], [11, 5000]]\n_outputs = [[8], [7], [18], [86], [214], [189], [309], [366], [487], [622], [567]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | 488 | 293 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to create function```isDivideBy``` (or ```is_divide_by```) to check if an integer number is divisible by each out of two arguments.
A few cases:
```
(-12, 2, -6) -> true
(-12, 2, -5) -> false
(45, 1, 6) -> false
(45, 5, 15) -> ... | {"functional": "_inputs = [[8, 2, 4], [12, -3, 4], [8, 3, 4], [48, 2, -5], [-100, -25, 10], [10000, 5, -3], [4, 4, 2], [5, 2, 3], [-96, 25, 17], [33, 1, 33]]\n_outputs = [[True], [True], [False], [False], [True], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | 174 | 285 |
coding | Solve the programming task below in a Python markdown code block.
# Introduction:
Reversi is a game usually played by 2 people on a 8x8 board.
Here we're only going to consider a single 8x1 row.
Players take turns placing pieces, which are black on one side and white on the
other, onto the board with their colour fac... | {"functional": "_inputs = [[[]], [[0]], [[0, 1]], [[0, 7, 4]], [[3]], [[3, 4]], [[3, 4, 5]], [[2, 1, 0]], [[0, 1, 4, 3, 2]], [[0, 1, 7, 2, 3]], [[3, 2, 7, 1, 0]], [[3, 4, 5, 6, 0, 2]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[7, 0, 1]], [[0, 7, 6]], [[1, 0, 2, 3, 4, 5, 6, 7]], [[5, 1, 3, 4, 6]], [[1, 7, 0, 5, 6, 4]]]\n_outputs = ... | 360 | 456 |
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.
There is a house with 4 levels.
In that house there is an elevator.
You can program this elevator to go up or down,
depending on what button the user touches inside the elevator.
Valid levels must be only these numbers: `0,1,2,3`
Valid buttons must be ... | {"functional": "_inputs = [[0, '0'], [0, '1'], [0, '2'], [0, '3'], [1, '0'], [1, '1'], [1, '2'], [1, '3'], [2, '0'], [2, '1'], [2, '2'], [2, '3'], [3, '0'], [3, '1'], [3, '2'], [3, '3'], [0, '4'], [0, None], [1, '4'], [1, None], [2, '4'], [2, None], [3, '4'], [3, None], [4, '2'], [None, '2'], [[], '2'], [3, {}], ['2', ... | 400 | 432 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Devu is learning Combinatorics in his college. He find it very interesting to calculate number of ways of going to point (c,d) from point (a,b) in co-ordinate plane. We can take horizontal and ... | {"inputs": ["2\n2 2\n4 5"], "outputs": ["8\n236"]} | 520 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.
Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is ve... | {"inputs": ["1 1\n1 0\n", "1 2\n1 0\n", "3 3\n3 0\n1 1\n2 2\n", "3 3\n2 0\n1 1\n3 2\n", "3 3\n3 0\n1 1\n2 4\n", "3 3\n2 0\n1 2\n3 2\n", "3 3\n2 0\n1 4\n3 2\n", "3 2\n2 1\n2 2.0\n1 3.100\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 638 | 172 |
coding | Solve the programming task below in a Python markdown code block.
An array B of length M consisting of only distinct elements is said to be *good* if the following condition holds:
Let i be the index of the maximum element of B.
Then, B[1,i] must be in ascending order, i.e, B_{1} < B_{2} < B_{3} < \ldots < B_{i}.
For ... | {"inputs": ["2\n4\n2 1 4 3\n5\n1 2 3 4 5\n"], "outputs": ["6\n16\n"]} | 615 | 39 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the lon... | {"functional": "def check(candidate):\n assert candidate(s = \"abpcplea\", dictionary = [\"ale\",\"apple\",\"monkey\",\"plea\"]) == \"apple\"\n assert candidate(s = \"abpcplea\", dictionary = [\"a\",\"b\",\"c\"]) == \"a\"\n\n\ncheck(Solution().findLongestWord)"} | 117 | 78 |
coding | Solve the programming task below in a Python markdown code block.
The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height a_{i} meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: fo... | {"inputs": ["1 99\n1\n", "1 99\n1\n", "1 65\n1\n", "1 99\n2\n", "3 1\n1 1 2\n", "3 1\n1 1 2\n", "3 1\n2 1 2\n", "3 1\n1 0 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "2\n+ 2 1\n+ 3 1\n", "2\n+ 2 1\n+ 3 1\n", "2\n+ 2 2\n+ 3 2\n", "2\n+ 2 2\n+ 3 1\n"]} | 464 | 170 |
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. You can rearrange the elements of nums to any order (including the given order).
Let prefix be the array containing the prefix sums of nums after rearranging it. In other ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,-1,0,1,-3,3,-3]) == 6\n assert candidate(nums = [-2,-3,0]) == 0\n\n\ncheck(Solution().maxScore)"} | 141 | 59 |
coding | Solve the programming task below in a Python markdown code block.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th c... | {"inputs": ["1", "0", "2", "0", "1", "2", "10", "11"], "outputs": ["2\n", "1\n", "1\n", "1\n", "2\n", "1\n", "4\n", "6\n"]} | 364 | 64 |
coding | Solve the programming task below in a Python markdown code block.
A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and ... | {"inputs": ["2 1\n1 1\n", "1 1\n1 1\n", "2 2\n1 1\n1 2\n", "20 3\n1 1\n1 2\n1 3\n", "38 3\n1 1\n1 2\n1 3\n", "10 3\n1 1\n1 2\n1 3\n", "2 4\n2 1\n1 2\n2 2\n1 1\n", "8 4\n4 3\n8 8\n6 5\n1 6\n"], "outputs": ["1 0 0 0 0 0 0 0 0\n", "1 0 0 0 0 0 0 0 0\n", "0 2 0 0 0 0 0 0 0\n", "0 2 1 0 0 0 0 0 0\n", "0 2 1 0 0 0 0 0 0\n", ... | 458 | 301 |
coding | Solve the programming task below in a Python markdown code block.
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over.
Find the number... | {"inputs": ["1 10\n3", "1 10\n9", "1 10\n17", "2 0\n0 0", "3 4\n1 2 3", "4 100000\n101000 100000 100000 100000", "4 101000\n101000 100000 100100 101000", "4 110000\n101000 100000 100000 100000"], "outputs": ["0\n", "0", "1\n", "1", "5", "665683269\n", "744244119\n", "741473440\n"]} | 324 | 218 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $500000$ integers (numbered from $1$ to $500000$). Initially all elements of $a$ are zero.
You have to process two types of queries to this array: $1$ $x$ $y$ — increase $a_x$ by $y$; $2$ $x$ $y$ — compute $\su... | {"inputs": ["2\n1 3213 321\n2 3213 0\n", "2\n1 3213 321\n2 3213 0\n", "2\n1 3213 321\n2 6100 0\n", "2\n1 3213 321\n2 2396 0\n", "2\n1 4824 321\n2 6100 0\n", "2\n1 4656 321\n2 2396 0\n", "2\n1 4824 528\n2 6100 0\n", "2\n1 4656 321\n2 2396 1\n"], "outputs": ["321\n", "321\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 427 | 234 |
coding | Solve the programming task below in a Python markdown code block.
You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix.
Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring cell to th... | {"inputs": ["1 0\nz\n", "1 1\ng\n", "1 0\na\n", "1 1\nz\n", "1 0\ng\n", "1 0\ny\n", "1 1\nf\n", "1 2\nf\n"], "outputs": ["z\n", "a\n", "a\n", "a\n", "g\n", "y", "a", "a"]} | 458 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Dhote and Shweta went on a tour by plane for the first time.Dhote was surprised by the conveyor belt at the airport.As Shweta was getting bored Dhote had an idea of playing a game with her.He asked Shweta to count the number of bags whose individual wei... | {"inputs": ["1\n4\n1 2 3 4"], "outputs": ["3"]} | 291 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - ... | {"inputs": ["0 0\n", "1 0\n", "0 1\n", "0 6\n", "1 1\n", "0 6\n", "1 1\n", "2 1\n"], "outputs": ["0\n", "0\n", "2\n", "22\n", "1\n", "22\n", "1\n", "5\n"]} | 318 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).
You may perform the following operations until both a and s are empty:
Take the first element of a, push it into s and remove it from a (if a is not... | {"inputs": ["5 1\n3\n", "2 1\n1\n", "2 1\n1\n", "9 1\n6\n", "7 1\n1\n", "5 1\n3\n", "10 1\n6\n", "10 1\n1\n"], "outputs": ["3 2 1 5 4 ", "1 2 ", "1 2 ", "6 5 4 3 2 1 9 8 7 ", "1 7 6 5 4 3 2 ", "3 2 1 5 4 ", "6 5 4 3 2 1 10 9 8 7 ", "1 10 9 8 7 6 5 4 3 2 "]} | 682 | 183 |
coding | Solve the programming task below in a Python markdown code block.
Remainder of Big Integers
Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the remainder in a line.
Constraints
* $0 \leq A, B \... | {"inputs": ["5 3", "9 3", "9 6", "4 3", "5 7", "6 7", "9 1", "5 1"], "outputs": ["2\n", "0\n", "3\n", "1\n", "5\n", "6\n", "0\n", "0\n"]} | 153 | 78 |
coding | Solve the programming task below in a Python markdown code block.
*** Nova polynomial from roots***
This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8... | {"functional": "_inputs = [[[4]], [[0, 0, 0, 0]], [[1, 1, 1, 1]], [[-1, 1, 2, -2]], [[]]]\n_outputs = [[[-4, 1]], [[0, 0, 0, 0, 1]], [[1, -4, 6, -4, 1]], [[4, 0, -5, 0, 1]], [[1]]]\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_to... | 468 | 247 |
coding | Solve the programming task below in a Python markdown code block.
You are given a list of $N$ numbers $a_1,a_2,\ldots,a_n$. For each element at position $\boldsymbol{i}$ ($1\leq i\leq N$), we define $\text{Left}(i)$ and $\textit{Right}(i)$ as:
$\text{Left}(i)$ = closest index j such that j < i and $a_j>a_i$. If no su... | {"inputs": ["5\n5 4 3 4 5\n"], "outputs": ["8\n"]} | 405 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Lucy loves to travel. Luckily she is a renowned computer scientist and gets to travel to international conferences using her department's budget.
Each year, Society for Exciting Computer Science Research (SECSR) organizes several conferences around the ... | {"functional": "_inputs = [[[], ['Philadelphia', 'Osaka', 'Tokyo', 'Melbourne']], [[], ['Brussels', 'Madrid', 'London']], [[], ['Sydney', 'Tokyo']], [['London', 'Berlin', 'Mexico City', 'Melbourne', 'Buenos Aires', 'Hong Kong', 'Madrid', 'Paris'], ['Berlin', 'Melbourne']], [['Beijing', 'Johannesburg', 'Sydney', 'Philad... | 311 | 519 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.
If node i has no l... | {"functional": "def check(candidate):\n assert candidate(n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]) == True\n assert candidate(n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]) == False\n assert candidate(n = 2, leftChild = [1,0], rightChild = [-1,-1]) == False\n\n\ncheck(Solution().val... | 150 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
There is a haunted town called HauntedLand. The structure of HauntedLand can be thought of as a grid of size n * m. There is a house in each cell of the grid. Some people hav... | {"inputs": ["2\n2 2\n*.\n..\n3 4\n.*..\n***.\n.*..", "2\n2 2\n*.\n..\n3 4\n.*..\n***.\n.*.."], "outputs": ["1\n2", "1\n2"]} | 581 | 66 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
Split the array into one or more disjoint subarrays such that:
Each element of the array belongs to exactly one subarray, and
The GCD of the elements of ea... | {"functional": "def check(candidate):\n assert candidate(nums = [12,6,3,14,8]) == 2\n assert candidate(nums = [4,12,6,14]) == 1\n\n\ncheck(Solution().minimumSplits)"} | 156 | 62 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.