task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n7\n", "1\n0\n", "1\n5\n"], "outputs": ["1\n1 \n", "1\n1\n", "1\n2 \n", "1\n4 \n", "1\n8 \n", "1\n7 \n", "1\n0 \n", "1\n5 \n"]}
478
109
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. You are given an array A of N elements. You can do the following operations on that array: Remove the leftmost element of the array, with index l, for the cost A_{l}. Thi...
{"inputs": ["3\n5 2 7\n9 10 11 12 13\n5 0 7\n9 9 9 9 9\n5 2 7\n9 1 2 3 10\n"], "outputs": ["23\n45\n13\n"]}
664
74
coding
Solve the programming task below in a Python markdown code block. These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day! Today, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it He...
{"inputs": ["2\n10 3\n20 2"], "outputs": ["Case #1: 43\nCase #2: 180"]}
287
37
coding
Solve the programming task below in a Python markdown code block. Implement `String#whitespace?(str)` (Ruby), `String.prototype.whitespace(str)` (JavaScript), `String::whitespace(str)` (CoffeeScript), or `whitespace(str)` (Python), which should return `true/True` if given object consists exclusively of zero or more whi...
{"functional": "_inputs = [[''], [' '], ['\\n\\r\\n\\r'], ['a'], ['w\\n'], ['\\t'], [' a\\n'], ['\\t \\n\\r\\n '], ['\\n\\r\\n\\r '], ['\\n\\r\\n\\r 3']]\n_outputs = [[True], [True], [True], [False], [False], [True], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, fl...
102
246
coding
Solve the programming task below in a Python markdown code block. Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are n mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in on...
{"inputs": ["5\n", "6\n", "4\n", "1\n", "8\n", "7\n", "3\n", "2\n"], "outputs": ["1 5 2 4 3", "1 6 2 5 3 4 ", "1 4 2 3 ", "1", "1 8 2 7 3 6 4 5\n", "1 7 2 6 3 5 4\n", "1 3 2", "1 2 "]}
282
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, find the longest palindromic subsequence's length in s. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaini...
{"functional": "def check(candidate):\n assert candidate(s = \"bbbab\") == 4\n assert candidate(s = \"cbbd\") == 2\n\n\ncheck(Solution().longestPalindromeSubseq)"}
96
49
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the ans...
{"functional": "def check(candidate):\n assert candidate(n = 4) == [[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]\n assert candidate(n = 1) == [[\"Q\"]]\n\n\ncheck(Solution().solveNQueens)"}
139
79
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b. A node a is an ancestor of b if either: any child of a is eq...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([8,3,10,1,6,None,14,None,None,4,7,13])) == 7\n assert candidate(root = tree_node([1,None,2,None,0,3])) == 3\n\n\ncheck(Solution().maxAncestorDiff)"}
173
79
coding
Solve the programming task below in a Python markdown code block. A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS" MATHE ATHEM THEMA HEMAT EMATI MATIC ATICS There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the...
{"inputs": ["1\n2 3\n"], "outputs": ["3\n"]}
379
18
coding
Solve the programming task below in a Python markdown code block. Complete the solution so that it takes the object (JavaScript/CoffeeScript) or hash (ruby) passed in and generates a human readable string from its key/value pairs. The format should be "KEY = VALUE". Each key/value pair should be separated by a comma ...
{"functional": "_inputs = [[{'a': 1, 'b': 2}], [{'a': 'b', 'b': 'a'}], [{'0': 'a', 'b': 2}], [{'b': 1, 'c': 2, 'e': 3}], [{}]]\n_outputs = [['a = 1,b = 2'], ['a = b,b = a'], ['0 = a,b = 2'], ['b = 1,c = 2,e = 3'], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
129
249
coding
Solve the programming task below in a Python markdown code block. Alice and Bob went to a pet store. There are N animals in the store where the i^{th} animal is of type A_{i}. Alice decides to buy some of these N animals. Bob decides that he will buy all the animals left in the store after Alice has made the purchase....
{"inputs": ["4\n3\n4 4 4\n4\n2 3 3 2\n4\n1 2 2 3\n6\n5 5 1 5 1 5\n"], "outputs": ["NO\nYES\nNO\nYES\n"]}
692
62
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$. First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le...
{"inputs": ["1\n6\n", "1\n6\n", "1\n2\n", "1\n1\n", "2\n1 1\n", "2\n3 9\n", "2\n1 1\n", "2\n3 9\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "3\n", "1\n", "3\n"]}
580
94
coding
Solve the programming task below in a Python markdown code block. Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on. Kyota Ootori has just ...
{"inputs": ["2 2\n", "9 1\n", "4 2\n", "1 1\n", "5 8\n", "3 3\n", "5 1\n", "7 2\n"], "outputs": ["2 1\n", "1 2 3 4 5 6 7 8 9\n", "1 2 4 3\n", "1\n", "2 1 4 3 5\n", "2 1 3\n", "1 2 3 4 5\n", "1 2 3 4 5 7 6\n"]}
647
142
coding
Solve the programming task below in a Python markdown code block. On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay fr...
{"inputs": ["2 2 0\n02\n64\n", "2 2 3\n15\n52\n", "2 2 9\n82\n68\n", "2 2 2\n82\n68\n", "2 2 2\n44\n68\n", "2 2 3\n15\n67\n", "2 2 10\n98\n12\n", "2 2 10\n98\n75\n"], "outputs": ["8\n1\nR\n", "-1\n", "-1\n", "-1", "12\n2\nL\n", "8\n2\nL\n", "11\n2\nL\n", "-1\n"]}
545
169
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of distinct strings words, return the minimal possible abbreviations for every word. The following are the rules for a string abbreviation: The initial abbreviation for each word is: the first characte...
{"functional": "def check(candidate):\n assert candidate(words = [\"like\", \"god\", \"internal\", \"me\", \"internet\", \"interval\", \"intension\", \"face\", \"intrusion\"]) == [\"l2e\",\"god\",\"internal\",\"me\",\"i6t\",\"interval\",\"inte4n\",\"f2e\",\"intr4n\"]\n assert candidate(words = [\"aa\",\"aaa\"]) =...
238
111
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a non-negative integer array nums. In one operation, you must: Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums. Subtract x from every positive elem...
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,0,3,5]) == 3\n assert candidate(nums = [0]) == 0\n\n\ncheck(Solution().minimumOperations)"}
114
51
coding
Solve the programming task below in a Python markdown code block. Chef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the first miss...
{"inputs": ["2\n9\nsharechat\n4\nchef"], "outputs": ["shizxvzsg\nsxuv"]}
510
29
coding
Solve the programming task below in a Python markdown code block. You are given N positive integers a_1, a_2, ..., a_N. For a non-negative integer m, let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N). Here, X\ mod\ Y denotes the remainder of the division of X by Y. Find the maximum value of f. -----Constr...
{"inputs": ["2\n8 5\n", "2\n3 10\n", "3\n3 1 6", "3\n3 2 6", "3\n3 3 6", "3\n2 1 6", "3\n7 0 6", "3\n2 0 6"], "outputs": ["11\n", "11\n", "7\n", "8\n", "9\n", "6\n", "10\n", "5\n"]}
243
112
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist. An alphanumeric string is a string consisting of lowercase English letters and digits.   Please ...
{"functional": "def check(candidate):\n assert candidate(s = \"dfa12321afd\") == 2\n assert candidate(s = \"abc1111\") == -1\n\n\ncheck(Solution().secondHighest)"}
87
53
coding
Solve the programming task below in a Python markdown code block. Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n0\n", "1 2\n0 1\n", "1 2\n1 0\n", "1 2\n1 1\n", "2 1\n1\n0\n", "2 1\n0\n1\n"], "outputs": ["0\n", "0", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]}
525
111
coding
Solve the programming task below in a Python markdown code block. Given an array $A$ of length $N$. We have to find the $maximum$ sum of elements of the subarray between $two$ nearest occurrences of $same$ elements (excluding both). If both the elements are $even$ then the total number of $even$ elements in that subarr...
{"inputs": ["1\n10\n1 2 3 2 1 5 1 2 8 2"], "outputs": ["7"]}
360
35
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array.   Please complete the followin...
{"functional": "def check(candidate):\n assert candidate(arr = [17,18,5,4,6,1]) == [18,6,6,6,1,-1]\n assert candidate(arr = [400]) == [-1]\n\n\ncheck(Solution().replaceElements)"}
90
70
coding
Solve the programming task below in a Python markdown code block. The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if th...
{"inputs": ["3\nmike 1\nandrew 5\nmike 2\n", "3\nmike 1\nandsew 5\nmike 2\n", "3\nmike 3\nandrew 5\nmike 2\n", "3\neikm 0\nwesdna 12\nejkm 0\n", "3\nemki 0\nwdsena 12\nejmk 0\n", "3\nelkh 0\nwdsema 12\nemjk 0\n", "3\nmike 1\nandsew 10\nmike 2\n", "3\nmike 1\nandsew 12\nmike 2\n"], "outputs": ["andrew\n", "andsew\n", "a...
371
216
coding
Solve the programming task below in a Python markdown code block. The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The se...
{"inputs": ["7 7\n", "9 5\n", "3 0\n", "5 0\n", "7 9\n", "5 4\n", "5 1\n", "9 4\n"], "outputs": ["YES\n.......\n.#####.\n.#...#.\n.......\n", "YES\n.........\n..#####..\n.........\n.........\n", "YES\n...\n...\n...\n...\n", "YES\n.....\n.....\n.....\n.....\n", "YES\n.......\n.#####.\n.##.##.\n.......\n", "YES\n.....\n....
363
193
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N...
{"inputs": ["2\n2\n1 1\n3\n1 9 8"], "outputs": ["3\n27"]}
334
29
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, partition it into two (contiguous) subarrays left and right so that: Every element in left is less than or equal to every element in right. left and right are non-empty. left has the smal...
{"functional": "def check(candidate):\n assert candidate(nums = [5,0,3,8,6]) == 3\n assert candidate(nums = [1,1,1,0,6,12]) == 4\n\n\ncheck(Solution().partitionDisjoint)"}
121
63
coding
Solve the programming task below in a Python markdown code block. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to ...
{"inputs": ["1 2\n1\n4", "1 4\n1\n4", "1 3\n1\n3", "1 4\n1\n1", "1 3\n1\n5", "1 4\n1\n2", "1 3\n1\n9", "1 1\n1\n4"], "outputs": ["30\n", "354\n", "36\n", "1\n", "225\n", "17\n", "2025\n", "10\n"]}
622
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Convert a non-negative integer num to its English words representation.   Please complete the following python code precisely: ```python class Solution: def numberToWords(self, num: int) -> str: ```
{"functional": "def check(candidate):\n assert candidate(num = 123) == \"One Hundred Twenty Three\"\n assert candidate(num = 12345) == \"Twelve Thousand Three Hundred Forty Five\"\n assert candidate(num = 1234567) == \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n\n\ncheck(Solution(...
60
91
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. There are n rooms numbered from 0 to n - 1. You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interv...
{"functional": "def check(candidate):\n assert candidate(n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]) == 0\n assert candidate(n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]) == 1\n\n\ncheck(Solution().mostBooked)"}
253
89
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.   Please complete the followi...
{"functional": "def check(candidate):\n assert candidate(nums = [\"777\",\"7\",\"77\",\"77\"], target = \"7777\") == 4\n assert candidate(nums = [\"123\",\"4\",\"12\",\"34\"], target = \"1234\") == 2\n assert candidate(nums = [\"1\",\"1\",\"1\"], target = \"11\") == 6\n\n\ncheck(Solution().numOfPairs)"}
99
108
coding
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"]}
337
104
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Every adjacent pair of words differs by a single letter. ...
{"functional": "def check(candidate):\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]) == 5\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]) == 0\n\n\ncheck(Solution().ladderLeng...
180
95
coding
Solve the programming task below in a Python markdown code block. You have been given a String S. You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes). Input Format The first and only line of input contains the String S. The Stri...
{"inputs": ["eovbgggijqjdsdhjyojeaujcdyyyxtpjlllowjyarfhxjxwkxpranhtlucoklahtokmqyozlrwhldozgbgpalkqlcsiowyeslusn", "sqfopldohhwnbhhpnbxiwzvkybggkgtftvvaqpejznlxluatcppctaulxlnzjepqavvtftgkggbykvzwixbnphhbnwhhodlpofqs", "fnjzxnxnjplfwzowfdrhrvhegkmoncbkembjoudteqchjwqfzlofyflkmxnooasxulwofjzknthqqxgshvwxdvhdnlzjzdjdiif...
135
256
coding
Solve the programming task below in a Python markdown code block. Write a function that accepts two square (`NxN`) matrices (two dimensional arrays), and returns the product of the two. Only square matrices will be given. How to multiply two square matrices: We are given two matrices, A and B, of size 2x2 (note: tes...
{"functional": "_inputs = [[[[1, 2], [3, 2]], [[3, 2], [1, 1]]], [[[9, 7], [0, 1]], [[1, 1], [4, 12]]], [[[1, 2, 3], [3, 2, 1], [2, 1, 3]], [[4, 5, 6], [6, 5, 4], [4, 6, 5]]]]\n_outputs = [[[[5, 4], [11, 8]]], [[[37, 93], [4, 12]]], [[[28, 33, 29], [28, 31, 31], [26, 33, 31]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5...
610
323
coding
Solve the programming task below in a Python markdown code block. Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose release ye...
{"inputs": ["8\n1 6 5 4 3 2 7 8"], "outputs": ["2 6"]}
483
30
coding
Solve the programming task below in a Python markdown code block. Your company, [Congo Pizza](http://interesting-africa-facts.com/Africa-Landforms/Congo-Rainforest-Facts.html), is the second-largest online frozen pizza retailer. You own a number of international warehouses that you use to store your frozen pizzas, and ...
{"functional": "_inputs = [[32, 64, 16], [20, 20, 20], [80, 40, 20], [70, 60, 15], [90, 7, 5], [53, 21, 13]]\n_outputs = [[13824], [3375], [27000], [25740], [1005], [5265]]\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, a...
294
257
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two positive integers n and k, the binary string Sn is formed as follows: S1 = "0" Si = Si - 1 + "1" + reverse(invert(Si - 1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reve...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 1) == \"0\"\n assert candidate(n = 4, k = 11) == \"1\"\n assert candidate(n = 1, k = 1) == \"0\"\n assert candidate(n = 2, k = 3) == \"1\"\n\n\ncheck(Solution().findKthBit)"}
223
94
coding
Solve the programming task below in a Python markdown code block. Chef wants to store some important numerical data on his personal computer. He is using a new data type that can store values only from 0 till N both inclusive. If this data type receives a value greater than N then it is cyclically converted to fit into...
{"inputs": ["5\n15 0\n15 10\n11 12\n27 37\n50 49"], "outputs": ["0\n10\n0\n9\n49"]}
519
51
coding
Solve the programming task below in a Python markdown code block. There are 'n' coins kept on the table, numbered from 0 to 'n-1'. Initially, each coin is kept tails up. You have to perform two types of operations : 1) Flip all coins numbered between A and B inclusive. This is represented by the command: 0 A B 2) Answe...
{"inputs": ["7\n3\n0\n3\n5\n1\n0\n6\n1\n3\n4"], "outputs": ["3\n2"]}
253
34
coding
Solve the programming task below in a Python markdown code block. Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree. Constraints * $1 \...
{"inputs": ["4\n1 2 3 4\n2 1 3 4", "4\n2 1 3 4\n2 1 3 4", "4\n2 1 3 4\n3 1 2 4", "4\n2 1 3 4\n1 2 3 4", "4\n1 4 3 2\n1 2 3 4", "4\n1 2 3 4\n1 2 4 3", "4\n2 1 3 4\n2 1 4 3", "4\n1 2 3 4\n2 1 3 4"], "outputs": ["2 4 3 1\n", "4 3 1 2\n", "3 1 4 2\n", "1 4 3 2\n", "2 3 4 1\n", "4 3 2 1\n", "4 3 1 2\n", "2 4 3 1\n"]}
268
238
coding
Solve the programming task below in a Python markdown code block. Suppose you are given a string $s$ of length $n$ consisting of lowercase English letters. You need to compress it using the smallest possible number of coins. To compress the string, you have to represent $s$ as a concatenation of several non-empty stri...
{"inputs": ["3 3 1\naba\n", "3 3 0\naba\n", "3 3 1\naba\n", "4 1 1\nabcd\n", "4 1 2\nabcd\n", "4 2 3\nabdd\n", "4 1 3\nabcd\n", "4 1 3\nabdd\n"], "outputs": ["7\n", "6\n", "7\n", "4\n", "4\n", "8\n", "4\n", "4\n"]}
599
120
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t.   Please complete the following python co...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\", t = \"abcde\") == \"e\"\n assert candidate(s = \"\", t = \"y\") == \"y\"\n\n\ncheck(Solution().findTheDifference)"}
91
56
coding
Solve the programming task below in a Python markdown code block. You are given four integers $a$, $b$, $x$ and $y$. Initially, $a \ge x$ and $b \ge y$. You can do the following operation no more than $n$ times: Choose either $a$ or $b$ and decrease it by one. However, as a result of this operation, value of $a$ can...
{"inputs": ["1\n10 10 8 5 3\n", "1\n10 10 8 5 3\n", "1\n10 10 8 1 3\n", "1\n10 10 0 1 3\n", "1\n10 10 10 5 3\n", "1\n10 10 10 5 4\n", "1\n10 20 10 5 3\n", "1\n10 10 10 5 0\n"], "outputs": ["70\n", "70\n", "70\n", "70\n", "70\n", "60\n", "170\n", "100\n"]}
661
180
coding
Solve the programming task below in a Python markdown code block. A string $s$ of length $n$ can be encrypted by the following algorithm: iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position...
{"inputs": ["1\nz\n", "1\ny\n", "1\nx\n", "1\n{\n", "1\n|\n", "1\nz\n", "2\nir\n", "2\nir\n"], "outputs": ["z\n", "y\n", "x\n", "{\n", "|\n", "z\n", "ri\n", "ri\n"]}
384
86
coding
Solve the programming task below in a Python markdown code block. You might know some pretty large perfect squares. But what about the NEXT one? Complete the `findNextSquare` method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n...
{"functional": "_inputs = [[121], [625], [319225], [15241383936], [155], [342786627]]\n_outputs = [[144], [676], [320356], [15241630849], [-1], [-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 isi...
183
233
coding
Solve the programming task below in a Python markdown code block. Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a_1, a_2, ..., a_{n}. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise a_{...
{"inputs": ["1\n10\n", "1\n19\n", "1\n19\n", "1\n10\n", "1\n19\n", "1\n35\n", "1\n14\n", "1\n70\n"], "outputs": ["chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n", "chest\n"]}
488
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones). A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,-1,8,4]) == 3\n assert candidate(nums = [1,-1,4]) == 2\n assert candidate(nums = [2,5]) == -1\n assert candidate(nums = [1]) == 0\n\n\ncheck(Solution().findMiddleIndex)"}
191
82
coding
Solve the programming task below in a Python markdown code block. You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from t...
{"inputs": ["4 2\n1\n1\n2\n6", "4 2\n1\n1\n3\n1", "4 2\n1\n1\n3\n0", "4 2\n1\n4\n3\n0", "3 4\n1\n0\n2\n6", "4 2\n1\n1\n3\n6", "4 2\n1\n2\n3\n0", "4 2\n1\n0\n2\n6"], "outputs": ["6\n", "4\n", "3\n", "5\n", "2\n", "6\n", "3\n", "6\n"]}
294
142
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1. You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirec...
{"functional": "def check(candidate):\n assert candidate(n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]) == 43\n assert candidate(n = 5, roads = [[0,3],[2,4],[1,3]]) == 20\n\n\ncheck(Solution().maximumImportance)"}
180
88
coding
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 where each node has a value in the range [0, 25] representing the letters 'a' to 'z'. Return the lexicographically smallest string that starts at a leaf of this tree and ends at...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([0,1,2,3,4,3,4])) == \"dba\"\n assert candidate(root = tree_node([25,1,3,1,3,0,2])) == \"adz\"\n assert candidate(root = tree_node([2,2,1,None,1,0,None,0])) == \"abc\"\n\n\ncheck(Solution().smallestFromLeaf)"}
201
104
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root1 = tree_node([1,3,2,5]), root2 = tree_node([2,1,3,None,4,None,7])), tree_node([3,4,5,5,4,None,7]))\n assert is_same_tree(candidate(root1 = tree_node([1]), root2 = tree_node([1,2])), tree_node([2,2]))\n\n\ncheck(Solution().mergeTrees)"}
224
108
coding
Solve the programming task below in a Python markdown code block. # Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. The letters called airstrike to help them in war -...
{"functional": "_inputs = [['z'], ['z*dq*mw*pb*s'], ['zdqmwpbs'], ['zz*zzs'], ['sz**z**zs'], ['z*z*z*zs'], ['*wwwwww*z*']]\n_outputs = [['Right side wins!'], [\"Let's fight again!\"], [\"Let's fight again!\"], ['Right side wins!'], ['Left side wins!'], ['Left side wins!'], ['Left side wins!']]\nimport math\ndef _deep_e...
336
244
coding
Solve the programming task below in a Python markdown code block. A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vert...
{"inputs": ["1\n\n6 2\n1 4\n1 6\n3 1\n6 2\n1 5\n", "1\n\n6 2\n1 4\n1 6\n3 1\n6 2\n2 5\n", "1\n\n6 4\n2 4\n1 2\n5 1\n6 1\n3 5\n", "1\n\n6 4\n1 4\n1 6\n3 1\n6 2\n1 5\n", "1\n\n6 2\n1 4\n1 2\n3 1\n6 2\n2 5\n", "1\n\n6 2\n1 4\n1 2\n3 1\n6 1\n2 5\n", "1\n\n6 2\n1 4\n1 2\n3 1\n6 1\n3 5\n", "1\n\n6 2\n1 4\n1 6\n3 1\n1 2\n2 5\...
431
276
coding
Solve the programming task below in a Python markdown code block. You work as a system administrator in a dormitory, which has $n$ rooms one after another along a straight hallway. Rooms are numbered from $1$ to $n$. You have to connect all $n$ rooms to the Internet. You can connect each room to the Internet directly...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "1 0\n1\n", "1 0\n0\n", "4 1\n0011\n", "4 2\n0011\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "4\n", "3\n"]}
673
108
coding
Solve the programming task below in a Python markdown code block. For 3 distinct prime integers A, B, and C (1 < A,B,C < 2^{30}), we define positive integers X, Y, and Z as: X = A\oplus B, Y = B\oplus C, and Z = C\oplus A, where \oplus denotes the [bitwise XOR] operation. Given only two integers X and Y and the fa...
{"inputs": ["2\n1 6\n9 15"], "outputs": ["2 3 5\n2 11 13"]}
540
33
coding
Solve the programming task below in a Python markdown code block. You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become d...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0", "0", "0", "0"]}
298
82
coding
Solve the programming task below in a Python markdown code block. King Arthur has a large kingdom that can be represented as a tree, where nodes correspond to cities and edges correspond to the roads between cities. The kingdom has a total of $n$ cities numbered from $\mbox{1}$ to $n$. The King wants to divide his ki...
{"inputs": ["5\n1 2\n1 3\n3 4\n3 5\n"], "outputs": ["4\n"]}
531
30
coding
Solve the programming task below in a Python markdown code block. Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he h...
{"inputs": ["2\n5 8", "2\n4 8", "2\n4 8\n", "2\n5 11", "2\n10 6", "2\n17 5", "2\n17 1", "2\n17 2"], "outputs": ["5\n", "8", "8\n", "18\n", "8\n", "72\n", "128\n", "113\n"]}
225
105
coding
Solve the programming task below in a Python markdown code block. Write a function that solves an algebraic expression given as a string. * The expression can include only sums and products. * The numbers in the expression are in standard notation (NOT scientific). * In contrast, the function should return a strin...
{"functional": "_inputs = [['5*4+6'], ['5+4*6'], ['3*8+6*5'], ['5*8+6*3*2'], ['5.4*4.0+6.2+8.0'], ['0.5*1.2*56+9.6*5*81+1'], ['1'], ['1.333333333*1.23456789+0.003*0.002']]\n_outputs = [['2.60000e+01'], ['2.90000e+01'], ['5.40000e+01'], ['7.60000e+01'], ['3.58000e+01'], ['3.92260e+03'], ['1.00000e+00'], ['1.64610e+00']]...
142
365
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n grid grid where: '.' is an empty cell. '#' is a wall. '@' is the starting point. Lowercase letters represent keys. Uppercase letters represent locks. You start at the starting point and one mo...
{"functional": "def check(candidate):\n assert candidate(grid = [\"@.a..\",\"###.#\",\"b.A.B\"]) == 8\n assert candidate(grid = [\"@..aA\",\"..B#.\",\"....b\"]) == 6\n\n\ncheck(Solution().shortestPathAllKeys)"}
251
72
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. Construct any permutation A of N integers such that the value LCM(1 + A_{1} , 2 + A_{2}, \ldots, N + A_{N}) is minimised. Note: LCM denotes the [least common multiple] of the integers. A permutation of N integers contains ...
{"inputs": ["1\n2\n"], "outputs": ["2 1 \n"]}
286
19
coding
Solve the programming task below in a Python markdown code block. Who's interested in football? Rayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since. He's got proper treatment and ...
{"inputs": ["3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 2 2 3", "3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 1 2 3", "3\n6\n3 1 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 1 2 3", "3\n6\n3 1 1 4 2 4\n5\n2 4 3 2 1\n5\n4 3 1 2 3", "3\n6\n1 1 0 4 2 4\n5\n4 4 3 2 1\n5\n4 0 1 2 3", "3\n6\n1 1 0 4 2 4\n5\n4 7 3 2 2\n5\n4 0 1 2 3", "3\n6\n1 1 1 4...
653
402
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = ...
{"functional": "def check(candidate):\n assert candidate(celsius = 36.50) == [309.65000,97.70000]\n assert candidate(celsius = 122.11) == [395.26000,251.79800]\n\n\ncheck(Solution().convertTemperature)"}
150
91
coding
Solve the programming task below in a Python markdown code block. This challenge is only forPython 2. input() In Python 2, the expression input() is equivalent to eval(raw _input(prompt)). Code >>> input() 1+2 3 >>> company = 'HackerRank' >>> website = 'www.hackerrank.com' >>> input() 'The company name: '+compan...
{"inputs": ["1 4\nx**3 + x**2 + x + 1\n"], "outputs": ["True\n"]}
317
29
coding
Solve the programming task below in a Python markdown code block. Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the...
{"inputs": ["FVF\nr \n", "FVF\nq \n", "FFV\nq \n", "VFF\nq \n", "VFG\nq \n", "GtPXu\nd\n", "GPtXu\nd\n", "XPtGu\nd\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
296
104
coding
Solve the programming task below in a Python markdown code block. Given is a number sequence A of length N. Find the number of integers i \left(1 \leq i \leq N\right) with the following property: - For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i. -----Constraints----- - ...
{"inputs": ["4\n6 8 5 5", "4\n5 8 5 5", "4\n6 8 2 5", "4\n7 8 5 5", "4\n8 8 5 5", "4\n3 8 2 5", "4\n7 9 5 5", "4\n7 9 8 5"], "outputs": ["2\n", "1\n", "2\n", "2\n", "0\n", "3\n", "2\n", "4\n"]}
209
126
coding
Solve the programming task below in a Python markdown code block. The code provided is supposed replace all the dots `.` in the specified String `str` with dashes `-` But it's not working properly. # Task Fix the bug so we can all go home early. # Notes String `str` will never be null. Also feel free to reuse/exte...
{"functional": "_inputs = [[''], ['no dots'], ['one.two.three'], ['........']]\n_outputs = [[''], ['no dots'], ['one-two-three'], ['--------']]\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 isinstanc...
90
179
coding
Solve the programming task below in a Python markdown code block. Given a tree T with n nodes, how many subtrees (T') of T have at most K edges connected to (T - T')? Input Format The first line contains two integers n and K followed by n-1 lines each containing two integers a & b denoting that there's an edge betwe...
{"inputs": ["3 1\n2 1\n2 3\n"], "outputs": ["6\n"]}
272
24
coding
Solve the programming task below in a Python markdown code block. You are given an integer N where N ≤ 10. Consider any array A with length N where each element can either be 0, 1, or 2, we define f(A) as the number of extrema in A. You need to find the sum of f(A) over all possible arrays A. Note: In an array A, we c...
{"inputs": ["3\n1\n3\n5"], "outputs": ["0\n10\n270\n"]}
592
26
coding
Solve the programming task below in a Python markdown code block. Takahashi has received an undirected graph with N vertices, numbered 1, 2, ..., N. The edges in this graph are represented by (u_i, v_i). There are no self-loops and multiple edges in this graph. Based on this graph, Takahashi is now constructing a new ...
{"inputs": ["3 1\n1 2", "7 5\n1 2\n3 4\n3 5\n4 1\n2 6", "7 5\n1 2\n3 7\n3 5\n4 1\n2 6", "7 5\n1 2\n3 7\n3 5\n4 1\n2 2", "7 5\n1 2\n3 7\n6 5\n4 1\n2 2", "7 5\n1 2\n3 7\n3 7\n4 1\n2 3", "7 5\n1 2\n2 6\n6 5\n4 1\n2 2", "7 5\n2 2\n2 6\n6 5\n4 1\n2 2"], "outputs": ["7", "15\n", "8\n", "18\n", "13\n", "26\n", "25\n", "29\n"]...
378
227
coding
Solve the programming task below in a Python markdown code block. **An [isogram](https://en.wikipedia.org/wiki/Isogram)** (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter. It is also used by some to mean a word or phrase in which each letter appears the same numb...
{"functional": "_inputs = [[None], [3], ['Dermatoglyphics'], ['isogram'], ['eleven'], ['moOse'], ['isIsogram'], [''], ['-.-'], ['subdermatoglyphic'], ['Alphabet'], ['thumbscrew-japingly'], ['Hjelmqvist-Gryb-Zock-Pfund-Wax'], ['Emily Jung Schwartzkopf'], ['aabbccddeeffgg']]\n_outputs = [[False], [False], [True], [True],...
218
281
coding
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence ...
{"inputs": ["5\n3\ncab\ncab\n1\na\nb\n6\nabbabc\nbbaacb\n10\nbcaabababc\ncbbababaac\n2\nba\nab\n"], "outputs": ["YES\nNO\nYES\nYES\nNO\n"]}
386
66
coding
Solve the programming task below in a Python markdown code block. Solve the mystery. Input : First line contains T - No. of test cases. For each test case there are two lines. first line contains N. Second line contains N space separated integers A[1] to A[N]. Output : Print answer of the mystery in separate...
{"inputs": ["10\n10\n9 83 61 91 57 0 89 87 83 68 \n10\n9 41 12 70 73 85 85 79 3 49 \n10\n25 14 34 85 24 19 0 13 72 15 \n10\n24 66 54 97 85 91 45 64 42 39 \n10\n44 39 78 94 54 81 35 18 10 67 \n10\n58 29 36 52 77 34 64 10 3 24 \n10\n8 42 31 40 6 53 66 77 76 58 \n10\n63 55 67 9 91 77 23 30 91 50 \n10\n36 12 34 78 45 18 21...
191
379
coding
Solve the programming task below in a Python markdown code block. In genetics a reading frame is a way to divide a sequence of nucleotides (DNA bases) into a set of consecutive non-overlapping triplets (also called codon). Each of this triplets is translated into an amino-acid during a translation process to create pro...
{"functional": "_inputs = [['AGGTGACACCGCAAGCCTTATATTAGC']]\n_outputs = [['Frame 1: AGG TGA CAC CGC AAG CCT TAT ATT AGC\\nFrame 2: A GGT GAC ACC GCA AGC CTT ATA TTA GC\\nFrame 3: AG GTG ACA CCG CAA GCC TTA TAT TAG C']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
461
233
coding
Solve the programming task below in a Python markdown code block. Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in ...
{"inputs": ["1 1\n5\n", "3 1\n1 1 1\n", "2 2\n97 197\n", "2 1\n97 197\n", "2 2\n193 193\n", "4 2\n0 2 1 2\n", "4 2\n0 2 2 2\n", "4 2\n1 2 1 2\n"], "outputs": [" 1\n", " 6\n", " ...
616
150
coding
Solve the programming task below in a Python markdown code block. Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to p...
{"inputs": ["7\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n"], "outputs": ["7\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n"]}
206
70
coding
Solve the programming task below in a Python markdown code block. It's your Birthday. Your colleagues buy you a cake. The numbers of candles on the cake is provided (x). Please note this is not reality, and your age can be anywhere up to 1,000. Yes, you would look a mess. As a surprise, your colleagues have arranged f...
{"functional": "_inputs = [[900, 'abcdef'], [56, 'ifkhchlhfd'], [256, 'aaaaaddddr'], [333, 'jfmgklfhglbe'], [12, 'jaam'], [808, 'alfbpmmpz'], [660, 'zyxsqwh'], [651, 'hmgoltyy'], [349, 'nxls'], [958, 'hovzfsxbmwu'], [301, 'doda'], [383, 'zwwl'], [871, 'gnlyvknjga'], [583, 'slhacx'], [0, 'jpipe']]\n_outputs = [['That wa...
296
374
coding
Solve the programming task below in a Python markdown code block. Indian National Olympiad in Informatics 2016 Boing Inc, has N employees, numbered 1 ... N. Every employee other than Mr. Hojo (the head of the company) has a manager (P[i] denotes the manager of employee i). Thus an employee may manage any number of oth...
{"inputs": ["4 5 10 6 12 2 -1 4 2"], "outputs": ["6"]}
637
30
coding
Solve the programming task below in a Python markdown code block. Chef is the new king of the country Chefland. As first and most important responsibility he wants to reconstruct the road system of Chefland. There are N (1 to N) cities in the country and each city i has a population Pi. Chef wants to build some bi-dire...
{"inputs": ["2\n2\n9 3\n4\n29 0 4 2", "2\n2\n8 9\n4\n5 18 2 5", "2\n2\n8 9\n4\n5 36 2 5", "2\n2\n9 2\n4\n29 0 4 2", "2\n2\n8 9\n4\n4 18 2 5", "2\n2\n8 9\n4\n5 18 2 13", "2\n2\n3 5\n4\n8 10 7 13", "2\n2\n3 5\n4\n9 10 7 13"], "outputs": ["27\n0\n", "72\n56\n", "72\n92\n", "18\n0\n", "72\n54\n", "72\n72\n", "15\n217\n", "...
339
233
coding
Solve the programming task below in a Python markdown code block. Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked v...
{"inputs": ["oh\n", "oh\n", "nh\n", "rhh\n", "rhh\n", "hhr\n", "pezu\n", "kmsk\n"], "outputs": ["CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "IGNORE HIM!\n"]}
371
99
coding
Solve the programming task below in a Python markdown code block. A sequence $a_1, a_2, \dots, a_k$ is called an arithmetic progression if for each $i$ from $1$ to $k$ elements satisfy the condition $a_i = a_1 + c \cdot (i - 1)$ for some fixed $c$. For example, these five sequences are arithmetic progressions: $[5, 7,...
{"inputs": ["2\n3 4\n", "2\n3 4\n", "2\n3 3\n", "2\n2 3\n", "3\n1 2 7\n", "3\n1 2 7\n", "3\n1 2 11\n", "3\n2 2 11\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]}
612
110
coding
Solve the programming task below in a Python markdown code block. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model soluti...
{"inputs": ["2\n0 1\n", "2\n0 1\n", "2\n0 2\n", "2\n73 37\n", "2\n73 37\n", "2\n129 37\n", "2\n129 16\n", "2\n129 20\n"], "outputs": ["1\n", "1\n", "2\n", "36\n", "36\n", "92\n", "113\n", "109\n"]}
682
122
coding
Solve the programming task below in a Python markdown code block. Appy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the problems...
{"inputs": ["1\n6 2 3 3"], "outputs": ["Win"]}
469
20
coding
Solve the programming task below in a Python markdown code block. Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such ...
{"inputs": ["2\n1 2\n", "2\n1 2\n", "3\n1 2\n1 3\n", "3\n1 2\n2 3\n", "3\n1 3\n2 3\n", "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n", "5\n1 3\n2 3\n3 4\n4 5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "2\n"]}
500
142
coding
Solve the programming task below in a Python markdown code block. Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. An array is Rainbow if it has the following structure: - First a1 elements equal 1. - Next a2 elements equal 2. - Next a3 element...
{"inputs": ["3\n19\n1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1\n14\n1 2 3 4 5 6 7 6 5 4 3 2 1 1\n13\n1 2 3 4 5 6 8 6 5 4 3 2 1"], "outputs": ["yes\nno\nno"]}
552
117
coding
Solve the programming task below in a Python markdown code block. Problem Given the strings $ s $, $ t $. First, let the string set $ A = $ {$ s $}, $ B = \ phi $. At this time, I want to perform the following operations as much as possible. operation step1 Perform the following processing for all $ u ∊ A $. 1. Fr...
{"inputs": ["AABABCAC\nB", "AACABCAC\nB", "AACABCAC\nC", "AACAACAC\nC", "@ACAACAC\nC", "AABABCAC\nA", "AbCdEfG\naBcDeFh", "AbGdEfC\naBcDeFh"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2", "0\n", "0\n"]}
642
109
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two sparse matrices mat1 of size m x k and mat2 of size k x n, return the result of mat1 x mat2. You may assume that multiplication is always possible.   Please complete the following python code precisely: ```p...
{"functional": "def check(candidate):\n assert candidate(mat1 = [[1,0,0],[-1,0,3]], mat2 = [[7,0,0],[0,0,0],[0,0,1]]) == [[7,0,0],[-7,0,3]]\n assert candidate(mat1 = [[0]], mat2 = [[0]]) == [[0]]\n\n\ncheck(Solution().multiply)"}
97
96
coding
Solve the programming task below in a Python markdown code block. Chief's bot is playing an old DOS based game. There is a row of buildings of different heights arranged at each index along a number line. The bot starts at building $\mbox{o}$ and at a height of $\mbox{o}$. You must determine the minimum energy his b...
{"inputs": ["3\n4 4 4\n", "3\n1 6 4\n", "5\n3 4 3 2 4\n"], "outputs": ["4\n", "3\n", "4\n"]}
696
52
coding
Solve the programming task below in a Python markdown code block. # Task John won the championship of a TV show. He can get some bonuses. He needs to play a game to determine the amount of his bonus. Here are some cards in a row. A number is written on each card. In each turn, John can take a card, but only from th...
{"functional": "_inputs = [[[1, 2, 5]], [[1]], [[1, 1]], [[1, 2, 1]], [[4, 10, 2, 3, 1, 3, 1, 6, 9]]]\n_outputs = [[50], [2], [6], [22], [6722]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstan...
400
222
coding
Solve the programming task below in a Python markdown code block. There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: Operation: Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by...
{"inputs": ["3\n0 1 1", "2\n-10 9\n", "3\n-1 5 1", "3\n-2 5 1", "3\n-1 1 1", "3\n-2 0 1", "3\n-10 5 0", "3\n-14 5 0"], "outputs": ["2\n", "1\n", "5\n", "6\n", "1\n", "3\n", "15\n", "19\n"]}
355
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n integer matrix. You can do the following operation any number of times: Choose any two adjacent elements of matrix and multiply each of them by -1. Two elements are considered adjacent if and ...
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,-1],[-1,1]]) == 4\n assert candidate(matrix = [[1,2,3],[-1,-2,-3],[1,2,3]]) == 16\n\n\ncheck(Solution().maxMatrixSum)"}
130
67
coding
Solve the programming task below in a Python markdown code block. We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column. Compute the following: - For each integer j (...
{"inputs": ["1000000000 1000000001 0", "1000000000 1000001000 0", "1000000000 1001001000 0", "1000000000 1001001010 0", "1000100000 1001001010 0", "1000000000 1000000000 0", "1000000000 1000000000 0\n", "4 5 8\n1 1\n1 4\n0 5\n2 3\n3 1\n3 2\n3 4\n4 4"], "outputs": ["999999997000000002\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "100...
436
519
coding
Solve the programming task below in a Python markdown code block. Find the last element of the given argument(s). ## Examples ```python last([1, 2, 3, 4]) ==> 4 last("xyz") ==> "z" last(1, 2, 3, 4) ==> 4 ``` In **javascript** and **CoffeeScript** a **list** will be an `array`, a `string` or the list of `ar...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [['a', 'b', 'c', 'k', 'x', 'y', 'z']], ['abckxyz'], ['a', 'b', 'c', 'z']]\n_outputs = [[10], [10], ['z'], ['z'], ['z']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
157
264
coding
Solve the programming task below in a Python markdown code block. It is holi festival, festival of colors. Devu is having fun playing holi and is throwing balloons with his girlfriend Glynis. Police saw this mischief and tried arresting his girlfriend, Devu being a mathematician asked police not to arrest his girlfrien...
{"inputs": ["1\n2 1 2 2 15\n"], "outputs": ["1\n"]}
371
25
coding
Solve the programming task below in a Python markdown code block. You are given an $array$ of size $N$ and an integer $K$ ( $N > 1 , K > 0$ ). Each element in the array can be incremented by $K$ or decremented by $K$ $at$ $most$ $once$. So there will be $3^n$ possible combinations of final array. (As there are 3 optio...
{"inputs": ["2\n4 3\n4 2 5 1\n3 5\n2 5 3"], "outputs": ["10\n13"]}
335
38
coding
Solve the programming task below in a Python markdown code block. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pie...
{"inputs": ["1\nabc\n", "1\nacc\n", "1\nbac\n", "1\naac\n", "1\ncaa\n", "2\nbba\nabb\n", "2\nabc\nbga\n", "2\naba\naba\n"], "outputs": ["YES\nabc\n", "YES\nacc\n", "YES\nbac\n", "YES\naac\n", "YES\ncaa\n", "YES\nabba\n", "NO\n", "NO\n"]}
384
107
coding
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$, each of length $n$ and consisting of lowercase Latin alphabets. You want to make $s$ equal to $t$. You can perform the following operation on $s$ any number of times to achieve it — Choose any substring of $s$ a...
{"inputs": ["1\n1\na\na\n", "1\n1\na\na\n", "1\n1\na\nb\n", "1\n1\nb\na\n", "3\n2\naa\naa\n2\nab\nab\n2\nab\nba\n", "3\n2\naa\naa\n2\nab\nab\n2\nab\nba\n", "3\n2\naa\naa\n2\nab\nab\n2\naa\nba\n", "3\n2\naa\naa\n2\nba\nab\n2\naa\nba\n"], "outputs": ["0\n", "0\n", "-1\n", "-1\n", "0\n0\n1\n", "0\n0\n1\n", "0\n0\n-1\n", "...
661
184
coding
Solve the programming task below in a Python markdown code block. You're familiar with [list slicing](https://docs.python.org/3/library/functions.html#slice) in Python and know, for example, that: ```python >>> ages = [12, 14, 63, 72, 55, 24] >>> ages[2:4] [63, 72] >>> ages[2:] [63, 72, 55, 24] >>> ages[:3] [12, 14, 6...
{"functional": "_inputs = [[[12, 14, 63, 72, 55, 24], 2, 4], [[12, 14, 63, 72, 55, 24], 0, 3], [['Intuition', 'is', 'a', 'poor', 'guide', 'when', 'facing', 'probabilistic', 'evidence'], 5, 13]]\n_outputs = [[[12, 14, 55, 24]], [[72, 55, 24]], [['Intuition', 'is', 'a', 'poor', 'guide']]]\nimport math\ndef _deep_eq(a, b,...
306
295
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period "." with "[.]".   Please complete the following python code precisely: ```python class Solutio...
{"functional": "def check(candidate):\n assert candidate(address = \"1.1.1.1\") == \"1[.]1[.]1[.]1\"\n assert candidate(address = \"255.100.50.0\") == \"255[.]100[.]50[.]0\"\n\n\ncheck(Solution().defangIPaddr)"}
86
87
coding
Solve the programming task below in a Python markdown code block. A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive. Input Input contain...
{"inputs": ["1\n", "3\n", "4\n", "8\n", "2\n", "6\n", "5\n", "9\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
135
70