problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000)
return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both)
```
Example:
countOnes 4 7 should return 8, because:
4(... | {"functional": "_inputs = [[1, 1000000000]]\n_outputs = [[14846928141]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | coding | 227 |
Solve the programming task below in a Python markdown code block.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group o... | {"inputs": ["1\n0\n", "0\n0\n", "0\n1\n", "1\n1\n", "0\n2\n", "2\n5\n", "1\n00\n", "0\n01\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "5\n"]} | coding | 272 |
Solve the programming task below in a Python markdown code block.
You are given an integer N.
Find a permutation P = [P_{1}, P_{2}, \ldots, P_{N}] of the integers \{1, 2, \ldots, N\} such that sum of averages of all consecutive triplets is minimized, i.e.
\sum_{i=1}^{N-2} \frac{P_{i} + P_{i+1} + P_{i+2}}{3}
is mini... | {"inputs": ["2\n4\n3\n"], "outputs": ["3 2 1 4\n3 2 1"]} | coding | 465 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time.
You are given a string keysPressed of length n, where keysPressed[i] was the ith key pressed in the testing sequence, and... | {"functional": "def check(candidate):\n assert candidate(releaseTimes = [9,29,49,50], keysPressed = \"cbcd\") == \"c\"\n assert candidate(releaseTimes = [12,23,36,46,62], keysPressed = \"spuda\") == \"a\"\n\n\ncheck(Solution().slowestKey)"} | coding | 281 |
Solve the programming task below in a Python markdown code block.
Two coordinates (a1, a2) and (b1, b2) on a two-dimensional grid of r × c are given. The cost of moving from a cell (e, f) to one of the cells (e + 1, f), (e-1, f), (e, f + 1), (e, f-1) is 1. And. You can also move between (e, c-1) and (e, 0), and between... | {"inputs": ["4 1 0 0 1 1", "4 4 1 0 3 3", "2 3 0 0 1 1", "2 1 0 0 1 1", "4 7 0 0 1 2", "4 4 0 0 1 1", "4 4 0 0 3 3", "2 3 0 0 1 2"], "outputs": ["1\n", "6\n", "4\n", "2\n", "3\n", "2", "2", "4"]} | coding | 335 |
Solve the programming task below in a Python markdown code block.
The SRA company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of... | {"inputs": ["6 4\n100 20 40 20 50 50"], "outputs": ["40"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
During Quarantine Time Chef is at home and he was quite confused about what to cook so, he went to his son and asked about what would he prefer to have? He replied, cakes.
Now, chef cook $N$ number of cake and number of layers for every cake is different... | {"inputs": ["1\n3\n2 3 5"], "outputs": ["2220"]} | coding | 420 |
Solve the programming task below in a Python markdown code block.
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's ... | {"inputs": ["3\nab\nbb\ncd\n", "3\nbc\ncb\ndb\n", "3\nab\nbb\nbd\n", "3\nab\ncb\nbd\n", "3\nba\ncb\nbd\n", "3\nab\ncb\ndb\n", "3\nbb\ncb\nbd\n", "3\nbb\nbc\nbd\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 536 |
Solve the programming task below in a Python markdown code block.
Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P ≤ 10000
* The input consists of alphabetical characters and digits
In... | {"inputs": ["yzyz\nyz", "xzyz\nyz", "zyzy\nyz", "xyzz\nyz", "aaabaa\naa", "aabbaa\naa", "aabaab\naa", "aababb\naa"], "outputs": ["0\n2\n", "2\n", "1\n", "1", "0\n1\n4\n", "0\n4\n", "0\n3\n", "0\n"]} | coding | 168 |
Solve the programming task below in a Python markdown code block.
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not.
Given a string S, determine whether S is a Hitachi string.
Constraints
* The length of S is ... | {"inputs": ["ah", "ih", "hb", "hh", "bh", "gi", "gb", "hg"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 164 |
Solve the programming task below in a Python markdown code block.
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for... | {"inputs": ["1 1\n2 1\n", "1 2\n2 1\n", "1 2\n3 1\n", "1 2\n3 2\n", "1 1\n2 1\n", "1 29\n2 8\n", "1 1\n1 10\n", "1 2\n2 10\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "8\n", "10\n", "10\n"]} | coding | 383 |
Solve the programming task below in a Python markdown code block.
Problem
There are $ N $ streetlights on a two-dimensional square of $ W \ times H $.
Gaccho wants to start with $ (1,1) $ and go to $ (W, H) $.
Gaccho is afraid of dark places, so he only wants to walk in the squares that are brightened by the streetlig... | {"inputs": ["8 6 1\n6 5", "8 6 1\n6 8", "1 1 1\n1 1", "8 10 1\n6 6", "24 4 1\n6 2", "8 10 1\n6 8", "10 3 1\n6 2", "8 10 1\n6 5"], "outputs": ["9\n", "12\n", "0", "10\n", "20\n", "12\n", "6\n", "9\n"]} | coding | 571 |
Solve the programming task below in a Python markdown code block.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
L... | {"inputs": ["1\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n"], "outputs": ["1\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n"]} | coding | 316 |
Solve the programming task below in a Python markdown code block.
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.
Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachach... | {"inputs": ["0 1 4", "9 2 9", "0 0 4", "3 2 9", "0 2 0", "0 0 0", "2 2 9", "3 1 4"], "outputs": ["3\n", "11\n", "1\n", "8\n", "2\n", "0\n", "7\n", "5"]} | coding | 220 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Consider a sequence $A_{1}, A_{2}, \ldots, A_{N}$, where initially, $A_{i} = i$ for each valid $i$. You may perform any number of operations on this ... | {"inputs": ["2\n3\n1 2 2\n4\n1 2 3 2"], "outputs": ["NO\nYES"]} | coding | 567 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary string s, you can split s into 3 non-empty strings s1, s2, and s3 where s1 + s2 + s3 = s.
Return the number of ways s can be split such that the number of ones is the same in s1, s2, and s3. Since the a... | {"functional": "def check(candidate):\n assert candidate(s = \"10101\") == 4\n assert candidate(s = \"1001\") == 0\n assert candidate(s = \"0000\") == 3\n assert candidate(s = \"100100010100110\") == 12\n\n\ncheck(Solution().numWays)"} | coding | 133 |
Solve the programming task below in a Python markdown code block.
Shil likes Round numbers very much . A number is called Round number if its non-negative and its first and last digits are same. For example 0 , 3 , 343 and 50005 are round numbers whereas 1000 is not a round number. Shil has an array A1 , A2 .. AN... | {"inputs": ["10 10\n999999999999980689 -999999999999985424 999999999999997259 -999999999999980547 999999999999980429 999999999999985309 999999999999988309 -999999999999978240 999999999999973229 -999999999999986703 \n2 9 999999999999974279\n2 3 999999999999975369\n2 3 999999999999991679\n2 5 999999999999968959\n1 1 7\n1... | coding | 521 |
Solve the programming task below in a Python markdown code block.
Chef is playing in a T20 cricket match. In a match, Team A plays for 20 overs. In a single over, the team gets to play 6 times, and in each of these 6 tries, they can score a maximum of 6 runs. After Team A's 20 overs are finished, Team B similarly plays... | {"inputs": ["719 18 648", "720 18 648"], "outputs": ["YES", "NO"]} | coding | 593 |
Solve the programming task below in a Python markdown code block.
You are given an integer N where N ≤ 10. Consider any array A with length N where each element can either be 0, 1, or 2, we define f(A) as the number of extrema in A. You need to find the sum of f(A) over all possible arrays A.
Note:
In an array A, we c... | {"inputs": ["3\n1\n3\n5"], "outputs": ["0\n10\n270\n"]} | coding | 592 |
Solve the programming task below in a Python markdown code block.
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I kn... | {"inputs": ["3 2\n2 3\n3 1\n2 1\n", "3 0\n2 3\n3 1\n2 1\n", "3 0\n2 1\n3 1\n2 1\n", "4 2\n3 4\n4 3\n4 2\n3 1\n", "4 4\n3 4\n4 3\n1 2\n2 1\n", "4 1\n3 2\n4 1\n4 2\n1 2\n", "4 4\n3 4\n3 4\n1 2\n1 2\n", "4 4\n2 3\n4 3\n2 1\n2 3\n"], "outputs": ["3\n", "3\n", "3\n", "6\n", "4\n", "6\n", "4\n", "3\n"]} | coding | 426 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do noth... | {"functional": "def check(candidate):\n assert candidate(word = \"abcdefd\", ch = \"d\") == \"dcbaefd\"\n assert candidate(word = \"xyxzxe\", ch = \"z\") == \"zxyxxe\"\n assert candidate(word = \"abcd\", ch = \"z\") == \"abcd\"\n\n\ncheck(Solution().reversePrefix)"} | coding | 152 |
Solve the programming task below in a Python markdown code block.
Given an amount and the denominations of coins available, determine how many ways change can be made for amount. There is a limitless supply of each coin type.
Example
$n=3$
$c=[8,3,1,2]$
There are $3$ ways to make change for $n=3$: $\{1,1,1\}... | {"inputs": ["4 3\n1 2 3\n", "10 4\n2 5 3 6\n"], "outputs": ["4\n", "5\n"]} | coding | 628 |
Solve the programming task below in a Python markdown code block.
The chef has one array of N natural numbers (might be in sorted order). Cheffina challenges chef to find the total number of inversions in the array.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
... | {"inputs": ["1\n5\n5 4 1 3 2"], "outputs": ["8"]} | coding | 192 |
Solve the programming task below in a Python markdown code block.
You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can... | {"inputs": ["2 2 1 0 0 1\n", "5 3 6 3 3 12\n", "5 3 6 3 1 12\n", "2 4 3 -1 3 7\n", "3 4 -8 5 6 -3\n", "4 4 3 2 10 -1\n", "3 5 -4 -7 5 0\n", "1 5 -4 -7 5 0\n"], "outputs": ["1", "2", "2\n", "2", "3", "1", "2", "8\n"]} | coding | 453 |
Solve the programming task below in a Python markdown code block.
Mr. Krabs loves money. He enters a bank and sees that there are n rooms arranged in a row. The only rooms with doors are the two rooms on either corner. Initially, all the rooms are locked (including the corner ones). To enter a room, it must be unlocked... | {"inputs": ["7\n1 2 3 4 5 6 1\n3"], "outputs": ["12"]} | coding | 504 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.
Return the sum of all subarray ranges of nums.
A subarray is a contiguou... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 4\n assert candidate(nums = [1,3,3]) == 4\n assert candidate(nums = [4,-2,-3,4,1]) == 59\n\n\ncheck(Solution().subArrayRanges)"} | coding | 105 |
Solve the programming task below in a Python markdown code block.
An array is beautiful if both of the following two conditions meet:
there are at least $l_1$ and at most $r_1$ elements in the array equal to its minimum;
there are at least $l_2$ and at most $r_2$ elements in the array equal to its maximum.
For examp... | {"inputs": ["1\n40 40 40 40\n", "1\n14 17 15 50\n", "7\n3 5 4 6\n5 8 5 5\n3 3 10 12\n1 5 3 3\n1 1 2 2\n2 2 1 1\n6 6 6 6\n"], "outputs": ["40\n", "15\n", "4\n5\n13\n3\n3\n3\n6\n"]} | coding | 649 |
Solve the programming task below in a Python markdown code block.
Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of... | {"inputs": ["1 1 1\n.\n", "1 1 1\n*\n", "1 1 1\n.\n", "1 1 1\n*\n", "1 2 2\n..\n", "1 2 1\n..\n", "1 2 3\n..\n", "1 2 2\n..\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "2\n", "0\n", "1\n"]} | coding | 421 |
Solve the programming task below in a Python markdown code block.
You are in the future. It's the time of autonomous cars. Switching lanes is a pretty difficult task for autonomous cars, and you have the logs from an experiment you had run with two cars. You want to verify whether the logs are corrupted, or could be va... | {"inputs": ["2\n3\n1 1 1 2 2\n2 2 1 2 2\n4 2 2 2 3\n1\n1 1 3 2 2"], "outputs": ["yes\nno"]} | coding | 746 |
Solve the programming task below in a Python markdown code block.
Fox Ciel is playing a game with numbers now.
Ciel has n positive integers: x_1, x_2, ..., x_{n}. She can do the following operation as many times as needed: select two different indexes i and j such that x_{i} > x_{j} hold, and then apply assignment x_... | {"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n3 5\n", "2\n8 5\n", "2\n1 1\n", "2\n3 5\n", "2\n8 5\n", "2\n3 9\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "6\n"]} | coding | 318 |
Solve the programming task below in a Python markdown code block.
Hanuman has been a great admirer of Ram. However, there is one thing that Hanuman finds really difficult when talking to Ram. Hanuman can only understand sentences in reverse order but Ram,though an incarnation of God,is somehow unable to speak in revers... | {"inputs": ["9\nI have always been fond of you, Hanuman\nSpacelessSentence\nHello how are ou?\n.\na . gg\nt t his is a random sentence\nabcdef\nreverse me please\ntestcase 1"], "outputs": ["Hanuman you, of fond been always have I \nSpacelessSentence \nou? are how Hello \n. \ngg . a \nsentence random a is his t t \nabcd... | coding | 216 |
Solve the programming task below in a Python markdown code block.
The Quarkgo Empire Expeditionary Force is an evil organization that plans to invade the Earth. In keeping with the tradition of the invaders, they continued to send monsters at a pace of one every week, targeting the area around Tokyo in Japan. However, ... | {"inputs": ["3", "5", "4", "6", "2", "7", "9", "8"], "outputs": ["1\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2"]} | coding | 701 |
Solve the programming task below in a Python markdown code block.
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has numbe... | {"inputs": ["1\nA1\n", "1\nB1\n", "1\nC1\n", "1\nB2\n", "2\nR33C55\nBC23\n", "2\nR33C55\nBC24\n", "2\nR23C55\nCC23\n", "2\nR33C55\nBC13\n"], "outputs": ["R1C1\n", "R1C2\n", "R1C3\n", "R2C2\n", "BC33\nR23C55\n", "BC33\nR24C55\n", "BC23\nR23C81\n", "BC33\nR13C55\n"]} | coding | 345 |
Solve the programming task below in a Python markdown code block.
# Description
"It's the end of trick-or-treating and we have a list/array representing how much candy each child in our group has made out with. We don't want the kids to start arguing, and using our parental intuition we know trouble is brewing as many ... | {"functional": "_inputs = [[[5, 8, 6, 4]], [[1, 2, 4, 6]], [[1, 2]], [[4, 2]], [[1, 3, 3, 7]], [[7, 7, 7, 7]], [[17, 20, 50, 61, 42, 44]], [[0]], [[]], [[4]], [[None]]]\n_outputs = [[9], [11], [1], [2], [14], [0], [132], [-1], [-1], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or... | coding | 582 |
Solve the programming task below in a Python markdown code block.
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This opera... | {"inputs": ["9\n2\n3\n1\n", "7\n2\n3\n1\n", "7\n2\n3\n1\n", "7\n2\n1\n1\n", "9\n2\n3\n0\n", "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n"], "outputs": ["6\n", "8\n", "8\n", "4\n", "3\n", "6\n", "8\n", "12\n"]} | coding | 404 |
Solve the programming task below in a Python markdown code block.
Write a function name `nextPerfectSquare` that returns the first perfect square that is greater than its integer argument. A `perfect square` is a integer that is equal to some integer squared. For example 16 is a perfect square because `16=4*4`.
```
ex... | {"functional": "_inputs = [[6], [36], [0], [-5]]\n_outputs = [[9], [49], [1], [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 if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fal... | coding | 177 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of $n$ positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that $a_1 < a_2 < \dots < a_n$ holds.
... | {"inputs": ["1\n1\n114514\n", "1\n1\n1919810\n", "1\n2\n1000000 1000001\n", "3\n4\n1 1 1 1\n5\n8 7 1 3 4\n1\n5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\nYES\nYES\n"]} | coding | 355 |
Solve the programming task below in a Python markdown code block.
For his birthday, Kevin received the set of pairwise distinct numbers $1, 2, 3, \ldots, n$ as a gift.
He is going to arrange these numbers in a way such that the minimum absolute difference between two consecutive numbers be maximum possible. More forma... | {"inputs": ["1\n2\n", "2\n4\n3\n"], "outputs": ["2 1 \n", "3 1 4 2 \n2 1 3 \n"]} | coding | 504 |
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, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome are minimized.
Return the minimum number of letter changes required.
A semi... | {"functional": "def check(candidate):\n assert candidate(s = \"abcac\", k = 2) == 1\n assert candidate(s = \"abcdef\", k = 2) == 2\n assert candidate(s = \"aabbaa\", k = 3) == 0\n\n\ncheck(Solution().minimumChanges)"} | coding | 464 |
Solve the programming task below in a Python markdown code block.
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play... | {"inputs": ["1\n1\n", "1\n2\n", "1\n5\n", "1\n5\n", "1\n4\n", "1\n3\n", "1\n2\n", "1\n1\n"], "outputs": ["3\n", "2\n", "3\n", "3\n", "2\n", "3\n", "2\n", "3\n"]} | coding | 447 |
Solve the programming task below in a Python markdown code block.
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line ... | {"inputs": ["3\n", "4\n", "5\n", "6\n", "7\n", "6\n", "5\n", "7\n"], "outputs": ["24", "132", "672", "3264", "15360", "3264\n", "672\n", "15360\n"]} | coding | 392 |
Solve the programming task below in a Python markdown code block.
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue bal... | {"inputs": ["4 3\n2 1 1\n", "3 9\n1 1 3\n", "1 1\n0 1 0\n", "0 0\n0 0 0\n", "4 3\n1 0 1\n", "6 0\n1 1 1\n", "4 0\n1 1 1\n", "0 0\n0 0 0\n"], "outputs": ["2\n", "1\n", "0\n", "0\n", "0\n", "4\n", "4\n", "0\n"]} | coding | 391 |
Solve the programming task below in a Python markdown code block.
Monocarp wants to draw four line segments on a sheet of paper. He wants the $i$-th segment to have its length equal to $a_i$ ($1 \le i \le 4$). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monoc... | {"inputs": ["4\n1 1 3 4\n2 8 5 5\n2 1 4 1\n101 21 0 111\n", "4\n1 1 3 4\n1 8 5 5\n2 1 4 1\n101 4 54 011\n", "4\n1 1 3 4\n2 8 5 5\n4 1 4 1\n101 21 0 011\n", "4\n1 1 3 4\n2 7 5 5\n2 1 4 1\n111 29 4 101\n", "4\n0 1 3 4\n2 5 1 5\n3 1 4 1\n101 8 20 101\n", "4\n1 1 3 4\n2 7 5 5\n2 0 4 1\n111 29 4 101\n", "4\n1 1 3 4\n2 8 4 5... | coding | 543 |
Solve the programming task below in a Python markdown code block.
# Story&Task
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all houses in the city were built in one row.
Let's enumerate all the houses from left to right, starting with 0. A house is c... | {"functional": "_inputs = [[[1, 2, 3, 1, 2]], [[3, 2, 1, 4]], [[1, 2, 3]], [[3, 2, 1]], [[1, 1, 1]]]\n_outputs = [[[3, 2, 0, 2, 0]], [[2, 3, 4, 0]], [[3, 2, 0]], [[0, 0, 0]], [[1, 1, 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,... | coding | 466 |
Solve the programming task below in a Python markdown code block.
Welcome.
In this kata you are required to, given a string, replace every letter with its position in the alphabet.
If anything in the text isn't a letter, ignore it and don't return it.
`"a" = 1`, `"b" = 2`, etc.
## Example
```python
alphabet_positi... | {"functional": "_inputs = [[\"-.-'\"]]\n_outputs = [['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_d... | coding | 193 |
Solve the programming task below in a Python markdown code block.
The previous challenges covered Insertion Sort, which is a simple and intuitive sorting algorithm with a running time of $unrecognized$. In these next few challenges, we're covering a divide-and-conquer algorithm called Quicksort (also known as Partition... | {"inputs": ["5 \n4 5 3 7 2 \n"], "outputs": ["3 2 4 5 7\n"]} | coding | 726 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.
A subarray is a contiguous non-empty sequence of elements within an array.
Please complete the following ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,1], k = 2) == 2\n assert candidate(nums = [1,2,3], k = 3) == 2\n\n\ncheck(Solution().subarraySum)"} | coding | 92 |
Solve the programming task below in a Python markdown code block.
Chef has a binary string S. He can replace any occurrence of -
- 01 with a
- 10 with b
- 010 with ab
- 101 with ba
While doing these operations, Chef noticed that he can end up with different strings depending upon the order of application of the opera... | {"inputs": ["3\nab\naa\nabb\n"], "outputs": ["2\n1\n2\n"]} | coding | 589 |
Solve the programming task below in a Python markdown code block.
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.
They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Her... | {"inputs": ["2\n-6 0", "2\n-1 8", "2\n0 13", "2\n15 1", "2\n23 0", "2\n51 0", "2\n0 -10", "2\n0 -19"], "outputs": ["6\n", "9\n", "13\n", "14\n", "23\n", "51\n", "10\n", "19\n"]} | coding | 296 |
Solve the programming task below in a Python markdown code block.
Chef feels that being the Head Chef is a very difficult job. More than cooking, managing the kitchen and distributing the work between various cooks proves to be a tiring task. There are many dishes to be prepared. And he has a team of talented cooks to ... | {"inputs": ["1\n3 2\n0 3\n1 3"], "outputs": ["3"]} | coding | 432 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of lengt... | {"functional": "def check(candidate):\n assert candidate(dist = [1,3,2], speed = 4, hoursBefore = 2) == 1\n assert candidate(dist = [7,3,5,5], speed = 2, hoursBefore = 10) == 2\n assert candidate(dist = [7,3,5,5], speed = 1, hoursBefore = 10) == -1\n\n\ncheck(Solution().minSkips)"} | coding | 364 |
Solve the programming task below in a Python markdown code block.
# Task
Consider an array of integers `a`. Let `min(a)` be its minimal element, and let `avg(a)` be its mean.
Define the center of the array `a` as array `b` such that:
```
- b is formed from a by erasing some of its elements.
- For each i, |b[i] - avg(... | {"functional": "_inputs = [[[8, 3, 4, 5, 2, 8]], [[1, 3, 2, 1]], [[10, 11, 12, 13, 14]]]\n_outputs = [[[4, 5]], [[1, 2, 1]], [[10, 11, 12, 13, 14]]]\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... | coding | 305 |
Solve the programming task below in a Python markdown code block.
Complete the function ```circleArea``` so that it will return the area of a circle with the given ```radius```. Round the returned number to two decimal places (except for Haskell). If the radius is not positive or not a number, return ```false```.
Exam... | {"functional": "_inputs = [[0], ['An integer']]\n_outputs = [[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=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n... | coding | 172 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array arr.
We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.
Return the largest ... | {"functional": "def check(candidate):\n assert candidate(arr = [5,4,3,2,1]) == 1\n assert candidate(arr = [2,1,3,4,4]) == 4\n\n\ncheck(Solution().maxChunksToSorted)"} | coding | 105 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.
Please complete the following python code precisely:
```python
class So... | {"functional": "def check(candidate):\n assert candidate(intervals = [[0,30],[5,10],[15,20]]) == 2\n assert candidate(intervals = [[7,10],[2,4]]) == 1\n\n\ncheck(Solution().minMeetingRooms)"} | coding | 79 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a linked list.
The nodes in the linked list are sequentially assigned to non-empty groups whose lengths form the sequence of the natural numbers (1, 2, 3, 4, ...). The length of a group is th... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([5,2,6,3,9,1,7,3,8,4])), list_node([5,6,2,3,9,1,4,8,3,7]))\n assert is_same_list(candidate(head = list_node([1,1,0,6])), list_node([1,0,1,6]))\n assert is_same_list(candidate(head = list_node([2,1])), list_node([2,1]))\n\n\n... | coding | 259 |
Solve the programming task below in a Python markdown code block.
# Hey You !
Sort these integers for me ...
By name ...
Do it now !
---
## Input
* Range is ```0```-```999```
* There may be duplicates
* The array may be empty
## Example
* Input: 1, 2, 3, 4
* Equivalent names: "one", "two", "three", "four"
* ... | {"functional": "_inputs = [[[0, 1, 2, 3]], [[]], [[8, 8, 9, 9, 10, 10]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]], [[99, 100, 200, 300, 999]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 3... | coding | 328 |
Solve the programming task below in a Python markdown code block.
Polycarp likes numbers that are divisible by 3.
He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. ... | {"inputs": ["6\n", "4\n", "4\n", "5\n", "8\n", "1\n", "2\n", "7\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 621 |
Solve the programming task below in a Python markdown code block.
In the new world, we also have a new system called Cybalphabit system.
The system assigns points to each Latin lowercase alphabet as follows:-
'a' is assigned $2^{0}$ , 'b' is assigned $2^{1}$, 'c' $2^{2}$ and so on. Thus, finally 'z' is assigned $2^{25}... | {"inputs": ["4\n2 2\n2 5\n4 5\n3 2"], "outputs": ["aa\nac\nbaaa\n-1"]} | coding | 557 |
Solve the programming task below in a Python markdown code block.
The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to another si... | {"inputs": ["4 3\n", "5 2\n", "7 2\n", "2 1\n", "2 1\n", "7 2\n", "3 2\n", "4 3\n"], "outputs": ["3\n", "2\n", "3\n", "2\n", "2\n", "3\n", "2\n", "3\n"]} | coding | 439 |
Solve the programming task below in a Python markdown code block.
You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the strin... | {"inputs": ["2\n4\nDCBA\n7\nXYZZYZZ", "2\n4\nDCBA\n7\nXYZZYZY", "2\n4\nDCBA\n7\nXZZZYZZ", "2\n4\nABCD\n7\nXYZZYZY", "2\n4\nCBAD\n7\nXYZZYZY", "2\n4\nCBAD\n7\nYZYZZYX", "2\n4\nCDAB\n7\nYZYZZYX", "2\n4\nCDAB\n7\nYZYZZYW"], "outputs": ["ADCB\nXYYZZZZ", "ADCB\nXYYZZYZ\n", "ADCB\nXYZZZZZ\n", "ABCD\nXYYZZYZ\n", "ACBD\nXYYZZY... | coding | 297 |
Solve the programming task below in a Python markdown code block.
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number".
Unfortunately, PolandBall is not exp... | {"inputs": ["3\n", "4\n", "1\n", "2\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1", "2", "3", "4", "1", "4", "1", "1"]} | coding | 313 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string num, representing a large integer, and an integer k.
We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful inte... | {"functional": "def check(candidate):\n assert candidate(num = \"5489355142\", k = 4) == 2\n assert candidate(num = \"11112\", k = 4) == 4\n assert candidate(num = \"00123\", k = 1) == 1\n\n\ncheck(Solution().getMinSwaps)"} | coding | 253 |
Solve the programming task below in a Python markdown code block.
At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$
We can see that if we choose some value $... | {"inputs": ["1 1\n", "2 1\n", "1 1\n", "2 1\n", "8 5\n", "11 3\n", "11 6\n", "14 5\n"], "outputs": ["1\n", "2\n", "1\n", "2\n", "2\n", "5\n", "4\n", "6\n"]} | coding | 599 |
Solve the programming task below in a Python markdown code block.
# Task
You are given a string consisting of `"D", "P" and "C"`. A positive integer N is called DPC of this string if it satisfies the following properties:
```
For each i = 1, 2, ... , size of the string:
If i-th character is "D", then N can be d... | {"functional": "_inputs = [['DDPDD'], ['DDDDPDDCCCDDPDCCPCDCDDPCPCCDDCD'], ['DPCPDPPPDCPDPDPC'], ['DDDDDDCD'], ['CDDDPDDD'], ['DDDDDDPCCDPDPP']]\n_outputs = [[20], [15782844], [-1], [-1], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | coding | 302 |
Solve the programming task below in a Python markdown code block.
You are given a tree consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is equal to $a_i$.
Recall that a simple path is a path that visits each vertex at most once. Let the weight of the path be the bitwise XOR of t... | {"inputs": ["1\n25\n", "4\n2 1 1 1\n1 2\n1 3\n1 4\n", "5\n2 2 2 2 2\n1 2\n2 3\n3 4\n4 5\n", "6\n3 2 1 3 2 1\n4 5\n3 4\n1 4\n2 1\n6 1\n", "10\n7 4 6 7 6 6 7 5 7 5\n8 7\n4 5\n9 6\n2 5\n4 8\n9 10\n4 3\n9 4\n1 8\n", "20\n4 1 3 4 7 3 8 7 7 3 1 1 7 1 9 5 1 10 6 3\n6 15\n12 11\n18 1\n9 17\n8 1\n1 20\n13 7\n10 15\n20 19\n10 16... | coding | 472 |
Solve the programming task below in a Python markdown code block.
You have a string s = s_1s_2...s_{|}s|, where |s| is the length of string s, and s_{i} its i-th character.
Let's introduce several definitions: A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string s_{i}s_{i} + 1...s_{j}. The prefix of string s... | {"inputs": ["A\n", "A\n", "AB\n", "ZZ\n", "ZZ\n", "AB\n", "BA\n", "AA\n"], "outputs": ["1\n1 1\n", "1\n1 1\n", "1\n2 1\n", "2\n1 2\n2 1\n", "2\n1 2\n2 1\n", "1\n2 1\n", "1\n2 1\n", "2\n1 2\n2 1\n"]} | coding | 403 |
Solve the programming task below in a Python markdown code block.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
There are $n$ books standing in a row on the shelf, the $i$-th book has color $a_i$.
Y... | {"inputs": ["5\n1 2 2 1 3\n", "5\n1 2 2 1 1\n", "5\n1 2 4 1 3\n", "5\n1 2 1 1 1\n", "5\n2 2 2 1 3\n", "5\n1 2 1 2 1\n", "5\n1 2 1 1 2\n", "5\n2 1 2 1 3\n"], "outputs": ["2\n", "1\n", "2\n", "1\n", "0\n", "2\n", "1\n", "2\n"]} | coding | 419 |
Solve the programming task below in a Python markdown code block.
## Task
You will receive a string consisting of lowercase letters, uppercase letters and digits as input. Your task is to return this string as blocks separated by dashes (`"-"`). The elements of a block should be sorted with respect to the hierarchy li... | {"functional": "_inputs = [['heyitssampletestkk'], ['dasf6ds65f45df65gdf651vdf5s1d6g5f65vqweAQWIDKsdds'], ['SDF45648374RHF8BFVYg378rg3784rf87g3278bdqG'], [''], ['aaaaaaaaaa']]\n_outputs = [['aehiklmpsty-ekst-est'], ['adefgqsvwADIKQW1456-dfgsv156-dfs56-dfs56-dfs56-df56-d5-d'], ['bdfgqrBDFGHRSVY2345678-grF3478-gF3478-347... | coding | 305 |
Solve the programming task below in a Python markdown code block.
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of pow... | {"inputs": ["6 2 \n0 1 1 1 1 0 \n"], "outputs": ["2\n"]} | coding | 652 |
Solve the programming task below in a Python markdown code block.
## Task
Write a function that accepts two arguments and generates a sequence containing the integers from the first argument to the second inclusive.
## Input
Pair of integers greater than or equal to `0`. The second argument will always be greater t... | {"functional": "_inputs = [[2, 5]]\n_outputs = [[[2, 3, 4, 5]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return ... | coding | 124 |
Solve the programming task below in a Python markdown code block.
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that th... | {"inputs": ["1 1\n1 2\n", "1 1\n1 5\n", "1 1\n1 2\n", "1 1\n1 5\n", "1 1\n1 7\n", "4 1\n1 0\n", "1 1\n1 0\n", "2 1\n1 0\n"], "outputs": ["2\n", "5\n", "2", "5", "7\n", "3\n", "0\n", "1\n"]} | coding | 560 |
Solve the programming task below in a Python markdown code block.
There are $n$ trees in a park, numbered from $1$ to $n$. The initial height of the $i$-th tree is $h_i$.
You want to water these trees, so they all grow to the same height.
The watering process goes as follows. You start watering trees at day $1$. Duri... | {"inputs": ["1\n3\n14159 26535 89793\n", "3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4\n"], "outputs": ["92595\n", "4\n3\n16\n"]} | coding | 625 |
Solve the programming task below in a Python markdown code block.
You are given an array B of length 2N . You have an unknown array A which is sorted and contains *distinct* elements. You need to find out the array A. B contains all the medians of each prefix and suffix of the array A.
A median is the middle element i... | {"inputs": ["2\n3\n6 5 5 7 6 6\n3\n1 2 1 4 2 4"], "outputs": ["5 6 7\n-1"]} | coding | 528 |
Solve the programming task below in a Python markdown code block.
There is a simple directed graph G with N vertices, numbered 1, 2, \ldots, N.
For each i and j (1 \leq i, j \leq N), you are given an integer a_{i, j} that represents whether there is a directed edge from Vertex i to j. If a_{i, j} = 1, there is a direc... | {"inputs": ["0 1\n0", "1 1\n0", "3 3\n0 1 0\n1 0 1\n0 0 0", "4 2\n0 3 0 0\n0 0 1 1\n0 0 1 1\n1 0 0 0", "4 2\n0 1 0 0\n0 0 1 1\n0 0 0 1\n1 0 0 0", "4 2\n0 1 0 0\n0 -1 1 1\n0 0 0 1\n1 0 0 0", "4 2\n0 1 0 0\n0 -1 1 1\n0 1 0 1\n1 0 0 0", "4 2\n0 1 0 0\n0 -1 1 2\n0 1 0 1\n1 0 0 0"], "outputs": ["0\n", "0", "3", "15\n", "6",... | coding | 697 |
Solve the programming task below in a Python markdown code block.
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunate... | {"inputs": ["3\n1 2 3\n3 2 1\n1 1\n1 1\n", "3\n3 2 1\n1 2 3\n1 1\n1 2\n", "3\n3 2 1\n1 2 3\n1 1\n1 4\n", "3\n1 2 3\n3 2 0\n1 1\n1 1\n", "3\n3 2 1\n1 2 3\n1 1\n2 4\n", "3\n3 0 1\n1 2 3\n1 1\n2 4\n", "3\n3 2 1\n1 2 3\n1 1\n1 2\n", "3\n1 2 3\n3 2 1\n1 1\n1 1\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n... | coding | 541 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles.
The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2... | {"functional": "def check(candidate):\n assert candidate(ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2) == 45\n assert candidate(ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2) == 16\n\n\ncheck(Solution().computeArea)"} | coding | 166 |
Solve the programming task below in a Python markdown code block.
You are given an unweighted, undirected graph. Write a program to check if it's a tree topology.
-----Input-----
The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M... | {"inputs": ["3 2\n1 2\n2 3"], "outputs": ["YES"]} | coding | 163 |
Solve the programming task below in a Python markdown code block.
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.
He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he h... | {"inputs": ["2\n5 8", "2\n4 8", "2\n4 8\n", "2\n5 11", "2\n10 6", "2\n17 5", "2\n17 1", "2\n17 2"], "outputs": ["5\n", "8", "8\n", "18\n", "8\n", "72\n", "128\n", "113\n"]} | coding | 225 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.
Given an integer n, return the largest number that is less than or equal to n with monotone increasing digi... | {"functional": "def check(candidate):\n assert candidate(n = 10) == 9\n assert candidate(n = 1234) == 1234\n assert candidate(n = 332) == 299\n\n\ncheck(Solution().monotoneIncreasingDigits)"} | coding | 96 |
Solve the programming task below in a Python markdown code block.
You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅ LCS(C,D) - |C| - |D|, where LCS(C,D) denotes the length of the Longest Common Subsequ... | {"inputs": ["1 1\na\nb\n", "4 5\nabca\nbaaab\n", "4 5\nabca\nbabab\n", "4 5\nabca\naabab\n", "4 5\nabba\nbabab\n", "6 6\nooojjj\nooookj\n", "7 7\nuiibwws\nqhtkxcn\n", "6 9\nvvvkvv\nvgkkvvvgg\n"], "outputs": ["0\n", "4\n", "5\n", "5\n", "5\n", "7\n", "0\n", "6\n"]} | coding | 538 |
Solve the programming task below in a Python markdown code block.
Chouti is working on a strange math problem.
There was a sequence of $n$ positive integers $x_1, x_2, \ldots, x_n$, where $n$ is even. The sequence was very special, namely for every integer $t$ from $1$ to $n$, $x_1+x_2+...+x_t$ is a square of some int... | {"inputs": ["2\n1\n", "2\n1\n", "2\n780\n", "2\n524\n", "2\n203\n", "2\n9900\n", "2\n9900\n", "4\n35 15\n"], "outputs": ["No\n", "No\n", "Yes\n4 780\n", "Yes\n16900 524\n", "Yes\n121 203\n", "Yes\n100 9900\n", "Yes\n100 9900 ", "Yes\n1 35 13 15\n"]} | coding | 690 |
Solve the programming task below in a Python markdown code block.
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elemen... | {"inputs": ["1\nz\n", "1\nz\n", "1\ny\n", "1\nx\n", "1\nlol\n", "1\nlol\n", "1\nlnl\n", "1\nlln\n"], "outputs": ["z\n", "z\n", "y\n", "x\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and... | {"inputs": ["2 2 1 1\n", "9 2 2 3\n", "9 2 2 3\n", "2 2 1 1\n", "20 4 5 2\n", "30 9 4 1\n", "31 3 2 8\n", "31 3 2 8\n"], "outputs": ["1\n", "4\n", "4\n", "1\n", "8\n", "4\n", "10\n", "10\n"]} | coding | 624 |
Solve the programming task below in a Python markdown code block.
An L-shape is a figure on gridded paper that looks like the first four pictures below. An L-shape contains exactly three shaded cells (denoted by *), which can be rotated in any way.
You are given a rectangular grid. Determine if it contains L-shapes on... | {"inputs": ["1\n4 4\n.**.\n*..*\n*..*\n.**.\n", "1\n4 5\n..*..\n.*.*.\n.*.*.\n..*..\n", "1\n6 6\n..**..\n.*..*.\n*....*\n*....*\n.*..*.\n..**..\n", "10\n6 10\n........**\n.**......*\n..*..*....\n.....**...\n...*.....*\n..**....**\n6 10\n....*...**\n.**......*\n..*..*....\n.....**...\n...*.....*\n..**....**\n3 3\n...\n*... | coding | 517 |
Solve the programming task below in a Python markdown code block.
Problem
There are n vertices that are not connected to any of the vertices.
An undirected side is stretched between each vertex.
Find out how many sides can be stretched when the diameter is set to d.
The diameter represents the largest of the shortest ... | {"inputs": ["0 1", "4 5", "6 5", "0 2", "4 1", "6 9", "0 8", "8 1"], "outputs": ["0\n", "2\n", "5\n", "-1\n", "6\n", "7\n", "26\n", "28\n"]} | coding | 189 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
A circular binary string is called *good* if it contains at least one character '1' and there is an integer $d$ such that for each character '1', the distance... | {"inputs": ["2\n6\n110011\n4\n0001"], "outputs": ["2\n0"]} | coding | 347 |
Solve the programming task below in a Python markdown code block.
A biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.
Find the total number of biscuits produced within T + 0.5 seconds after activation.
----... | {"inputs": ["4 2 9", "8 2 9", "1 9 8", "2 6 2", "1 9 1", "1 2 5", "8 0 6", "3 5 7"], "outputs": ["4\n", "2\n", "72\n", "6\n", "9\n", "10\n", "0\n", "10"]} | coding | 194 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right.
When two ants moving ... | {"functional": "def check(candidate):\n assert candidate(n = 4, left = [4,3], right = [0,1]) == 4\n assert candidate(n = 7, left = [], right = [0,1,2,3,4,5,6,7]) == 7\n assert candidate(n = 7, left = [0,1,2,3,4,5,6,7], right = []) == 7\n\n\ncheck(Solution().getLastMoment)"} | coding | 199 |
Solve the programming task below in a Python markdown code block.
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Pr... | {"inputs": ["1 0 0 0\n0\n", "1 0 0 0\n0\n", "1 1 1 1\n-1\n", "1 1 2 3\n-1\n", "1 1 1 1\n-1\n", "1 1 2 3\n-1\n", "1 0 0 0\n-1\n", "1 2 2 3\n-1\n"], "outputs": ["0\n", "0", "-3\n", "-6\n", "-3", "-6", "0\n", "-7\n"]} | coding | 443 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game with a binary string S of length N and an empty string T.
They both take turns and Alice plays first.
In Alice's turn, she picks the first character of string S, appends the character to either the front or back of str... | {"inputs": ["4\n2\n10\n4\n0001\n6\n010111\n10\n1110000010"], "outputs": ["10\n0100\n101101\n0011011000"]} | coding | 583 |
Solve the programming task below in a Python markdown code block.
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)
Dreamoon will perfor... | {"inputs": ["1 1\n1\n", "13 1\n1\n", "15 1\n1\n", "10 1\n1\n", "2 2\n1 2\n", "2 2\n2 2\n", "2 2\n3 2\n", "10 2\n9 2\n"], "outputs": ["1 \n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "1 9 \n"]} | coding | 374 |
Solve the programming task below in a Python markdown code block.
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented... | {"inputs": ["1\n2\n", "1\n2\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | coding | 506 |
Solve the programming task below in a Python markdown code block.
Given are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.
- There exists a non-ne... | {"inputs": ["aba\naaaab", "aba\naa`ab", "`ba\naa`ab", "`ab\naa`ab", "ab`\naa`ab", "ab`\naa`ac", "ac`\naa`ac", "`ca\naa`ac"], "outputs": ["0", "0", "0", "0", "0", "0", "0", "0"]} | coding | 468 |
Solve the programming task below in a Python markdown code block.
Snuke has decided to play with N cards and a deque (that is, a double-ended queue).
Each card shows an integer from 1 through N, and the deque is initially empty.
Snuke will insert the cards at the beginning or the end of the deque one at a time, in orde... | {"inputs": ["4 2", "4 1", "1 1", "3 1", "5 2", "5 1", "9 2", "9 1"], "outputs": ["6", "4", "1", "2", "16", "8", "512", "128"]} | coding | 303 |
Solve the programming task below in a Python markdown code block.
There is a robot staying at $X=0$ on the $Ox$ axis. He has to walk to $X=n$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.
The $i$-th segment of the path (from $X=i-1$ to $X=i$... | {"inputs": ["1 1 1\n0\n", "1 1 1\n0\n", "2 1 1\n0 0\n", "2 1 1\n0 0\n", "2 0 1\n0 0\n", "3 1 1\n1 1 1\n", "3 1 1\n1 1 1\n", "4 1 1\n1 1 1 0\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "3\n", "3\n", "3\n"]} | coding | 706 |
Solve the programming task below in a Python markdown code block.
Petya has a rectangular Board of size $n \times m$. Initially, $k$ chips are placed on the board, $i$-th chip is located in the cell at the intersection of $sx_i$-th row and $sy_i$-th column.
In one action, Petya can move all the chips to the left, righ... | {"inputs": ["2 2 1\n1 1\n1 1\n", "2 2 1\n1 1\n2 2\n", "2 2 1\n1 1\n1 1\n", "2 2 1\n1 1\n2 2\n", "3 2 1\n1 1\n1 1\n", "2 2 1\n2 1\n2 2\n", "3 3 2\n1 2\n2 1\n3 3\n3 2\n", "2 5 2\n1 1\n1 1\n1 1\n1 1\n"], "outputs": ["5\nULRDL", "5\nULRDL", "5\nULRDL", "5\nULRDL", "8\nUULRDLDR", "5\nULRDL", "12\nUULLRRDLLDRR", "14\nULLLLRR... | coding | 648 |
Solve the programming task below in a Python markdown code block.
The objective is to return all pairs of integers from a given array of integers that have a difference of 2.
The result array should be sorted in ascending order of values.
Assume there are no duplicate integers in the array. The order of the integers ... | {"functional": "_inputs = [[[1, 2, 3, 4]], [[1, 3, 4, 6]], [[0, 3, 1, 4]], [[4, 1, 2, 3]], [[6, 3, 4, 1, 5]], [[3, 1, 6, 4]], [[1, 3, 5, 6, 8, 10, 15, 32, 12, 14, 56]], [[1, 4, 7, 10]], [[]]]\n_outputs = [[[[1, 3], [2, 4]]], [[[1, 3], [4, 6]]], [[[1, 3]]], [[[1, 3], [2, 4]]], [[[1, 3], [3, 5], [4, 6]]], [[[1, 3], [4, 6... | coding | 350 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
Assume the environment does not allow y... | {"functional": "def check(candidate):\n assert candidate(x = 123) == 321\n assert candidate(x = -123) == -321\n assert candidate(x = 120) == 21\n assert candidate(x = 0) == 0\n\n\ncheck(Solution().reverse)"} | coding | 118 |
Solve the programming task below in a Python markdown code block.
Chef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. "abab" has a period P = 2, It als... | {"inputs": ["5\n3 1\n2 2\n3 3\n4 4\n6 3"], "outputs": ["impossible\nimpossible\naba\nabba\nabaaba"]} | coding | 504 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.