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
Solve the programming task below in a Python markdown code block. Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only s...
{"inputs": ["3 4 2\n2 2\n2 3\n", "2 2 2\n2 1\n1 2\n", "2 2 2\n2 1\n1 2\n", "3 4 2\n2 2\n1 3\n", "3 4 2\n2 2\n2 3\n", "100000 100000 2\n1 2\n2 1\n", "100000 100000 2\n1 2\n2 1\n", "100000 100000 2\n2 2\n2 1\n"], "outputs": ["2\n", "0\n", "0\n", "1\n", "2\n", "0\n", "0\n", "307833736\n"]}
477
204
coding
Solve the programming task below in a Python markdown code block. # Task You are given a string `s`. Every letter in `s` appears once. Consider all strings formed by rearranging the letters in `s`. After ordering these strings in dictionary order, return the middle term. (If the sequence has a even length `n`, def...
{"functional": "_inputs = [['abc'], ['abcd'], ['abcdx'], ['abcdxg'], ['abcdxgz']]\n_outputs = [['bac'], ['bdca'], ['cbxda'], ['cxgdba'], ['dczxgba']]\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 isi...
204
191
coding
Solve the programming task below in a Python markdown code block. Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $u$ and $v$, find any pair of integers (not necessarily positive) $x$, $y$, such that: ...
{"inputs": ["4\n1 1\n2 3\n3 5\n6 9\n", "1\n144266828 777818251\n"], "outputs": ["-1 1\n-4 9\n-9 25\n-36 81\n", "-20812917661181584 605001231588699001\n"]}
540
114
coding
Solve the programming task below in a Python markdown code block. Allen wants to enter a fan zone that occupies a round square and has $n$ entrances. There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses...
{"inputs": ["2\n0 1\n", "2\n0 0\n", "2\n3 3\n", "2\n1 0\n", "2\n1 1\n", "2\n1 1\n", "2\n1 0\n", "2\n0 0\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n"]}
724
102
coding
Solve the programming task below in a Python markdown code block. We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple...
{"inputs": ["7 5 0", "2 2 0", "2 4 0", "4 5 1", "2 3 0", "4 4 0", "0 9 0", "4 5 0"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
218
94
coding
Solve the programming task below in a Python markdown code block. Given a sorted array of numbers, return the summary of its ranges. ## Examples ```python summary_ranges([1, 2, 3, 4]) == ["1->4"] summary_ranges([1, 1, 1, 1, 1]) == ["1"] summary_ranges([0, 1, 2, 5, 6, 9]) == ["0->2", "5->6", "9"] summary_ranges([0, 1, ...
{"functional": "_inputs = [[[]], [[1, 1, 1, 1]], [[1, 2, 3, 4]], [[0, 1, 2, 5, 6, 9]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7, 9, 10]], [[-2, 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 12]], [[-3, -2, -1, 0, 2, 3]], [[-2]]]\n_outputs = [[[]], [['1']], [['1->4']], [['0->2', '5->6', '9']], [['0...
304
416
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings current and correct representing two 24-hour times. 24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and...
{"functional": "def check(candidate):\n assert candidate(current = \"02:30\", correct = \"04:35\") == 3\n assert candidate(current = \"11:00\", correct = \"11:01\") == 1\n\n\ncheck(Solution().convertTime)"}
178
69
coding
Solve the programming task below in a Python markdown code block. Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop. They saw it for the first time but were already getting bored to see a bunch of sentence...
{"inputs": ["3 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\nCLICK 1"], "outputs": ["1\n2\n3\n2\n0\n1"]}
509
47
coding
Solve the programming task below in a Python markdown code block. Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ tu...
{"inputs": ["1\n8\n", "1\n2\n", "1\n0\n", "1\n124\n", "2\n2 1\n", "1\n124\n", "2\n2 1\n", "1\n150\n"], "outputs": ["8\n", "2\n", "0\n", "124", "1", "124\n", "1\n", "150\n"]}
330
100
coding
Solve the programming task below in a Python markdown code block. The Padovan sequence is the sequence of integers `P(n)` defined by the initial values `P(0)=P(1)=P(2)=1` and the recurrence relation `P(n)=P(n-2)+P(n-3)` The first few values of `P(n)` are `1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 8...
{"functional": "_inputs = [[100]]\n_outputs = [[1177482265857]]\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 ...
255
168
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Hasan has recently heard about Chef's restaurant, which serves the tastiest dishes. The restaurant has published a list of $N$ dishes (numbered $1$ ...
{"inputs": ["2\n3 6\n5 7\n1 9\n2 5\n3 7\n5 8\n2 5\n5 10"], "outputs": ["16\n15"]}
563
49
coding
Solve the programming task below in a Python markdown code block. It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters. Also feel free to...
{"functional": "_inputs = [['eloquent'], ['country'], ['person'], ['place'], ['ok'], ['ooopsss']]\n_outputs = [['loquen'], ['ountr'], ['erso'], ['lac'], [''], ['oopss']]\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_...
82
191
coding
Solve the programming task below in a Python markdown code block. Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let'...
{"inputs": ["2 1\n1 2\n5 6\n1\n", "2 1\n1 2\n5 6\n1\n", "2 1\n1 2\n5 3\n2\n", "2 1\n0 2\n5 3\n2\n", "2 1\n1 2\n5 6\n0\n", "2 1\n1 2\n5 10\n1\n", "2 1\n1 2\n5 10\n2\n", "2 1\n1 1\n100 100\n5\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
741
172
coding
Solve the programming task below in a Python markdown code block. Consider the numbers `6969` and `9116`. When you rotate them `180 degrees` (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numbe...
{"functional": "_inputs = [[0, 10], [10, 100], [100, 1000], [1000, 10000], [10000, 15000], [15000, 20000], [60000, 70000], [60000, 130000]]\n_outputs = [[3], [4], [12], [20], [6], [9], [15], [55]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl...
329
273
coding
Solve the programming task below in a Python markdown code block. A Narcissistic Number is a number of length n in which the sum of its digits to the power of n is equal to the original number. If this seems confusing, refer to the example below. Ex: 153, where n = 3 (number of digits in 153) 1^(3) + 5^(3) + 3^(3) = 1...
{"functional": "_inputs = [[153], [370], [371], [407], [1634], [8208], [9474], [54748], [92727], [93084], [548834], [1741725], [4210818], [9800817], [9926315], [24678050], [88593477], [146511208], [472335975], [534494836], [912985153], [4679307774], [115132219018763992565095597973971522401]]\n_outputs = [[True], [True]...
159
440
coding
Solve the programming task below in a Python markdown code block. Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that poin...
{"inputs": ["3\n2 5 3", "3\n2 8 3", "3\n2 8 2", "3\n2 0 4", "3\n1 0 6", "3\n1 0 1", "3\n2 4 3", "12\n001 0 107 5 0 196 001 1 2 101 0 110"], "outputs": ["4\n", "7\n", "8\n", "2\n", "5\n", "0\n", "3", "94\n"]}
372
141
coding
Solve the programming task below in a Python markdown code block. Your back at your newly acquired decrypting job for the secret organization when a new assignment comes in. Apparently the enemy has been communicating using a device they call "The Mirror". It is a rudimentary device with encrypts the message by swi...
{"functional": "_inputs = [['Welcome home'], ['hello'], ['goodbye'], ['ngmlsoor'], ['gsrh rh z hvxivg'], ['Welcome home', 'w'], ['hello', 'abcdefgh'], ['goodbye', ''], ['CodeWars', '+-*/='], ['this is a secret', ' *']]\n_outputs = [['dvoxlnv slnv'], ['svool'], ['tllwybv'], ['mtnohlli'], ['this is a secret'], ['welcome ...
269
267
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return true if the s can be palindrome after deleting at most one character from it.   Please complete the following python code precisely: ```python class Solution: def validPalindrome(self, s: ...
{"functional": "def check(candidate):\n assert candidate(s = \"aba\") == True\n assert candidate(s = \"abca\") == True\n assert candidate(s = \"abc\") == False\n\n\ncheck(Solution().validPalindrome)"}
69
53
coding
Solve the programming task below in a Python markdown code block. Given a string, return a new string that has transformed based on the input: * Change case of every character, ie. lower case to upper case, upper case to lower case. * Reverse the order of words from the input. **Note:** You will have to handle multip...
{"functional": "_inputs = [['Example string'], ['Example Input'], ['To be OR not to be That is the Question'], [''], ['You Know When THAT Hotline Bling'], [' A b C d E f G ']]\n_outputs = [['STRING eXAMPLE'], ['iNPUT eXAMPLE'], ['qUESTION THE IS tHAT BE TO NOT or BE tO'], [''], ['bLING hOTLINE that wHEN kNOW yOU'],...
131
252
coding
Solve the programming task below in a Python markdown code block. You are given a tree with N vertices. Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of...
{"inputs": ["5\n1 2 1\n1 3 1\n2 4 1\n3 5 2\n3 1\n2 4\n2 3\n4 5", "5\n1 2 1\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 3\n2 3\n4 5", "5\n1 2 1\n1 3 2\n2 4 1\n3 5 1\n3 1\n2 3\n2 3\n4 4", "5\n1 2 1\n2 3 2\n2 4 1\n3 5 1\n3 1\n2 3\n2 3\n4 4", "5\n1 2 2\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 4\n2 3\n4 5", "5\n1 2 1\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 4\n2...
521
429
coding
Solve the programming task below in a Python markdown code block. # Task You are given three integers `l, d and x`. Your task is: ``` • determine the minimal integer n such that l ≤ n ≤ d, and the sum of its digits equals x. • determine the maximal integer m such that l ≤ m ≤ d, and the sum of its digits equ...
{"functional": "_inputs = [[100, 200, 10], [123, 456, 5], [99, 501, 5], [99, 234, 1], [99, 234, 19], [99, 5001, 27], [99, 5001, 28], [2000, 7000, 3]]\n_outputs = [[[109, 190]], [[131, 410]], [[104, 500]], [[100, 100]], [[199, 199]], [[999, 4995]], [[1999, 4996]], [[2001, 3000]]]\nimport math\ndef _deep_eq(a, b, tol=1e-...
290
341
coding
Solve the programming task below in a Python markdown code block. According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine ...
{"inputs": ["1\n0\n", "2\n0\n17\n", "2\n2\nGIN\n", "2\n4\nGHN\n", "2\n4\nGIN\n", "2\n2\nGHN\n", "2\n2\nHIN\n", "2\n2\nHNI\n"], "outputs": ["1\n", "2\n", "2\n", "1\n", "2\n", "1\n", "1\n", "1\n"]}
356
105
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well. You are given a grid with $N$ rows and $M$ columns, where each cell contains either '0' or '1'. Find out whether all the cells containing '1'-s form a rectan...
{"inputs": ["3\n3 3\n010\n111\n010\n4 4\n0000\n0110\n1110\n1100\n3 3\n011\n011\n000"], "outputs": ["NO\nNO\nYES"]}
534
72
coding
Solve the programming task below in a Python markdown code block. problem AOR Ika is studying to pass the test. AOR Ika-chan solved the $ N $ question. After that, round the solved problem according to the following procedure. 1. Check the correctness of the answer. 2. If the answer is correct, write a circle mark, ...
{"inputs": ["3\nnxx", "3\nnwx", "3\nxxo", "3\nxwn", "3\nowx", "3\npxx", "3\npyx", "3\npzx"], "outputs": ["2\n", "3\n", "1\n", "3\n", "3\n", "2\n", "3\n", "3\n"]}
306
85
coding
Solve the programming task below in a Python markdown code block. The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. ...
{"inputs": ["3\nab\nb\ndef\n", "3\nab\na\ndef\n", "3\nab\na\ndeg\n", "3\nba\na\ndeg\n", "3\nba\na\ndef\n", "3\nab\nc\ndef\n", "3\nac\nabc\nca\n", "3\nab\nacb\nba\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "5\n", "5\n"]}
673
120
coding
Solve the programming task below in a Python markdown code block. ----- RANJANA QUIZ ----- Prof. Ranjana decided to conduct a quiz in her class. She divided all the students of her class into groups of three. Consider that no student was left out after the division. She gave different sets of questions to every group....
{"inputs": ["5\n6 5 4\n2 3 7\n4 6 5\n7 2 3\n5 3 1"], "outputs": ["1"]}
326
42
coding
Solve the programming task below in a Python markdown code block. ## Witamy! You are in Poland and want to order a drink. You need to ask "One beer please": "Jedno piwo poprosze" ``` java Translator.orderingBeers(1) = "Jedno piwo poprosze" ``` But let's say you are really thirsty and want several beers. Then you nee...
{"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [8], [10], [11], [12], [13], [14], [15], [16], [20], [21], [22], [28], [33], [44], [55], [98], [99]]\n_outputs = [['Woda mineralna poprosze'], ['Jedno piwo poprosze'], ['Dwa piwa poprosze'], ['Trzy piwa poprosze'], ['Cztery piwa poprosze'], ['Piec piw poprosze'],...
722
516
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and a target element target. A target index is an index i such that nums[i] == target. Return a list of the target indices of nums after sorting nums in non-decreasing orde...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,5,2,3], target = 2) == [1,2]\n assert candidate(nums = [1,2,5,2,3], target = 3) == [3]\n assert candidate(nums = [1,2,5,2,3], target = 5) == [4]\n assert candidate(nums = [1,2,5,2,3], target = 4) == []\n\n\ncheck(Solution().targetIndices)"...
125
124
coding
Solve the programming task below in a Python markdown code block. For each bill you pay using CRED, you earn X CRED coins. At CodeChef store, each bag is worth 100 CRED coins. Chef pays Y number of bills using CRED. Find the maximum number of bags he can get from the CodeChef store. ------ Input Format ------ - ...
{"inputs": ["3\n10 10\n20 4\n70 7"], "outputs": ["1\n0\n4"]}
410
32
coding
Solve the programming task below in a Python markdown code block. Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the fi...
{"inputs": ["2\n><\n1 2\n", "2\n>>\n1 1\n", "2\n><\n5 5\n", "2\n>>\n1 1\n", "2\n><\n1 2\n", "2\n><\n5 5\n", "2\n><\n1 4\n", "2\n><\n5 6\n"], "outputs": ["FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n"]}
355
126
coding
Solve the programming task below in a Python markdown code block. One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appointed Judg...
{"inputs": ["2 1\n", "4 1\n", "1 1\n", "1 2\n", "2 2\n", "7 3\n", "6 3\n", "4 2\n"], "outputs": ["-1\n", "4\n1 2\n2 3\n3 4\n4 1\n", "-1\n", "-1\n", "-1\n", "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3\n", "-1\n", "-1\n"]}
376
188
coding
Solve the programming task below in a Python markdown code block. Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges hav...
{"inputs": ["4\n1 1 1\n2 1 4\n3 0\n4 1 3", "4\n1 1 1\n2 1 4\n3 0\n4 1 2", "4\n1 1 3\n2 1 4\n3 0\n4 1 3", "4\n1 1 3\n2 1 1\n3 0\n4 1 3", "4\n1 1 2\n2 1 4\n3 0\n4 1 2", "4\n1 1 2\n2 1 2\n3 0\n4 1 3", "4\n1 1 1\n2 1 1\n3 0\n4 1 2", "4\n1 1 1\n2 1 3\n3 0\n4 1 3"], "outputs": ["1 1 2\n2 3 8\n3 5 6\n4 4 7\n", "1 1 2\n2 3 6\n...
601
414
coding
Solve the programming task below in a Python markdown code block. There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: either employee y became...
{"inputs": ["1 2\n2 1\n3 1 1\n", "1 2\n2 1\n3 1 1\n", "2 3\n1 2 1\n2 1\n3 2 1\n", "2 3\n1 1 2\n2 1\n3 2 1\n", "2 3\n1 2 1\n2 1\n3 2 1\n", "2 3\n1 1 2\n2 1\n3 2 1\n", "10 5\n1 5 4\n2 5\n2 3\n3 7 2\n1 8 4\n", "10 5\n1 5 4\n2 5\n2 3\n3 7 2\n1 8 4\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n",...
535
224
coding
Solve the programming task below in a Python markdown code block. A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again ...
{"inputs": ["0 1 2\n2 0 0", "0 0 2\n4 0 0", "0 1 2\n1 0 0", "0 1 2\n12 0 0", "0 -1 2\n2 0 0", "7 0 1\n-1 0 0", "-9 0 3\n58 0 1", "0 1 -7\n96 0 0"], "outputs": ["2\n", "4\n", "1\n", "12\n", "3\n", "9\n", "67\n", "96\n"]}
415
149
coding
Solve the programming task below in a Python markdown code block. # Grasshopper - Function syntax debugging A student was working on a function and made some syntax mistakes while coding. Help them find their mistakes and fix them. Also feel free to reuse/extend the following starter code: ```python def main(verb, nou...
{"functional": "_inputs = [['take ', 'item'], ['use ', 'sword']]\n_outputs = [['take item'], ['use sword']]\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...
69
167
coding
Solve the programming task below in a Python markdown code block. While working at DTL, Ela is very aware of her physical and mental health. She started to practice various sports, such as Archery, Yoga, and Football. Since she started engaging in sports activities, Ela switches to trying a new sport on days she consi...
{"inputs": ["1\n200274443973227574 485348695690455822\n", "1\n999999999999999999 1000000000000000000\n", "5\n8 19\n8 20\n119 121\n1 100000000000000000\n1234567891011 1000000000000000000\n", "2\n747173626475907138 967354071062227214\n818273638681004942 983018368662317582\n", "2\n1000000000000000000 1000000000000000000\n...
728
1,013
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. The value of this array is defined as the sum of |nums[i] - nums[i + 1]| for all 0 <= i < nums.length - 1. You are allowed to select any subarray of the given array and reverse it....
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,5,4]) == 10\n assert candidate(nums = [2,4,9,24,2,1,10]) == 68\n\n\ncheck(Solution().maxValueAfterReverse)"}
125
69
coding
Solve the programming task below in a Python markdown code block. There are two towers consisting of blocks of two colors: red and blue. Both towers are represented by strings of characters B and/or R denoting the order of blocks in them from the bottom to the top, where B corresponds to a blue block, and R corresponds...
{"inputs": ["1\n1 1\nR\nB\n", "2\n1 2\nR\nRB\n1 2\nR\nRB\n", "5\n1 1\nB\nB\n1 1\nB\nB\n1 1\nB\nB\n1 1\nB\nB\n1 1\nB\nB\n", "5\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n", "5\n1 1\nR\nB\n1 1\nR\nB\n1 1\nR\nB\n1 1\nR\nB\n1 1\nR\nB\n", "7\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1...
532
416
coding
Solve the programming task below in a Python markdown code block. A few years ago, Aaron left his old school and registered at another due to security reasons. Now he wishes to find Jane, one of his schoolmates and good friends. There are `n` schools numbered from 1 to `n`. One can travel between each pair of schools ...
{"functional": "_inputs = [[2], [10]]\n_outputs = [[0], [4]]\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...
169
162
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef has N simple polygons (non self intersecting polygons) in which no two of them intersect with each other. For any two polygons P_{1}, P_{2}, either P_{1} lies inside P_{2} or vice versa. C...
{"inputs": ["1\n3\n6\n0 4 -1 1 4 1 0 -1 1 -2 -3 -2\n2\n0 -1 1 0 1 0\n2\n3 3 0 1 -3 -3 3 -3", "1\n2\n6\n0 4 -1 1 2 1 0 -1 1 0 -3 0\n3\n-2 -1 0 0 1 0\n2\n6 3 -1 1 -1 -3 3 -3", "1\n2\n5\n-1 4 -1 1 2 2 0 -1 1 0 0 0\n3\n-3 -1 0 -1 1 0\n2\n6 3 0 1 -2 -3 6 -3", "1\n2\n6\n0 4 -1 1 2 1 0 -1 0 0 -3 0\n3\n-2 -1 0 0 1 0\n2\n6 3 -1...
534
569
coding
Solve the programming task below in a Python markdown code block. You are given a valid XML document, and you have to print its score. The score is calculated by the sum of the score of each element. For any element, the score is equal to the number of attributes it has. Input Format The first line contains $N$, the...
{"inputs": ["6\n<feed xml:lang='en'>\n <title>HackerRank</title>\n <subtitle lang='en'>Programming challenges</subtitle>\n <link rel='alternate' type='text/html' href='http://hackerrank.com/'/>\n <updated>2013-12-25T12:00:00</updated>\n</feed>\n"], "outputs": ["5\n"]}
369
101
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are painting a fence of n posts with k different colors. You must paint the posts following these rules: Every post must be painted exactly one color. There cannot be three or more consecutive posts with the same...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 2) == 6\n assert candidate(n = 1, k = 1) == 1\n assert candidate(n = 7, k = 2) == 42\n\n\ncheck(Solution().numWays)"}
115
72
coding
Solve the programming task below in a Python markdown code block. Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation...
{"inputs": ["2\n", "4\n", "8\n", "8\n", "1\n", "4\n", "2\n", "110\n"], "outputs": ["1\n", "-1\n", "2\n", "2\n", "-1\n", "-1\n", "1\n", "10\n"]}
329
73
coding
Solve the programming task below in a Python markdown code block. We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that A follows Z. For example, shifting A by...
{"inputs": ["13\nA\n", "0\nYBCXAZ", "2\nABDXYZ", "0\nYBBXAZ", "2\nZYXDBA", "0\nYABXAZ", "2\nZXXDBA", "0\nZAXBAY"], "outputs": ["N\n", "YBCXAZ\n", "CDFZAB\n", "YBBXAZ\n", "BAZFDC\n", "YABXAZ\n", "BZZFDC\n", "ZAXBAY\n"]}
205
117
coding
Solve the programming task below in a Python markdown code block. Transformation Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th...
{"inputs": ["xyz\n3\nprint 0 2\nreplace 1 2 abc\nprint 0 2", "xyz\n1\nprint 0 2\nreplace 0 2 abc\nprint 0 2", "xyz\n3\nprint 0 1\nreplace 1 2 abc\nprint 0 2", "wyz\n1\nprint 0 2\nreplace 0 2 abc\nprint 0 2", "xyz\n3\nprint 0 2\nreplace 1 2 abb\nprint 0 4", "zyx\n3\nprint 0 2\nreplace 0 2 abc\nprint 0 2", "xyz\n3\nprint...
317
245
coding
Solve the programming task below in a Python markdown code block. When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at le...
{"inputs": ["3\n2\n10\n3\n001\n4\n0100"], "outputs": ["YES\nNO\nYES"]}
622
34
coding
Solve the programming task below in a Python markdown code block. Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya. Looking at her coins, a question cam...
{"inputs": ["1 79\n79\n", "1 114\n114\n", "3 50\n24 25 50\n", "3 50\n36 25 50\n", "3 50\n25 25 50\n", "5 6\n0 8 7 27 6\n", "5 6\n2 71 7 27 6\n", "5 6\n0 71 7 27 6\n"], "outputs": ["2\n0 79 ", "2\n0 114 ", "2\n0 50\n", "2\n0 50\n", "3\n0 25 50 ", "2\n0 6\n", "2\n0 6 ", "2\n0 6\n"]}
440
198
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team. However, th...
{"functional": "def check(candidate):\n assert candidate(scores = [1,3,5,10,15], ages = [1,2,3,4,5]) == 34\n assert candidate(scores = [4,5,6,5], ages = [2,1,2,1]) == 16\n assert candidate(scores = [1,2,3,5], ages = [8,9,10,1]) == 6\n\n\ncheck(Solution().bestTeamScore)"}
179
116
coding
Solve the programming task below in a Python markdown code block. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic i...
{"inputs": ["4 4 4\n", "4 4 8\n", "1 80 7\n", "1 10 2\n", "6 19 5\n", "12 23 3\n", "2 1000 4\n", "1 124 11\n"], "outputs": ["0\n", "0\n", "3\n", "5\n", "0\n", "2\n", "0\n", "2\n"]}
453
113
coding
Solve the programming task below in a Python markdown code block. It's winter and taking a bath is a delicate matter. Chef has two buckets of water. The first bucket has $v_1$ volume of cold water at temperature $t_1$. The second has $v_2$ volume of hot water at temperature $t_2$. Chef wants to take a bath with at leas...
{"inputs": ["3\n5 10 5 20 8 15\n5 10 5 20 1 30\n5 10 5 20 5 20"], "outputs": ["YES\nNO\nYES"]}
585
61
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. Find the largest even sum of any subsequence of nums that has a length of k. Return this sum, or -1 if such a sum does not exist. A subsequence is an array that ca...
{"functional": "def check(candidate):\n assert candidate(nums = [4,1,5,3,1], k = 3) == 12\n assert candidate(nums = [4,6,2], k = 3) == 12\n assert candidate(nums = [1,3,5], k = 1) == -1\n\n\ncheck(Solution().largestEvenSum)"}
126
90
coding
Solve the programming task below in a Python markdown code block. You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions...
{"inputs": ["1\nbaaa\n", "1\nbaaa\n", "3\ncbabc\n", "2\nabcab\n", "3\nbbabc\n", "2\nabbab\n", "3\ncbabc\n", "2\nabcab\n"], "outputs": ["aaab\n", "aaab", "a\n", "aab\n", "a\n", "aab\n", "a", "aab"]}
494
95
coding
Solve the programming task below in a Python markdown code block. After the Tatvik Hiring Challenge, Karan's NLP professor has given him another homework. Since Manhattan Associates Hiring Challenge is round the corner and Karan is busy preparing for it, he turns to you for help. Given a string, replace all the consec...
{"inputs": ["10\naabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nabcdefghijklmnopqrstuvwxyz\n...............................aaaaaaaaaaaaaaaaaaaaaa\n....................,,,,,,,,,,,,,,,,,,,,,aaaaaaaaaaaaa\naaaaaaaaaaaaa.................dddddddddddkkkkkkkkkkkkvvvvvvvvvvlll...
150
224
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are o...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,0],[0,1]]) == 0\n assert candidate(grid = [[1,0],[1,1]]) == 3\n assert candidate(grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]) == 4\n\n\ncheck(Solution().countServers)"}
124
97
coding
Solve the programming task below in a Python markdown code block. Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a wa...
{"inputs": ["4 4\n1 2 3 4\n9 1 10 6\n", "4 4\n1 3 3 4\n9 1 10 6\n", "4 4\n1 3 6 4\n7 1 10 6\n", "4 4\n2 3 3 4\n7 1 10 6\n", "4 4\n2 3 3 4\n1 1 10 6\n", "4 4\n1 3 3 4\n7 1 10 6\n", "4 4\n1 2 6 4\n9 1 10 6\n", "4 4\n1 2 3 4\n9 1 10 6\n"], "outputs": ["1\n4\n4\n1\n", "1\n1\n4\n2\n", "2\n2\n4\n2\n", "2\n1\n4\n2\n", "4\n3\n...
671
270
coding
Solve the programming task below in a Python markdown code block. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is display...
{"inputs": ["2\nD\nT", "2\nE\nU", "2\nF\nU", "2\nD\nS", "2\nC\nU", "2\nB\nU", "2\nD\nV", "2\nD\nR"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
375
94
coding
Solve the programming task below in a Python markdown code block. In my town ,there live a coder named Chef . He is a cool programmer . One day , he participate in a programming contest ,the contest give him only one problem . If he can’t solve the problem ,the problem setter will kill him . But the round allow you to ...
{"inputs": ["2\n3 5 6 5\n2\n4 5\n6 8\n3 4 7 10\n1\n7 4"], "outputs": ["Test case : 1\nYES\nNO\n3.000000\nTest case : 2\nNO\n3.328201"]}
444
88
coding
Solve the programming task below in a Python markdown code block. Complete the function `scramble(str1, str2)` that returns `true` if a portion of ```str1``` characters can be rearranged to match ```str2```, otherwise returns ```false```. **Notes:** * Only lower case letters will be used (a-z). No punctuation or digi...
{"functional": "_inputs = [['rkqodlw', 'world'], ['cedewaraaossoqqyt', 'codewars'], ['katas', 'steak'], ['scriptjavx', 'javascript'], ['scriptingjava', 'javascript'], ['scriptsjava', 'javascripts'], ['javscripts', 'javascript'], ['aabbcamaomsccdd', 'commas'], ['commas', 'commas'], ['sammoc', 'commas']]\n_outputs = [[Tr...
170
270
coding
Solve the programming task below in a Python markdown code block. Taru likes reading. Every month he gets a copy of the magazine "BIT". The magazine contains information about the latest advancements in technology. Taru reads the book at night and writes the page number to which he has read on a piece of paper so th...
{"inputs": ["2\n10\n2 1 2\n2\n10\n1 8\n0"], "outputs": ["31.2000\n47.0000"]}
537
46
coding
Solve the programming task below in a Python markdown code block. A city has been infected by a contagious virus. In a survey, it was found that A out of the N people living in the city are currently infected. It has been observed that the only way for a person to get infected is if he comes in contact with an already...
{"inputs": ["3\n2 1\n3 2\n3 1"], "outputs": ["1\n1\n1"]}
456
28
coding
Solve the programming task below in a Python markdown code block. Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's me...
{"inputs": ["1 22\n3 5\n1 3\n", "1 22\n0 5\n1 3\n", "1 22\n0 5\n0 3\n", "1 22\n0 2\n0 3\n", "1 100\n6 10\n14 8\n", "1 110\n6 10\n14 8\n", "1 100\n6 10\n14 19\n", "2 160\n6 9\n11 9\n6 6\n"], "outputs": ["1\n1\n", "1\n1 \n", "1\n1 \n", "1\n1 \n", "0\n\n", "0\n\n", "0\n\n", "1\n2\n"]}
577
190
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees. The employees are numbered from 0 to n...
{"functional": "def check(candidate):\n assert candidate(favorite = [2,2,1,2]) == 3\n assert candidate(favorite = [1,2,0]) == 3\n assert candidate(favorite = [3,0,1,4,1]) == 4\n\n\ncheck(Solution().maximumInvitations)"}
172
77
coding
Solve the programming task below in a Python markdown code block. # Task The sequence of `Chando` is an infinite sequence of all Chando's numbers in ascending order. A number is called `Chando's` if it is an integer that can be represented as a sum of different positive integer powers of 5. The first Chando's numb...
{"functional": "_inputs = [[1], [2], [9], [123], [23]]\n_outputs = [[5], [25], [630], [97530], [3280]]\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) !...
239
195
coding
Solve the programming task below in a Python markdown code block. An array is sorted if it has no inversions A Young Boy You are given an array of $n$ positive integers $a_1,a_2,\ldots,a_n$. In one operation you do the following: Choose any integer $x$. For all $i$ such that $a_i = x$, do $a_i := 0$ (assign $0$ to...
{"inputs": ["5\n3\n3 3 2\n4\n1 3 1 3\n5\n4 1 5 3 2\n4\n2 4 1 2\n1\n1\n"], "outputs": ["1\n2\n4\n3\n0\n"]}
425
66
coding
Solve the programming task below in a Python markdown code block. You are given an array A containing N integers. A [subsequence] of this array is called *good* if all the elements of this subsequence are distinct. Find the number of *good* non-empty subsequences of A. This number can be large, so report it modulo 10^...
{"inputs": ["2\n2\n1 1\n2\n1 2\n"], "outputs": ["2\n3\n"]}
434
28
coding
Solve the programming task below in a Python markdown code block. Write a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below. Class ID Ship ClassB or bBattleShipC or cCruiserD or dDestroyerF or fFrigate -----Input----- The first l...
{"inputs": ["3\nB\nc\nD", "3 \nC\nc\nD", "3 \nB\nc\nC", "3 \nB\nc\nB", "3 \nC\nc\nB", "3 \nC\nb\nB", "3 \nB\nd\nD", "3 \nC\nd\nD"], "outputs": ["BattleShip\nCruiser\nDestroyer", "Cruiser\nCruiser\nDestroyer\n", "BattleShip\nCruiser\nCruiser\n", "BattleShip\nCruiser\nBattleShip\n", "Cruiser\nCruiser\nBattleShip\n", "Cru...
160
182
coding
Solve the programming task below in a Python markdown code block. We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, y_1),...
{"inputs": ["4 2 2", "4 5 7", "2 3 2", "4 6 7", "2 3 3", "2 4 3", "1 4 3", "1 4 4"], "outputs": ["56\n", "4883760\n", "25\n", "24227280\n", "100\n", "336\n", "20\n", "10\n"]}
510
115
coding
Solve the programming task below in a Python markdown code block. This contest, AtCoder Beginner Contest, is abbreviated as ABC. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write ...
{"inputs": ["7", "3", "4", "8", "9", "0", "1", "2"], "outputs": ["ABC7\n", "ABC3\n", "ABC4\n", "ABC8\n", "ABC9\n", "ABC0\n", "ABC1\n", "ABC2\n"]}
161
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of points on the X-Y plane points where points[i] = [xi, yi]. The points form a polygon when joined sequentially. Return true if this polygon is convex and false otherwise. You may assume the po...
{"functional": "def check(candidate):\n assert candidate(points = [[0,0],[0,5],[5,5],[5,0]]) == True\n assert candidate(points = [[0,0],[0,10],[10,10],[10,0],[5,5]]) == False\n\n\ncheck(Solution().isConvex)"}
132
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing tha...
{"functional": "def check(candidate):\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2) == 0.25000\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2) == 0.30000\n assert candidate(n = 3, edges = [[0,1]], succPr...
207
180
coding
Solve the programming task below in a Python markdown code block. There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least a_{i} candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i...
{"inputs": ["1 3\n5\n", "1 4\n3\n", "1 4\n3\n", "1 3\n5\n", "1 8\n3\n", "1 3\n6\n", "1 2\n3\n", "1 6\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
470
102
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, return the maximum length of a subarray that appears in both arrays.   Please complete the following python code precisely: ```python class Solution: def findLength(self, ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]) == 3\n assert candidate(nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]) == 5\n\n\ncheck(Solution().findLength)"}
79
89
coding
Solve the programming task below in a Python markdown code block. "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, t...
{"inputs": ["1\n2\n", "1\n1\n", "2\n2 3\n", "2\n1 1\n", "2\n1 2\n", "2\n3 4\n", "2\n3 3\n", "2\n1 4\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0\n", "2\n", "2\n", "1\n"]}
380
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n binary matrix image where 0 represents a white pixel and 1 represents a black pixel. The black pixels are connected (i.e., there is only one black region). Pixels are connected horizontally and ...
{"functional": "def check(candidate):\n assert candidate(image = [[\"0\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"1\",\"0\"],[\"0\",\"1\",\"0\",\"0\"]], x = 0, y = 2) == 6\n assert candidate(image = [[\"1\"]], x = 0, y = 0) == 1\n\n\ncheck(Solution().minArea)"}
155
93
coding
Solve the programming task below in a Python markdown code block. One day, Delta, the dog, got very angry. He has $N$ items with different values, and he decided to destroy a few of them. However, Delta loves his hooman as well. So he only destroyed those items whose Least Significant Bit in binary representation is 0....
{"inputs": ["1\n5\n1 2 3 4 5"], "outputs": ["6"]}
262
24
coding
Solve the programming task below in a Python markdown code block. So the Chef has become health conscious and is now lifting weights at the gym. But its his first time so the trainer gives him a simple job to do. He has been given a weight lifting rod and N heavy weights, each weighing 20, 21, .... , 2n-1. He has to ...
{"inputs": ["3\n2\n5\n18"], "outputs": ["3\n945\n221643095476699771875"]}
276
45
coding
Solve the programming task below in a Python markdown code block. Snuke loves working out. He is now exercising N times. Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely lar...
{"inputs": ["1", "6", "4", "7", "2", "8", "5", "9"], "outputs": ["1\n", "720\n", "24\n", "5040\n", "2\n", "40320\n", "120\n", "362880\n"]}
216
79
coding
Solve the programming task below in a Python markdown code block. We define the score of permutations of combinations, of an integer number (the function to obtain this value:```sc_perm_comb```) as the total sum of all the numbers obtained from the permutations of all the possible combinations of its digits. For exampl...
{"functional": "_inputs = [[348], [340], [333], [6], [0]]\n_outputs = [[3675], [1631], [369], [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 if isinstance(a, (list, tuple)):\n if len(a) ...
359
193
coding
Solve the programming task below in a Python markdown code block. There are n cities in Berland. Each city has its index — an integer number from 1 to n. The capital has index r1. All the roads in Berland are two-way. The road system is such that there is exactly one path from the capital to each city, i.e. the road ma...
{"inputs": ["2 2 1\n2\n", "2 1 2\n1\n", "3 1 3\n1 2\n", "3 2 3\n2 2\n", "4 2 3\n3 2 2\n", "4 2 3\n2 1 3\n", "4 2 3\n3 2 1\n", "5 2 3\n2 4 2 3\n"], "outputs": ["1\n", "2\n", "2 3\n", "2 3\n", "3 3 2\n", "3 1 3\n", "3 3 1\n", "2 4 3 3\n"]}
385
162
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums. A subarray is defined as a contiguous sequence of numbers in an array. A subarray [numsl, numsl+1, ..., numsr...
{"functional": "def check(candidate):\n assert candidate(nums = [10,20,30,5,10,50]) == 65\n assert candidate(nums = [10,20,30,40,50]) == 150\n assert candidate(nums = [12,17,15,13,10,11,12]) == 33\n assert candidate(nums = [100,10,1]) == 100\n\n\ncheck(Solution().maxAscendingSum)"}
140
128
coding
Solve the programming task below in a Python markdown code block. Binod and his family live in Codingland. They have a festival called N-Halloween. The festival is celebrated for N consecutive days. On each day Binod gets some candies from his mother. He may or may not take them. On a given day , Binod will be sad if...
{"inputs": ["5 2\n4 6 5 8 7\n1\n2", "6 3\n20 10 12 3 30 5\n2\n6\n13"], "outputs": ["30\n30", "77\n62\n30"]}
533
70
coding
Solve the programming task below in a Python markdown code block. You have a tree consisting of n vertices. You want to color each vertex of the tree in one of the k colors such that for any pair of vertices having same color, all the vertices belonging to the path joining them should also have same color. In other wor...
{"inputs": ["3\n3 2\n1 2\n2 3\n3 1\n1 2\n2 3\n4 3\n1 2\n2 3\n2 4"], "outputs": ["6\n1\n39"]}
532
57
coding
Solve the programming task below in a Python markdown code block. Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and {Ac, Ac+1, ... , Ad} simu...
{"inputs": ["2\n3\n1 2 3\n4\n1 2 1 2"], "outputs": ["5\n4"]}
457
32
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef doesn't love math anymore. He loves Sasha. Sashen'ka is cute. Chef goes on a date with her. Flowers are boring, while numbers are not. He knows that most of all this girl loves numbers, ...
{"inputs": ["1\n1 10"], "outputs": ["6"]}
305
17
coding
Solve the programming task below in a Python markdown code block. Peter can see a clock in the mirror from the place he sits in the office. When he saw the clock shows 12:22 1 2 3 4 5 6 7 8 9 10 11 12 He knows that the time is 11:38 1 2 3 4 5 6 7 8 9 10 11 12 in the same manner: 05:25 --> 06:35 01:50 --...
{"functional": "_inputs = [['06:35'], ['11:59'], ['12:02'], ['04:00'], ['06:00'], ['12:00']]\n_outputs = [['05:25'], ['12:01'], ['11:58'], ['08:00'], ['06:00'], ['12:00']]\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, ab...
289
235
coding
Solve the programming task below in a Python markdown code block. Chef and Chefina are at positions X and Y on a number line. They both love badminton. It is known that badminton courts are located at every integer point. They want to find a court such that the *maximum* distance travelled by either of them is minim...
{"inputs": ["4\n3 5\n7 6\n1 10\n63 31\n"], "outputs": ["1\n1\n5\n16\n"]}
352
40
coding
Solve the programming task below in a Python markdown code block. Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i ...
{"inputs": ["1\n1\n", "1\n0\n", "1\n4\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n69\n", "1\n69\n"], "outputs": ["1\n", "0\n", "4\n", "2\n", "3\n", "5\n", "69\n", "69\n"]}
438
90
coding
Solve the programming task below in a Python markdown code block. Demodogs from the Upside-down have attacked Hawkins again. El wants to reach Mike and also kill as many Demodogs in the way as possible. Hawkins can be represented as an $n \times n$ grid. The number of Demodogs in a cell at the $i$-th row and the $j$-t...
{"inputs": ["4\n2\n3\n50\n1000000000\n"], "outputs": ["14154\n44484\n171010650\n999589541\n"]}
545
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Element...
{"functional": "def check(candidate):\n assert candidate(arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]) == [2,2,2,1,4,3,3,9,6,7,19]\n assert candidate(arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6]) == [22,28,8,6,17,44]\n\n\ncheck(Solution().relativeSortArray)"}
131
148
coding
Solve the programming task below in a Python markdown code block. Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole. Arkady can block some of...
{"inputs": ["1 1 1\n1\n", "1 2 1\n1\n", "1 2 1\n1\n", "1 1 1\n1\n", "1 2 1\n2\n", "1 1 1\n2\n", "1 2 2\n2\n", "1 2 2\n4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
551
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array pairs, where pairs[i] = [xi, yi], and: There are no duplicates. xi < yi Let ways be the number of rooted trees that satisfy the following conditions: The tree consists of nodes whose values a...
{"functional": "def check(candidate):\n assert candidate(pairs = [[1,2],[2,3]]) == 1\n assert candidate(pairs = [[1,2],[2,3],[1,3]]) == 2\n assert candidate(pairs = [[1,2],[2,3],[2,4],[1,5]]) == 0\n\n\ncheck(Solution().checkWays)"}
243
89
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a date string in the form Day Month Year, where: Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}. Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "...
{"functional": "def check(candidate):\n assert candidate(date = \"20th Oct 2052\") == \"2052-10-20\"\n assert candidate(date = \"6th Jun 1933\") == \"1933-06-06\"\n assert candidate(date = \"26th May 1960\") == \"1960-05-26\"\n\n\ncheck(Solution().reformatDate)"}
194
109
coding
Solve the programming task below in a Python markdown code block. Write a function that takes a string and returns an array of the repeated characters (letters, numbers, whitespace) in the string. If a charater is repeated more than once, only show it once in the result array. Characters should be shown **by the orde...
{"functional": "_inputs = [['apple'], ['limbojackassin the garden'], ['11pinguin'], ['Claustrophobic'], ['apPle'], ['11 pinguin'], ['pippi'], ['Pippi'], ['kamehameha'], ['']]\n_outputs = [[['p']], [['a', 's', 'i', ' ', 'e', 'n']], [['1', 'i', 'n']], [['o']], [[]], [['1', 'i', 'n']], [['p', 'i']], [['p', 'i']], [['a', '...
203
270
coding
Solve the programming task below in a Python markdown code block. Is every value in the array an array? This should only test the second array dimension of the array. The values of the nested arrays don't have to be arrays. Examples: ```python [[1],[2]] => true ['1','2'] => false [{1:1},{2:2}] => false ``` Also fee...
{"functional": "_inputs = [[[]], [[['string']]], [[[], {}]], [[[1], [2], [3]]], [['A', 'R', 'R', 'A', 'Y']]]\n_outputs = [[True], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=to...
104
201
coding
Solve the programming task below in a Python markdown code block. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, .....
{"inputs": ["3\na\nA\na\nA\nb\n", "3\na\nA\na\nA\na\n", "3\nb\nA\na\nA\nb\n", "3\nb\nA\na\nB\nb\n", "3\nab\nBa\naB\nABBA\nl\n", "3\nab\nBa\naB\nABBA\na\n", "3\nab\nBa\naB\nABBB\nl\n", "3\nab\naB\naB\nABBA\na\n"], "outputs": ["B\n", "B\n", "B\n", "A\n", "LLLL\n", "BAAB\n", "LLBB\n", "BABA\n"]}
693
162
coding
Solve the programming task below in a Python markdown code block. problem Taro bought 10 books. Later, I tried to find out the price based on the receipt, but the receipt was dirty and I could not read the price of a book. We decided to calculate the price of the book from the total price of 10 books and the prices of...
{"inputs": ["9850\n38\n8\n357\n78\n55\n946\n2795\n4727\n980\n0", "9850\n38\n8\n357\n67\n55\n946\n2795\n4727\n980\n0", "9850\n38\n8\n357\n380\n55\n946\n2795\n4727\n980\n0", "9850\n38\n8\n357\n435\n55\n946\n2795\n4727\n980\n0", "9850\n74\n51\n420\n1221\n600\n28\n363\n1693\n44\n0", "9850\n74\n28\n420\n1221\n600\n28\n363\n...
174
392
coding
Solve the programming task below in a Python markdown code block. Write a program to take a character (C) as input and check whether the given character is a vowel or a consonant. NOTE:- Vowels are 'A', 'E', 'I', 'O', 'U'. Rest all alphabets are called consonants. ------ Input Format ------ - First line will contai...
{"inputs": ["Z\n"], "outputs": ["Consonant"]}
157
15
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": ["0\n01\n10\n012\n101\n210\n0123\n1012\n2101\n3210"]}
216
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surro...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]) == 16\n assert candidate(grid = [[1]]) == 4\n assert candidate(grid = [[1,0]]) == 4\n\n\ncheck(Solution().islandPerimeter)"}
179
90
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.   Please complete the following python code precisely: `...
{"functional": "def check(candidate):\n assert candidate(points = [[1,1],[2,2],[3,3]]) == 3\n assert candidate(points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]) == 4\n\n\ncheck(Solution().maxPoints)"}
87
75