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. N ants are in a circular race. The length of the race is 1000 meters and ant number i is initially Vi meters far from starting point (point 0) of the race in clockwise order. All the ants walk with a speed of 0.1 meters per second, some of them walk in c...
{"inputs": ["2\n0 500\n"], "outputs": ["400000 \n"]}
coding
478
Solve the programming task below in a Python markdown code block. This is another problem about Indraneel's library. His library has one long shelf. His books are numbered and he identifies the books by their number. Each book has a distinct number. He has lost many books, since many of his friends borrow his books and...
{"inputs": ["5\n26 1 42 15 3\n2\n3\n4"], "outputs": ["42\n3"]}
coding
622
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit. Return the minimum number of elements you need to add to make the sum of the ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,-1,1], limit = 3, goal = -4) == 2\n assert candidate(nums = [1,-10,9,1], limit = 100, goal = 0) == 1\n\n\ncheck(Solution().minElements)"}
coding
138
Solve the programming task below in a Python markdown code block. Complete the function that takes two integers (`a, b`, where `a < b`) and return an array of all integers between the input parameters, **including** them. For example: ``` a = 1 b = 4 --> [1, 2, 3, 4] ``` Also feel free to reuse/extend the following st...
{"functional": "_inputs = [[1, 4], [-2, 2], [-10, 10], [5, 100]]\n_outputs = [[[1, 2, 3, 4]], [[-2, -1, 0, 1, 2]], [[-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 3...
coding
99
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and b...
{"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]) == 4\n assert candidate(n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]) == 3\n\n\ncheck(Solution().reachableNodes)"}
coding
168
Solve the programming task below in a Python markdown code block. You have to write a function that describe Leo: ```python def leo(oscar): pass ``` if oscar was (integer) 88, you have to return "Leo finally won the oscar! Leo is happy". if oscar was 86, you have to return "Not even for Wolf of wallstreet?!" if it w...
{"functional": "_inputs = [[88], [87], [86]]\n_outputs = [['Leo finally won the oscar! Leo is happy'], ['When will you give Leo an Oscar?'], ['Not even for Wolf of wallstreet?!']]\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...
coding
152
Solve the programming task below in a Python markdown code block. You are given a string containing characters $\mbox{A}$ and $\mbox{B}$ only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string. You...
{"inputs": ["5\nAAAA\nBBBBB\nABABABAB\nBABABA\nAAABBB\n"], "outputs": ["3\n4\n0\n0\n4\n"]}
coding
356
Solve the programming task below in a Python markdown code block. Go around the Labyrinth Explorer Taro got a floor plan of a labyrinth. The floor of this labyrinth is in the form of a two-dimensional grid. Each of the cells on the floor plan corresponds to a room and is indicated whether it can be entered or not. The...
{"inputs": ["3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n.....\n.....\n3 8\n..#.....\n........\n.....#..\n3 5\n..#..\n-....\n..#..\n4 4\n....\n....\n..##\n..#.\n0 0", "3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n../..\n.....\n3 8\n..#.....\n........\n..#.....\n3 5\n..#..\n....-\n..#..\n4 4\n....\n....\n..##\n..#.\n...
coding
690
Solve the programming task below in a Python markdown code block. Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely fu...
{"inputs": ["1 1\n1\n", "2 1\n2\n", "2 1\n2\n", "1 1\n1\n", "2 1\n4\n", "2 1\n1\n", "2 1\n7\n", "3 1\n7\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "1 0\n", "1 2\n", "1 0\n", "1 0\n"]}
coding
413
Solve the programming task below in a Python markdown code block. Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this o...
{"inputs": ["5 2\nbacba", "5 2\nbacaa", "5 1\nbabba", "5 1\nbabbb", "5 1\nbabbc", "5 2\nbabbc", "5 2\ncabab", "5 1\nbacaa"], "outputs": ["aaaab\n", "aaaaa\n", "aabba\n", "abbbb\n", "abbcc\n", "aabbc\n", "aabab\n", "aaaac\n"]}
coding
235
Solve the programming task below in a Python markdown code block. Chef has two ranges [A, B] and [C, D]. Chef needs to find the number of integers that belong to at least one of the ranges. Note: A range [P, Q] contains all the integers \{P, P+1, P+2, \dots, Q-1, Q\}. ------ Input Format ------ - The first line of ...
{"inputs": ["4\n1 3 5 5\n3 8 2 5\n1 8 4 6\n5 5 5 5\n"], "outputs": ["4\n7\n8\n1\n"]}
coding
423
Solve the programming task below in a Python markdown code block. Akash is stuck in a N \times N grid, where N is odd. The rows of the grid are numbered 1 to N from top to bottom, and the columns are numbered 1 to N from left to right. The cell at the intersection of the i-th row and j-th column will be denoted (i, j)....
{"inputs": ["2\n3 2 1\n5 3 1"], "outputs": ["1\n0\n"]}
coding
669
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point. You are given a 0-indexed string directions of length n. directions[i] c...
{"functional": "def check(candidate):\n assert candidate(directions = \"RLRSLL\") == 5\n assert candidate(directions = \"LLRR\") == 0\n\n\ncheck(Solution().countCollisions)"}
coding
245
Solve the programming task below in a Python markdown code block. Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can ...
{"inputs": ["6 3\n", "8 5\n", "4 3\n", "5 4\n", "4 3\n", "5 4\n", "8 5\n", "6 3\n"], "outputs": ["4\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "4\n"]}
coding
469
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Your friend Сhef has prepared a rectangular cake for you. Both of you want to divide the cake among yourselves. Your friend is generous enough to let you choose your share first. You have...
{"inputs": ["2\n1 1 18 7\n8 20 32 6\n0 1 8 17\n22 1 90 8", "2\n1 1 18 7\n8 20 32 6\n0 1 8 17\n22 0 90 8", "2\n1 1 18 7\n2 20 32 6\n0 1 8 17\n22 0 90 8", "2\n1 1 18 7\n0 20 32 6\n0 1 8 17\n22 0 90 8", "2\n1 1 18 7\n0 20 32 6\n0 1 8 17\n22 0 90 2", "2\n0 2 7 1\n3 8 8 20\n1 0 20 20\n16 11 39 30", "2\n0 2 7 1\n3 8 8 20\n2 ...
coding
563
Solve the programming task below in a Python markdown code block. Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants...
{"inputs": ["bbbabb\nbb\n1 6 3 4 2 5\n", "bababc\nbb\n1 6 3 4 2 5\n", "bbbabc\nbb\n1 6 3 4 2 5\n", "cbabbb\nbb\n1 6 3 4 2 5\n", "bbabbb\nbb\n1 6 3 4 2 5\n", "bbbabb\nba\n1 6 3 4 2 5\n", "abbabb\nba\n1 6 3 4 2 5\n", "bbabba\nba\n1 6 3 4 2 5\n"], "outputs": ["4", "2\n", "4\n", "4\n", "4\n", "3\n", "3\n", "2\n"]}
coding
614
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. For each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k. The score of nums is the difference between the maximum and mi...
{"functional": "def check(candidate):\n assert candidate(nums = [1], k = 0) == 0\n assert candidate(nums = [0,10], k = 2) == 6\n assert candidate(nums = [1,3,6], k = 3) == 3\n\n\ncheck(Solution().smallestRangeII)"}
coding
127
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob are opponents in an archery competition. The competition has set the following rules: Alice first shoots numArrows arrows and then Bob shoots numArrows arrows. The points are then calculated as follows:...
{"functional": "def check(candidate):\n assert candidate(numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0]) == [0,0,0,0,1,1,0,0,1,2,3,1]\n assert candidate(numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2]) == [0,0,0,0,0,0,0,0,1,1,1,0]\n\n\ncheck(Solution().maximumBobPoints)"}
coding
374
Solve the programming task below in a Python markdown code block. You just took a contract with the Jedi council. They need you to write a function, `greet_jedi()`, which takes two arguments (a first name and a last name), works out the corresponding *Jedi name*, and returns a string greeting the Jedi. A person's *Jed...
{"functional": "_inputs = [['Beyonce', 'Knowles'], ['Chris', 'Angelico'], ['grae', 'drake']]\n_outputs = [['Greetings, master KnoBe'], ['Greetings, master AngCh'], ['Greetings, master DraGr']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(...
coding
270
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n binary matrix grid. Let us call a non-empty subset of rows good if the sum of each column of the subset is at most half of the length of the subset. More formally, if the length of the ...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1,0],[0,0,0,1],[1,1,1,1]]) == [0,1]\n assert candidate(grid = [[0]]) == [0]\n assert candidate(grid = [[1,1,1],[1,1,1]]) == []\n\n\ncheck(Solution().goodSubsetofBinaryMatrix)"}
coding
200
Solve the programming task below in a Python markdown code block. Given a number, return a string with dash``` '-' ```marks before and after each odd integer, but do not begin or end the string with a dash mark. Ex: Also feel free to reuse/extend the following starter code: ```python def dashatize(num): ```
{"functional": "_inputs = [[274], [5311], [86320], [974302]]\n_outputs = [['2-7-4'], ['5-3-1-1'], ['86-3-20'], ['9-7-4-3-02']]\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
71
Solve the programming task below in a Python markdown code block. The EEE classes are so boring that the students play games rather than paying attention during the lectures. Harsha and Dubey are playing one such game. The game involves counting the number of anagramic pairs of a given string (you can read about anagr...
{"inputs": ["3\nrama\nabba\nabcd"], "outputs": ["2\n4\n0"]}
coding
271
Solve the programming task below in a Python markdown code block. Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them. Recently, she was presented with an array $a$ of the size of $10^9$ elements that is filled as follows: $a_1 = -1$ $a_2 = 2...
{"inputs": ["1\n682736 1001010010\n", "1\n580408 1001010010\n", "1\n1042324 1001010010\n", "1\n4162847 1001001010\n", "1\n1133909 1001010010\n", "1\n6379767 1001001010\n", "1\n1133909 1001010011\n", "1\n6379767 1001101010\n"], "outputs": ["500846373\n", "500795209\n", "501026167\n", "498419082\n", "499938051\n", "49731...
coding
664
Solve the programming task below in a Python markdown code block. You are given a sequence of integers $A_1, A_2, \ldots, A_N$. This sequence is circular ― for each valid $i$, the element $A_{i+1}$ follows after $A_i$, and the element $A_1$ follows after $A_N$. You may insert any positive integers at any positions you ...
{"inputs": ["1\n5\n3 6 4 5 9"], "outputs": ["3 1 1 0"]}
coding
539
Please solve the programming task below using a self-contained code snippet in a markdown code block. An array A is larger than some array B if for the first index i where A[i] != B[i], A[i] > B[i]. For example, consider 0-indexing: [1,3,2,4] > [1,2,2,4], since at index 1, 3 > 2. [1,4,4,4] < [2,1,1,1], since at index...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4,5,2,3], k = 3) == [5,2,3]\n assert candidate(nums = [1,4,5,2,3], k = 4) == [4,5,2,3]\n assert candidate(nums = [1,4,5,2,3], k = 1) == [5]\n\n\ncheck(Solution().largestSubarray)"}
coding
187
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstruct and return the binar...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1]), tree_node([1,2,3,4,5,6,7]))\n\n\ncheck(Solution().constructFromPrePost)"}
coding
164
Solve the programming task below in a Python markdown code block. You love coffee and want to know what beans you can afford to buy it. The first argument to your search function will be a number which represents your budget. The second argument will be an array of coffee bean prices. Your 'search' function should r...
{"functional": "_inputs = [[3, [6, 1, 2, 9, 2]], [14, [7, 3, 23, 9, 14, 20, 7]], [0, [6, 1, 2, 9, 2]], [10, []], [24, [24, 0, 100, 2, 5]], [24, [2.7, 0, 100.9, 1, 5.5]], [-1, [1, 2, 3, 4]], [-1, [-1, 0, 1, 2, 3, 4]], [14, [17, 33, 23, 19, 19, 20, 17]], [14, [13, 15, 14, 14, 15, 13]]]\n_outputs = [['1,2,2'], ['3,7,7,9,1...
coding
128
Solve the programming task below in a Python markdown code block. Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. ...
{"inputs": ["1\n2 3 1\n2 3 1\n2\n", "1\n2 3 1\n2 3 1\n1\n", "2\n6 4 5 1 3 2\n6 1 3\n4 5 2\n6\n", "2\n2 3 4 5 6 1\n2 3 4\n5 6 1\n1\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n2\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n1\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n3\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n5\n"], "outputs": ["1 3\n", "2 3", "1 3 2 4 ...
coding
761
Solve the programming task below in a Python markdown code block. There are 32 letters in the Polish alphabet: 9 vowels and 23 consonants. Your task is to change the letters with diacritics: ``` ą -> a, ć -> c, ę -> e, ł -> l, ń -> n, ó -> o, ś -> s, ź -> z, ż -> z ``` and print out the string without the use of th...
{"functional": "_inputs = [['J\u0119drzej B\u0142\u0105dzi\u0144ski'], ['Lech Wa\u0142\u0119sa'], ['Maria Sk\u0142odowska-Curie'], ['W\u0142adys\u0142aw Reymont'], ['Miko\u0142aj Kopernik'], ['J\u00f3zef Pi\u0142sudski'], ['Czes\u0142aw Mi\u0142osz'], ['Agnieszka Radwa\u0144ska'], ['Wojciech Szcz\u0119sny'], ['Za\u017c...
coding
154
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has taken his first dose of vaccine D days ago. He may take the second dose no less than L days and no more than R days since his first dose. Determine if Chef ...
{"inputs": ["4\n10 8 12 \n14 2 10\n4444 5555 6666 \n8 8 12\n"], "outputs": ["Take second dose now\nToo Late\nToo Early\nTake second dose now"]}
coding
479
Solve the programming task below in a Python markdown code block. Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each...
{"inputs": ["1\n6 3\n", "1\n1 1\n", "1\n1 1\n", "1\n6 3\n", "1\n0 1\n", "1\n6 6\n", "1\n9 6\n", "1\n9 11\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
401
Solve the programming task below in a Python markdown code block. On Unix system type files can be identified with the ls -l command which displays the type of the file in the first alphabetic letter of the file system permissions field. You can find more information about file type on Unix system on the [wikipedia pag...
{"functional": "_inputs = [['-rwxrwxrwx'], ['Drwxr-xr-x'], ['lrwxrw-rw-'], ['srwxrwxrwx']]\n_outputs = [['file'], ['door'], ['symlink'], ['socket']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isin...
coding
289
Solve the programming task below in a Python markdown code block. I have a plan to go on a school trip at a school. I conducted a questionnaire survey for that purpose. Students have student numbers from 1 to n, and the locations of travel candidates are represented by numbers from 1 to m, and where they want to go ○ ,...
{"inputs": ["4 6\n1 0 1 0 1 1\n1 2 0 1 0 0\n1 1 1 0 0 0\n1 0 1 0 1 0\n4 6\n1 0 1 0 1 1\n1 1 0 1 0 0\n1 1 1 0 0 0\n1 0 1 0 1 0\n0 0", "4 6\n1 0 1 0 1 1\n1 2 0 1 0 0\n1 1 1 0 0 0\n1 0 1 0 1 0\n4 6\n1 0 1 0 1 1\n2 1 0 1 1 0\n1 1 1 0 0 0\n1 0 1 0 1 0\n0 0", "4 6\n1 0 1 0 1 1\n1 1 0 1 0 0\n1 1 1 0 0 0\n1 0 1 0 1 0\n4 6\n0 0...
coding
469
Solve the programming task below in a Python markdown code block. Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions. Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to t...
{"inputs": ["1.0", "0.(2)", "1.(3)", "1.(2)", "0.(3)", "0.0739", "3.2(145)", "3.3(145)"], "outputs": ["1/1", "2/9\n", "4/3\n", "11/9\n", "1/3", "739/10000", "32113/9990\n", "16556/4995\n"]}
coding
352
Solve the programming task below in a Python markdown code block. A company has N members, who are assigned ID numbers 1, ..., N. Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number. When a person X is the immediate boss of a person Y, the person Y is said to be an immedi...
{"inputs": ["5\n1 1 2 3", "5\n1 2 2 3", "5\n1 2 2 2", "5\n1 1 2 5", "5\n1 2 4 3", "5\n1 2 4 2", "5\n2 1 2 5", "5\n1 2 4 5"], "outputs": ["2\n1\n1\n0\n0\n", "1\n2\n1\n0\n0\n", "1\n3\n0\n0\n0\n", "2\n1\n0\n0\n1\n", "1\n1\n1\n1\n0\n", "1\n2\n0\n1\n0\n", "1\n2\n0\n0\n1\n", "1\n1\n0\n1\n1\n"]}
coding
290
Solve the programming task below in a Python markdown code block. You are given three strings A, B and C. Check whether they form a word chain. More formally, determine whether both of the following are true: - The last character in A and the initial character in B are the same. - The last character in B and the init...
{"inputs": ["a a `", "a b a", "a b `", "b a a", "b a b", "c a b", "c b b", "c b a"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
201
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody win...
{"inputs": ["8 50 50 0", "1 000 0 0", "2 100 0 0", "6 50 50 0", "5 50 50 0", "3 50 50 0", "4 100 0 0", "2 50 50 0"], "outputs": ["127441420\n", "0\n", "2\n", "386718762\n", "351562510\n", "125000005\n", "4\n", "500000006\n"]}
coding
359
Solve the programming task below in a Python markdown code block. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column f...
{"inputs": ["2 1\nb\na\n", "2 1\nb\na\n", "2 1\nc\na\n", "2 1\nc\nb\n", "2 2\nfb\nye\n", "2 2\nfb\nye\n", "2 2\nbf\nye\n", "2 3\naxc\nbxa\n"], "outputs": ["1\n", "1", "1\n", "1\n", "0\n", "0", "0\n", "0\n"]}
coding
378
Solve the programming task below in a Python markdown code block. This is a very simply formulated task. Let's call an integer number `N` 'green' if `N²` ends with all of the digits of `N`. Some examples: `5` is green, because `5² = 25` and `25` ends with `5`. `11` is not green, because `11² = 121` and `121` does not...
{"functional": "_inputs = [[1], [2], [3], [4], [12], [13], [100], [110]]\n_outputs = [[1], [5], [6], [25], [2890625], [7109376], [6188999442576576769103890995893380022607743740081787109376], [9580863811000557423423230896109004106619977392256259918212890625]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc...
coding
303
Solve the programming task below in a Python markdown code block. You are given an empty grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You should fill this grid with integers in a way that satisfies the following rules: - For any three cells $c_1$, $c_2$ and $c_3$ such that $...
{"inputs": ["2\n1 1\n2 3"], "outputs": ["1\n1\n3\n1 1 2\n2 3 3"]}
coding
604
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an al...
{"functional": "def check(candidate):\n assert candidate(nums = [-1,0,3,5,9,12], target = 9) == 4\n assert candidate(nums = [-1,0,3,5,9,12], target = 2) == -1\n\n\ncheck(Solution().search)"}
coding
106
Solve the programming task below in a Python markdown code block. You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of m...
{"inputs": ["1\n0 0 1 5\n", "1\n0 0 1 1\n", "1\n0 0 1 4\n", "1\n0 0 1 7\n", "1\n0 0 1 1\n", "1\n0 0 1 4\n", "1\n0 0 1 5\n", "1\n0 0 1 7\n"], "outputs": ["NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
coding
386
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2, of equal length n. In one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices. Find the mini...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5]) == 10\n assert candidate(nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3]) == 10\n assert candidate(nums1 = [1,2,2], nums2 = [1,2,2]) == -1\n\n\ncheck(Solution().minimumTotalCost)"}
coding
176
Solve the programming task below in a Python markdown code block. Your task is to write a function named `do_math` that receives a single argument. This argument is a string that contains multiple whitespace delimited numbers. Each number has a single alphabet letter somewhere within it. ``` Example : "24z6 1x23 y369 ...
{"functional": "_inputs = [['24z6 1z23 y369 89z 900b'], ['24z6 1x23 y369 89a 900b'], ['10a 90x 14b 78u 45a 7b 34y'], ['111a 222c 444y 777u 999a 888p'], ['1z 2t 3q 5x 6u 8a 7b']]\n_outputs = [[1414], [1299], [60], [1459], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, floa...
coding
499
Solve the programming task below in a Python markdown code block. There were $n$ types of swords in the theater basement which had been used during the plays. Moreover there were exactly $x$ swords of each type. $y$ people have broken into the theater basement and each of them has taken exactly $z$ swords of some singl...
{"inputs": ["2\n2 9\n", "2\n1 9\n", "2\n2 9\n", "2\n1 15\n", "2\n0 15\n", "2\n0 13\n", "3\n3 8 6\n", "3\n3 8 0\n"], "outputs": ["1 7\n", "1 8\n", "1 7\n", "1 14\n", "1 15\n", "1 13\n", "7 1\n", "13 1\n"]}
coding
717
Solve the programming task below in a Python markdown code block. Given a list of integers, return the nth smallest integer in the list. **Only distinct elements should be considered** when calculating the answer. `n` will always be positive (`n > 0`) If the nth small integer doesn't exist, return `-1` (C++) / `None` ...
{"functional": "_inputs = [[[14, 12, 46, 34, 334], 3], [[4000], 1], [[14, 12, 46, 0, 334], 1]]\n_outputs = [[34], [4000], [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...
coding
285
Solve the programming task below in a Python markdown code block. There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only p levels of the game. And Little Y can pass only q levels o...
{"inputs": ["1\n0\n0\n", "1\n0\n0\n", "1\n0\n1 1\n", "1\n1 1\n0\n", "100\n0\n0\n", "1\n0\n1 1\n", "1\n1 1\n0\n", "100\n0\n0\n"], "outputs": ["Oh, my keyboard!\n", "Oh, my keyboard!\n", "I become the guy.\n", "I become the guy.\n", "Oh, my keyboard!\n", "I become the guy.\n", "I become the guy.\n", "Oh, my keyboard!\n"]...
coding
363
Solve the programming task below in a Python markdown code block. Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where * <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 ...
{"inputs": ["@\n", "/\n", ".\n", "@ops\n", "$@ru\n", "o@ps\n", "%@ru\n", "@mike\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n"]}
coding
343
Solve the programming task below in a Python markdown code block. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from t...
{"inputs": ["3\n3 4 1", "3\n1 3 4", "3\n3 5 1", "3\n3 5 2", "3\n3 5 3", "3\n3 7 3", "3\n3 1 3", "3\n3 3 1"], "outputs": ["2", "1", "2", "2", "2", "2", "2", "2"]}
coding
233
Solve the programming task below in a Python markdown code block. Given two integer arrays where the second array is a shuffled duplicate of the first array with one element missing, find the missing element. Please note, there may be duplicates in the arrays, so checking if a numerical value exists in one and not the...
{"functional": "_inputs = [[[1, 2, 3], [1, 3]], [[6, 1, 3, 6, 8, 2], [3, 6, 6, 1, 2]], [[7], []], [[4, 3, 3, 61, 8, 8], [8, 61, 8, 3, 4]], [[0, 0, 0, 0, 0], [0, 0, 0, 0]]]\n_outputs = [[2], [8], [7], [3], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ret...
coding
179
Solve the programming task below in a Python markdown code block. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be...
{"inputs": ["3\n1 2\n1 3", "3\n1 3\n2 3", "3\n1 3\n2 1", "3\n1 2\n2 3", "3\n1 2\n2 3\n", "4\n1 2\n2 3\n2 4", "4\n1 2\n2 3\n1 4", "4\n1 2\n1 3\n2 4"], "outputs": ["125000001\n", "125000001\n", "125000001\n", "125000001", "125000001\n", "250000002\n", "375000003\n", "375000003\n"]}
coding
503
Solve the programming task below in a Python markdown code block. # Task A newspaper is published in Walrusland. Its heading is `s1` , it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. ...
{"functional": "_inputs = [['abc', 'bcac'], ['abc', 'xyz'], ['abc', 'abcabc'], ['abc', 'abccba'], ['abc', 'aaaaaa']]\n_outputs = [[2], [-1], [2], [4], [6]]\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
352
Solve the programming task below in a Python markdown code block. Given an array of numbers, return a string made up of four parts: a) a four character 'word', made up of the characters derived from the first two and last two numbers in the array. order should be as read left to right (first, second, second last, last...
{"functional": "_inputs = [[[111, 112, 113, 114, 115, 113, 114, 110]], [[51, 62, 73, 84, 95, 100, 99, 126]], [[66, 101, 55, 111, 113]], [[78, 117, 110, 99, 104, 117, 107, 115, 120, 121, 125]], [[101, 48, 75, 105, 99, 107, 121, 122, 124]], [[80, 117, 115, 104, 65, 85, 112, 115, 66, 76, 62]], [[91, 100, 111, 121, 51, 62,...
coding
178
Solve the programming task below in a Python markdown code block. Chef Vivek is good in mathematics and likes solving problems on prime numbers. One day his friend Jatin told him about Victory numbers. Victory number can be defined as a number formed after summing up all the prime numbers till given number n. Now, chef...
{"inputs": ["3\n22\n13\n10"], "outputs": ["77\n41\n17"]}
coding
225
Solve the programming task below in a Python markdown code block. Implement a function, so it will produce a sentence out of the given parts. Array of parts could contain: - words; - commas in the middle; - multiple periods at the end. Sentence making rules: - there must always be a space between words; - there must ...
{"functional": "_inputs = [[['hello', 'world']], [['Quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']], [['hello', ',', 'my', 'dear']], [['one', ',', 'two', ',', 'three']], [['One', ',', 'two', 'two', ',', 'three', 'three', 'three', ',', '4', '4', '4', '4']], [['hello', 'world', '.']], [['Bye', '.']], [['...
coding
123
Solve the programming task below in a Python markdown code block. Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the h...
{"inputs": ["7 1\n", "1 1\n", "9 1\n", "1 1\n", "9 1\n", "7 8\n", "1 1\n", "7 8\n"], "outputs": ["7\n", "1\n", "9\n", "1\n", "9\n", "7\n", "1\n", "7\n"]}
coding
508
Solve the programming task below in a Python markdown code block. HackerLand University has the following grading policy: Every student receives a $\textit{grade}$ in the inclusive range from $0$ to $100$. Any $\textit{grade}$ less than $\boldsymbol{40}$ is a failing grade. Sam is a professor at the university and l...
{"inputs": ["4\n73\n67\n38\n33\n"], "outputs": ["75\n67\n40\n33\n"]}
coding
623
Solve the programming task below in a Python markdown code block. When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (wh...
{"inputs": ["3\n9\n", "5\n5\n", "3\n7\n", "3\n8\n", "5\n30\n", "6\n18\n", "2\n64\n", "3\n27\n"], "outputs": ["YES\n1\n", "YES\n0\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n5\n", "YES\n2\n"]}
coding
352
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree with unique values. In one operation, you can choose any two nodes at the same level and swap their values. Return the minimum number of operations needed to make the values at ...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,4,3,7,6,8,5,None,None,None,None,9,None,10])) == 3\n assert candidate(root = tree_node([1,3,2,7,6,5,4])) == 3\n assert candidate(root = tree_node([1,2,3,4,5,6])) == 0\n\n\ncheck(Solution().minimumOperations)"}
coding
173
Solve the programming task below in a Python markdown code block. There is a circular pond with a perimeter of K meters, and N houses around them. The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond. When traveling between these houses, you can on...
{"inputs": ["7 3\n0 5 17", "7 3\n0 4 17", "7 3\n0 4 28", "7 3\n0 8 28", "7 3\n1 8 31", "9 3\n0 5 17", "7 3\n0 8 17", "7 3\n0 2 28"], "outputs": ["-5\n", "-6\n", "-17\n", "-13\n", "-16\n", "-3\n", "-2\n", "-19\n"]}
coding
276
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at n...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,1,4]) == 2\n assert candidate(nums = [2,3,0,1,4]) == 2\n\n\ncheck(Solution().jump)"}
coding
157
Solve the programming task below in a Python markdown code block. In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel c...
{"inputs": ["2 1\n00\n", "2 1\n00\n", "3 2\n000\n", "3 1\n010\n", "3 1\n010\n", "3 1\n000\n", "3 1\n001\n", "2 1\n001\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n", "1\n"]}
coding
509
Solve the programming task below in a Python markdown code block. You are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \le Z \le N$ and $(X \oplus Z) < (Y \oplus Z)$, where $\oplus$ denotes the bitwise XOR operation. -----Input----- - The first line of the input cont...
{"inputs": ["3\n1 2 10\n2 1 10\n0 0 7"], "outputs": ["6\n5\n0"]}
coding
281
Solve the programming task below in a Python markdown code block. You are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N · K as the array that's formed by concatenating K copies of array A. For example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, 2}. You h...
{"inputs": ["2\n2 3\n1 2\n3 2\n1 -2 1\n\n"], "outputs": ["9\n2"]}
coding
466
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array cookies, where cookies[i] denotes the number of cookies in the ith bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All ...
{"functional": "def check(candidate):\n assert candidate(cookies = [8,15,10,20,8], k = 2) == 31\n assert candidate(cookies = [6,1,3,2,2,4,1,2], k = 3) == 7\n\n\ncheck(Solution().distributeCookies)"}
coding
146
Solve the programming task below in a Python markdown code block. You have to create a function which receives 3 arguments: 2 numbers, and the result of an unknown operation performed on them (also a number). Based on those 3 values you have to return a string, that describes which operation was used to get the given ...
{"functional": "_inputs = [[1, 2, 3], [10, 5, 5], [10, 4, 40], [9, 5, 1.8]]\n_outputs = [['addition'], ['subtraction'], ['multiplication'], ['division']]\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...
coding
218
Solve the programming task below in a Python markdown code block. Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a...
{"inputs": ["8\n", "1\n", "9\n", "6\n", "2\n", "3\n", "7\n", "4\n"], "outputs": ["40 73\n", "17 17\n", "41 81\n", "34 57\n", "22 25\n", "27 33\n", "47 65\n", "28 41\n"]}
coding
728
Solve the programming task below in a Python markdown code block. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elepha...
{"inputs": ["1\n1 2\n", "1\n1 1\n", "1\n0 2\n", "1\n2 2\n", "1\n2 4\n", "2\n1 2\n2 1\n", "2\n1 2\n2 3\n", "2\n1 1\n1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
421
Solve the programming task below in a Python markdown code block. Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? -----Input----- The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and...
{"inputs": ["9 5\n", "3 3\n", "5 2\n", "6 0\n", "2 0\n", "2 2\n", "3 1\n", "6 2\n"], "outputs": ["4\n", "2\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n"]}
coding
219
Solve the programming task below in a Python markdown code block. A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his...
{"inputs": ["1\nq\n", "1\na\n", "1\na\n", "1\nq\n", "1\nb\n", "1\np\n", "1\no\n", "1\nn\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
375
Solve the programming task below in a Python markdown code block. Leonardo Fibonacci in a rare portrait of his younger days I assume you are all familiar with the famous Fibonacci sequence, having to get each number as the sum of the previous two (and typically starting with either `[0,1]` or `[1,1]` as the first numb...
{"functional": "_inputs = [[[1, 1], [0, 1], 2], [[1, 1], [0, 1], 3], [[1, 1], [0, 1], 4], [[3, 5, 2], [0, 1, 2], 4], [[7, 3, 4, 1], [1, 1], 6]]\n_outputs = [[2], [3], [5], [17], [2]]\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_...
coding
556
Solve the programming task below in a Python markdown code block. Complete the function that returns an array of length `n`, starting with the given number `x` and the squares of the previous number. If `n` is negative or zero, return an empty array/list. ## Examples ``` 2, 5 --> [2, 4, 16, 256, 65536] 3, 3 --> [...
{"functional": "_inputs = [[2, 5], [3, 3], [5, 3], [10, 4], [2, 0], [2, -4]]\n_outputs = [[[2, 4, 16, 256, 65536]], [[3, 9, 81]], [[5, 25, 625]], [[10, 100, 10000, 100000000]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b...
coding
131
Solve the programming task below in a Python markdown code block. Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals. Constraints * $ 1 \leq N \leq 100000 $ * $ 0 \leq x1_i < x2_i \leq 1000 $ * $ 0 \leq y1_i < y2_i \leq...
{"inputs": ["2\n0 0 2 2\n2 0 4 4", "2\n0 0 3 2\n2 1 4 2", "2\n0 0 0 1\n2 2 4 2", "2\n0 0 3 1\n2 1 4 3", "2\n0 0 3 1\n2 1 4 2", "2\n0 0 3 1\n2 1 4 4", "2\n0 0 2 2\n2 0 2 2", "2\n0 0 3 1\n2 1 2 3"], "outputs": ["1\n", "2\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
354
Solve the programming task below in a Python markdown code block. ## The Problem James is a DJ at a local radio station. As it's getting to the top of the hour, he needs to find a song to play that will be short enough to fit in before the news block. He's got a database of songs that he'd like you to help him filter ...
{"functional": "_inputs = [[215], [270], [13], [300]]\n_outputs = [['For Reasons Unknown'], ['YYZ'], [False], ['Surfing With The Alien']]\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
477
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef likes problems involving arrays. Unfortunately, the last one he tried to solve didn't quite get solved. Chef has an array A of N positive numbers. He wants to find the ...
{"inputs": ["3\n3\n1 3 2\n4\n4 1 2 1\n6\n1 2 2 2 2 1", "3\n3\n1 3 2\n4\n4 1 3 1\n6\n1 2 2 2 2 1", "3\n3\n1 3 2\n4\n4 1 3 1\n6\n1 2 2 0 2 1", "3\n3\n1 3 2\n4\n4 1 3 1\n6\n1 1 2 0 2 1", "3\n3\n1 3 2\n4\n4 2 3 1\n6\n1 2 2 2 2 1", "3\n3\n1 5 2\n4\n4 2 3 1\n6\n1 2 2 2 2 1", "3\n3\n1 3 3\n4\n4 1 3 1\n6\n1 0 2 0 2 1", "3\n3\n...
coding
362
Solve the programming task below in a Python markdown code block. Bob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions: There will be 4 different kinds of queries:- - Alice gives an integer $i$ and Bob has to repor...
{"inputs": ["1\n2 2\n2\n1\n1\n1"], "outputs": ["ON"]}
coding
551
Solve the programming task below in a Python markdown code block. Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises...
{"inputs": ["6\n9 english\n6 mathematics\n8 geography\n-1\n3 graphics\n-1"], "outputs": ["1 mathematics\n0 graphics"]}
coding
500
Solve the programming task below in a Python markdown code block. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try t...
{"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n-1\n", "1\n-2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
365
Solve the programming task below in a Python markdown code block. You are given an integer K. Consider an integer sequence A = [A_{1}, A_{2}, \ldots, A_{N}]. Define another sequence S of length N, such that S_{i} = A_{1} + A_{2} + \ldots + A_{i} for each 1 ≤ i ≤ N. A is said to be *interesting* if A_{i} + S_{i} = K ...
{"inputs": ["2\n8\n4"], "outputs": ["3\n2"]}
coding
498
Solve the programming task below in a Python markdown code block. Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all wat...
{"inputs": ["2 4\n4 4\n", "2 1\n1 1\n", "2 1\n2 2\n", "2 1\n1 1\n", "2 4\n4 4\n", "2 1\n2 2\n", "2 1\n3 2\n", "2 1\n3 4\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
coding
366
Solve the programming task below in a Python markdown code block. Complete the function that takes two numbers as input, ```num``` and ```nth``` and return the `nth` digit of `num` (counting from right to left). ## Note - If ```num``` is negative, ignore its sign and treat it as a positive value - If ```nth``` is not ...
{"functional": "_inputs = [[5673, 4], [129, 2], [-2825, 3], [0, 20], [65, 0], [24, -8], [-456, 5], [-1234, 2], [-5540, 1], [678998, 0], [-67854, -57], [0, -3]]\n_outputs = [[5], [2], [8], [0], [-1], [-1], [0], [3], [0], [-1], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst...
coding
253
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For ...
{"functional": "def check(candidate):\n assert candidate(n = 12) == 3 \n assert candidate(n = 13) == 2\n\n\ncheck(Solution().numSquares)"}
coding
123
Solve the programming task below in a Python markdown code block. Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define a pair of integers (a, b) good, if GCD(a, b) ...
{"inputs": ["1 2 1 2\n", "3 3 1 1\n", "2 2 3 3\n", "3 3 3 9\n", "3 3 3 9\n", "3 3 1 1\n", "2 2 3 3\n", "3 3 3 5\n"], "outputs": ["2\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
407
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array arr, return the length of a maximum size turbulent subarray of arr. A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray. More formally, a ...
{"functional": "def check(candidate):\n assert candidate(arr = [9,4,2,10,7,8,8,1,9]) == 5\n assert candidate(arr = [4,8,12,16]) == 2\n assert candidate(arr = [100]) == 1\n\n\ncheck(Solution().maxTurbulenceSize)"}
coding
205
Solve the programming task below in a Python markdown code block. We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time....
{"inputs": ["3\n0 2\n4 0\n0 0", "3\n0 0\n-2 0\n2 0", "3\n1 0\n-2 0\n2 0", "3\n1 0\n-2 0\n2 1", "3\n1 0\n-2 0\n0 1", "3\n1 0\n-2 0\n0 2", "3\n1 0\n-1 0\n0 1", "3\n1 4\n-1 1\n2 -1"], "outputs": ["3\n", "4\n", "7\n", "7\n", "4\n", "4\n", "4\n", "7\n"]}
coding
349
Solve the programming task below in a Python markdown code block. Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). ...
{"inputs": ["a\n", "b\n", "x\n", "b\n", "x\n", "a\n", "c\n", "y\n"], "outputs": ["a \n", "b \n", "x \n", "b\n", "x\n", "a\n", "c\n", "y\n"]}
coding
453
Solve the programming task below in a Python markdown code block. Vasya's older brother, Petya, attends an algorithm course in his school. Today he learned about matchings in graphs. Formally, a set of edges in a graph is called a matching if no pair of distinct edges in the set shares a common endpoint. Petya instantl...
{"inputs": ["3\n3 3\n1 2\n1 3\n2 3\n4 2\n1 2\n3 4\n5 0"], "outputs": ["3\n1\n0"]}
coding
597
Solve the programming task below in a Python markdown code block. You are a real estate broker in ancient Knossos. You have $m$ unsold houses, and each house $j$ has an area, $x_j$, and a minimum price, $y_j$. You also have $n$ clients, and each client $\boldsymbol{i}$ wants a house with an area greater than $a_i$ and ...
{"inputs": ["3 3\n5 110\n9 500\n20 400\n10 100\n2 200\n30 300\n"], "outputs": ["2\n"]}
coding
745
Please solve the programming task below using a self-contained code snippet in a markdown code block. A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple...
{"functional": "def check(candidate):\n assert candidate(answerKey = \"TTFF\", k = 2) == 4\n assert candidate(answerKey = \"TFFT\", k = 1) == 3\n assert candidate(answerKey = \"TTFTTFTT\", k = 1) == 5\n\n\ncheck(Solution().maxConsecutiveAnswers)"}
coding
213
Solve the programming task below in a Python markdown code block. To access CRED programs, one needs to have a credit score of 750 or more. Given that the present credit score is X, determine if one can access CRED programs or not. If it is possible to access CRED programs, output \texttt{YES}, otherwise output \tex...
{"inputs": ["823", "251"], "outputs": ["YES", "NO"]}
coding
313
Solve the programming task below in a Python markdown code block. Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them ...
{"inputs": ["4 7 2 3", "4 5 2 3", "4 7 9 3", "4 7 9 3\n", "0 011 5 8", "0 011 5 3", "0 111 5 3", "0 111 1 3"], "outputs": ["Yes\n", "Yes\n", "Yes", "Yes\n", "Yes\n", "No\n", "No\n", "Yes\n"]}
coding
228
Solve the programming task below in a Python markdown code block. The re.sub() tool (sub stands for substitution) evaluates a pattern and, for each valid match, it calls a method (or lambda). The method is called for all matches and can be used to modify strings in different ways. The re.sub() method returns the mo...
{"inputs": ["11\na = 1;\nb = input();\n\nif a + b > 0 && a - b < 0:\n start()\nelif a*b > 10 || a/b < 1:\n stop()\nprint set(list(a)) | set(list(b)) \n#Note do not change &&& or ||| or & or |\n#Only change those '&&' which have space on both sides.\n#Only change those '|| which have space on both sides.\n"], "out...
coding
648
Solve the programming task below in a Python markdown code block. # Task: Given a list of numbers, determine whether the sum of its elements is odd or even. Give your answer as a string matching `"odd"` or `"even"`. If the input array is empty consider it as: `[0]` (array with a zero). ## Example: ``` odd_or_even([...
{"functional": "_inputs = [[[0, 1, 2]], [[0, 1, 3]], [[1023, 1, 2]]]\n_outputs = [['odd'], ['even'], ['even']]\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 ...
coding
149
Solve the programming task below in a Python markdown code block. The courier charges for a courier company are set according to size and weight as shown in the table below. A size | B size | C size | D size | E size | F size --- | --- | --- | --- | --- | --- | --- Size | 60 cm or less | 80 cm or less | 100 cm or less...
{"inputs": ["2\n26 1 8 2\n80 82 0 0\n3\n18 0 0 24\n4 0 4 3\n30 30 1 1\n0", "2\n51 1 5 5\n80 82 3 0\n3\n7 2 0 24\n2 0 12 3\n30 30 0 11\n0", "2\n51 2 5 5\n80 82 3 0\n3\n7 2 0 24\n2 0 12 3\n30 30 0 11\n0", "2\n51 1 5 5\n80 82 3 0\n3\n10 2 0 24\n2 0 12 3\n30 30 0 11\n0", "2\n51 2 5 5\n80 82 3 0\n3\n7 2 0 24\n2 0 12 3\n30 3...
coding
555
Solve the programming task below in a Python markdown code block. There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor. The game is played on a square field consisting...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "4\n", "5\n", "3\n"], "outputs": ["1", "2", "1", "2", "1", "2", "1", "1"]}
coding
258
Solve the programming task below in a Python markdown code block. Complete the code which should return `true` if the given object is a single ASCII letter (lower or upper case), `false` otherwise. Also feel free to reuse/extend the following starter code: ```python def is_letter(s): ```
{"functional": "_inputs = [[''], ['a'], ['X'], ['7'], ['_'], ['ab'], ['a\\n']]\n_outputs = [[False], [True], [True], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if ...
coding
63
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.   Please complete the following python code precisely: ```pyth...
{"functional": "def check(candidate):\n assert candidate(arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4) == 3\n assert candidate(arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5) == 6\n\n\ncheck(Solution().numOfSubarrays)"}
coding
89
Solve the programming task below in a Python markdown code block. Sereja has two integers — A and B — in 7-ary system. He wants to calculate the number C, such that B * C = A. It is guaranteed that B is a divisor of A. Please, help Sereja calculate the number C modulo 7L. -----Input----- First line of input contains...
{"inputs": ["3\n21\n5\n10\n202\n13\n1\n202\n13\n2"], "outputs": ["3\n3\n13"]}
coding
320
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [directioni, amounti]: directioni can be 0 (for left shift) or 1 (for right shift). amounti is the amount by which s...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\", shift = [[0,1],[1,2]]) == \"cab\"\n assert candidate(s = \"abcdefg\", shift = [[1,1],[1,1],[0,2],[1,3]]) == \"efgabcd\"\n\n\ncheck(Solution().stringShift)"}
coding
164
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,4,3,2,4,2,5,None,None,None,None,None,None,4,6])) == 20\n assert candidate(root = tree_node([4,3,None,1,2])) == 2\n assert candidate(root = tree_node([-4,-2,-5])) == 0\n assert candidate(root = tree_node([2,1,3])) == 6\n assert c...
coding
187