problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number. -----Constraints----- - 1 ≤ a,b ≤ 100 - a and b are integers. -----Input----- Input is given from Standard In...
{"inputs": ["7 6", "9 6", "5 6", "5 2", "5 4", "5 0", "3 0", "2 0"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
148
Solve the programming task below in a Python markdown code block. Supermarket Dilemma Chef is going to local supermarket but there appears a problem with chef as he is confused about which Supermarket he can choose to go as he is not able to decide whether he can park his car in that particular supermarket’s parking lo...
{"inputs": ["2\n4\n5"], "outputs": ["YES\nNO"]}
coding
300
Solve the programming task below in a Python markdown code block. -----Coal Company ----- The Tunisian Coal Mining company uses a train to ferry out coal blocks from its coal mines. The train has N containers numbered from 1 to N which need to be filled with blocks of coal. Assume there are infinite coal blocks. The ...
{"inputs": ["2\n3 2\n5 4 7\n5 1\n5 3 4 5 6"], "outputs": ["2\n1"]}
coding
427
Solve the programming task below in a Python markdown code block. Today a plane was hijacked by a maniac. All the passengers of the flight are taken as hostage. Chef is also one of them. He invited one of the passengers to play a game with him. If he loses the game, he will release all the passengers, otherwise he will...
{"inputs": ["2\n3 3 3\n1\n3 3 3\n2"], "outputs": ["1\n4"]}
coding
495
Solve the programming task below in a Python markdown code block. Shivam owns a gambling house, which has a special wheel called The Wheel of Fortune. This wheel is meant for giving free coins to people coming in the house. The wheel of fortune is a game of chance. It uses a spinning wheel with exactly N numbered po...
{"inputs": ["2\n3\n1 2 3\n3\n1\n2\n3\n6\n2 1 5 3 2 1\n4\n1\n2\n3\n5"], "outputs": ["3\n3\n3\n2\n2\n6\n6"]}
coding
526
Solve the programming task below in a Python markdown code block. Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller? -----Constraints----- - 1 \leq a \leq ...
{"inputs": ["7 2", "4 6", "7 4", "7 8", "5 7", "1 3", "5 2", "6 6"], "outputs": ["2222222\n", "444444\n", "4444444\n", "77777777\n", "5555555\n", "111\n", "22222\n", "666666\n"]}
coding
188
Solve the programming task below in a Python markdown code block. Mihai has an $8 \times 8$ chessboard whose rows are numbered from $1$ to $8$ from top to bottom and whose columns are numbered from $1$ to $8$ from left to right. Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edg...
{"inputs": ["3\n\n.....#..\n#...#...\n.#.#....\n..#.....\n.#.#....\n#...#...\n.....#..\n......#.\n\n#.#.....\n.#......\n#.#.....\n...#....\n....#...\n.....#..\n......#.\n.......#\n\n.#.....#\n..#...#.\n...#.#..\n....#...\n...#.#..\n..#...#.\n.#.....#\n#.......\n"], "outputs": ["4 3\n2 2\n4 5\n"]}
coding
502
Solve the programming task below in a Python markdown code block. N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green. The person numbered i says: * "In front of me, exactly A_i people are wearing hats with the same color as mine." As...
{"inputs": ["3\n0 0 0", "6\n0 1 2 0 3 4", "6\n0 1 1 3 4 5", "6\n0 1 0 3 4 5", "6\n0 1 0 1 4 5", "6\n0 1 0 1 2 5", "6\n0 1 1 1 2 5", "6\n0 1 1 1 2 6"], "outputs": ["6", "6\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
411
Solve the programming task below in a Python markdown code block. Your task is to make a program takes in a sentence (without puncuation), adds all words to a list and returns the sentence as a string which is the positions of the word in the list. Casing should not matter too. Example ----- `"Ask not what your COUN...
{"functional": "_inputs = [['The bumble bee'], ['SILLY LITTLE BOYS silly little boys'], ['Ask not what your COUNTRY can do for you ASK WHAT YOU CAN DO FOR YOUR country'], ['The number 0 is such a strange number Strangely it has zero meaning']]\n_outputs = [['012'], ['012012'], ['01234567802856734'], ['012345617891011']...
coding
160
Solve the programming task below in a Python markdown code block. You are given a binary string S. You need to transform this string into another string of equal length consisting only of zeros, with the minimum number of operations. A single operation consists of taking some prefix of the string S and flipping all its...
{"inputs": ["01001001"], "outputs": ["6"]}
coding
444
Solve the programming task below in a Python markdown code block. Write a method that takes one argument as name and then greets that name, capitalized and ends with an exclamation point. Example: ``` "riley" --> "Hello Riley!" "JACK" --> "Hello Jack!" ``` Also feel free to reuse/extend the following starter code: `...
{"functional": "_inputs = [['riley'], ['molly'], ['BILLY']]\n_outputs = [['Hello Riley!'], ['Hello Molly!'], ['Hello Billy!']]\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
83
Solve the programming task below in a Python markdown code block. Maya writes weekly articles to a well known magazine, but she is missing one word each time she is about to send the article to the editor. The article is not complete without this word. Maya has a friend, Dan, and he is very good with words, but he does...
{"functional": "_inputs = [[637], [7468], [49632], [1425], [6250], [12674], [4735], [7345], [3850], [2394], [2068], [137], [1065], [6509], [3549], [5394], [56124], [968], [103247], [67935], [7415], [2687], [261], [8054], [942547]]\n_outputs = [['aid'], ['dean'], ['email'], ['belt'], ['alto'], ['blade'], ['edit'], ['die...
coding
308
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the ti...
{"functional": "def check(candidate):\n assert candidate(times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2) == 2\n assert candidate(times = [[1,2,1]], n = 2, k = 1) == 1\n assert candidate(times = [[1,2,1]], n = 2, k = 2) == -1\n\n\ncheck(Solution().networkDelayTime)"}
coding
174
Solve the programming task below in a Python markdown code block. Given an integer `n` return `"odd"` if the number of its divisors is odd. Otherwise return `"even"`. **Note**: big inputs will be tested. ## Examples: All prime numbers have exactly two divisors (hence `"even"`). For `n = 12` the divisors are `[1, 2,...
{"functional": "_inputs = [[1], [5], [16], [27], [121]]\n_outputs = [['odd'], ['even'], ['odd'], ['even'], ['odd']]\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 ...
coding
150
Solve the programming task below in a Python markdown code block. Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What...
{"inputs": ["s\ninput\n6 6 4\noutput\n4"], "outputs": [""]}
coding
214
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given three integers x, y, and z. You have x strings equal to "AA", y strings equal to "BB", and z strings equal to "AB". You want to choose some (possibly all or none) of these strings and concatenate them in...
{"functional": "def check(candidate):\n assert candidate(x = 2, y = 5, z = 1) == 12\n assert candidate(x = 3, y = 2, z = 2) == 14\n\n\ncheck(Solution().longestString)"}
coding
159
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...
coding
150
Solve the programming task below in a Python markdown code block. You have an N \times M grid consisting of N rows numbered 1 to N from top to bottom and M columns numbered 1 to M from left to right. Each cell of the grid is initially white. You can perform the following operation any number of times (possibly zero): ...
{"inputs": ["2\n3 5 13\n3627 17424 27008005"], "outputs": ["YES\nNO"]}
coding
454
Solve the programming task below in a Python markdown code block. You are given a set $\mbox{A}$ and $n$ other sets. Your job is to find whether set $\mbox{A}$ is a strict superset of each of the $N$ sets. Print True, if $\mbox{A}$ is a strict superset of each of the $N$ sets. Otherwise, print False. A strict s...
{"inputs": ["1 2 3 4 5 6 7 8 9 10 11 12 23 45 84 78\n2\n1 2 3 4 5\n100 11 12\n"], "outputs": ["False\n"]}
coding
577
Solve the programming task below in a Python markdown code block. You are given a pair of integers $(a, b)$ and an integer $x$. You can change the pair in two different ways: set (assign) $a := |a - b|$; set (assign) $b := |a - b|$, where $|a - b|$ is the absolute difference between $a$ and $b$. The pair $(a, b)$ ...
{"inputs": ["1\n4398046511104 4398050705408 8388608\n", "8\n6 9 3\n15 38 7\n18 8 8\n30 30 30\n40 50 90\n24 28 20\n365 216 52\n537037812705867558 338887693834423551 3199921013340\n"], "outputs": ["YES\n", "YES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n"]}
coding
466
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.   Please complete the follo...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), left = 2, right = 4), list_node([1,4,3,2,5]))\n assert is_same_list(candidate(head = list_node([5]), left = 1, right = 1), list_node([5]))\n\n\ncheck(Solution().reverseBetween)"}
coding
137
Solve the programming task below in a Python markdown code block. Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm. .#.#.#.#. .#.#.#.#.# .#.#.#.#. .#.#.#.#.# .#.#.#.#. .#.#.#.#.# Note that the top l...
{"inputs": ["3 4\n5 6\n3 3\n2 2\n1 0\n0 0", "3 7\n5 6\n3 3\n2 2\n1 0\n0 0", "3 7\n5 6\n3 0\n2 2\n1 0\n0 0", "6 7\n5 6\n3 0\n2 2\n1 0\n0 0", "3 4\n5 6\n2 3\n2 2\n1 1\n0 0", "3 4\n5 6\n3 3\n2 4\n1 0\n0 0", "3 7\n5 6\n4 3\n2 2\n1 0\n0 0", "3 7\n5 5\n3 0\n2 2\n1 0\n0 0"], "outputs": ["#.#.\n.#.#\n#.#.\n\n#.#.#.\n.#.#.#\n#....
coding
261
Solve the programming task below in a Python markdown code block. Kulyash loves perfect squares and hates perfect cubes. For any natural number N, F(N) = \texttt{number of perfect squares smaller than or equal to } N - \texttt{number of positive perfect cubes smaller than or equal to } N. Kulyash gives you an int...
{"inputs": ["3\n1\n3\n3151\n"], "outputs": ["4\n25\n11397376\n"]}
coding
450
Solve the programming task below in a Python markdown code block. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doc...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n8 3\n", "1\n8 1\n", "1\n10 3\n", "1\n10 10\n", "1\n10 10\n", "1\n10 13\n"], "outputs": ["1\n", "1\n", "8\n", "8\n", "10\n", "10\n", "10\n", "10\n"]}
coding
370
Solve the programming task below in a Python markdown code block. Chef loves problems about digits and he came up with an interesting one. Chef has given you two integers N and K. You should find the minimum non-negative integer X, such that N + X has at most K distinct digits in its decimal representation. For examp...
{"inputs": ["9\n30 1\n56 4\n364 2\n125 3\n37662730 3\n41872528 4\n73170084 8\n90032975 1\n7487471 3"], "outputs": ["3\n0\n2\n0\n603\n1583\n0\n9967024\n3"]}
coding
381
Solve the programming task below in a Python markdown code block. Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this characte...
{"inputs": ["a\n", "a\n", "a\n", "a\n", "b\n", "b\n", "a\n", "c\n"], "outputs": ["a\n", "a\n", "a\n", "a\n", "b\n", "b\n", "a\n", "c\n"]}
coding
180
Solve the programming task below in a Python markdown code block. You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353. Constraints * 1 \leq N, M \leq 524288 * 0 \...
{"inputs": ["1 1\n10000000\n10100000", "1 1\n10001000\n10100000", "4 5\n1 2 3 4\n5 6 7 4 9", "1 1\n10001000\n10110000", "4 5\n1 1 3 4\n5 6 7 4 9", "1 1\n10001000\n00110000", "4 5\n1 2 3 8\n5 6 7 8 9", "1 1\n10010000\n10100000"], "outputs": ["631096519\n", "748652989\n", "5 16 34 56 62 58 43 36\n", "934217689\n", "5 11 ...
coding
361
Solve the programming task below in a Python markdown code block. Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it. At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words an...
{"inputs": ["1 1 1\nv\n", "1 1 1\nn\n", "1 1 1\nz\n", "1 1 1\nd\n", "1 1 1\nb\n", "1 1 1\ny\n", "1 1 1\nc\n", "1 1 1\nx\n"], "outputs": ["v\n", "n\n", "z\n", "d\n", "b\n", "y\n", "c\n", "x\n"]}
coding
306
Solve the programming task below in a Python markdown code block. You're a statistics professor and the deadline for submitting your students' grades is tonight at midnight. Each student's grade is determined by their mean score across all of the tests they took this semester. You've decided to automate grade calculat...
{"functional": "_inputs = [[[92, 94, 99]], [[50, 60, 70, 80, 90]], [[50, 55]]]\n_outputs = [['A'], ['C'], ['F']]\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 i...
coding
284
Solve the programming task below in a Python markdown code block. Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to pla...
{"inputs": ["1\n", "2\n", "01\n", "010\n", "110\n", "100\n", "000001\n", "010001\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
264
Solve the programming task below in a Python markdown code block. Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows: - Let the current rating of the user b...
{"inputs": ["4500\n1", "4500\n2", "2002\n2", "2002\n3", "2002\n0", "2002\n1", "2002\n4", "2002\n8"], "outputs": ["-4498\n", "-4496\n", "-1998\n", "-1996\n", "-2002\n", "-2000\n", "-1994\n", "-1986\n"]}
coding
326
Solve the programming task below in a Python markdown code block. Chef Leonardo has a decimal integer $N$ and a non-zero decimal digit $d$. $N$ does not contain the digit zero; specifically, $N$ should always be treated as a decimal integer without leading zeroes. Chef likes $d$ and does not like any other digit, so he...
{"inputs": ["3\n35 4\n42 4\n24 9"], "outputs": ["34\n24\n24"]}
coding
496
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".   Please complete the following python code precisely: ```python class So...
{"functional": "def check(candidate):\n assert candidate(strs = [\"flower\",\"flow\",\"flight\"]) == \"fl\"\n assert candidate(strs = [\"dog\",\"racecar\",\"car\"]) == \"\"\n\n\ncheck(Solution().longestCommonPrefix)"}
coding
78
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string word and an array of strings forbidden. A string is called valid if none of its substrings are present in forbidden. Return the length of the longest valid substring of the string word. A substr...
{"functional": "def check(candidate):\n assert candidate(word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]) == 4\n assert candidate(word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]) == 4\n\n\ncheck(Solution().longestValidSubstring)"}
coding
110
Solve the programming task below in a Python markdown code block. Toad Zitz has an array of integers, each integer is between $0$ and $m-1$ inclusive. The integers are $a_1, a_2, \ldots, a_n$. In one operation Zitz can choose an integer $k$ and $k$ indices $i_1, i_2, \ldots, i_k$ such that $1 \leq i_1 < i_2 < \ldots <...
{"inputs": ["1 1\n0\n", "1 1\n0\n", "1 2\n0\n", "2 1\n0 0\n", "2 2\n0 1\n", "2 2\n1 0\n", "2 2\n1 0\n", "2 2\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]}
coding
488
Solve the programming task below in a Python markdown code block. Indian National Olympiad in Informatics 2013 Calvin wakes up early one morning and finds that all his friends in the hostel are asleep. To amuse himself, he decides to play the following game : he draws a sequence of N squares on the ground, numbered 1 t...
{"inputs": ["and output corresponding to the example above.\nSample input\n5 2\n5 3 -2 1 1\nSample output\n11\nNote : Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous out...
coding
650
Solve the programming task below in a Python markdown code block. You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume. You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one t...
{"inputs": ["1\n1\n100\n", "1\n1\n100\n", "1\n100000000\n1\n", "1\n100000000\n1\n", "5\n5 4 3 7 3\n7 7 14 57 94\n", "5\n5 4 3 7 3\n7 7 14 57 94\n", "5\n5 4 3 7 3\n7 7 14 57 61\n", "5\n5 4 3 7 3\n7 1 14 57 61\n"], "outputs": ["10\n", "10\n", "100000000000\n", "100000000000\n", "89\n", "89\n", "112\n", "118\n"]}
coding
613
Solve the programming task below in a Python markdown code block. On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set has N bulbs placed sequentially on a string which is programmed to change patterns every second. If at least one bulb in the set is on at any given...
{"inputs": ["2\n1\n2\n"], "outputs": ["1\n3\n"]}
coding
234
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi ...
{"functional": "def check(candidate):\n assert candidate(edges = [[0,1],[1,2],[1,3],[4,2]], guesses = [[1,3],[0,1],[1,0],[2,4]], k = 3) == 3\n assert candidate(edges = [[0,1],[1,2],[2,3],[3,4]], guesses = [[1,0],[3,4],[2,1],[3,2]], k = 1) == 5\n\n\ncheck(Solution().rootCount)"}
coding
295
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.   Please complete the following python code pr...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1],[1,0,1],[1,1,1]]) == 9\n assert candidate(grid = [[1,1,0,0]]) == 1\n\n\ncheck(Solution().largest1BorderedSquare)"}
coding
106
Solve the programming task below in a Python markdown code block. The Little Elephant from the Zoo of Lviv has an array A that consists of N positive integers. Let A[i] be the i-th number in this array (i = 1, 2, ..., N). Find the minimal number x > 1 such that x is a divisor of all integers from array A. More formall...
{"inputs": ["2\n2\n7 2 8\n3\n0 8 5", "2\n2\n2 0 8\n3\n0 0 9", "2\n2\n0 7 0\n3\n1 5 5", "2\n3\n6 0 3\n2\n1 4 2", "2\n2\n2 4 8\n3\n1 5 5", "2\n2\n2 4 4\n3\n1 5 5", "2\n2\n2 2 4\n3\n1 5 5", "2\n2\n2 2 8\n3\n1 5 5"], "outputs": ["-1\n-1\n", "2\n3\n", "7\n-1\n", "3\n-1\n", "2\n-1\n", "2\n-1\n", "2\n-1\n", "2\n-1\n"]}
coding
508
Solve the programming task below in a Python markdown code block. You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t` is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth of seco...
{"functional": "_inputs = [[37], [45], [99], [85], [136], [52], [16], [127], [137], [14]]\n_outputs = [[10], [13], [28], [24], [39], [15], [5], [36], [39], [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)\...
coding
331
Solve the programming task below in a Python markdown code block. Move every letter in the provided string forward 10 letters through the alphabet. If it goes past 'z', start again at 'a'. Input will be a string with length > 0. Also feel free to reuse/extend the following starter code: ```python def move_ten(st): ``...
{"functional": "_inputs = [['testcase'], ['codewars'], ['exampletesthere'], ['returnofthespacecamel'], ['bringonthebootcamp'], ['weneedanofficedog']]\n_outputs = [['docdmkco'], ['mynogkbc'], ['ohkwzvodocdrobo'], ['bodebxypdroczkmomkwov'], ['lbsxqyxdrolyydmkwz'], ['goxoonkxyppsmonyq']]\nimport math\ndef _deep_eq(a, b, t...
coding
74
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of length n. Assume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow: F(k) = 0 * arrk[0] + 1 * arrk[1] +...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,6]) == 26\n assert candidate(nums = [100]) == 0\n\n\ncheck(Solution().maxRotateFunction)"}
coding
164
Solve the programming task below in a Python markdown code block. Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th...
{"inputs": ["2\n8 20\n1\n1", "2\n0 40\n5\n5", "2\n8 20\n1\n19", "2\n8 23\n1\n19", "2\n8 44\n1\n19", "3\n0 1\n4\n5\n2", "3\n7 1\n2\n9\n9", "2\n0 44\n1\n15"], "outputs": ["36\n", "40\n", "29\n", "32\n", "53\n", "1\n", "7\n", "44\n"]}
coding
426
Solve the programming task below in a Python markdown code block. Given a string $s$ of length $n$ and integer $k$ ($1 \le k \le n$). The string $s$ has a level $x$, if $x$ is largest non-negative integer, such that it's possible to find in $s$: $x$ non-intersecting (non-overlapping) substrings of length $k$, all cha...
{"inputs": ["1 1\nq\n", "1 1\nq\n", "1 1\np\n", "2 1\nab\n", "1 1\nab\n", "1 1\nba\n", "2 1\nba\n", "1 1\nac\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
540
Solve the programming task below in a Python markdown code block. Asmany strings are strings of '0's and '1's that have as many 00 as 11. A string such as 00110001 consists of 3 "00" and 1 "11". Of course this is not an Asmany string. 0011, 1100, 000111000111 are Asmany strings. An L'th Asmany number is the number of A...
{"inputs": ["2\n3\n4", "2\n1\n4", "2\n2\n4", "2\n2\n1", "2\n1\n1", "2\n4\n4", "2\n5\n4", "2\n1\n6"], "outputs": ["NO\nYES", "NO\nYES\n", "YES\nYES\n", "YES\nNO\n", "NO\nNO\n", "YES\nYES\n", "NO\nYES\n", "NO\nYES\n"]}
coding
384
Solve the programming task below in a Python markdown code block. Consider the following arithmetic progression with n terms: * x, x + d, x + 2d, \ldots, x + (n-1)d What is the product of all terms in this sequence? Compute the answer modulo 1\ 000\ 003. You are given Q queries of this form. In the i-th query, com...
{"inputs": ["2\n7 3 4\n12345 30036 63", "2\n7 3 4\n12345 57737 63", "2\n7 1 1\n9796 9219 1485", "2\n7 2 4\n12345 57737 63", "2\n7 1 1\n9796 9219 2637", "2\n3 2 4\n12345 57737 63", "2\n3 1 4\n12345 57737 63", "2\n3 1 0\n12345 57737 63"], "outputs": ["14560\n487009\n", "14560\n462686\n", "7\n37900\n", "9009\n462686\n", "...
coding
276
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget] that you are trying to get to. There are several ghos...
{"functional": "def check(candidate):\n assert candidate(ghosts = [[1,0],[0,3]], target = [0,1]) == True\n assert candidate(ghosts = [[1,0]], target = [2,0]) == False\n assert candidate(ghosts = [[2,0]], target = [1,0]) == False\n\n\ncheck(Solution().escapeGhosts)"}
coding
257
Please solve the programming task below using a self-contained code snippet in a markdown code block. The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And ...
{"functional": "def check(candidate):\n assert candidate(s = \"PAYPALISHIRING\", numRows = 3) == \"PAHNAPLSIIGYIR\"\n assert candidate(s = \"PAYPALISHIRING\", numRows = 4) == \"PINALSIGYAHRPI\"\n assert candidate(s = \"A\", numRows = 1) == \"A\"\n\n\ncheck(Solution().convert)"}
coding
157
Solve the programming task below in a Python markdown code block. Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer L, how many pairs of positive integers a, b (a ≤ b) such that LCM(a, b) = L are there? Here, LCM(a, b) stands for the least com...
{"inputs": ["12\n9\n3\n0", "12\n8\n2\n0", "12\n9\n0\n0", "12\n0\n3\n0", "12\n9\n1\n0", "12\n8\n1\n0", "12\n9\n4\n0", "12\n8\n0\n0"], "outputs": ["8\n3\n2\n", "8\n4\n2\n", "8\n3\n", "8\n", "8\n3\n1\n", "8\n4\n1\n", "8\n3\n3\n", "8\n4\n"]}
coding
157
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums consisting of positive integers. We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0. Return the lengt...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,8,48,10]) == 3\n assert candidate(nums = [3,1,5,11,13]) == 1\n\n\ncheck(Solution().longestNiceSubarray)"}
coding
127
Solve the programming task below in a Python markdown code block. You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'. In one move, you can choose exactly one bracket and move it t...
{"inputs": ["4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n", "4\n2\n)(\n4\n)()(\n8\n())()()(\n10\n)))((((())\n", "4\n2\n)(\n4\n()()\n8\n())()()(\n10\n())((()())\n", "4\n2\n)(\n4\n()()\n8\n()()())(\n10\n)))((((())\n", "4\n2\n)(\n4\n)()(\n8\n())()()(\n10\n))((((()))\n", "4\n2\n)(\n4\n)()(\n8\n())()()(\n10\n())(()(())\...
coding
552
Solve the programming task below in a Python markdown code block. For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations. Max is a young biologist. For $n$ days he watched a specific shark, and now he kn...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "2\n1 2\n", "2\n2 1\n", "2\n2 1\n"], "outputs": ["2", "2\n", "3\n", "4\n", "5\n", "2", "2", "2\n"]}
coding
580
Please solve the programming task below using a self-contained code snippet in a markdown code block. A magical string s consists of only '1' and '2' and obeys the following rules: The string s is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string s itsel...
{"functional": "def check(candidate):\n assert candidate(n = 6) == 3\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().magicalString)"}
coding
253
Solve the programming task below in a Python markdown code block. Alice and Bob are meeting after a long time. As usual they love to play some math games. This times Alice takes the call and decides the game. The game is very simple, Alice says out an integer and Bob has to say whether the number is prime or not. Bob a...
{"inputs": ["5\n14\n3\n28\n1000\n849", "5\n32\n19\n20\n1100\n793", "5\n32\n28\n20\n1100\n793", "5\n32\n31\n20\n1100\n793", "5\n10\n31\n20\n1100\n793", "5\n10\n31\n20\n1101\n793", "5\n14\n22\n28\n1010\n849", "5\n10\n31\n39\n1100\n793"], "outputs": ["no\nyes\nno\nno\nno\n", "no\nyes\nno\nno\nno\n", "no\nno\nno\nno\nno\n"...
coding
260
Solve the programming task below in a Python markdown code block. In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', w...
{"inputs": ["2\n", "3\n", "1\n", "6\n", "4\n", "6\n", "1\n", "3\n"], "outputs": ["aa\n", "aab\n", "a\n", "aabbaa\n", "aabb\n", "aabbaa\n", "a\n", "aab\n"]}
coding
236
Solve the programming task below in a Python markdown code block. There's a waiting room with N chairs set in single row. Chairs are consecutively numbered from 1 to N. First is closest to the entrance (which is exit as well). For some reason people choose a chair in the following way 1. Find a place as far from oth...
{"functional": "_inputs = [[10]]\n_outputs = [[9]]\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(_deep_eq(...
coding
230
Solve the programming task below in a Python markdown code block. # Task Consider the following algorithm for constructing 26 strings S(1) .. S(26): ``` S(1) = "a"; For i in [2, 3, ..., 26]: S(i) = S(i - 1) + character(i) + S(i - 1).``` For example: ``` S(1) = "a" S(2) = S(1) + "b" + S(1) = "a" + "b" + "a" = "aba" S...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [8], [12], [16]]\n_outputs = [['a'], ['b'], ['a'], ['c'], ['a'], ['b'], ['a'], ['d'], ['c'], ['e']]\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)...
coding
308
Solve the programming task below in a Python markdown code block. This kata is all about adding numbers. You will create a function named add. It will return the sum of all the arguments. Sounds easy, doesn't it? Well Here's the Twist. The inputs will gradually decrease with their index as parameter to the function. ...
{"functional": "_inputs = [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]]\n_outputs = [[300], [2], [2], [-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 ...
coding
225
Solve the programming task below in a Python markdown code block. You're re-designing a blog and the blog's posts have the following format for showing the date and time a post was made: *Weekday* *Month* *Day*, *time* e.g., Friday May 2, 7pm You're running out of screen real estate, and on some pages you want to d...
{"functional": "_inputs = [['Monday February 2, 8pm'], ['Tuesday May 29, 8pm'], ['Wed September 1, 3am'], ['Friday May 2, 9am'], ['Tuesday January 29, 10pm']]\n_outputs = [['Monday February 2'], ['Tuesday May 29'], ['Wed September 1'], ['Friday May 2'], ['Tuesday January 29']]\nimport math\ndef _deep_eq(a, b, tol=1e-5)...
coding
197
Solve the programming task below in a Python markdown code block. The four bases found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T). In genetics, GC-content is the percentage of Guanine (G) and Cytosine (C) bases on a DNA molecule that are either guanine or cytosine. Given a DNA sequence (a stri...
{"functional": "_inputs = [[''], ['A'], ['C'], ['CA']]\n_outputs = [[0.0], [0.0], [100.0], [50.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) != le...
coding
218
Solve the programming task below in a Python markdown code block. MoEngage has a bundle of N sticks. The i^{th} stick has a length L_{i} meters. Find the minimum number of sticks (of any length) you need to add to the bundle such that you can construct some [rectangles] where each stick of the bundle belongs to exact...
{"inputs": ["4\n1\n1\n2\n2 5\n4\n2 2 3 3\n7\n1 3 5 7 1 7 5\n"], "outputs": ["3\n2\n0\n1\n"]}
coding
473
Solve the programming task below in a Python markdown code block. Let there be a function f(N) such that f(N) denotes number of zeroes at the end of N! (factorial of N). For example, f(5) = 1 because 5! = 120. You have to compute f(N) for given N. Input format : Input begins with integer t ( 1 ≤ t ≤ 10000) denoting...
{"inputs": ["1000\n65\n85\n45\n23\n85\n63\n52\n79\n24\n5\n6\n74\n64\n64\n99\n45\n66\n76\n65\n21\n57\n88\n100\n94\n17\n82\n100\n46\n88\n29\n70\n7\n50\n46\n92\n95\n96\n94\n97\n85\n84\n12\n27\n51\n59\n54\n91\n44\n89\n69\n72\n63\n82\n92\n98\n39\n15\n36\n92\n13\n43\n6\n99\n84\n37\n53\n51\n18\n79\n86\n99\n64\n50\n46\n21\n65\...
coding
183
Solve the programming task below in a Python markdown code block. There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N oper...
{"inputs": ["3 4\n1 1\n2 2\n3 2", "3 4\n1 1\n2 3\n3 2", "3 4\n1 1\n4 3\n3 2", "3 5\n2 2\n1 1\n8 3", "3 3\n2 2\n1 0\n5 3", "3 3\n2 2\n1 0\n7 3", "3 4\n1 0\n2 1\n6 6", "3 0\n2 2\n0 0\n3 6"], "outputs": ["3\n", "2\n", "4\n", "8\n", "5\n", "7\n", "6\n", "0\n"]}
coding
244
Solve the programming task below in a Python markdown code block. My friend wants a new band name for her band. She like bands that use the formula: "The" + a noun with the first letter capitalized, for example: `"dolphin" -> "The Dolphin"` However, when a noun STARTS and ENDS with the same letter, she likes to repea...
{"functional": "_inputs = [['knife'], ['tart'], ['sandles'], ['bed'], ['qq']]\n_outputs = [['The Knife'], ['Tartart'], ['Sandlesandles'], ['The Bed'], ['Qqq']]\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...
coding
162
Solve the programming task below in a Python markdown code block. You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and e...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n1 2\n", "2\n1 4\n", "2\n0 4\n", "3\n4 1 2\n", "3\n3 1 2\n", "3\n3 1 1\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "3\n", "0\n"]}
coding
658
Solve the programming task below in a Python markdown code block. A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|). You've got two strings — s and t. Let's consider all subsequences of string s, coinciding with...
{"inputs": ["aa\naaa\n", "cba\nba\n", "cca\nba\n", "abc\nba\n", "abc\nbac\n", "ab\nabcd\n", "abc\nbab\n", "ab\ndbca\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
387
Solve the programming task below in a Python markdown code block. You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here htt...
{"inputs": ["10:10\n0\n", "10:01\n0\n", "04:05\n0\n", "02:59\n1\n", "09:11\n0\n", "19:00\n0\n", "23:59\n1\n", "11:59\n1\n"], "outputs": ["10:10\n", "10:01\n", "04:05\n", "03:00\n", "09:11\n", "19:00\n", "00:00\n", "12:00\n"]}
coding
281
Solve the programming task below in a Python markdown code block. Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ i...
{"inputs": ["1 1\n", "2 3\n", "2 2\n", "2 6\n", "6 9\n", "2 3\n", "2 2\n", "2 6\n"], "outputs": ["0", "0", "0", "0", "0", "0\n", "0\n", "0\n"]}
coding
307
Solve the programming task below in a Python markdown code block. It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N? -----Constraints----- - 10≤N≤99 -----Input----- Input is given from Standard Input in the following format: N -----...
{"inputs": ["1", "0", "8", "3", "2", "4", "7", "6"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
124
Solve the programming task below in a Python markdown code block. Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photo...
{"inputs": ["1\n0 0 0 0\n", "1\n0 0 -1 0\n", "1\n0 10 0 19\n", "1\n0 10 1 11\n", "1\n0 -1 -1 0\n", "1\n0 10 0 11\n", "1\n0 -1 -1 1\n", "1\n0 10 0 10\n"], "outputs": ["0", "0\n", "-10\n", "-9\n", "0\n", "-10\n", "0\n", "-10"]}
coding
452
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \...
{"inputs": ["1 1 1\n2\n", "1 1 1\n2\n", "1 1 1\n0\n", "2 1 2\n3 5\n", "2 1 2\n0 5\n", "2 2 2\n0 5\n", "1 10 1\n-10\n", "1 10 1\n-10\n"], "outputs": ["1\n", "1\n", "0\n", "4\n", "3\n", "3\n", "0\n", "0\n"]}
coding
668
Solve the programming task below in a Python markdown code block. Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e...
{"inputs": ["1 1\ne\ne\ne\ne\n", "1 1\na\na\na\na\n", "1 1\ne\na\na\na\n", "1 1\ne\na\ne\na\n", "1 1\na\na\na\ne\n", "1 1\ne\na\ne\ne\n", "1 1\ne\na\na\ne\n", "1 1\na\ne\na\ni\n"], "outputs": ["aaaa\n", "aaaa\n", "NO\n", "abab\n", "NO\n", "NO\n", "abba\n", "NO\n"]}
coding
688
Solve the programming task below in a Python markdown code block. Chef likes strings a lot but he likes palindromic strings even more. Today he found an old string s in his garage. The string is so old that some of its characters have faded and are unidentifiable now. Faded characters in the string are represented by '...
{"inputs": ["3\na.ba\ncb.bc\na.b"], "outputs": ["abba\ncbabc\n-1"]}
coding
425
Solve the programming task below in a Python markdown code block. Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, ev...
{"inputs": ["1 0\n2\n3\n", "1 0\n2\n0\n", "1 0\n0\n0\n", "1 0\n2\n3\n", "2 0\n2 3\n3 3\n", "2 0\n2 3\n3 3\n", "2 0\n1 3\n3 3\n", "2 0\n1 3\n0 3\n"], "outputs": ["3 ", "0\n", "0\n", "3\n", "3 3 ", "3 3\n", "3 3\n", "0 3\n"]}
coding
588
Solve the programming task below in a Python markdown code block. According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the...
{"inputs": ["1 1\n2\n", "3 3\n000\n011\n222\n", "3 3\n001\n000\n111\n", "3 3\n001\n011\n222\n", "3 3\n001\n000\n110\n", "3 3\n011\n000\n110\n", "3 3\n011\n010\n110\n", "3 3\n011\n010\n010\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
272
Solve the programming task below in a Python markdown code block. For a rooted tree, find the lowest common ancestor of two nodes u and v. The given tree consists of n nodes and every node has a unique ID from 0 to n-1 where 0 is the root. Constraints * 1 ≤ n ≤ 100000 * 1 ≤ q ≤ 100000 Input n k0 c1 c2 ... ck0 k1 ...
{"inputs": ["8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 0\n2 3\n7 3", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n2 3\n3 3", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n3 3\n5 2", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n6 6\n4 7\n2 2\n7 3", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\...
coding
322
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s containing only lowercase English letters and the '?' character, convert all the '?' characters into lowercase letters such that the final string does not contain any consecutive repeating characters....
{"functional": "def check(candidate):\n assert candidate(s = \"?zs\") == \"azs\"\n assert candidate(s = \"ubv?w\") == \"ubvaw\"\n\n\ncheck(Solution().modifyString)"}
coding
152
Solve the programming task below in a Python markdown code block. If you can't sleep, just count sheep!! ## Task: Given a non-negative integer, `3` for example, return a string with a murmur: `"1 sheep...2 sheep...3 sheep..."`. Input will always be valid, i.e. no negative integers. Also feel free to reuse/extend the ...
{"functional": "_inputs = [[3]]\n_outputs = [['1 sheep...2 sheep...3 sheep...']]\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...
coding
94
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k. An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from th...
{"functional": "def check(candidate):\n assert candidate(nums = [3,5,2,6], k = 2) == [2,6]\n assert candidate(nums = [2,4,3,3,5,4,9,6], k = 4) == [2,3,3,4]\n\n\ncheck(Solution().mostCompetitive)"}
coding
188
Solve the programming task below in a Python markdown code block. Nikita has a row of $N$ white tiles indexed from $\mbox{1}$ to $N$. This time, she's painting them green! Find the number of ways Nikita can paint certain tiles in green so that the indices of the green tiles form an Arithmetic Progression. As this val...
{"inputs": ["3\n3\n4\n5\n"], "outputs": ["7\n13\n22\n"]}
coding
454
Solve the programming task below in a Python markdown code block. You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars) and then return the first value. The returned value must be a string, and have `"***"` between each of its letters. You ...
{"functional": "_inputs = [[['bitcoin', 'take', 'over', 'the', 'world', 'maybe', 'who', 'knows', 'perhaps']], [['turns', 'out', 'random', 'test', 'cases', 'are', 'easier', 'than', 'writing', 'out', 'basic', 'ones']], [['lets', 'talk', 'about', 'javascript', 'the', 'best', 'language']], [['i', 'want', 'to', 'travel', 't...
coding
101
Solve the programming task below in a Python markdown code block. # Problem In China,there is an ancient mathematical book, called "The Mathematical Classic of Sun Zi"(《孙子算经》). In the book, there is a classic math problem: “今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问物几何?” Ahh, Sorry. I forgot that you don't know Chinese. Let's t...
{"functional": "_inputs = [[2, 3, 2], [1, 2, 3], [1, 3, 5], [0, 0, 0], [1, 1, 1]]\n_outputs = [[23], [52], [103], [105], [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)...
coding
530
Solve the programming task below in a Python markdown code block. There are $n$ block towers in a row, where tower $i$ has a height of $a_i$. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation: Choose two indices $i$ and...
{"inputs": ["3\n3\n9 7 4\n4\n3 3 1 3\n5\n0 3 6 1 5\n", "3\n3\n9 7 4\n4\n3 3 1 6\n5\n0 3 6 1 5\n", "3\n3\n3 7 4\n4\n6 3 1 6\n5\n0 3 2 1 5\n", "3\n3\n9 7 7\n4\n3 3 1 6\n5\n0 3 6 1 5\n", "3\n3\n4 7 4\n4\n6 3 1 6\n5\n0 3 2 1 5\n", "3\n3\n6 5 0\n4\n6 1 2 2\n5\n1 4 3 1 4\n", "3\n3\n16 5 5\n4\n3 3 0 3\n5\n0 3 6 1 5\n", "3\n3\...
coding
612
Solve the programming task below in a Python markdown code block. Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that w...
{"inputs": ["1\n4\n", "1\n7\n", "1\n9\n", "1\n87\n", "1\n17\n", "1\n10\n", "1\n64\n", "2\n3 1\n"], "outputs": [" 0\n", "0\n", "0\n", " 0\n", "0\n", "0\n", "0\n", " ...
coding
287
Please solve the programming task below using a self-contained code snippet in a markdown code block. A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID. Each employee has one direct manager given in the manager array where manager[i] is the dir...
{"functional": "def check(candidate):\n assert candidate(n = 1, headID = 0, manager = [-1], informTime = [0]) == 0\n assert candidate(n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]) == 1\n\n\ncheck(Solution().numOfMinutes)"}
coding
248
Solve the programming task below in a Python markdown code block. Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $1$, starting from the topmost one. The columns are numbered from $1$, starting from the leftmost one. Initially, the table hasn't been filled and Polyc...
{"inputs": ["1\n8\n", "1\n7\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n48\n", "1\n38\n", "1\n33\n"], "outputs": ["3 2\n", "3 3\n", "1 1\n", "1 2\n", "2 1\n", "7 2\n", "2 7\n", "6 4\n"]}
coding
543
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class ...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,3,2,5,3,None,9])) == [1,3,9]\n assert candidate(root = tree_node([1,2,3])) == [1,3]\n\n\ncheck(Solution().largestValues)"}
coding
127
Solve the programming task below in a Python markdown code block. Given a word w, rearrange the letters of w to construct another word s in such a way that s is lexicographic-ally greater than w. In case of multiple possible answers, find the lexicographic-ally smallest one. Input Format The first line of input conta...
{"inputs": ["5\nab\nbb\nhefg\ndhck\ndkhc"], "outputs": ["ba\nno answer\nhegf\ndhkc\nhcdk"]}
coding
339
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\naa\nc\ndef\n", "3\nba\nb\nfde\n", "3\naa\nc\nedf\n", "3\naa\nb\nedf\n", "3\naa\nb\nfde\n", "3\nba\nc\nfde\n", "3\nab\nc\ndef\n", "3\nab\nacb\nba\n"], "outputs": ["2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "5\n"]}
coding
673
Solve the programming task below in a Python markdown code block. Let N be a positive even number. We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below. First, let q be an empty sequence. Then, perform the follow...
{"inputs": ["2\n0 2", "2\n0 1", "2\n0 0", "2\n2 2", "2\n1 0", "2\n1 1", "2\n1 2", "2\n1 2\n"], "outputs": ["0 2 ", "0 1 ", "0 0 ", "2 2 ", "1 0 ", "1 1 ", "1 2", "1 2\n"]}
coding
337
Solve the programming task below in a Python markdown code block. Chef is making Window frames for his new office, for this he has n wooden Logs whose lengths are l1, l2, … ln respectively. Chef Doesn’t want to break any logs or Stick 2 or more logs together. To make a h × w Window Frame, he needs two Logs with lengt...
{"inputs": ["2\n4\n1 2 1 2\n8\n1 2 1 3 4 1 5 6"], "outputs": ["1\n0"]}
coding
361
Solve the programming task below in a Python markdown code block. Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence a_1, a_1 +...
{"inputs": ["1 1 1 1\n", "9 8 7 5\n", "2 6 6 8\n", "2 4 8 8\n", "2 4 4 2\n", "1 2 4 8\n", "8 4 2 1\n", "2 3 4 6\n"], "outputs": ["1\n", "42\n", "42\n", "42\n", "42\n", "16\n", "42\n", "42\n"]}
coding
370
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, invert the tree, and return its root.   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class TreeNode: # def __init__(self, v...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3,6,9])), tree_node([4,7,2,9,6,3,1]))\n assert is_same_tree(candidate(root = tree_node([2,1,3])), tree_node([2,3,1]))\n assert is_same_tree(candidate(root = tree_node([])), tree_node([]))\n\n\ncheck(Solution().inver...
coding
119
Solve the programming task below in a Python markdown code block. Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string s. Namely, he reme...
{"inputs": ["1\na 1 1\n", "1\na 1 3\n", "2\naba 1 1\nb 1 2\n", "3\nab 1 1\naba 1 3\nab 2 3 5\n", "3\na 4 1 3 5 7\nab 2 1 5\nca 1 4\n", "4\na 2 1 10\na 3 1 2 9\na 2 3 8\na 2 4 7\n", "4\na 2 1 10\na 3 1 2 9\na 2 3 8\na 2 4 3\n", "4\na 2 1 3\na 3 1 1 9\na 2 3 15\na 2 4 3\n"], "outputs": ["a\n", "aaa\n", "aba\n", "ababab\n...
coding
447
Solve the programming task below in a Python markdown code block. You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above. The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner? -----Constraints----- - -40 \leq X \leq 40...
{"inputs": ["3", "1", "5", "0", "6", "2", "4", "8"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
129
Solve the programming task below in a Python markdown code block. # Task A ciphertext alphabet is obtained from the plaintext alphabet by means of rearranging some characters. For example "bacdef...xyz" will be a simple ciphertext alphabet where a and b are rearranged. A substitution cipher is a method of encoding w...
{"functional": "_inputs = [['aacb', 'aabc'], ['aa', 'bc'], ['aaxxaaz', 'aazzaay'], ['aaxyaa', 'aazzaa'], ['aazzaa', 'aaxyaa'], ['jpeuizmi', 'mxxcwriq']]\n_outputs = [[True], [False], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
294
Please solve the programming task below using a self-contained code snippet in a markdown code block. A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where: s[i] == 'I' if perm[i] < perm[i + 1], and s[i] == 'D' if perm[i] > perm[i + 1]. Given ...
{"functional": "def check(candidate):\n assert candidate(s = \"IDID\") == [0,4,1,3,2]\n assert candidate(s = \"III\") == [0,1,2,3]\n assert candidate(s = \"DDI\") == [3,2,0,1]\n\n\ncheck(Solution().diStringMatch)"}
coding
146
Solve the programming task below in a Python markdown code block. A and B are brothers and like playing with marbles.Their mother buys them N marbles to play with.The preciousness of each marble is a natural number from 1 to N and no two marbles have same preciousness. Since A and B are good at maths they want to divid...
{"inputs": ["2\n5 7\n1 2"], "outputs": ["Yes\nNo"]}
coding
413