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. Consider the string `"1 2 36 4 8"`. Lets take pairs of these numbers, concatenate each pair and determine how many of them of divisible by `k`. ```Pearl If k = 3, we get following numbers ['12', '18', '21', '24', '42', '48', '81', '84'], all divisible...
{"functional": "_inputs = [['1 2 36 4 8', 2], ['1 2 36 4 8', 3], ['1 2 36 4 8', 4], ['1 2 36 4 8', 8]]\n_outputs = [[16], [8], [11], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (...
342
222
coding
Solve the programming task below in a Python markdown code block. Your task it to return ```true``` if the fractional part (rounded to 1 digit) of the result (```a``` / ```b```) exists, more than ```0``` and is multiple of ```n```. Otherwise return ```false```. (For Python return True or False) All arguments are posit...
{"functional": "_inputs = [[5, 2, 3], [5, 3, 4], [5, 4, 3], [666, 665, 2], [3691401, 1892272, 5]]\n_outputs = [[False], [False], [True], [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 i...
244
224
coding
Solve the programming task below in a Python markdown code block. Your company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing. Skipping the repair is necessary because ...
{"inputs": ["3\n6 1 1\n9 2 9\n1000000 1 1000000\n", "3\n6 1 2\n9 2 9\n1000000 1 1000000\n", "3\n5 1 2\n9 1 4\n1000001 1 1000100\n", "3\n5 1 2\n9 2 4\n1000001 1 1000100\n", "3\n5 1 1\n9 2 4\n1000000 1 1000000\n", "3\n4 1 1\n8 6 6\n1000001 2 1000000\n", "3\n3 1 2\n9 2 4\n1000001 1 1000100\n", "3\n5 1 1\n9 2 2\n1000000 1 ...
530
436
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return true if s is a good string, or false otherwise. A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).   Please complete the ...
{"functional": "def check(candidate):\n assert candidate(s = \"abacbc\") == True\n assert candidate(s = \"aaabb\") == False\n\n\ncheck(Solution().areOccurrencesEqual)"}
93
45
coding
Solve the programming task below in a Python markdown code block. Implement a function/class, which should return an integer if the input string is in one of the formats specified below, or `null/nil/None` otherwise. Format: * Optional `-` or `+` * Base prefix `0b` (binary), `0x` (hexadecimal), `0o` (octal), or in cas...
{"functional": "_inputs = [['123'], ['0x123'], ['0o123'], ['0123'], ['123 '], [' 123'], ['0b1010'], ['+123'], ['-123'], ['0B1010'], ['0b12'], ['-0x123'], ['-0o123'], ['-0123'], ['123\\n'], ['\\n123'], ['-0b1010'], ['0xDEADbeef'], ['0X123'], ['0O123'], ['0o18']]\n_outputs = [[123], [291], [83], [123], [None], [None], [1...
163
377
coding
Solve the programming task below in a Python markdown code block. In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And d...
{"inputs": ["2\n2 3\n", "2\n2 3\n", "3\n2 3 5\n", "3\n2 3 5\n", "3\n2 3 4\n", "4\n2 4 4 2\n", "4\n2 2 3 5\n", "1\n1000000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "0\n", "0\n"]}
515
120
coding
Solve the programming task below in a Python markdown code block. Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. -----Input----- A single line contains a n...
{"inputs": ["a\n", "A\n", "z\n", "P\n", "z\n", "a\n", "P\n", "A\n"], "outputs": ["A\n", "A\n", "Z\n", "P\n", "Z\n", "A\n", "P\n", "A\n"]}
124
70
coding
Solve the programming task below in a Python markdown code block. For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X,...
{"inputs": ["2 1 0", "1 1 0", "0 2 0", "1 0 1", "2 0 0", "1 0 0", "2 2 1", "2 0 1"], "outputs": ["aab\n", "ab\n", "bb\n", "ac\n", "aa\n", "a\n", "abbac\n", "aac\n"]}
236
95
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this absolute path into its simplified canonical path. The rules of a Unix-style file system...
{"functional": "def check(candidate):\n assert candidate(path = \"/home/\") == \"/home\"\n assert candidate(path = \"/../\") == \"/\"\n assert candidate(path = \"/home//foo/\") == \"/home/foo\"\n assert candidate(path = \"/a/./b/../../c/\") == \"/c\"\n\n\ncheck(Solution().simplifyPath)"}
249
91
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will check if it is possible to convert a string to a palindrome by changing one character. For instance: ```Haskell solve ("abbx") = True, because we can convert 'x' to 'a' and get a palindrome. solve ("abba") = False, because we ca...
{"functional": "_inputs = [['abba'], ['abbaa'], ['abbx'], ['aa'], ['ab'], ['abcba']]\n_outputs = [[False], [True], [True], [False], [True], [True]]\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 isins...
189
189
coding
Solve the programming task below in a Python markdown code block. Section numbers are strings of dot-separated integers. The highest level sections (chapters) are numbered 1, 2, 3, etc. Second level sections are numbered 1.1, 1.2, 1.3, 2.1, 2.2, 2.3, etc. Next level sections are numbered 1.1.1, 1.1.2, 1.1.2, 1.2.1, 1.2...
{"functional": "_inputs = [['1', '2'], ['1.1', '1.2'], ['1.1', '1'], ['1.2.3.4', '1.2.3.4'], ['3', '3.0'], ['3', '3.0.0.0'], ['1.2.1', '1.2.0'], ['3.0.0', '3.1.1'], ['3.0.1', '3.1'], ['1.2.3', '1.02.003'], ['1.20', '1.5']]\n_outputs = [[-1], [-1], [1], [0], [0], [0], [1], [-1], [-1], [0], [1]]\nimport math\ndef _deep_e...
446
311
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an unsorted integer array nums. Return the smallest positive integer that is not present in nums. You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.   Please complete the follo...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,0]) == 3\n assert candidate(nums = [3,4,-1,1]) == 2\n assert candidate(nums = [7,8,9,11,12]) == 1\n\n\ncheck(Solution().firstMissingPositive)"}
90
76
coding
Solve the programming task below in a Python markdown code block. You are given a string $S$ and an integer $L$. A operation is described as :- "You are allowed to pick any substring from first $L$ charcaters of $S$, and place it at the end of the string $S$. A string $A$ is a substring of an string $B$ if $A$ can be ...
{"inputs": ["2\n1 rga\n2 cab"], "outputs": ["arg\nabc"]}
358
21
coding
Solve the programming task below in a Python markdown code block. Chef has a binary string S of length N. Chef can perform the following operation on the string: Choose any substring of S; Remove the chosen substring from S; Concatenate the remaining parts of the string S, obtained after removing the substring. Find ...
{"inputs": ["3\n4\n1010\n6\n011011\n11\n01011011101\n"], "outputs": ["2\n2\n3\n"]}
645
49
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal. For example, 2373 is made up of three distinct digits: 2, 3, a...
{"functional": "def check(candidate):\n assert candidate(nums = [51,71,17,24,42]) == 88\n assert candidate(nums = [1,2,3,4]) == -1\n\n\ncheck(Solution().maxSum)"}
129
63
coding
Solve the programming task below in a Python markdown code block. The Indian bank issues coins in 4 denominations, ₹1, ₹2, ₹5 and ₹10. Given a limited supply of each of the above denominations, in how many ways can you sum them up to a total of ₹N? Input Format The first line contains an integer T (number of testc...
{"inputs": ["2\n15\n2 3 1 1\n12\n2 2 1 1\n"], "outputs": ["2\n2\n"]}
290
38
coding
Solve the programming task below in a Python markdown code block. There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If...
{"inputs": ["3\n0\n2\n1", "3\n0\n1\n0", "3\n0\n0\n0", "3\n0\n2\n2", "3\n0\n1\n2", "3\n0\n2\n0", "3\n1\n1\n0", "3\n1\n0\n0"], "outputs": ["-1\n", "1\n", "0\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]}
297
111
coding
Solve the programming task below in a Python markdown code block. A reversed arabic no is one whose digits have been written in the reversed order. However in this any trailing zeroes are omitted. The task at hand here is a simple one. You need to add two numbers which have been written in reversed arabic and return th...
{"inputs": ["1\n24 1"], "outputs": ["34"]}
185
18
coding
Solve the programming task below in a Python markdown code block. Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1...
{"inputs": ["2\n-1 -1 1\n", "2\n-1 -1 1\n", "2\n-1 -1 0\n", "2\n50 50 50\n", "2\n50 50 63\n", "2\n-1 -1 -1\n", "2\n50 98 63\n", "2\n50 50 50\n"], "outputs": ["3\n", "3\n", "2\n", "150\n", "163\n", "1\n", "211\n", "150\n"]}
291
142
coding
Solve the programming task below in a Python markdown code block. Snuke loves flags. Snuke is placing N flags on a line. The i-th flag can be placed at either coordinate x_i or coordinate y_i. Snuke thinks that the flags look nicer when the smallest distance between two of them, d, is larger. Find the maximum possib...
{"inputs": ["3\n1 3\n2 5\n2 9", "3\n2 3\n2 5\n2 9", "3\n1 3\n2 5\n1 9", "3\n3 3\n2 5\n2 16", "3\n4 0\n5 0\n1 21", "3\n2 1\n8 0\n1 45", "3\n2 3\n2 5\n2 16", "3\n3 3\n2 5\n1 16"], "outputs": ["4\n", "3\n", "4", "2\n", "5\n", "7\n", "3\n", "2\n"]}
379
162
coding
Solve the programming task below in a Python markdown code block. Watson gives Sherlock two integers, $n$ and $\boldsymbol{\mbox{k}}$, and asks him to count the number of positive integer $\boldsymbol{i}$'s such that: $i\cdot(n-i)\leq n\cdot k,\ \text{and}\ i<n$ Given $\textit{q}$ queries where each query consists...
{"inputs": ["2\n5 1\n5 2\n"], "outputs": ["2\n4\n"]}
428
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. You are given a 0-indexed integer array vals of length n where vals[i] denote...
{"functional": "def check(candidate):\n assert candidate(vals = [1,3,2,1,3], edges = [[0,1],[0,2],[2,3],[2,4]]) == 6\n assert candidate(vals = [1,1,2,2,3], edges = [[0,1],[1,2],[2,3],[2,4]]) == 7\n assert candidate(vals = [1], edges = []) == 1\n\n\ncheck(Solution().numberOfGoodPaths)"}
272
113
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. It’s Chef's birthday. He and his twin have received $N$ gifts in total. The $i$-th gift has a price of $A_{i}$. Each twin wants to keep the most expensive gif...
{"inputs": ["3\n3 1\n1 3 2\n3 1\n3 1 3\n5 2\n5 1 3 2 4"], "outputs": ["3\n4\n8"]}
592
50
coding
Solve the programming task below in a Python markdown code block. Find the sum of the odd numbers within an array, after cubing the initial integers. The function should return `undefined`/`None`/`nil`/`NULL` if any of the values aren't numbers. ~~~if:java,csharp Note: There are ONLY integers in the JAVA and C# versi...
{"functional": "_inputs = [[[1, 2, 3, 4]], [[-3, -2, 2, 3]], [['a', 12, 9, 'z', 42]], [[True, False, 2, 4, 1]]]\n_outputs = [[28], [0], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i...
127
217
coding
Solve the programming task below in a Python markdown code block. Write a function that takes a positive integer n, sums all the cubed values from 1 to n, and returns that sum. Assume that the input n will always be a positive integer. Examples: ```python sum_cubes(2) > 9 # sum of the cubes of 1 and 2 is 1 + 8 ``` ...
{"functional": "_inputs = [[1], [2], [3], [4], [10], [123]]\n_outputs = [[1], [9], [36], [100], [3025], [58155876]]\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 ...
110
201
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array candies, where candies[i] represents the flavor of the ith candy. Your mom wants you to share these candies with your little sister by giving her k consecutive candies, but you ...
{"functional": "def check(candidate):\n assert candidate(candies = [1,2,2,3,4,3], k = 3) == 3\n assert candidate(candies = [2,2,2,2,3,3], k = 2) == 2\n assert candidate(candies = [2,4,5], k = 0) == 3\n\n\ncheck(Solution().shareCandies)"}
129
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string st...
{"functional": "def check(candidate):\n assert candidate(start = \"RXXLRXRXL\", end = \"XRLXXRRLX\") == True\n assert candidate(start = \"X\", end = \"L\") == False\n\n\ncheck(Solution().canTransform)"}
134
60
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate ...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\", k = 2) == \"abcd\"\n assert candidate(s = \"deeedbbcccbdaa\", k = 3) == \"aa\"\n assert candidate(s = \"pbbcggttciiippooaais\", k = 2) == \"ps\"\n\n\ncheck(Solution().removeDuplicates)"}
133
88
coding
Solve the programming task below in a Python markdown code block. There is a universal library, where there is a big waiting room with seating capacity for maximum $m$ people, each of whom completes reading $n$ books sequentially. Reading each book requires one unit of time. Unfortunately, reading service is provided ...
{"inputs": ["1 100 9\n11 2 10\n12 2 11\n0 0 0"], "outputs": ["9\n15\n16"]}
559
46
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a string s with length n. You should find a permutation P of numbers 1 through n such that if you apply this permutation on the string s, you will get a palindr...
{"inputs": ["4\naa\nbaa\nabc\nabab"], "outputs": ["1 2\n2 1 3\n-1\n1 2 4 3"]}
596
41
coding
Solve the programming task below in a Python markdown code block. For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows: - Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations. - Change S_i ...
{"inputs": ["2\n8 8", "2\n8 6", "2\n3 8", "2\n2 6", "2\n9 6", "2\n4 8", "2\n8 9", "2\n0 6"], "outputs": ["160\n", "136\n", "100\n", "72\n", "144\n", "112\n", "168\n", "48\n"]}
515
108
coding
Solve the programming task below in a Python markdown code block. Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhai...
{"inputs": ["1 1\n", "6 4\n", "3 1\n", "5 8\n", "4 9\n", "5 8\n", "4 9\n", "3 1\n"], "outputs": ["40\n", "172\n", "2530\n", "16\n", "10\n", "16", "10", "2530"]}
402
96
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n binary matrix matrix. You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa). Return the maximum num...
{"functional": "def check(candidate):\n assert candidate(matrix = [[0,1],[1,1]]) == 1\n assert candidate(matrix = [[0,1],[1,0]]) == 2\n assert candidate(matrix = [[0,0,0],[0,0,1],[1,1,0]]) == 2\n\n\ncheck(Solution().maxEqualRowsAfterFlips)"}
118
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An array is monotonic if it is either monotone increasing or monotone decreasing. An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, num...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,3]) == True\n assert candidate(nums = [6,5,4,4]) == True\n assert candidate(nums = [1,3,2]) == False\n\n\ncheck(Solution().isMonotonic)"}
129
70
coding
Solve the programming task below in a Python markdown code block. It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices. It is known ...
{"inputs": ["2 9\n6 1 7\n6 7 1\n", "2 9\n6 1 7\n6 7 1\n", "2 9\n5 1 7\n6 7 1\n", "2 9\n5 1 7\n6 9 1\n", "2 10\n7 2 1\n7 1 2\n", "2 10\n9 1 2\n9 2 1\n", "2 10\n9 1 2\n9 2 1\n", "2 10\n7 2 1\n7 1 2\n"], "outputs": ["84\n", "84\n", "77\n", "89\n", "28\n", "36\n", "36\n", "28\n"]}
517
194
coding
Solve the programming task below in a Python markdown code block. I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests [wheat](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem), for some reason) problem, but a quick recap for you: a young man asks as a compensati...
{"functional": "_inputs = [[0], [1], [2], [3], [4]]\n_outputs = [[0], [1], [2], [2], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): ret...
311
179
coding
Solve the programming task below in a Python markdown code block. It's almost summertime, so Big Cat and Little Cat are getting in shape. They decide the core of their fitness plan is to start jogging every day. Their city consists of $N$ intersections connected by $\mbox{M}$ bidirectional roads. The cats decide that ...
{"inputs": ["4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n"], "outputs": ["3\n"]}
513
40
coding
Solve the programming task below in a Python markdown code block. *This kata is based on [Project Euler Problem 539](https://projecteuler.net/problem=539)* ##Object Find the last number between 1 and `n` (inclusive) that survives the elimination process ####How It Works Start with the first number on the left then ...
{"functional": "_inputs = [[9], [10], [100], [1000], [50000]]\n_outputs = [[6], [8], [54], [510], [22358]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(...
324
197
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["2\n24\n68\n246\n81012\n141618\n2468\n10121416\n18202224\n26283032"]}
233
75
coding
Solve the programming task below in a Python markdown code block. There are $n$ students standing in a circle in some order. The index of the $i$-th student is $p_i$. It is guaranteed that all indices of students are distinct integers from $1$ to $n$ (i. e. they form a permutation). Students want to start a round danc...
{"inputs": ["1\n11\n11 2 3 4 5 6 7 8 9 10 1\n", "1\n11\n11 2 1 4 5 6 7 8 9 10 1\n", "1\n11\n11 2 1 4 5 6 7 9 9 10 1\n", "1\n11\n11 2 3 4 5 6 7 4 9 10 1\n", "1\n11\n11 2 3 4 5 6 7 13 9 10 1\n", "1\n11\n11 2 3 4 5 6 7 13 5 10 1\n", "1\n11\n11 2 3 6 5 6 7 13 5 10 1\n", "1\n11\n11 2 6 6 5 6 7 13 5 10 1\n"], "outputs": ["NO...
605
290
coding
Solve the programming task below in a Python markdown code block. Chef is the financial incharge of Chefland and one of his duties is identifying if any company has gained a monopolistic advantage in the market. There are exactly 3 companies in the market each of whose revenues are denoted by R_{1}, R_{2} and R_{3} re...
{"inputs": ["4\n1 1 1\n1 2 4\n2 10 3\n1 2 3\n"], "outputs": ["No\nYes\nYes\nNo\n"]}
437
45
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. You are given a grid with size $N \times M$. Each cell of this grid contains either $0$ or $1$. We should perform the following operation until the size of t...
{"inputs": ["2\n1 2\n01\n3 3\n000\n111\n010"], "outputs": ["YES\nNO"]}
692
37
coding
Solve the programming task below in a Python markdown code block. Write a function which converts the input string to uppercase. ~~~if:bf For BF all inputs end with \0, all inputs are lowercases and there is no space between. ~~~ Also feel free to reuse/extend the following starter code: ```python def make_upper_case...
{"functional": "_inputs = [['hello'], ['hello world'], ['hello world !'], ['heLlO wORLd !'], ['1,2,3 hello world!']]\n_outputs = [['HELLO'], ['HELLO WORLD'], ['HELLO WORLD !'], ['HELLO WORLD !'], ['1,2,3 HELLO WORLD!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
76
214
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed binary matrix grid. In one operation, you can flip any 1 in grid to be 0. A binary matrix is well-isolated if there is no 1 in the matrix that is 4-directionally connected (i.e., horizontal a...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0],[0,1,1],[1,1,1]]) == 3\n assert candidate(grid = [[0,0,0],[0,0,0],[0,0,0]]) == 0\n assert candidate(grid = [[0,1],[1,0]]) == 0\n\n\ncheck(Solution().minimumOperations)"}
127
93
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr: Starting from left to right, remove the first number and every other number afterwa...
{"functional": "def check(candidate):\n assert candidate(n = 9) == 6\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().lastRemaining)"}
164
43
coding
Solve the programming task below in a Python markdown code block. Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university. There are m working hours during each Berland day, and each lesson at the university lasts exac...
{"inputs": ["1 1 5\n1\n", "1 1 1\n0\n", "1 1 1\n1\n", "1 1 2\n1\n", "1 1 0\n1\n", "1 1 2\n0\n", "1 1 5\n1\n", "1 1 1\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0", "0"]}
537
116
coding
Solve the programming task below in a Python markdown code block. This is the performance edition of [this kata](https://www.codewars.com/kata/ulam-sequences). If you didn't do it yet, you should begin there. --- The Ulam sequence U is defined by `u0=u`, `u1=v`, with the general term `u_n` for `n>2` given by the leas...
{"functional": "_inputs = [[1, 2, 5], [3, 4, 5], [5, 6, 8]]\n_outputs = [[[1, 2, 3, 4, 6]], [[3, 4, 7, 10, 11]], [[5, 6, 11, 16, 17, 21, 23, 26]]]\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 isinst...
638
239
coding
Solve the programming task below in a Python markdown code block. Ravi is very good student in mathematics and he also like Even numbers very much . On the other hand his friend Jhon like Odd numbers . Both of them are preparing for IIT JEE Advance .One day they are solving a question together the question was Find t...
{"inputs": ["2\n3"], "outputs": ["Jhon\nRavi"]}
367
18
coding
Solve the programming task below in a Python markdown code block. You are given a three-digit positive integer N. Determine whether N is a palindromic number. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation. -----Constraints----- - 100≤N≤999 - N is an integer. ...
{"inputs": ["559", "676", "665", "179", "129", "371", "344", "158"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
160
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters. You can add either pattern[0] or pattern[1] anywhere in text exactly onc...
{"functional": "def check(candidate):\n assert candidate(text = \"abdcdbc\", pattern = \"ac\") == 4\n assert candidate(text = \"aabb\", pattern = \"ab\") == 6\n\n\ncheck(Solution().maximumSubsequenceCount)"}
169
58
coding
Solve the programming task below in a Python markdown code block. You are given an array of integers $b_1, b_2, \ldots, b_n$. An array $a_1, a_2, \ldots, a_n$ of integers is hybrid if for each $i$ ($1 \leq i \leq n$) at least one of these conditions is true: $b_i = a_i$, or $b_i = \sum_{j=1}^{i} a_j$. Find the numb...
{"inputs": ["4\n3\n2 0 1\n4\n1 2 2 4\n10\n2 0 1 0 1 2 -6 0 -2 -2\n4\n0 0 0 1\n", "4\n3\n2 0 1\n4\n1 2 2 4\n10\n2 0 1 0 0 2 -6 0 -2 -2\n4\n0 0 0 2\n", "4\n3\n1 -2 1\n4\n1 2 3 4\n10\n2 -1 1 -2 2 3 -5 0 2 0\n4\n0 0 1 2\n", "4\n3\n1 -1 1\n4\n1 2 3 6\n10\n2 -1 1 -2 2 3 -5 0 2 0\n4\n0 0 1 2\n", "4\n3\n1 -2 1\n4\n1 2 3 4\n10\...
606
542
coding
Solve the programming task below in a Python markdown code block. # Task Given a sorted array of integers `A`, find such an integer x that the value of `abs(A[0] - x) + abs(A[1] - x) + ... + abs(A[A.length - 1] - x)` is the smallest possible (here abs denotes the `absolute value`). If there are several possible answ...
{"functional": "_inputs = [[[2, 4, 7]], [[1, 1, 3, 4]], [[23]], [[-10, -10, -10, -10, -10, -9, -9, -9, -8, -8, -7, -6, -5, -4, -3, -2, -1, 0, 0, 0, 0, 1, 2, 3, 4, 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, 37, 38, 39, 40, 41, 42, 43, 44, 45...
216
563
coding
Solve the programming task below in a Python markdown code block. Chef has two binary strings A and B, each of length N. Chef can rearrange both the strings in any way. Find the maximum [bitwise XOR] he can achieve if he rearranges the strings optimally. ------ Input Format ------ - The first line of input will con...
{"inputs": ["4\n0011\n1011\n100\n100\n11111\n11101\n1\n0\n"], "outputs": ["1110\n110\n10000\n1\n"]}
583
63
coding
Solve the programming task below in a Python markdown code block. Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he...
{"inputs": ["1\n1000\n", "1\n1001\n", "1\n1011\n", "1\n1111\n", "1\n0111\n", "1\n1010\n", "1\n1110\n", "1\n1100\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
553
110
coding
Solve the programming task below in a Python markdown code block. You are given a fair coin and two integers X and N. You repeatedly flip the coin and perform the following operation based on the result: If it lands on heads, then X will increase by 1. However, if X = N then X will not change. If it lands on tails, X ...
{"inputs": ["4\n1 3\n2 2\n12 12\n568 57800"], "outputs": ["0\n2\n132\n65223144\n"]}
403
52
coding
Solve the programming task below in a Python markdown code block. For given two circles $c1$ and $c2$, print 4 if they do not cross (there are 4 common tangent lines), 3 if they are circumscribed (there are 3 common tangent lines), 2 if they intersect (there are 2 common tangent lines), 1 if a circle is...
{"inputs": ["0 0 0\n1 0 2", "1 2 1\n3 4 2", "1 2 0\n4 2 2", "0 0 1\n0 1 2", "0 0 0\n0 0 2", "1 1 1\n9 2 2", "0 1 0\n0 0 2", "1 2 1\n5 4 2"], "outputs": ["0\n", "2\n", "4\n", "1\n", "0\n", "4\n", "0\n", "4\n"]}
413
142
coding
Solve the programming task below in a Python markdown code block. You are given a permutation $p_1, p_2, \dots, p_n$. Recall that sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once. Find three indices $i$, $j$ and $k$ such that: $1 \le i < j < k \le n$; $p_i < ...
{"inputs": ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 2 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n8 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n6 3 1 2 4\n", "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 5\n", "3\n4\n2 1 4 3...
394
486
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has a standard chocolate of n by m pieces. More formally, chocolate is a rectangular plate consisting of n rows and m columns. Here you can see an example of a standard...
{"inputs": ["2\n1 2\n1 3"], "outputs": ["Yes\nNo"]}
482
22
coding
Solve the programming task below in a Python markdown code block. -----Problem Statement----- We have an integer sequence $A$, whose length is $N$. Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the contents...
{"inputs": ["6\n1 3 -4 2 2 -2"], "outputs": ["3"]}
269
24
coding
Solve the programming task below in a Python markdown code block. You have an array $a$ of size $n$ consisting only of zeroes and ones. You can do the following operation: choose two indices $1 \le i , j \le n$, $i \ne j$, add $a_{i}$ to $a_{j}$, remove $a_{i}$ from $a$. Note that elements of $a$ can become bigger ...
{"inputs": ["4\n8\n0 0 1 1 1 1 1 1\n5\n1 0 0 1 1\n2\n1 0\n11\n1 1 0 0 1 0 0 1 1 1 0\n"], "outputs": ["0\n1\n1\n3\n"]}
535
81
coding
Solve the programming task below in a Python markdown code block. There is an array with some numbers. All numbers are equal except for one. Try to find it! ```python find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2 find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55 ``` It’s guaranteed that array contains at least 3 numbers. The tests con...
{"functional": "_inputs = [[[1, 1, 1, 2, 1, 1]], [[0, 0, 0.55, 0, 0]], [[4, 4, 4, 3, 4, 4, 4, 4]], [[5, 5, 5, 5, 4, 5, 5, 5]], [[6, 6, 6, 6, 6, 5, 6, 6]], [[7, 7, 7, 7, 7, 7, 6, 7]], [[8, 8, 8, 8, 8, 8, 8, 7]], [[3, 3, 3, 3, 3, 3, 3, 2]], [[2, 2, 2, 2, 2, 2, 2, 1]], [[0, 1, 1, 1, 1, 1, 1, 1]]]\n_outputs = [[2], [0.55],...
238
410
coding
Solve the programming task below in a Python markdown code block. You have to build a pyramid. This pyramid should be built from characters from a given string. You have to create the code for these four methods: ```python watch_pyramid_from_the_side(characters): watch_pyramid_from_above(characters): count_visible_...
{"functional": "_inputs = [[None], ['']]\n_outputs = [[None], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ret...
467
163
coding
Solve the programming task below in a Python markdown code block. # Task Given an array of roots of a polynomial equation, you should reconstruct this equation. ___ ## Output details: * If the power equals `1`, omit it: `x = 0` instead of `x^1 = 0` * If the power equals `0`, omit the `x`: `x - 2 = 0` instead of `x ...
{"functional": "_inputs = [[[0]], [[0, 0]], [[-1]], [[1]], [[1, -1]], [[0, -2, -3]], [[0, 2, 3]], [[1, 2, 3, 4, 5]]]\n_outputs = [['x = 0'], ['x^2 = 0'], ['x + 1 = 0'], ['x - 1 = 0'], ['x^2 - 1 = 0'], ['x^3 + 5x^2 + 6x = 0'], ['x^3 - 5x^2 + 6x = 0'], ['x^5 - 15x^4 + 85x^3 - 225x^2 + 274x - 120 = 0']]\nimport math\ndef ...
472
324
coding
Solve the programming task below in a Python markdown code block. King loves to go on tours with his friends. King has N cars that can seat 5 people each and M cars that can seat 7 people each. Determine the maximum number of people that can travel together in these cars. ------ Input Format ------ - The first line...
{"inputs": ["4\n4 8\n2 13\n14 5\n8 8"], "outputs": ["76\n101\n105\n96"]}
442
42
coding
Solve the programming task below in a Python markdown code block. Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0. Vitya ...
{"inputs": ["2 2\n1 6\n1\n3\n", "2 2\n2 5\n1\n1\n", "2 2\n1 3\n2\n3\n", "2 2\n1 6\n1\n0\n", "2 2\n1 6\n1\n1\n", "2 2\n1 3\n1\n1\n", "2 2\n1 5\n1\n1\n", "2 2\n2 5\n2\n1\n"], "outputs": ["1\n0\n", "0\n0\n", "0\n1\n", "1\n1\n", "1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n"]}
364
166
coding
Solve the programming task below in a Python markdown code block. We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required. -----Constraints----- - 1 \leq N \leq 10000 - N is ...
{"inputs": ["8", "0", "1", "2", "3", "4", "6", "9"], "outputs": ["992\n", "0\n", "999\n", "998\n", "997\n", "996\n", "994\n", "991\n"]}
163
76
coding
Solve the programming task below in a Python markdown code block. Write a function name `nextPerfectSquare` that returns the first perfect square that is greater than its integer argument. A `perfect square` is a integer that is equal to some integer squared. For example 16 is a perfect square because `16=4*4`. ``` ex...
{"functional": "_inputs = [[6], [36], [0], [-5]]\n_outputs = [[9], [49], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fal...
177
176
coding
Solve the programming task below in a Python markdown code block. Snuke has a blackboard and a set S consisting of N integers. The i-th element in S is S_i. He wrote an integer X on the blackboard, then performed the following operation N times: * Choose one element from S and remove it. * Let x be the number written...
{"inputs": ["2 17\n3 7", "2 20\n6 3", "2 19\n3 7", "2 19\n3 11", "2 12\n6 11", "5 193\n5 13 7 5 4", "5 82\n22 11 6 7 13", "5 82\n27 11 6 7 13"], "outputs": ["2\n", "4\n", "3", "3\n", "1\n", "198\n", "516\n", "456\n"]}
373
151
coding
Solve the programming task below in a Python markdown code block. An input string S of length N is transferred through the network using a special protocol. The protocol can send the string through a series of operations. In one operation, we can choose a lowercase english alphabet C and do one of the following: Trans...
{"inputs": ["2\n5\ncbcdc\n6\naabeee\n"], "outputs": ["5\n4\n"]}
462
27
coding
Solve the programming task below in a Python markdown code block. A: IP Address (Internet Protocol Address) problem Since one number string is given, find the number of valid delimiters for IPv4 IP addresses. However, the effective delimiters for IPv4 IP addresses are as follows. * The sequence of numbers is divided...
{"inputs": ["17", "15", "14", "25", "16", "59", "13", "30"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
282
70
coding
Solve the programming task below in a Python markdown code block. There are N children, numbered 1, 2, ..., N. Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets. For each i (1 \leq i \leq N), Child i will be happy if he/she gets ex...
{"inputs": ["2 1\n30 1", "2 0\n30 20", "2 1\n30 20", "2 1\n30 26", "2 0\n30 26", "2 10\n20 2", "2 0\n30 17", "2 0\n20 26"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n"]}
296
125
coding
Solve the programming task below in a Python markdown code block. James found a love letter that his friend Harry has written to his girlfriend. James is a prankster, so he decides to meddle with the letter. He changes all the words in the letter into palindromes. To do this, he follows two rules: He can only re...
{"inputs": ["4\nabc\nabcba\nabcd\ncba\n"], "outputs": ["2\n0\n4\n2\n"]}
418
30
coding
Solve the programming task below in a Python markdown code block. ## Description Given an array X of positive integers, its elements are to be transformed by running the following operation on them as many times as required: ```if X[i] > X[j] then X[i] = X[i] - X[j]``` When no more transformations are possible, retu...
{"functional": "_inputs = [[[6, 9, 21]], [[9]], [[30, 12]], [[11, 22]], [[1, 21, 55]], [[4, 16, 24]], [[3, 13, 23, 7, 83]], [[60, 12, 96, 48, 60, 24, 72, 36, 72, 72, 48]], [[71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71]]]\n_outputs = [[9], [9], [12], [22], [3], [12], [5], [132], [923]]\nimport math\ndef _deep_eq(...
403
346
coding
Solve the programming task below in a Python markdown code block. Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks. The student...
{"inputs": ["1 3\n", "3 2\n", "5 0\n", "4 2\n", "6 4\n", "6 3\n", "7 3\n", "5 4\n"], "outputs": ["9\n", "8\n", "10\n", "9\n", "15\n", "14\n", "15\n", "14\n"]}
334
91
coding
Solve the programming task below in a Python markdown code block. There is a string, $unrecognized$, of lowercase English letters that is repeated infinitely many times. Given an integer, $unrecognized$, find and print the number of letter a's in the first $unrecognized$ letters of the infinite string. Example $unr...
{"inputs": ["aba\n10\n", "a\n1000000000000\n"], "outputs": ["7\n", "1000000000000\n"]}
342
51
coding
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .....
{"inputs": ["1\n5\n0 1 2 0 2\n5 6 7 8 2"], "outputs": ["21"]}
508
35
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: if there is at least one letter 'a', remove the lef...
{"inputs": ["1 1\nu\n", "1 1\nu\n", "2 1\nzz\n", "2 1\nzz\n", "4 3\nhack\n", "4 3\nzzzz\n", "4 3\nhack\n", "4 3\nzzzz\n"], "outputs": ["\n", "\n", "z\n", "z\n", "k\n", "z\n", "k\n", "z\n"]}
365
103
coding
Solve the programming task below in a Python markdown code block. A binary string is a string consisting only of the characters 0 and 1. You are given a binary string $s_1 s_2 \ldots s_n$. It is necessary to make this string non-decreasing in the least number of operations. In other words, each character should be not ...
{"inputs": ["8\n1\n1\n2\n10\n3\n101\n4\n1100\n5\n11001\n6\n100010\n10\n0000110000\n7\n0101010\n"], "outputs": ["0\n1\n2\n1\n2\n3\n1\n5\n"]}
624
91
coding
Solve the programming task below in a Python markdown code block. You start with a value in dollar form, e.g. $5.00. You must convert this value to a string in which the value is said, like '5 dollars' for example. This should account for ones, cents, zeroes, and negative values. Here are some examples: ```python dolla...
{"functional": "_inputs = [['$20.18'], ['$5.62'], ['$83.47'], ['$16.93'], ['$0.00'], ['$0.01'], ['$0.63'], ['$0.28'], ['$1.00'], ['$2.00'], ['$31.00'], ['$45.00'], ['$-5843.21'], ['$-45.32'], ['$-2.63'], ['$-234.48']]\n_outputs = [['20 dollars and 18 cents.'], ['5 dollars and 62 cents.'], ['83 dollars and 47 cents.'], ...
227
382
coding
Solve the programming task below in a Python markdown code block. There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or sev...
{"inputs": ["1 1 3 4\n7\n", "2 1 3 4\n7\n", "2 1 3 8\n7\n", "1 1 3 4\n7\n", "4 3 4 2\n7 9 11\n", "4 3 4 2\n3 9 11\n", "5 3 4 2\n7 9 11\n", "5 3 4 4\n7 9 11\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "4\n", "4\n", "5\n", "3\n"]}
554
154
coding
Solve the programming task below in a Python markdown code block. The purpose of this kata is to work out just how many bottles of duty free whiskey you would have to buy such that the saving over the normal high street price would effectively cover the cost of your holiday. You will be given the high street price (n...
{"functional": "_inputs = [[12, 50, 1000], [17, 10, 500], [24, 35, 3000], [1400, 35, 10000], [700, 26, 7000]]\n_outputs = [[166], [294], [357], [20], [38]]\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 ...
173
245
coding
Solve the programming task below in a Python markdown code block. For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following progr...
{"inputs": ["3\n6 1 2", "3\n6 1 0", "3\n6 2 0", "3\n6 2 1", "3\n6 2 2", "3\n6 0 1", "3\n1 0 0", "3\n1 0 1"], "outputs": ["2\n", "3\n", "3\n", "3\n", "2\n", "2\n", "2\n", "1\n"]}
326
110
coding
Solve the programming task below in a Python markdown code block. As the first step in algebra, students learn quadratic formulas and their factorization. Often, the factorization is a severe burden for them. A large number of students cannot master the factorization; such students cannot be aware of the elegance of ad...
{"inputs": ["2 5 2\n1 1 1\n9 -7 0\n1 0 -3\n0 0 0", "2 7 2\n1 1 1\n9 -7 0\n1 0 -3\n0 0 0", "2 5 2\n1 1 1\n7 -7 1\n1 0 -3\n0 0 0", "3 5 3\n1 2 1\n4 -11 0\n1 1 1\n0 0 0", "3 5 3\n1 2 1\n4 -15 0\n2 0 1\n0 0 0", "3 4 6\n2 2 1\n4 -15 0\n2 0 1\n0 0 0", "3 5 3\n1 2 1\n4 -11 0\n1 1 0\n0 0 0", "2 5 3\n1 2 1\n4 -11 0\n2 0 1\n0 0 ...
636
434
coding
Solve the programming task below in a Python markdown code block. Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\operatorname{d...
{"inputs": ["1 1\n", "2 2\n", "4 1\n", "4 2\n", "4 3\n", "4 4\n", "3 4\n", "2 4\n"], "outputs": ["0\n", "8\n", "0\n", "24\n", "102\n", "264\n", "162\n", "84\n"]}
348
94
coding
Solve the programming task below in a Python markdown code block. How many different ways can you make change for an amount, given a list of coins? In this problem, your code will need to efficiently compute the answer. Task Write a program that, given An amount N and types of infinite available coins M. A list of ...
{"inputs": ["4 3\n1 2 3", "240 23\n23 20 35 42 19 3 34 9 28 38 13 41 26 14 27 39 24 37 46 29 43 1 21", "250 26\n8 47 13 24 25 31 32 35 3 19 40 48 1 4 17 38 22 30 33 15 44 46 36 9 20 49"], "outputs": ["4", "127101770", "3542323427"]}
319
198
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries: For a query of type 1, queries[i] = [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nu...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]) == [3]\n assert candidate(nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]) == [5]\n\n\ncheck(Solution().handleQuery)"}
249
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a link...
{"functional": "def check(candidate):\n assert is_same_list(candidate(l1 = list_node([7,2,4,3]), l2 = list_node([5,6,4])), list_node([7,8,0,7]))\n assert is_same_list(candidate(l1 = list_node([2,4,3]), l2 = list_node([5,6,4])), list_node([8,0,7]))\n assert is_same_list(candidate(l1 = list_node([0]), l2 = list_...
163
135
coding
Solve the programming task below in a Python markdown code block. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know...
{"inputs": ["1\n1\n", "1\n4\n", "1\n1\n", "1\n4\n", "1\n2\n", "2\n1 1\n", "2\n2 3\n", "2\n1 4\n"], "outputs": ["-1\n", "0\n", "-1\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
424
93
coding
Solve the programming task below in a Python markdown code block. Given a standard english sentence passed in as a string, write a method that will return a sentence made up of the same words, but sorted by their first letter. However, the method of sorting has a twist to it: * All words that begin with a lower case le...
{"functional": "_inputs = [['I, habitan of the Alleghanies, treating of him as he is in himself in his own rights'], ['take up the task eternal, and the burden and the lesson'], ['Land of the eastern Chesapeake'], ['And I send these words to Paris with my love'], ['O Liberty! O mate for me!'], ['With Egypt, India, Phen...
240
443
coding
Solve the programming task below in a Python markdown code block. You've made it through the moat and up the steps of knowledge. You've won the temples games and now you're hunting for treasure in the final temple run. There's good news and bad news. You've found the treasure but you've triggered a nasty trap. You'll s...
{"functional": "_inputs = [[5], [1], [[]], [11], ['treasure'], ['5'], [-1], [3], [2], [0.5]]\n_outputs = [['X X\\n X X\\n X\\n X X\\nX X\\n'], ['X\\n'], ['?'], ['X X\\n X X\\n X X\\n X X\\n X X\\n X\\n X X\\n X...
348
312
coding
Solve the programming task below in a Python markdown code block. ##Background - the Collatz Conjecture: Imagine you are given a positive integer, `n`, then: * if `n` is even, calculate: `n / 2` * if `n` is odd, calculate: `3 * n + 1` Repeat until your answer is `1`. The Collatz conjecture states that performing thi...
{"functional": "_inputs = [[[1, 5, 27, 4]], [[64, 64, 27, 64]], [[75, 226, 113, 340]], [[340, 113, 226, 75]], [[75, 113, 226, 75]]]\n_outputs = [[27], [27], [75], [75], [75]]\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,...
436
255
coding
Solve the programming task below in a Python markdown code block. Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other wo...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n28\n", "1\n-1\n", "1\n-2\n", "3\n1 2 3\n", "3\n3 2 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "2\n", "2\n"]}
189
97
coding
Solve the programming task below in a Python markdown code block. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any nu...
{"inputs": ["1 1\n1 1\n1\n1\n", "1 1\n1 1\n1\n1\n", "1 1\n1 1\n1\n0\n", "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "3 3\n1 1\n1 2 3\n1 2 3\n", "3 3\n1 2\n1 2 3\n1 2 3\n", "3 3\n2 2\n1 2 3\n1 2 3\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n"]}
524
190
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, add a dot (".") as the thousands separator and return it in string format.   Please complete the following python code precisely: ```python class Solution: def thousandSeparator(self, n: int) -...
{"functional": "def check(candidate):\n assert candidate(n = 987) == \"987\"\n assert candidate(n = 1234) == \"1.234\"\n assert candidate(n = 123456789) == \"123.456.789\"\n assert candidate(n = 0) == \"0\"\n\n\ncheck(Solution().thousandSeparator)"}
69
101
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n ...
{"functional": "def check(candidate):\n assert candidate(s = \"7+3*1*2\", answers = [20,13,42]) == 7\n assert candidate(s = \"3+5*2\", answers = [13,0,10,13,13,16,16]) == 19\n assert candidate(s = \"6+0*1\", answers = [12,9,6,4,8,6]) == 10\n\n\ncheck(Solution().scoreOfStudents)"}
256
123
coding
Solve the programming task below in a Python markdown code block. Given an array of integers `a` and integers `t` and `x`, count how many elements in the array you can make equal to `t` by **increasing** / **decreasing** it by `x` (or doing nothing). *EASY!* ```python # ex 1 a = [11, 5, 3] t = 7 x = 2 count(a, t, x)...
{"functional": "_inputs = [[[11, 5, 3], 7, 2], [[-4, 6, 8], -7, -3]]\n_outputs = [[3], [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_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r...
268
185
coding
Solve the programming task below in a Python markdown code block. Vasya is reading a e-book. The file of the book consists of $n$ pages, numbered from $1$ to $n$. The screen is currently displaying the contents of page $x$, and Vasya wants to read the page $y$. There are two buttons on the book which allow Vasya to scr...
{"inputs": ["1\n11 0 0 9\n", "1\n7 0 0 22\n", "1\n11 0 11 9\n", "1\n11 0 0 18\n", "1\n11 0 0 22\n", "1\n5 0 -1 22\n", "1\n7 0 -1 22\n", "1\n11 11 11 9\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "0\n", "-1\n", "-1\n", "0\n"]}
498
147
coding
Solve the programming task below in a Python markdown code block. SKIT’s canteen sells Patties in packages of 6, 9 or 20 . Thus, it is possible, for example, to buy exactly 15 Patties (with one package of 6 and a second package of 9), but it is not possible to buy exactly 16 Patties, since no non- negative integer comb...
{"inputs": ["2\n45\n1", "5\n1991\n991\n43\n57\n1000000"], "outputs": ["True\nFalse", "True\nTrue\nFalse\nTrue\nTrue"]}
310
56
coding
Solve the programming task below in a Python markdown code block. A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers p_{i}, a_{i} and b_{i}, where p_{i} is the price of the i-th t-shirt, a_{i} is front color of the i-th t-shirt and b_{i} is back color of the i-th t-shirt. A...
{"inputs": ["1\n529469903\n1\n3\n1\n3\n", "1\n529469903\n1\n3\n1\n3\n", "1\n529469903\n1\n1\n1\n3\n", "1\n529469903\n1\n1\n1\n1\n", "2\n1000000000 1\n1 1\n1 2\n2\n2 1\n", "2\n1000000000 1\n1 1\n1 3\n2\n2 1\n", "2\n1000000000 1\n2 1\n1 3\n2\n2 1\n", "2\n1000000100 1\n1 1\n1 3\n2\n2 1\n"], "outputs": ["529469903 \n", "52...
717
299
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive. A subarray of an array is a consecutive sequence of zero or more values taken out of that array...
{"functional": "def check(candidate):\n assert candidate(nums = [1,-2,-3,4]) == 4\n assert candidate(nums = [0,1,-2,-3,-4]) == 3\n assert candidate(nums = [-1,-2,-3,0,1]) == 2\n\n\ncheck(Solution().getMaxLen)"}
106
78