problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
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)"}
coding
194
Solve the programming task below in a Python markdown code block. Scheduling is how the processor decides which jobs (processes) get to use the processor and for how long. This can cause a lot of problems. Like a really long process taking the entire CPU and freezing all the other processes. One solution is Round-Robin...
{"functional": "_inputs = [[[10], 4, 0], [[10, 20], 5, 0], [[10, 20, 1, 2, 3], 5, 2], [[10, 20, 1, 2, 3], 5, 0], [[10, 20, 1, 2, 3], 4, 2], [[10, 20, 1, 2, 3], 4, 3]]\n_outputs = [[10], [15], [11], [21], [9], [11]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
486
Solve the programming task below in a Python markdown code block. Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem. Find the maximum decimal number without zeroes and with no equal digits in a...
{"inputs": ["5\n1\n2\n3\n4\n5\n"], "outputs": ["1\n2\n21\n121\n212\n"]}
coding
441
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. Swaps of adjacent elements are able to be performed on nums. A valid array meets the following conditions: The largest element (any of the largest elements if there are m...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,5,5,3,1]) == 6\n assert candidate(nums = [9]) == 0\n\n\ncheck(Solution().minimumSwaps)"}
coding
142
Solve the programming task below in a Python markdown code block. Find the number of positive integral solutions for the equations $\dfrac{1}{x}+\dfrac{1}{y}=\dfrac{1}{N!}$ Input Format An integer N  Output Format The number of positive integral solutions for the above equation modulo 1000007 Constraints ...
{"inputs": ["1 \n", "32327\n", "40921\n"], "outputs": ["1\n", "656502 \n", "686720\n"]}
coding
157
Solve the programming task below in a Python markdown code block. Array inversion indicates how far the array is from being sorted. Inversions are pairs of elements in array that are out of order. ## Examples ``` [1, 2, 3, 4] => 0 inversions [1, 3, 2, 4] => 1 inversion: 2 and 3 [4, 1, 2, 3] => 3 inversions: 4 ...
{"functional": "_inputs = [[[]], [[1, 2, 3]], [[2, 1, 3]], [[6, 5, 4, 3, 2, 1]], [[6, 5, 4, 3, 3, 3, 3, 2, 1]]]\n_outputs = [[0], [0], [1], [15], [30]]\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 i...
coding
229
Solve the programming task below in a Python markdown code block. Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] ...
{"inputs": ["5\n7 3 2 4 1", "5\n7 3 2 3 1", "5\n7 3 2 3 0", "5\n7 3 4 3 0", "5\n7 1 4 3 0", "5\n7 1 4 3 1", "5\n4 2 4 3 1", "5\n4 2 5 3 1"], "outputs": ["1 2 3 4 7\n8\n", "1 2 3 3 7\n8\n", "0 2 3 3 7\n8\n", "0 3 3 4 7\n8\n", "0 1 3 4 7\n8\n", "1 1 3 4 7\n7\n", "1 2 3 4 4\n7\n", "1 2 3 4 5\n7\n"]}
coding
288
Solve the programming task below in a Python markdown code block. For this kata, you are given three points ```(x1,y1,z1)```, ```(x2,y2,z2)```, and ```(x3,y3,z3)``` that lie on a straight line in 3-dimensional space. You have to figure out which point lies in between the other two. Your function should return 1, 2, or...
{"functional": "_inputs = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 0, 6, -2, 8, 3, 0, 4], [0.25, 0.5, 0.75, 3.25, -0.5, -0.25, 1.0, 0.25, 0.5], [1, 0, 4, 5, 0, 6, -7, 0, 0], [-1, 0, 2, -2, 4, -1, -3, 8, -4]]\n_outputs = [[2], [3], [3], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or is...
coding
150
Solve the programming task below in a Python markdown code block. Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG". Maxim was very boring to sit in class, so the teacher came up with a task for him: o...
{"inputs": ["4\nZCTH\n", "4\nNPGT\n", "4\nAZTG\n", "4\nYCTG\n", "4\nANTG\n", "4\nOCTG\n", "4\nACHG\n", "4\nANTG\n"], "outputs": ["2", "52", "3", "2", "11", "12", "12", "11\n"]}
coding
536
Solve the programming task below in a Python markdown code block. In this problem, we'll use the term "longest common substring" loosely. It refers to substrings differing at some number or fewer characters when compared index by index. For example, 'abc' and 'adc' differ in one position, 'aab' and 'aba' differ in tw...
{"inputs": ["3\n2 tabriz torino\n0 abacba abcaba\n3 helloworld yellomarin\n"], "outputs": ["4\n3\n8\n"]}
coding
677
Solve the programming task below in a Python markdown code block. There are S sheep and W wolves. If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep. If the wolves will attack the sheep, print unsafe; otherwise, print safe. -----Constraints----- - 1 \leq S \leq 100 - ...
{"inputs": ["1 5", "1 6", "0 6", "0 7", "0 8", "0 1", "0 0", "1 0"], "outputs": ["unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "safe\n"]}
coding
168
Solve the programming task below in a Python markdown code block. You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and a goal, determine the minmum number of mov...
{"inputs": ["3\n.X.\n.X.\n...\n0 0 0 2\n"], "outputs": ["3\n"]}
coding
504
Solve the programming task below in a Python markdown code block. Chef is multi-talented. He has developed a cure for coronavirus called COVAC-19. Now that everyone in the world is infected, it is time to distribute it throughout the world efficiently to wipe out coronavirus from the Earth. Chef just cooks the cure, yo...
{"inputs": ["3\n5 5\n1 2 3 4 5\n5 1\n40 30 20 10 50\n3 10\n20 1 110"], "outputs": ["5\n9\n6"]}
coding
633
Solve the programming task below in a Python markdown code block. Chef has two integers X and S. He is interested in sequences of non-negative integers such that the sum of their elements is S and the [bitwise OR] of their elements is X. Chef would like to know the shortest possible length such a sequence can have. Fo...
{"inputs": ["3\n13 23\n6 13\n1 25\n"], "outputs": ["3\n-1\n25\n"]}
coding
483
Solve the programming task below in a Python markdown code block. Bob has ladder. He wants to climb this ladder, but being a precocious child, he wonders about exactly how many ways he could to climb this `n` size ladder using jumps of up to distance `k`. Consider this example... n = 5\ k = 3 Here, Bob has ladder of...
{"functional": "_inputs = [[1, 3], [3, 3], [2, 3], [5, 3], [4, 3], [10, 6], [14, 7]]\n_outputs = [[1], [4], [2], [13], [7], [492], [7936]]\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, ...
coding
287
Solve the programming task below in a Python markdown code block. ### Task: You have to write a function `pattern` which returns the following Pattern(See Examples) upto (2n-1) rows, where n is parameter. * Note:`Returning` the pattern is not the same as `Printing` the pattern. #### Parameters: pattern( ...
{"functional": "_inputs = [[3], [15], [-3], [-25], [0]]\n_outputs = [['1 1\\n 2 2 \\n 3 \\n 2 2 \\n1 1'], ['1 1\\n 2 2 \\n 3 3 \\n 4 4 \\n 5 5 \\n 6 6 \\n 7 ...
coding
634
Solve the programming task below in a Python markdown code block. # Task You are given an array of integers `a` and a non-negative number of operations `k`, applied to the array. Each operation consists of two parts: ``` find the maximum element value of the array; replace each element a[i] with (maximum element value...
{"functional": "_inputs = [[[-4, 0, -1, 0], 2], [[0, -1, 0, 0, -1, -1, -1, -1, 1, -1], 1], [[-1], 10000]]\n_outputs = [[[0, 4, 3, 4]], [[1, 2, 1, 1, 2, 2, 2, 2, 0, 2]], [[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...
coding
604
Solve the programming task below in a Python markdown code block. In this kata you need to create a function that takes a 2D array/list of non-negative integer pairs and returns the sum of all the "saving" that you can have getting the [LCM](https://en.wikipedia.org/wiki/Least_common_multiple) of each couple of number ...
{"functional": "_inputs = [[[[15, 18], [4, 5], [12, 60]]], [[[1, 1], [0, 0], [13, 91]]], [[[15, 7], [4, 5], [19, 60]]], [[[20, 50], [10, 10], [50, 20]]], [[]]]\n_outputs = [[840], [1092], [0], [1890], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ...
coding
269
Solve the programming task below in a Python markdown code block. Ayush is learning how to decrease a number by one, but he does it wrong with a number consisting of two or more digits. Ayush subtracts one from a number by the following algorithm: if the last digit of the number is non-zero, he decreases the number by ...
{"inputs": ["512 4", "1000000000 9"], "outputs": ["50", "1"]}
coding
263
Solve the programming task below in a Python markdown code block. ### Happy Holidays fellow Code Warriors! Now, Dasher! Now, Dancer! Now, Prancer, and Vixen! On, Comet! On, Cupid! On, Donder and Blitzen! That's the order Santa wanted his reindeer...right? What do you mean he wants them in order by their last names!? L...
{"functional": "_inputs = [[['Kenjiro Mori', 'Susumu Tokugawa', 'Juzo Okita', 'Akira Sanada']], [[]], [['Yasuo Kodai', 'Kenjiro Sado', 'Daisuke Aihara', 'Susumu Shima', 'Akira Sanada', 'Yoshikazu Okita', 'Shiro Yabu', 'Sukeharu Nanbu', 'Sakezo Yamamoto', 'Hikozaemon Ohta', 'Juzo Mori', 'Saburo Tokugawa']], [['Daisuke M...
coding
338
Solve the programming task below in a Python markdown code block. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i. -----Constraints---...
{"inputs": ["1\n3 9", "1\n5 9", "1\n9 9", "1\n3 7", "1\n3 7\n", "1\n3 13", "4\n11 13\n7 0\n1 11\n39 2017", "4\n2 13\n7 1\n7 17\n879 2017"], "outputs": ["2\n", "1\n", "0\n", "2", "2\n", "3\n", "1\n-2\n2\n32\n", "3\n-2\n1\n16\n"]}
coding
306
Solve the programming task below in a Python markdown code block. There are 'n' coins kept on the table, numbered from 0 to 'n-1'. Initially, each coin is kept tails up. You have to perform two types of operations : 1) Flip all coins numbered between A and B inclusive. This is represented by the command: 0 A B 2) Answe...
{"inputs": ["7\n3\n0\n3\n5\n1\n0\n6\n1\n3\n4"], "outputs": ["3\n2"]}
coding
253
Solve the programming task below in a Python markdown code block. There is a chess board of size $n \times m$. The rows are numbered from $1$ to $n$, the columns are numbered from $1$ to $m$. Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knigh...
{"inputs": ["3\n1 7\n8 8\n3 3\n", "4\n1 1\n1 1\n1 1\n1 6\n", "62\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\...
coding
372
Solve the programming task below in a Python markdown code block. # A History Lesson The Pony Express was a mail service operating in the US in 1859-60. It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the transcontinental telegrap...
{"functional": "_inputs = [[[43, 23, 40, 13], 4], [[18, 15], 2], [[43, 23, 40, 13], 3], [[33, 8, 16, 47, 30, 30, 46], 5], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49], 2], [[50, 50], 2], [[50, 50, 25, 50, 24], 3], [[50, 51, 25, 50, 25], 3], [[50, 100, 25, 50, 26], 3], [[100], 2], [[50, 50], 3], [[50, 51], 3]]\...
coding
575
Solve the programming task below in a Python markdown code block. Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has n rows of keys containing m keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys wo...
{"inputs": ["1 1 50\nS\n1\nS\n", "1 1 65\nS\n1\nS\n", "2 2 1\nab\ndc\n1\ne\n", "2 2 1\nba\ndc\n1\ne\n", "2 2 1\nba\ncc\n1\ne\n", "2 2 1\nab\ncd\n1\ne\n", "2 2 1\nab\ncd\n1\nA\n", "2 1 2\nS\nc\n4\nCSSA\n"], "outputs": ["-1", "-1\n", "-1\n", "-1\n", "-1\n", "-1", "-1", "-1"]}
coding
650
Solve the programming task below in a Python markdown code block. You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! $m$ Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decre...
{"inputs": ["1\n1 1\n3 1\n", "1\n1 5\n6 7\n", "1\n1 5\n5 5\n", "1\n1 5\n5 7\n", "1\n1 1\n2 2\n", "1\n1 1\n5 6\n", "1\n1 2\n2 2\n", "1\n1 5\n5 6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
679
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1. The matrix is disconnected if there is no path from (0...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1],[1,0,0],[1,1,1]]) == True\n assert candidate(grid = [[1,1,1],[1,0,1],[1,1,1]]) == False\n\n\ncheck(Solution().isPossibleToCutPath)"}
coding
211
Solve the programming task below in a Python markdown code block. Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so ...
{"inputs": ["1 0\n5\n", "1 0\n8\n", "1 0\n3\n", "3 1\n108\n", "3 2\n108\n", "5 2\n39923\n", "5 2\n20409\n", "5 2\n59455\n"], "outputs": ["5\n", "8\n", "3\n", "27\n", "9\n", "2667\n", "792\n", "2409\n"]}
coding
445
Solve the programming task below in a Python markdown code block. You are batting at the pitch and all eyes are on you, the best player in all of IPL! The opposing team will relentlessly bowl at you an infinite number of balls! You notice that you only ever score a boundary on the M^{th} ball, if N mod M ≤ N/2, where ...
{"inputs": ["1\n3"], "outputs": ["3"]}
coding
313
Solve the programming task below in a Python markdown code block. ```if-not:swift Write simple .camelCase method (`camel_case` function in PHP, `CamelCase` in C# or `camelCase` in Java) for strings. All words must have their first letter capitalized without spaces. ``` ```if:swift Write a simple `camelCase` function fo...
{"functional": "_inputs = [['test case'], ['camel case method'], ['say hello '], [' camel case word'], ['']]\n_outputs = [['TestCase'], ['CamelCaseMethod'], ['SayHello'], ['CamelCaseWord'], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo...
coding
196
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of integers, return how many of them contain an even number of digits.   Please complete the following python code precisely: ```python class Solution: def findNumbers(self, nums: List[int]) ->...
{"functional": "def check(candidate):\n assert candidate(nums = [12,345,2,6,7896]) == 2\n assert candidate(nums = [555,901,482,1771]) == 1 \n\n\ncheck(Solution().findNumbers)"}
coding
67
Solve the programming task below in a Python markdown code block. Chef is working on his swap-based sorting algorithm for strings. Given a string S of length N, he wants to know whether he can sort the string using his algorithm. According to the algorithm, one can perform the following operation on string S any numb...
{"inputs": ["3\n4\ndbca\n3\nccc\n3\nbza"], "outputs": ["YES\nYES\nNO"]}
coding
588
Solve the programming task below in a Python markdown code block. You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented ...
{"inputs": ["A\n", "G\n", "T\n", "C\n", "C\n", "G\n", "A\n", "T\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
434
Solve the programming task below in a Python markdown code block. Complete the solution so that it takes the object (JavaScript/CoffeeScript) or hash (ruby) passed in and generates a human readable string from its key/value pairs. The format should be "KEY = VALUE". Each key/value pair should be separated by a comma ...
{"functional": "_inputs = [[{'a': 1, 'b': 2}], [{'a': 'b', 'b': 'a'}], [{'0': 'a', 'b': 2}], [{'b': 1, 'c': 2, 'e': 3}], [{}]]\n_outputs = [['a = 1,b = 2'], ['a = b,b = a'], ['0 = a,b = 2'], ['b = 1,c = 2,e = 3'], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
129
Solve the programming task below in a Python markdown code block. Like all minions Dave also like to eat bananas. So as to his obsession, he is eating banana, but this time in different way. There are N bananas in dish. Dave wants to eat all of them. He starts eating at speed 1 banana/second. He can increase or decreas...
{"inputs": ["2\n2\n4"], "outputs": ["2\n3"]}
coding
295
Solve the programming task below in a Python markdown code block. Impliment the reverse function, which takes in input n and reverses it. For instance, `reverse(123)` should return `321`. You should do this without converting the inputted number into a string. Also feel free to reuse/extend the following starter code: ...
{"functional": "_inputs = [[1234], [4321], [1001], [1010], [12005000]]\n_outputs = [[4321], [1234], [1001], [101], [50021]]\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)):...
coding
80
Solve the programming task below in a Python markdown code block. A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters + and 1 into this sequence. For example, sequences (())(), () and (()(())) are regular, while )(, (() and (()))( are not. Let's call a ...
{"inputs": ["5\n()\n(?)\n(??)\n??()\n)?(?\n", "5\n()\n(?)\n)??(\n??()\n)?(?\n", "5\n()\n(?)\n(??)\n??()\n?(?)\n", "5\n()\n?()\n(??)\n??()\n)?(?\n", "5\n()\n(?)\n(??)\n)(??\n?(?)\n", "5\n)(\n?()\n(??)\n??()\n)?(?\n", "5\n)(\n(?)\n(??)\n)(??\n?(?)\n", "5\n()\n(?)\n)??(\n??()\n?(?)\n"], "outputs": ["YES\nNO\nYES\nYES\nNO\...
coding
392
Solve the programming task below in a Python markdown code block. Chef has learned a new technique for comparing two recipes. A recipe contains a list of ingredients in increasing order of the times they will be processed. An ingredient is represented by a letter 'a'-'z'. The i-th letter in a recipe denotes the i-th in...
{"inputs": ["3\nalex axle\nparadise diapers\nalice bob", "3\nalex axle\nesidarap diapers\nalice bob", "3\nelax axle\nesidarap djapers\nalice bob", "3\nelax axle\nesidarap diapers\nalice bob", "3\nelax ayle\nesidarap djapers\nalice bob", "3\nelax ayle\nesidarap srepajd\nalice bob", "3\nelax ayle\netidarap srepajd\nalice...
coding
571
Solve the programming task below in a Python markdown code block. To help Lavanya learn all about binary numbers and binary sequences, her father has bought her a collection of square tiles, each of which has either a 0 or a 1 written on it. Her brother Nikhil has played a rather nasty prank. He has glued together pair...
{"inputs": ["4"], "outputs": ["5"]}
coding
405
Solve the programming task below in a Python markdown code block. Andrew likes meatballs very much. He has N plates of meatballs, here the i^{th} plate contains P_{i} meatballs. You need to find the minimal number of plates Andrew needs to take to his trip to Las Vegas, if he wants to eat there at least M meatballs. No...
{"inputs": ["1\n4 7\n1 2 3 4"], "outputs": ["2"]}
coding
331
Solve the programming task below in a Python markdown code block. Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a bl...
{"inputs": ["4 3 2 1\n2\n", "0 0 0 0\n1\n", "1 2 3 4\n4\n", "1 2 3 4\n4\n", "4 3 2 1\n2\n", "0 0 0 0\n1\n", "0 2 3 4\n4\n", "0 3 2 1\n2\n"], "outputs": ["3\n", "0\n", "4\n", "4\n", "3\n", "0\n", "4\n", "3\n"]}
coding
361
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.   Please complete the following python code precisely: ```python class Solution: def numDupDigi...
{"functional": "def check(candidate):\n assert candidate(n = 20) == 1\n assert candidate(n = 100) == 10\n assert candidate(n = 1000) == 262\n\n\ncheck(Solution().numDupDigitsAtMostN)"}
coding
78
Please solve the programming task below using a self-contained code snippet in a markdown code block. In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition. The ordering of teams is decided by who received the most position-one votes. If two or more t...
{"functional": "def check(candidate):\n assert candidate(votes = [\"ABC\",\"ACB\",\"ABC\",\"ACB\",\"ACB\"]) == \"ACB\"\n assert candidate(votes = [\"WXYZ\",\"XYZW\"]) == \"XWYZ\"\n assert candidate(votes = [\"ZMNAGUEDSJYLBOPHRQICWFXTVK\"]) == \"ZMNAGUEDSJYLBOPHRQICWFXTVK\"\n assert candidate(votes = [\"BCA\...
coding
189
Please solve the programming task below using a self-contained code snippet in a markdown code block. A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes labelled from 0 to n - 1, and an ...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[1,0],[1,2],[1,3]]) == [1]\n assert candidate(n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]) == [3,4]\n\n\ncheck(Solution().findMinHeightTrees)"}
coding
255
Solve the programming task below in a Python markdown code block. Square Route Square root English text is not available in this practice contest. Millionaire Shinada, who has decided to build a new mansion, is wondering in which city to build the new mansion. To tell the truth, Mr. Shinada is a strange person who l...
{"inputs": ["3 3\n2\n1\n1\n2\n3\n1\n1 2\n7\n8\n3\n0 0", "3 3\n2\n1\n1\n2\n3\n1\n1 2\n1\n8\n3\n0 0", "3 3\n2\n1\n1\n2\n0\n1\n1 2\n7\n8\n26\n0 0", "3 3\n1\n2\n1\n2\n6\n1\n1 2\n10\n7\n6\n0 0", "3 3\n2\n1\n4\n2\n3\n1\n1 2\n7\n8\n26\n0 0", "3 3\n2\n1\n1\n2\n3\n1\n1 2\n7\n8\n26\n0 0", "3 3\n1\n0\n4\n2\n3\n2\n1 2\n10\n4\n2\n0...
coding
558
Solve the programming task below in a Python markdown code block. Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter...
{"inputs": ["a\nZ\n", "q\nq\n", "O\ni\n", "m\na\n", "b\nZ\n", "q\nr\n", "O\nj\n", "m\nb\n"], "outputs": ["-1\n", "0\n", "1\n", "1\n", "-1\n", "-1\n", "1\n", "1\n"]}
coding
284
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be: 1 which means go to the cell to the right. (i.e go fr...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]) == 3\n assert candidate(grid = [[1,1,3],[3,2,2],[1,1,4]]) == 0\n assert candidate(grid = [[1,2],[4,3]]) == 1\n assert candidate(grid = [[2,2,2],[2,2,2]]) == 3\n assert candidate(grid = [[4]]) == 0\n...
coding
340
Solve the programming task below in a Python markdown code block. There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters `R`, `G`, and `B`. Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adj...
{"functional": "_inputs = [['RRGGBB'], ['RGBRGB'], ['BGRBBGGBRRR'], ['GBBBGGRRGRB'], ['GBRGGRBBBBRRGGGB']]\n_outputs = [[3], [0], [4], [4], [7]]\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 isinstan...
coding
144
Solve the programming task below in a Python markdown code block. A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the student h...
{"inputs": ["2\nL\n", "3\nR=\n", "3\n=R\n", "4\nRRL\n", "4\nLRR\n", "4\nRLR\n", "5\nRLRL\n", "5\nRRR=\n"], "outputs": ["2 1 \n", "1 2 2 \n", "1 1 2\n", "1 2 3 1 \n", "2 1 2 3\n", "1 2 1 2\n", "1 2 1 2 1\n", "1 2 3 4 4\n"]}
coding
316
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef found a very useful open-source code for the current problem. Unfortunately, one fragment of code isn't optimized. Consider that problem: given an array D of size N and Q...
{"inputs": ["2\n2 3\n2 3\n5 100 8\n3 2\n2 2 2\n16 8"], "outputs": ["0 16 1\n2 1"]}
coding
475
Solve the programming task below in a Python markdown code block. Bit Vectors/Bitmaps A bitmap is one way of efficiently representing sets of unique integers using single bits. To see how this works, we can represent a set of unique integers between `0` and `< 20` using a vector/array of 20 bits: ``` var set = [3, 14, ...
{"functional": "_inputs = [['4814\\n3815\\n54\\n2747\\n1449\\n1880\\n1109\\n4942\\n1646\\n1750\\n2933\\n963\\n1757\\n137\\n4100\\n2188\\n2487\\n3027\\n1771\\n1223\\n4458\\n2755\\n247\\n3975\\n2125\\n1071\\n3967\\n3557\\n2741\\n3052\\n2013\\n4741\\n4501\\n975\\n1194\\n2352\\n3548\\n3436\\n462\\n2990\\n1072\\n53\\n920\\n...
coding
536
Solve the programming task below in a Python markdown code block. Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing successiv...
{"inputs": ["2 1 1 1\n", "2 2 1 2\n", "1 2 1 1\n", "1 1 1 1\n", "1 3 1 2\n", "2 1 1 2\n", "2 3 1 3\n", "1 5 4 4\n"], "outputs": ["1\n", "3\n", "1\n", "2\n", "2\n", "1\n", "6\n", "4\n"]}
coding
410
Solve the programming task below in a Python markdown code block. Recently, Chef visited his doctor. The doctor advised Chef to drink at least 2000 ml of water each day. Chef drank X ml of water today. Determine if Chef followed the doctor's advice or not. ------ Input Format ------ - The first line contains a sin...
{"inputs": ["3\n2999\n1450\n2000\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
356
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of: Choosing any x with 0 < x < n and n...
{"functional": "def check(candidate):\n assert candidate(n = 2) == True\n assert candidate(n = 3) == False\n\n\ncheck(Solution().divisorGame)"}
coding
151
Solve the programming task below in a Python markdown code block. # Triple Trouble Create a function that will return a string that combines all of the letters of the three inputed strings in groups. Taking the first letter of all of the inputs and grouping them next to each other. Do this for every letter, see exam...
{"functional": "_inputs = [['aaa', 'bbb', 'ccc'], ['aaaaaa', 'bbbbbb', 'cccccc'], ['burn', 'reds', 'roll'], ['Bm', 'aa', 'tn'], ['LLh', 'euo', 'xtr']]\n_outputs = [['abcabcabc'], ['abcabcabcabcabcabc'], ['brrueordlnsl'], ['Batman'], ['LexLuthor']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)...
coding
136
Solve the programming task below in a Python markdown code block. # Task In ChessLand there is a small but proud chess bishop with a recurring dream. In the dream the bishop finds itself on an `n × m` chessboard with mirrors along each edge, and it is not a bishop but a ray of light. This ray of light moves only a...
{"functional": "_inputs = [[[3, 7], [1, 2], [-1, 1], 13], [[1, 2], [0, 0], [1, 1], 6], [[2, 2], [1, 0], [1, 1], 12], [[1, 1], [0, 0], [1, -1], 1000000000], [[2, 3], [1, 2], [-1, -1], 41], [[17, 19], [14, 8], [1, -1], 239239], [[17, 19], [16, 18], [1, 1], 239239239]]\n_outputs = [[[0, 1]], [[0, 1]], [[1, 0]], [[0, 0]], ...
coding
720
Solve the programming task below in a Python markdown code block. N teams have come to participate in a competitive coding event called “Binary Battles”. It is a [single-elimination tournament] consisting of several rounds. Note: It is known that N is a power of 2. In one round, each team will be paired up with and c...
{"inputs": ["4\n4 10 5\n16 30 5\n32 45 15\n1024 23 9\n"], "outputs": ["25\n135\n285\n311"]}
coding
675
Please solve the programming task below using a self-contained code snippet in a markdown code block. Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed). Given three integers m, n, and k, return the kth smallest elemen...
{"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, k = 5) == 3\n assert candidate(m = 2, n = 3, k = 6) == 6\n\n\ncheck(Solution().findKthNumber)"}
coding
118
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed permutation of n integers nums. A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want u...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,4,3]) == 2\n assert candidate(nums = [2,4,1,3]) == 3\n assert candidate(nums = [1,3,4,2,5]) == 0\n\n\ncheck(Solution().semiOrderedPermutation)"}
coding
154
Solve the programming task below in a Python markdown code block. Create a program that converts the date expressed in the Christian era to the Japanese calendar using the era name and outputs the date. The input is three integers, as shown in the example, in the order year, month, and day. Convert this as shown in the...
{"inputs": ["2005 6 3\n53 5 1\n581 9 2", "2447 6 3\n53 5 1\n581 9 2", "2297 5 3\n411 5 1\n581 9 2", "2005 9 3\n1868 9 3\n359 9 7", "2965 9 3\n1868 9 3\n359 9 7", "4983 9 3\n1868 9 3\n359 9 7", "2005 4 3\n1868 9 3\n359 9 7", "3378 9 3\n373 10 3\n329 9 7"], "outputs": ["heisei 17 6 3\npre-meiji\npre-meiji\n", "heisei 459...
coding
344
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's ...
{"inputs": ["1\n", "4\n", "7\n", "9\n", "3\n", "6\n", "2\n", "5\n"], "outputs": ["47\n", "47\n", "47\n", "47\n", "47\n", "47\n", "47\n", "47\n"]}
coding
277
Solve the programming task below in a Python markdown code block. Nezzar's favorite digit among $1,\ldots,9$ is $d$. He calls a positive integer lucky if $d$ occurs at least once in its decimal representation. Given $q$ integers $a_1,a_2,\ldots,a_q$, for each $1 \le i \le q$ Nezzar would like to know if $a_i$ can be e...
{"inputs": ["2\n3 2\n6 47 1\n10 3\n50 52 2 43 113 92 9 73 42 60\n", "2\n3 7\n24 44 40\n10 7\n4 52 4 54 64 54 66 2 25 60\n", "2\n3 2\n5 47 1\n10 3\n50 52 2 43 113 92 9 73 42 60\n", "2\n3 7\n10 25 27\n10 5\n13 52 53 2 55 56 57 58 9 8\n", "2\n3 2\n5 47 1\n10 3\n50 52 1 43 113 92 8 73 42 60\n", "2\n3 2\n24 44 10\n10 7\n4 5...
coding
399
Solve the programming task below in a Python markdown code block. You have full control over a robot that walks around in a rectangular field paved with square tiles like a chessboard. There are m columns of tiles from west to east, and n rows of tiles from south to north (1 <= m, n <= 100). Each tile is given a pair o...
{"inputs": ["6 5\nFORWARD 3\nRIGHT\nFORWARD 5\nLEFT\nBACKWARD 2\nSTOP\n5 1\nFORWARD 2\nSTOP\n0 0", "6 5\nFORWARD 3\nRIGHT\nFORWARD 5\nLEFT\nBACKWARD 3\nSTOP\n3 1\nFORWARD 2\nSTOP\n0 0", "6 6\nFORDARW 1\nRIGHT\nFORWARD 5\nLEFT\nBACKWARD 3\nSTOP\n3 2\nFORWARD 2\nSTOP\n0 0", "1 2\nFORDARW 3\nRIGHT\nFORWARD 5\nLEFT\nBACKWA...
coding
612
Solve the programming task below in a Python markdown code block. A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices. A subtree of a tree T is a tree with both vertices a...
{"inputs": ["3\n1 2\n1 3\n2 0 1\n", "3\n1 2\n1 3\n1 -1 1\n", "3\n1 2\n1 3\n1 -1 2\n", "3\n1 2\n1 3\n2 -1 1\n", "3\n1 2\n1 3\n1 -1 3\n", "3\n1 2\n1 3\n2 -1 3\n", "3\n1 2\n1 3\n1 -1 1\n", "5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3\n"], "outputs": ["2\n", "3\n", "3\n", "4\n", "5\n", "4\n", "3\n", "8\n"]}
coding
417
Solve the programming task below in a Python markdown code block. Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a). -----Input----- ...
{"inputs": ["1 0\n1\n", "1 1\n1\n", "1 3\n1\n", "1 9\n1\n", "1 3\n1\n", "1 1\n1\n", "1 0\n1\n", "1 9\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
256
Solve the programming task below in a Python markdown code block. Young Sheldon is given the task to teach Chemistry to his brother Georgie. After teaching him how to find total atomic weight, Sheldon gives him some formulas which consist of $x$, $y$ and $z$ atoms as an assignment. You already know that Georgie doesn'...
{"inputs": ["2\n(xy)2\nx(x2y)3(z)2"], "outputs": ["12\n46"]}
coding
379
Solve the programming task below in a Python markdown code block. Given a binary number (of $N$ bits) $X$. Find the highest power of 2 that divides this number. Note: If the binary number is "100" then the highest power of 2 that divides it is 2 (as $2^{2}$ = 4) ------ Input: ------ The first line contains N the num...
{"inputs": ["5\n10100"], "outputs": ["2"]}
coding
175
Solve the programming task below in a Python markdown code block. Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i}...
{"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n1\n1 2\n2 1\n-1\n"]}
coding
474
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them. We repeatedly make duplicate removals on s until we no longe...
{"functional": "def check(candidate):\n assert candidate(\"abbaca\") == \"ca\"\n\n\ncheck(Solution().removeDuplicates)"}
coding
112
Solve the programming task below in a Python markdown code block. Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether S...
{"inputs": ["4 0", "1 2", "7 0", "0 2", "5 0", "0 8", "0 6", "0 0"], "outputs": ["Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n"]}
coding
205
Solve the programming task below in a Python markdown code block. In 2300, the Life Science Division of Federal Republic of Space starts a very ambitious project to complete the genome sequencing of all living creatures in the entire universe and develop the genomic database of all space life. Thanks to scientific rese...
{"inputs": ["ABC 3\nABB 0\n2(4(AB)3(XY))10C 2\n1000(1000(1000(1000(1000(1000(NM)))))) 76895\n0 0", "ABC 3\nABC 0\n2(4(AB)3(XY))10C 3\n1000(1000(1000(1000(1000(1000(NM)))))) 999999\n0 0", "ABC 3\nABC 0\n2(4(AB)3(XY))10C 3\n1000(1000(1000(1000(1000(1000(NM)))))) 976314\n0 0", "ABC 3\nBAB 0\n2(4(AB)3(XY))10C 3\n1000(1000(...
coding
717
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Today is Chef's birthday. His mom gifted him a truly lovable gift, a permutation of first N positive integers. She placed the permutation on a very long table in front of Chef and left it for ...
{"inputs": ["2\n5 2\n3 5\n5 1\n1", "2\n5 2\n3 5\n7 1\n1", "2\n5 2\n3 3\n7 1\n1", "2\n6 2\n1 3\n7 1\n2", "2\n6 0\n1 3\n7 0\n1", "2\n5 2\n3 3\n7 0\n1", "2\n5 2\n1 3\n7 0\n1", "2\n6 2\n1 3\n7 0\n1"], "outputs": ["Mom\nChef", "Mom\nChef\n", "Chef\nChef\n", "Chef\nMom\n", "Mom\nMom\n", "Chef\nChef\n", "Chef\nChef\n", "Chef\...
coding
739
Solve the programming task below in a Python markdown code block. Following from the previous kata and taking into account how cool psionic powers are compare to the Vance spell system (really, the idea of slots to dumb down the game sucks, not to mention that D&D became a smash hit among geeks, so...), your task in th...
{"functional": "_inputs = [[1, 0], [1, 10], [1, 11], [0, 11], [1, 20], [21, 30]]\n_outputs = [[0], [0], [2], [0], [4], [448]]\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)...
coding
594
Solve the programming task below in a Python markdown code block. Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them a...
{"inputs": ["1 0\n", "2 0\n", "6 1\n0 6\n", "3 2\n0 1\n1 2\n", "2 2\n0 1\n1 2\n", "1000000000 0\n", "3 2\n-1 1\n1 2\n", "3 3\n1 2\n2 3\n1 3\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n"]}
coding
615
Solve the programming task below in a Python markdown code block. Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three...
{"inputs": ["x\n", "x\n", "y\n", "z\n", "{\n", "|\n", "zz\n", "xy\n"], "outputs": ["x\n", "x\n", "y\n", "z\n", "{\n", "|\n", "zz\n", "xy\n"]}
coding
283
Solve the programming task below in a Python markdown code block. We have the numbers with different colours with the sequence: ['red', 'yellow', 'blue']. That sequence colours the numbers in the following way: 1 2 3 4 5 6 7 8 9 10 11 12 13 ..... We have got the following recursive function:...
{"functional": "_inputs = [[3, 3, 'blue'], [100, 4, 'red'], [250, 6, 'yellow'], [1000, 7, 'red']]\n_outputs = [[[6, 15, 21]], [[136, 190, 253, 325]], [[]], [[1081, 1225, 1378, 1540, 1711, 1891, 2080]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math...
coding
537
Solve the programming task below in a Python markdown code block. # Task Dudka has `n` details. He must keep exactly 3 of them. To do this, he performs the following operations until he has only 3 details left: ``` He numbers them. He keeps those with either odd or even numbers and throws the others away.``` Dudka...
{"functional": "_inputs = [[3], [6], [4], [10], [15]]\n_outputs = [[1], [2], [0], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r...
coding
423
Solve the programming task below in a Python markdown code block. Create a function that takes a string as a parameter and does the following, in this order: 1. replaces every letter with the letter following it in the alphabet (see note below) 2. makes any vowels capital 3. makes any consonants lower case **Note:** ...
{"functional": "_inputs = [['Cat30'], ['Alice'], ['sponge1'], ['Hello World'], ['dogs'], ['z']]\n_outputs = [['dbU30'], ['bmjdf'], ['tqpOhf1'], ['Ifmmp xpsmE'], ['Epht'], ['A']]\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=t...
coding
137
Solve the programming task below in a Python markdown code block. Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment ...
{"inputs": ["U\n", "T\n", "V\n", "W\n", "X\n", "Y\n", "Z\n", "0\n2\n"], "outputs": ["***\n*U*\n***", "***\n*T*\n***\n", "***\n*V*\n***\n", "***\n*W*\n***\n", "***\n*X*\n***\n", "***\n*Y*\n***\n", "***\n*Z*\n***\n", "***\n*0*\n*2*\n***"]}
coding
351
Solve the programming task below in a Python markdown code block. Petya is preparing for his birthday. He decided that there would be $n$ different dishes on the dinner table, numbered from $1$ to $n$. Since Petya doesn't like to cook, he wants to order these dishes in restaurants. Unfortunately, all dishes are prepar...
{"inputs": ["4\n4\n3 7 4 2\n2 1 2 0\n4\n1 0 3 8\n3 5 4 3\n2\n1 2\n10 4\n2\n9 10\n0 2\n", "4\n4\n3 7 4 2\n2 1 2 0\n4\n1 0 3 8\n3 5 4 3\n2\n1 2\n10 4\n2\n9 10\n1 2\n", "4\n4\n3 7 4 2\n2 1 2 0\n4\n1 0 3 8\n3 5 4 3\n2\n1 2\n10 10\n2\n9 6\n1 2\n", "4\n4\n3 7 4 2\n2 1 3 0\n4\n1 0 3 4\n3 3 4 3\n2\n1 2\n10 10\n2\n9 10\n1 2\n",...
coding
743
Solve the programming task below in a Python markdown code block. Karan's mathematics professor has given him a lots of homework. Since he is busy preparing for September Easy Challenge, he needs your help. Given two numbers, find the sum of prime numbers between them, both inclusive. Input: The first line contains...
{"inputs": ["13\n1 99999\n10000 99999\n1 2\n1 1\n2 2\n1 6\n1579 2345\n2349 87324\n12345 23789\n12345 67890\n1 99999\n1 99999\n1 99999"], "outputs": ["454396537\n448660141\n2\n0\n2\n10\n193665\n349887984\n21106440\n208424627\n454396537\n454396537\n454396537\n"]}
coding
129
Solve the programming task below in a Python markdown code block. You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? -----Input--...
{"inputs": ["1 1\n9\n1\n", "1 1\n8\n9\n", "1 1\n9\n8\n", "1 1\n1\n2\n", "1 1\n2\n1\n", "1 1\n9\n9\n", "1 1\n1\n1\n", "1 1\n1\n2\n"], "outputs": ["19\n", "89\n", "89\n", "12\n", "12\n", "9\n", "1\n", "12\n"]}
coding
353
Solve the programming task below in a Python markdown code block. A matrix B (consisting of integers) of dimension N × N is said to be good if there exists an array A (consisting of integers) such that B[i][j] = |A[i] - A[j]|, where |x| denotes absolute value of integer x. You are given a partially filled matrix B of ...
{"inputs": ["4\n2 2\n1 1 0\n1 2 1\n2 3\n1 1 0\n1 2 1\n2 1 0\n3 2\n2 2 0\n2 3 1\n3 3\n1 2 1\n2 3 1\n1 3 1"], "outputs": ["yes\nno\nyes\nno"]}
coding
574
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1. Return the length of n. If there is no such n, return -1. Note...
{"functional": "def check(candidate):\n assert candidate(k = 1) == 1\n assert candidate(k = 2) == -1\n assert candidate(k = 3) == 3\n\n\ncheck(Solution().smallestRepunitDivByK)"}
coding
118
Please solve the programming task below using a self-contained code snippet in a markdown code block. The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the ans...
{"functional": "def check(candidate):\n assert candidate(n = 4) == [[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]\n assert candidate(n = 1) == [[\"Q\"]]\n\n\ncheck(Solution().solveNQueens)"}
coding
139
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i]. For example, if nums1 = [1,2,3,8], and nums2 = [5,6,7,4], you can swap the elemen...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,3,5,4], nums2 = [1,2,3,7]) == 1\n assert candidate(nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]) == 1\n\n\ncheck(Solution().minSwap)"}
coding
221
Solve the programming task below in a Python markdown code block. Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But som...
{"inputs": ["2 0\n", "2 0\n", "1 1\n1\n", "2 1\n1\n", "2 1\n1\n", "1 1\n1\n", "10 1\n1\n", "10 1\n1\n"], "outputs": ["YES", "YES\n", "NO", "NO", "NO\n", "NO\n", "NO", "NO\n"]}
coding
361
Solve the programming task below in a Python markdown code block. $Neha$ is given a number $N$. She always looks for special thing , this time she is looking for $Special$ $Number$ and $Partial$ $Special$ $Number$. A $Special$ $Number$ is a number whose product of its digits is equal to number itself i.e. $N $, and in...
{"inputs": ["3"], "outputs": ["1 20"]}
coding
439
Solve the programming task below in a Python markdown code block. You are given an array A of size N. Let us list down all the subarrays of the given array. There will be a total of N * (N + 1) / 2 subarrays of the given array. Let us sort each of the subarrays in descending order of the numbers in it. Now you want t...
{"inputs": ["1\n4 2\n3 1 2 4\n1\n5"], "outputs": ["4\n3"]}
coding
476
Solve the programming task below in a Python markdown code block. Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through. It is known that there were N stops, all on different integer heights between 1 and N kilometers (inclusive) above the sea leve...
{"inputs": ["2\n0", "2\n2", "2\n1", "0\n1\n", "2\n1\n", "0\n3\n", "1\n1\n", "3\n7\n"], "outputs": ["1 2 3 \n", "3 4 5 2 1 \n", "2 3 4 1 ", "2 1 \n", "2 3 4 1 \n", "4 3 2 1 \n", "2 3 1 \n", "8 9 10 11 7 6 5 4 3 2 1 \n"]}
coding
315
Solve the programming task below in a Python markdown code block. Given an array of n$n$ integers : A1,A2,...,An$ A_1, A_2,... , A_n$, find the longest size subsequence which satisfies the following property: The xor of adjacent integers in the subsequence must be non-decreasing. -----Input:----- - First line contains...
{"inputs": ["8\n1 200 3 0 400 4 1 7"], "outputs": ["6"]}
coding
275
Solve the programming task below in a Python markdown code block. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences. Consider all integer sequences of length N whose elements are bet...
{"inputs": ["5 4 3 3", "5 4 2 3", "0 4 2 3", "8 5 7 5", "3 3 7 5", "7 4 2 3", "5 8 3 3", "8 4 2 3"], "outputs": ["460\n", "435\n", "0\n", "1761124\n", "1\n", "78735\n", "574\n", "962894\n"]}
coding
404
Solve the programming task below in a Python markdown code block. Shivani is interning at HackerEarth. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and may have distributed the chocolates unequally. One of the program managers gets to know this and orders Shivani to...
{"inputs": ["1\n4\n2 2 3 7"], "outputs": ["2"]}
coding
403
Solve the programming task below in a Python markdown code block. Vasya had three strings $a$, $b$ and $s$, which consist of lowercase English letters. The lengths of strings $a$ and $b$ are equal to $n$, the length of the string $s$ is equal to $m$. Vasya decided to choose a substring of the string $a$, then choose ...
{"inputs": ["1 2\nt\nt\ntt\n", "1 2\nj\nj\njj\n", "1 2\nj\nj\njj\n", "1 2\nt\nt\ntt\n", "5 4\nazaza\nzazaz\nazaz\n", "5 4\nazaza\nzazaz\nazaz\n", "6 5\naabbaa\nbaaaab\naaaaa\n", "6 5\naabbaa\nbaaaab\naaaaa\n"], "outputs": ["1\n", "1\n", "1", "1", "11\n", "11", "4\n", "4"]}
coding
689
Solve the programming task below in a Python markdown code block. Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages. Recent actions shows a list of n differen...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 2 3\n", "3\n2 1 3\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
coding
540
Please solve the programming task below using a self-contained code snippet in a markdown code block. An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x. Given an integer n, return the smallest numerically balanced number strictly greater than ...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 22\n assert candidate(n = 1000) == 1333\n assert candidate(n = 3000) == 3133\n\n\ncheck(Solution().nextBeautifulNumber)"}
coding
93
Solve the programming task below in a Python markdown code block. Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest f...
{"inputs": ["1\n", "3\n", "2\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "2\n", "1\n", "3\n", "0\n"]}
coding
219
Solve the programming task below in a Python markdown code block. There are n stone quarries in Petrograd. Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last f...
{"inputs": ["2\n2 0\n3 2\n", "2\n2 0\n5 2\n", "2\n2 0\n1 2\n", "2\n2 0\n2 2\n", "2\n2 0\n4 2\n", "2\n3 0\n4 2\n", "2\n2 1\n3 2\n", "4\n1 1\n1 1\n1 1\n1 1\n"], "outputs": ["tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "bolik\n"]}
coding
364
Solve the programming task below in a Python markdown code block. As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues A and B and...
{"inputs": ["1 0 1\n", "1 0 10\n", "1 0 11\n", "1 0 14\n", "3 0 110\n", "3 0 100\n", "1 0 10000\n", "1 0 10001\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "3\n", "3\n", "1\n", "1\n"]}
coding
614
Solve the programming task below in a Python markdown code block. A system is transmitting messages in binary, however it is not a perfect transmission, and sometimes errors will occur which result in a single bit flipping from 0 to 1, or from 1 to 0. To resolve this, A 2-dimensional Parity Bit Code is used: https://e...
{"functional": "_inputs = [[1, 1, '111'], [1, 1, '011'], [1, 1, '101'], [1, 1, '110'], [2, 3, '11111010001'], [2, 3, '11011010001'], [2, 3, '11111011001'], [2, 3, '11111010011']]\n_outputs = [['111'], ['111'], ['111'], ['111'], ['11111010001'], ['11111010001'], ['11111010001'], ['11111010001']]\nimport math\ndef _deep_...
coding
647