problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably...
{"inputs": ["1\n2\n3\n", "1\n1\n1\n", "1\n2\n1\n", "5\n1\n3\n", "3\n1\n5\n", "6\n7\n1\n", "1\n8\n3\n", "9\n7\n2\n"], "outputs": ["9\n", "3\n", "4\n", "20\n", "20\n", "48\n", "27\n", "126\n"]}
coding
313
Solve the programming task below in a Python markdown code block. In programming you know the use of the logical negation operator (**!**), it reverses the meaning of a condition. Your task is to complete the function 'negationValue()' that takes a string of negations with a value and returns what the value would be i...
{"functional": "_inputs = [['!', False], ['!', True], ['!!!', []]]\n_outputs = [[True], [False], [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 isinstance(a, (list, tuple)):\n if len(a)...
coding
169
Solve the programming task below in a Python markdown code block. Your job is to write a function which increments a string, to create a new string. - If the string already ends with a number, the number should be incremented by 1. - If the string does not end with a number. the number 1 should be appended to the new ...
{"functional": "_inputs = [['foo'], ['foobar001'], ['foobar1'], ['foobar00'], ['foobar99'], [''], ['foobar000'], ['foobar999'], ['foobar00999'], ['1'], ['009']]\n_outputs = [['foo1'], ['foobar002'], ['foobar2'], ['foobar01'], ['foobar100'], ['1'], ['foobar001'], ['foobar1000'], ['foobar01000'], ['2'], ['010']]\nimport ...
coding
162
Solve the programming task below in a Python markdown code block. For a collection of integers $S$, define $\operatorname{mex}(S)$ as the smallest non-negative integer that does not appear in $S$. NIT, the cleaver, decides to destroy the universe. He is not so powerful as Thanos, so he can only destroy the universe by...
{"inputs": ["4\n4\n0 0 0 0\n5\n0 1 2 3 4\n7\n0 2 3 0 1 2 0\n1\n1000000000\n"], "outputs": ["0\n1\n2\n1\n"]}
coding
613
Solve the programming task below in a Python markdown code block. While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016...
{"inputs": ["2 1\n1 2\n", "2 1\n2 1\n", "2 1\n2 1\n", "2 1\n2 1\n", "2 1\n1 2\n", "4 1\n2 1\n", "4 1\n4 1\n", "3 1\n2 1\n"], "outputs": ["1\n", "1\n", "1\n", "1", "1", "-1\n", "-1\n", "-1\n"]}
coding
556
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the ith stick. You can connect any two sticks of lengths x and y into one stic...
{"functional": "def check(candidate):\n assert candidate(sticks = [2,4,3]) == 14\n assert candidate(sticks = [1,8,3,5]) == 30\n assert candidate(sticks = [5]) == 0\n\n\ncheck(Solution().connectSticks)"}
coding
143
Solve the programming task below in a Python markdown code block. Chef has an array A of size N. He can perform the following operation on A: Select an i (1 ≤ i ≤ N) and for all 1 ≤ j ≤ i, set A_{j} := A_{j} + 1 (i.e. add 1 to every element in the prefix of length i). Chef wants to convert A to a *palindrome* by using...
{"inputs": ["3\n4\n4 2 2 4\n5\n5 4 3 2 1\n4\n1 2 3 4\n"], "outputs": ["0\n-1\n3\n"]}
coding
595
Solve the programming task below in a Python markdown code block. $Alien$ likes to give challenges to $Codezen$ team to check their implementation ability, this time he has given a string $S$ and asked to find out whether the given string is a $GOOD$ string or not. According to the challenge $GOOD$ String is a string t...
{"inputs": ["COOEY", "AMBITIOUSNESS"], "outputs": ["-1", "GOOD"]}
coding
298
Solve the programming task below in a Python markdown code block. A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The cente...
{"inputs": ["2\n0 1\n0 1\n", "2\n1 0\n1 0\n", "2\n1 0\n0 1\n", "3\n0 1 2\n0 1 2\n", "3\n0 1 2\n1 0 2\n", "3\n0 2 1\n2 0 1\n", "3\n0 2 1\n1 2 0\n", "3\n2 0 1\n1 0 2\n"], "outputs": ["YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]}
coding
508
Solve the programming task below in a Python markdown code block. Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $1$ to $n$ and then $3n$ times takes a r...
{"inputs": ["5\n2 4 5 1 3\n", "5\n4 3 5 1 2\n", "5\n4 1 5 2 3\n", "5\n2 4 5 1 3\n"], "outputs": ["Petr\n", "Petr\n", "Petr\n", "Petr\n"]}
coding
404
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 ...
coding
110
Solve the programming task below in a Python markdown code block. Debug the functions Should be easy, begin by looking at the code. Debug the code and the functions should work. There are three functions: ```Multiplication (x)``` ```Addition (+)``` and ```Reverse (!esreveR)``` i { font-size:16px; } #heading { pad...
{"functional": "_inputs = [[[8, 2, 5]]]\n_outputs = [[80]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_...
coding
140
Solve the programming task below in a Python markdown code block. Finally the clowns of Synapse have decided to take their site online. The convener of the clowns has heard from somewhere that knowing URI's is very important for their website, so kindly help him with this task. Uniform Resource Identifiers (or URIs) a...
{"inputs": ["Happy Joy Joy!\nhttp://synapse.daiict.ac.in/\nplain_vanilla\n(**)\n?\nthe 7% solution\n#"], "outputs": ["Happy%20Joy%20Joy%21\nhttp://synapse.daiict.ac.in/\nplain_vanilla\n%28%2a%2a%29\n?\nthe%207%25%20solution"]}
coding
547
Solve the programming task below in a Python markdown code block. Santa has to send presents to the kids. He has a large stack of $n$ presents, numbered from $1$ to $n$; the topmost present has number $a_1$, the next present is $a_2$, and so on; the bottom present has number $a_n$. All numbers are distinct. Santa has ...
{"inputs": ["2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n3 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n4 1 7 3 4 5 6\n3 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n6 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n4 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 5 7 6\n2 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 5 5 6\n1 2\n", "2...
coding
611
Solve the programming task below in a Python markdown code block. Vlad went into his appartment house entrance, now he is on the $1$-th floor. He was going to call the elevator to go up to his apartment. There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor ...
{"inputs": ["1\n1902 3 5\n", "1\n2001 1 2\n", "1\n2001 1 3\n", "1\n5086 1 2\n", "1\n2002 1 2\n", "1\n2003 3 2\n", "1\n2002 2 3\n", "1\n5086 5607 4560\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n"]}
coding
598
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consisting of n...
{"inputs": ["2 0\n47\n", "3 8\n276\n", "3 8\n167\n", "3 8\n278\n", "3 8\n262\n", "3 8\n187\n", "3 8\n155\n", "3 8\n161\n"], "outputs": ["47\n", "276\n", "167\n", "278\n", "262\n", "187\n", "155\n", "161\n"]}
coding
469
Solve the programming task below in a Python markdown code block. You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to st...
{"inputs": ["1 4\n", "2 4\n", "2 1\n", "7 1\n", "4 8\n", "1 2\n", "2 3\n", "1 3\n"], "outputs": ["1 0\n", "2 0\n", "0 1\n", "1 1\n", "4 0\n", "1 0\n", "2 3\n", "1 1\n"]}
coding
340
Solve the programming task below in a Python markdown code block. Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mar...
{"inputs": ["1\n", "4\n", "3\n", "8\n", "2\n", "3\n", "8\n", "2\n"], "outputs": ["1\n", "2\n", "1\n", "3\n", "1\n", " 1", " 3", " 1"]}
coding
492
Solve the programming task below in a Python markdown code block. Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day. Du will chat in the group for n days....
{"inputs": ["1 1 0\n0\n", "1 1 1\n2\n", "1 1 1\n0\n", "1 1 0\n2\n", "1 1 1\n1\n", "1 0 1\n0\n", "5 3 3\n8 5 5 1 14\n", "5 3 3\n8 5 5 2 14\n"], "outputs": ["0\n", "2\n", "0\n", "2\n", "1\n", "0\n", "22\n", "22\n"]}
coding
558
Solve the programming task below in a Python markdown code block. In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter. It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we m...
{"inputs": ["0 1", "0 2", "1 2", "5 1", "5 0", "7 0", "7 1", "2 2"], "outputs": ["0\n", "1\n", "-1\n", "5\n", "10\n", "21\n", "14\n", "-2\n"]}
coding
313
Solve the programming task below in a Python markdown code block. Colour plays an important role in our lifes. Most of us like this colour better then another. User experience specialists believe that certain colours have certain psychological meanings for us. You are given a 2D array, composed of a colour and its 'co...
{"functional": "_inputs = [[[['white', 'goodness'], ['blue', 'tranquility']]], [[['red', 'energy'], ['yellow', 'creativity'], ['brown', 'friendly'], ['green', 'growth']]], [[['pink', 'compassion'], ['purple', 'ambition']]], [[['gray', 'intelligence'], ['black', 'classy']]], [[['white', 'goodness'], ['blue', 'goodness']...
coding
143
Solve the programming task below in a Python markdown code block. itertools.product() This tool computes the cartesian product of input iterables. It is equivalent to nested for-loops. For example, product(A, B) returns the same as ((x,y) for x in A for y in B). Sample Code >>> from itertools import product >>...
{"inputs": [" 1 2\n 3 4\n"], "outputs": [" (1, 3) (1, 4) (2, 3) (2, 4)\n"]}
coding
707
Solve the programming task below in a Python markdown code block. You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array. If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must return ...
{"functional": "_inputs = [[[0, 1]], [[1, 4, 6]], [[3, 4, 5]], [[2, 1]], [[1, 4, 4, 6]]]\n_outputs = [[[0, 1]], [[0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5]], [[0, 1, 2]], [[0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=...
coding
245
Solve the programming task below in a Python markdown code block. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in th...
{"inputs": ["3\n-2 3\n2 2\n3 0", "3\n-2 5\n2 2\n3 0", "3\n-1 3\n2 2\n3 -2", "3\n-1 3\n2 0\n3 -2", "3\n-1 5\n2 0\n3 -2", "3\n-2 5\n2 0\n3 -2", "3\n-1 3\n2 1\n3 -3", "3\n-2 3\n2 2\n3 -2"], "outputs": ["13", "13", "13", "13", "13", "13", "13", "13"]}
coding
577
Solve the programming task below in a Python markdown code block. Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese). You are given an integer $n$. You need to find two integers $l$ and $r$ such that $-10^{18} \le l < r \le 10^{18}$ and $l ...
{"inputs": ["7\n2\n4\n7\n3\n111\n6\n56293238153\n", "7\n1\n2\n6\n2\n101\n2\n390536414718\n", "7\n1\n2\n6\n2\n001\n2\n390536414718\n", "7\n1\n2\n6\n2\n001\n2\n133532318784\n", "7\n1\n2\n4\n2\n001\n2\n133532318784\n", "7\n1\n2\n8\n2\n001\n2\n133532318784\n", "7\n1\n2\n8\n4\n001\n2\n133532318784\n", "7\n2\n2\n8\n4\n001\n2...
coding
507
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted. Return the number of ways to color the grid with n...
{"functional": "def check(candidate):\n assert candidate(m = 1, n = 1) == 3\n assert candidate(m = 1, n = 2) == 6\n assert candidate(m = 5, n = 5) == 580986\n\n\ncheck(Solution().colorTheGrid)"}
coding
130
Please solve the programming task below using a self-contained code snippet in a markdown code block. An element x of an integer array arr of length m is dominant if freq(x) * 2 > m, where freq(x) is the number of occurrences of x in arr. Note that this definition implies that arr can have at most one dominant element...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,2]) == 2\n assert candidate(nums = [2,1,3,1,1,1,7,1,2,1]) == 4\n assert candidate(nums = [3,3,3,3,7,2,2]) == -1\n\n\ncheck(Solution().minimumIndex)"}
coding
260
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Watson gives an array A of N integers A_{1}, A_{2}, ..., A_{N} to Sherlock. He wants Sherlock to reorganize the array in a way such that no two adjacent numbers differ by mor...
{"inputs": ["2\n4\n3 2 2 3 \n2\n1 5"], "outputs": ["YES\nNO"]}
coding
359
Solve the programming task below in a Python markdown code block. Chef has a garden with $N$ plants arranged in a line in decreasing order of height. Initially the height of the plants are $A_1, A_2, ..., A_N$. The plants are growing, after each hour the height of the $i$-th plant increases by $i$ millimeters. Find the...
{"inputs": ["1\n3\n8 4 2"], "outputs": ["2"]}
coding
373
Solve the programming task below in a Python markdown code block. The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a tear of ...
{"inputs": ["1 2\n8 8\n0 0\n0 1\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n2 2\n3 3\n1 2 5\n2 8 6\n0 1 2\n0 0\n1 2\n2 2\n1 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0", "1 2\n8 8\n0 0\n0 1\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n2 2\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n1 2\n2 2\n2 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0", "1...
coding
631
Solve the programming task below in a Python markdown code block. # Task You are given two strings s and t of the same length, consisting of uppercase English letters. Your task is to find the minimum number of "replacement operations" needed to get some `anagram` of the string t from the string s. A replacement opera...
{"functional": "_inputs = [['AABAA', 'BBAAA'], ['OVGHK', 'RPGUC'], ['AAAAAAAAAAAAAAAAAAAAAAAAAAAAAB', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAC']]\n_outputs = [[1], [4], [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=t...
coding
309
Solve the programming task below in a Python markdown code block. In this Kata, you will be given two numbers, `a` and `b`, and your task is to determine if the first number `a` is divisible by `all` the prime factors of the second number `b`. For example: `solve(15,12) = False` because `15` is not divisible by all the...
{"functional": "_inputs = [[2, 256], [2, 253], [9, 243], [15, 12], [21, 2893401], [21, 2893406], [54, 2834352], [54, 2834359], [1000013, 7187761], [1000013, 7187762]]\n_outputs = [[True], [False], [True], [False], [True], [False], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isi...
coding
214
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 and a positive integer k. The level sum in the tree is the sum of the values of the nodes that are on the same level. Return the kth largest level sum in the tree (not necessari...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,8,9,2,1,3,7,4,6]), k = 2) == 13\n assert candidate(root = tree_node([1,2,None,3]), k = 1) == 3\n\n\ncheck(Solution().kthLargestLevelSum)"}
coding
194
Solve the programming task below in a Python markdown code block. Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For exam...
{"inputs": ["a\n", "z\n", "a\n", "z\n", "ee\n", "iq\n", "iq\n", "ee\n"], "outputs": ["aa\n", "zz\n", "aa\n", "zz\n", "eee\n", "qiq\n", "qiq\n", "eee"]}
coding
403
Solve the programming task below in a Python markdown code block. Description: The mean (or average) is the most popular measure of central tendency; however it does not behave very well when the data is skewed (i.e. wages distribution). In such cases, it's better to use the median. Your task for this kata is to find...
{"functional": "_inputs = [[[1, 2, 3, 4]], [[3, 4, 1, 2, 5]], [[10, 29, 23, 94, 76, 96, 5, 85, 4, 33, 47, 41, 87]], [[1]], [[1, -1]]]\n_outputs = [[2.5], [3], [41], [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,...
coding
186
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$. The string $s$ consists of lowercase Latin letters and at most one wildcard character '*', the string $t$ consists only of lowercase Latin letters. The length of the string $s$ equals $n$, the length of the string $...
{"inputs": ["1 1\nv\nk\n", "1 1\n*\na\n", "1 1\na\na\n", "1 1\nb\na\n", "1 1\n*\na\n", "1 1\nb\na\n", "1 1\na\na\n", "1 1\n+\na\n"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n"]}
coding
596
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square. The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order. A va...
{"functional": "def check(candidate):\n assert candidate(p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,12]) == False\n assert candidate(p1 = [1,0], p2 = [-1,0], p3 = [0,1], p4 = [0,-1]) == True\n\n\ncheck(Solution().validSquare)"}
coding
143
Solve the programming task below in a Python markdown code block. Four players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals of the t...
{"inputs": ["1\n8 6 2 7\n", "1\n8 6 2 7\n", "1\n8 6 0 7\n", "1\n9 4 0 7\n", "1\n2 4 0 1\n", "1\n1 6 2 7\n", "1\n9 6 0 7\n", "1\n9 4 0 6\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
coding
494
Solve the programming task below in a Python markdown code block. Sam has opened a new sushi train restaurant - a restaurant where sushi is served on plates that travel around the bar on a conveyor belt and customers take the plate that they like. Sam is using Glamazon's new visual recognition technology that allows a...
{"functional": "_inputs = [['rr'], ['rr rrr'], ['rr rrr rrr rr'], ['rrrrrrrrrrrrrrrrrr rr r'], ['']]\n_outputs = [[4], [8], [16], [34], [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...
coding
352
Solve the programming task below in a Python markdown code block. There is a square grid with N rows and M columns. Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}. Among the 2^{N+M} possible pairs of a subset A of the rows and a subset...
{"inputs": ["2 2\n1 1\n1 0", "2 2\n1 0\n1 0", "2 2\n1 0\n2 0", "1 2\n1 0\n2 0", "2 2\n2 1\n1 0", "2 2\n2 0\n1 0", "1 2\n2 0\n2 0", "2 2\n0 1\n1 0"], "outputs": ["6\n", "4\n", "4\n", "2\n", "6\n", "4\n", "2\n", "6"]}
coding
321
Solve the programming task below in a Python markdown code block. In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be isomorphic when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j ...
{"inputs": ["4", "6", "3", "7", "5", "8", "4", "3"], "outputs": ["aaaa\naaab\naaba\naabb\naabc\nabaa\nabab\nabac\nabba\nabbb\nabbc\nabca\nabcb\nabcc\nabcd\n", "aaaaaa\naaaaab\naaaaba\naaaabb\naaaabc\naaabaa\naaabab\naaabac\naaabba\naaabbb\naaabbc\naaabca\naaabcb\naaabcc\naaabcd\naabaaa\naabaab\naabaac\naababa\naababb\n...
coding
401
Solve the programming task below in a Python markdown code block. Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m ho...
{"inputs": ["2", "8", "16", "1000010000000", "1000011000000", "1100011000000", "1110011000000", "1110011100000"], "outputs": ["0\n", "10", "22\n", "2716922731275\n", "3307289212967\n", "2999416055122\n", "3146654438234\n", "4080876601631\n"]}
coding
180
Solve the programming task below in a Python markdown code block. You are given three integers $n$, $a$, and $b$. Determine if there exist two permutations $p$ and $q$ of length $n$, for which the following conditions hold: The length of the longest common prefix of $p$ and $q$ is $a$. The length of the longest commo...
{"inputs": ["4\n1 1 1\n2 1 2\n3 1 1\n4 1 1\n"], "outputs": ["Yes\nNo\nNo\nYes\n"]}
coding
435
Solve the programming task below in a Python markdown code block. A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object. There are $n$ students in the class, a...
{"inputs": ["2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21\n", "2\n7\n2 2 3 3 3 4 4\n6\n1 2 2 2 3 3\n", "6\n1\n95\n12\n1 1 1 1 1 1 1 39 39 39 39 39\n3\n5 5 5\n9\n46 46 46 46 46 46 46 46 46\n8\n18 18 18 18 35 35 35 35\n17\n23 23 25 25 25 25 25 25 25 36 36 66 66 95 95 96 96\n", "3\n11\n195927690 195927690 195927690 195927690 648407...
coding
709
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, find three numbers whose product is maximum and return the maximum product.   Please complete the following python code precisely: ```python class Solution: def maximumProduct(self, nu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 6\n assert candidate(nums = [1,2,3,4]) == 24\n assert candidate(nums = [-1,-2,-3]) == -6\n\n\ncheck(Solution().maximumProduct)"}
coding
67
Solve the programming task below in a Python markdown code block. Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its fin...
{"inputs": ["1 1\n28 2\n", "1 1\n28 4\n", "1 1\n28 28\n", "2 2\n1 2\n1 2\n", "2 2\n1 2\n1 1\n", "2 1\n50 50\n50 49\n", "2 2\n50 50\n50 50\n", "2 1\n50 50\n50 50\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "2\n"]}
coding
706
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (No...
{"functional": "def check(candidate):\n assert candidate(\"Mr John Smith \", 13) == \"Mr%20John%20Smith\"\n assert candidate(\" \", 5) == \"%20%20%20%20%20\"\n\n\ncheck(Solution().replaceSpaces)"}
coding
119
Solve the programming task below in a Python markdown code block. Given an array of $n$ positive integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$). Find the maximum value of $i + j$ such that $a_i$ and $a_j$ are coprime,$^{\dagger}$ or $-1$ if no such $i$, $j$ exist. For example consider the array $[1, 3, 5, 2, 4...
{"inputs": ["1\n2\n1 1\n", "1\n3\n2 3 6\n", "1\n3\n4 6 12\n", "1\n2\n3 1000\n", "1\n5\n2 3 6 6 6\n", "1\n4\n2 2 1 1000\n", "1\n4\n1 1 1 1000\n", "1\n5\n1 1 6 20 45\n"], "outputs": ["4\n", "3\n", "-1\n", "3\n", "3\n", "7\n", "7\n", "7\n"]}
coding
644
Solve the programming task below in a Python markdown code block. For an array $b$ of length $m$ we define the function $f$ as $ f(b) = \begin{cases} b[1] & \quad \text{if } m = 1 \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise,} \end{cases} $ where $\oplus$ is bitwise exclus...
{"inputs": ["3\n8 4 1\n2\n2 3\n1 2\n", "3\n6 4 1\n2\n2 3\n1 2\n", "3\n8 4 1\n2\n2 3\n2 2\n", "3\n8 0 1\n2\n2 3\n2 2\n", "3\n8 1 1\n2\n2 3\n2 2\n", "3\n8 4 1\n2\n1 3\n1 2\n", "3\n8 4 1\n2\n1 3\n2 2\n", "3\n8 0 1\n2\n2 2\n2 2\n"], "outputs": ["5\n12\n", "5\n6\n", "5\n4\n", "1\n0\n", "1\n1\n", "12\n12\n", "12\n4\n", "0\n0...
coding
592
Solve the programming task below in a Python markdown code block. Given are N positive integers A_1,...,A_N. Consider positive integers B_1, ..., B_N that satisfy the following condition. Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds. Find the minimum possible value of B_1 + ... + B_N f...
{"inputs": ["1\n1\n", "1\n12\n", "3\n2 3 2", "3\n2 6 2", "3\n1 6 2", "3\n3 3 4", "3\n2 5 2", "3\n3 6 2"], "outputs": ["1\n", "1\n", "8\n", "7\n", "10\n", "11\n", "12\n", "6\n"]}
coding
270
Solve the programming task below in a Python markdown code block. ### Description: Remove all exclamation marks from sentence except at the end. ### Examples ``` remove("Hi!") == "Hi!" remove("Hi!!!") == "Hi!!!" remove("!Hi") == "Hi" remove("!Hi!") == "Hi!" remove("Hi! Hi!") == "Hi Hi!" remove("Hi") == "Hi" ``` Als...
{"functional": "_inputs = [['Hi!'], ['Hi!!!'], ['!Hi'], ['!Hi!'], ['Hi! Hi!'], ['Hi']]\n_outputs = [['Hi!'], ['Hi!!!'], ['Hi'], ['Hi!'], ['Hi Hi!'], ['Hi']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ...
coding
108
Solve the programming task below in a Python markdown code block. You will be given a list of integers, $\textbf{arr}$, and a single integer $\boldsymbol{\mbox{k}}$. You must create an array of length $\boldsymbol{\mbox{k}}$ from elements of $\textbf{arr}$ such that its unfairness is minimized. Call that array $arr'$....
{"inputs": ["5\n2\n1\n2\n1\n2\n1\n", "7\n3\n10\n100\n300\n200\n1000\n20\n30\n", "10\n4\n1\n2\n3\n4\n10\n20\n30\n40\n100\n200\n"], "outputs": ["0\n", "20\n", "3\n"]}
coding
675
Solve the programming task below in a Python markdown code block. n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number o...
{"inputs": ["2 2\n0 0\n0 0\n", "2 2\n0 0\n0 1\n", "2 2\n1 1\n1 0\n", "2 2\n2 1\n1 0\n", "2 2\n2 0\n1 0\n", "2 2\n0 1\n1 0\n", "2 2\n0 0\n0 -1\n", "3 2\n1 2 2\n3 4\n"], "outputs": ["0\n", "1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "13\n"]}
coding
731
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef doesn't love math anymore. He loves Sasha. Sashen'ka is cute. Chef goes on a date with her. Flowers are boring, while numbers are not. He knows that most of all this girl loves numbers, ...
{"inputs": ["1\n1 10"], "outputs": ["6"]}
coding
305
Solve the programming task below in a Python markdown code block. This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced. Polycarp likes to play computer role-playing game «Lizards and Basements...
{"inputs": ["3 5 3\n3 2 2\n", "3 5 3\n1 2 1\n", "3 5 2\n9 3 6\n", "3 5 3\n1 4 1\n", "3 2 1\n2 2 2\n", "3 5 3\n10 9 7\n", "3 5 1\n1 9 10\n", "3 5 3\n12 9 7\n"], "outputs": ["2\n2 2 ", "1\n2 ", "5\n2 2 2 2 2 ", "1\n2 ", "3\n2 2 2 ", "4\n2 2 2 2 ", "11\n2 2 2 2 2 2 2 2 2 2 2 ", "5\n2 2 2 2 2 "]}
coding
493
Solve the programming task below in a Python markdown code block. There is Kannon-do in the mountain behind Ichiro's house. There are 30 steps from the foot to this Kannon-do, and Ichiro goes to Kannon-do almost every day. Ichiro can go up the stairs up to 3 steps with one foot. While playing, I noticed that there are ...
{"inputs": ["1\n2\n4\n0\n0", "1\n0\n14\n6\n0", "1\n2\n21\n0\n0", "1\n1\n16\n5\n0", "1\n1\n16\n0\n1", "1\n20\n7\n5\n0", "1\n26\n0\n9\n0", "1\n9\n1\n20\n0"], "outputs": ["1\n1\n1\n", "1\n", "1\n1\n62\n", "1\n1\n3\n1\n", "1\n1\n3\n", "1\n34\n1\n1\n", "1\n1288\n", "1\n1\n1\n34\n"]}
coding
346
Solve the programming task below in a Python markdown code block. Given an array containing only zeros and ones, find the index of the zero that, if converted to one, will make the longest sequence of ones. For instance, given the array: ``` [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1] ``` replacing the...
{"functional": "_inputs = [[[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1]], [[1, 1, 0, 1, 1, 0, 1, 1]], [[1, 1, 1, 0, 1, 1, 0, 1, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]], [[1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1]], [[0, 0, 0, 0, 0, 1]], [[0, 0, 0, 0, 1, 0]], [[1, 0, 0, 0, 0, 0]], [[0, 1, 0, 0, 0, 0]]]\n_outputs ...
coding
312
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef is on a vacation these days, so his friend Chefza is trying to solve Chef's everyday tasks. Today's task is to make a sweet roll. Rolls are made by a newly invented cooking machine. The ma...
{"inputs": ["6\n1 1\n2 1\n3 8\n4 1\n2 1\n2 4", "6\n1 2\n2 4\n6 8\n4 8\n1 1\n2 4", "6\n1 1\n2 4\n3 2\n4 4\n4 1\n1 4", "6\n2 2\n2 4\n6 8\n4 8\n1 1\n2 4", "6\n1 1\n2 1\n4 8\n5 1\n2 1\n2 4", "6\n1 1\n2 4\n3 8\n4 16\n4 1\n1 4", "6\n1 1\n2 4\n3 1\n4 16\n4 1\n1 4", "6\n1 1\n2 4\n3 8\n4 16\n1 1\n1 4"], "outputs": ["0\n1\n4\n2\...
coding
662
Solve the programming task below in a Python markdown code block. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection ...
{"inputs": ["2 3 1 1\n", "10 7 3 4\n", "100000 100000 99999 99999\n", "100000 100000 44444 55555\n"], "outputs": ["2\n", "3570\n", "1\n", "738162020\n"]}
coding
285
Solve the programming task below in a Python markdown code block. A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this ...
{"inputs": ["c\n", "a\n", "b\n", "c\n", "b\n", "a\n", "cc\n", "bc\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
421
Solve the programming task below in a Python markdown code block. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to ...
{"inputs": ["1\n7 9 7\n1 7 8\n2 1\n2 2 1\n0", "1\n7 4 2\n1 9 8\n2 1\n9 2 1\n0", "1\n7 3 4\n1 7 8\n2 1\n3 3 1\n0", "1\n7 9 7\n1 7 2\n2 1\n2 2 1\n0", "1\n7 4 2\n1 9 8\n2 1\n1 2 1\n0", "1\n7 1 7\n7 7 8\n8 1\n3 1 2\n0", "1\n7 9 7\n2 7 2\n2 1\n2 2 1\n0", "1\n7 4 2\n1 9 8\n2 1\n2 2 1\n0"], "outputs": ["11\n0\n16\n13\n15\n", ...
coding
380
Solve the programming task below in a Python markdown code block. Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question. Suppose you are given a positive integer $a$. You want to choose some integer $b$ from $1$ to $a - 1$ inclusive in such a way that the gr...
{"inputs": ["1\n4\n", "1\n7\n", "1\n2\n", "1\n9\n", "1\n8\n", "1\n6\n", "1\n3\n", "1\n5\n"], "outputs": ["7\n", "1\n", "3\n", "15\n", "15\n", "7\n", "1\n", "7\n"]}
coding
574
Solve the programming task below in a Python markdown code block. The elections in which three candidates participated have recently ended. The first candidate received $a$ votes, the second one received $b$ votes, the third one received $c$ votes. For each candidate, solve the following problem: how many votes should ...
{"inputs": ["1\n47 74 4774\n", "5\n0 0 0\n10 75 15\n13 13 17\n1000 0 0\n0 1000000000 0\n"], "outputs": ["4728 4701 0\n", "1 1 1\n66 0 61\n5 5 0\n0 1001 1001\n1000000001 0 1000000001\n"]}
coding
390
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a strictly increasing sequence of integers $A_{1}, A_{2}, \ldots, A_{N}$. Your task is to compress this sequence. The *compressed form* of this...
{"inputs": ["3\n12\n1 2 3 5 6 8 9 10 11 12 15 17\n4\n4 5 7 8\n1\n4"], "outputs": ["1...3,5,6,8...12,15,17\n4,5,7,8\n4"]}
coding
677
Solve the programming task below in a Python markdown code block. One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are...
{"inputs": ["1\nABB\n", "1\nAAB\n", "1\nBAB\n", "1\nBAC\n", "1\nACB\n", "1\nCAB\n", "1\nC@B\n", "1\nB@C\n"], "outputs": ["ABB\n", "AAB\n", "BAB\n", "BAC\n", "ACB\n", "CAB\n", "C@B\n", "B@C\n"]}
coding
272
Solve the programming task below in a Python markdown code block. Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. Th...
{"inputs": ["1\n5\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n8\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
431
Solve the programming task below in a Python markdown code block. Let's dive into decorators! You are given $N$ mobile numbers. Sort them in ascending order then print them in the standard format shown below: +91 xxxxx xxxxx The given mobile numbers may have $+91$, $91$ or $\mbox{0}$ written before the actual $10$ di...
{"inputs": ["3\n07895462130\n919875641230\n9195969878\n"], "outputs": ["+91 78954 62130\n+91 91959 69878\n+91 98756 41230\n"]}
coding
322
Solve the programming task below in a Python markdown code block. There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, t...
{"inputs": ["4\n2 4\n1 2 1 2\n2 4\n1 1 1 1\n5 5\n5 1 3 2 4\n1 1\n1\n"], "outputs": ["2\n3\n1\n1\n"]}
coding
574
Solve the programming task below in a Python markdown code block. You are given a positive integer N. Find the minimum positive integer divisible by both 2 and N. -----Constraints----- - 1 \leq N \leq 10^9 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format...
{"inputs": ["5", "8", "1", "0", "9", "4", "7", "6"], "outputs": ["10\n", "8\n", "2\n", "0\n", "18\n", "4\n", "14\n", "6\n"]}
coding
146
Solve the programming task below in a Python markdown code block. HELP! Jason can't find his textbook! It is two days before the test date, and Jason's textbooks are all out of order! Help him sort a list (ArrayList in java) full of textbooks by subject, so he can study before the test. The sorting should **NOT** be c...
{"functional": "_inputs = [[['Algebra', 'History', 'Geometry', 'English']], [['Algebra', 'history', 'Geometry', 'english']], [['Alg#bra', '$istory', 'Geom^try', '**english']]]\n_outputs = [[['Algebra', 'English', 'Geometry', 'History']], [['Algebra', 'english', 'Geometry', 'history']], [['$istory', '**english', 'Alg#br...
coding
96
Solve the programming task below in a Python markdown code block. You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make thes...
{"inputs": ["4\n4 4 3\n1 6 7\n3 4 3\n2 3 4\n"], "outputs": ["YES\nYES\nNO\nYES\n"]}
coding
566
Solve the programming task below in a Python markdown code block. Dolphin loves programming contests. Today, he will take part in a contest in AtCoder. In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock". The current time is A o'clock, and a contest will begin in exactly B ho...
{"inputs": ["7 0", "5 0", "0 0", "4 0", "8 4", "5 1", "6 0", "1 0"], "outputs": ["7\n", "5\n", "0\n", "4\n", "12\n", "6\n", "6\n", "1\n"]}
coding
211
Solve the programming task below in a Python markdown code block. One day, Chef prepared D brand new dishes. He named the i-th dish by a string Si. After the cooking, he decided to categorize each of these D dishes as special or not. A dish Si is called special if it's name (i.e. the string Si) can be represented in t...
{"inputs": ["3\naba\nabac\nabcd", "3\naba\nabac\naacd", "3\nbca\nb`dc\naabd", "3\ncdd\n_a_a\n_ed[", "3\nfda\n`a`a\nb`Ze", "3\naba\nabac\ndaca", "3\naba\nabac\ndaac", "3\naba\nabac\nadac"], "outputs": ["YES\nNO\nNO", "YES\nNO\nNO\n", "NO\nNO\nNO\n", "YES\nYES\nNO\n", "NO\nYES\nNO\n", "YES\nNO\nNO\n", "YES\nNO\nNO\n", "Y...
coding
494
Solve the programming task below in a Python markdown code block. Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to...
{"inputs": ["3 0010\n3\n101\n5", "3 1\n575\n3\n9\n15", "3 1\n668\n3\n9\n15", "3 2\n668\n3\n9\n15", "3 2\n668\n6\n9\n15", "3 2\n668\n1\n9\n15", "3 1010\n17\n101\n6", "3 0010\n17\n101\n6"], "outputs": ["-30\n", "-193\n", "-224\n", "-223\n", "-111\n", "-673\n", "150\n", "-16\n"]}
coding
456
Solve the programming task below in a Python markdown code block. "Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction. ## Task Given t...
{"functional": "_inputs = [[[0, 0], [1, 1]], [[2, 6], [-2, -6]], [[10, -10], [-10, 10]], [[1, -35], [-12, 1]], [[1000, 15], [-7, -214]], [[0, 0], [0, 0]]]\n_outputs = [[[2, 2]], [[-6, -18]], [[-30, 30]], [[-25, 37]], [[-1014, -443]], [[0, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or ...
coding
185
Solve the programming task below in a Python markdown code block. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn. Your task is to find such permutation p of length n, that the group o...
{"inputs": ["2 1\n", "4 2\n", "5 4\n", "7 5\n", "4 1\n", "9 8\n", "8 2\n", "5 3\n"], "outputs": ["1 2 \n", "1 3 2 4 ", "1 5 2 4 3 \n", "1 6 2 5 3 4 7 ", "1 2 3 4 \n", "1 9 2 8 3 7 4 6 5 \n", "1 3 2 4 5 6 7 8 ", "1 4 2 3 5 "]}
coding
220
Solve the programming task below in a Python markdown code block. Write a function `generatePairs` that accepts an integer argument `n` and generates an array containing the pairs of integers `[a, b]` that satisfy the following conditions: ``` 0 <= a <= b <= n ``` The pairs should be sorted by increasing values of `a`...
{"functional": "_inputs = [[2], [0]]\n_outputs = [[[[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]]], [[[0, 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 ...
coding
155
Solve the programming task below in a Python markdown code block. We all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows : Given an array of integers,find the length of the largest subarray(contiguous) of th...
{"inputs": ["4\n2 4 8 3"], "outputs": ["1"]}
coding
317
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. The ugliness of a string is defined as the count of two consecutive ones i.e. "11" in the given string. For example, the ugliness of string "10111" is $2$. You are...
{"inputs": ["2 \n3\n3 6 5\n2\n7 6"], "outputs": ["5 6 3\n6 7"]}
coding
507
Solve the programming task below in a Python markdown code block. Given two integers `a` and `x`, return the minimum non-negative number to **add to** / **subtract from** `a` to make it a multiple of `x`. ```python minimum(10, 6) #= 2 10+2 = 12 which is a multiple of 6 ``` ## Note - 0 is always a multiple of `x` #...
{"functional": "_inputs = [[9, 4], [10, 6]]\n_outputs = [[1], [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): return False\n retu...
coding
149
Solve the programming task below in a Python markdown code block. Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to gain dexterity that never mistypes by carefully stacking blocks. Since there are many building blo...
{"inputs": ["3\n5 49\n9 9\n28 0", "3\n0 2\n1 59\n1 -2", "3\n5 14\n9 9\n45 0", "3\n7 34\n1 41\n2 0", "3\n1 7\n79 0\n1 -1", "3\n6 42\n6 40\n28 0", "3\n6 49\n6 40\n28 0", "3\n6 49\n9 40\n28 0"], "outputs": ["86\n", "62\n", "68\n", "77\n", "87\n", "76\n", "83\n", "117\n"]}
coding
317
Solve the programming task below in a Python markdown code block. Your task is to write function which takes string and list of delimiters as an input and returns list of strings/characters after splitting given string. Example: ```python multiple_split('Hi, how are you?', [' ']) => ['Hi,', 'how', 'are', 'you?'] multi...
{"functional": "_inputs = [['Hi everybody!', [' ', '!']], ['(1+2)*6-3^9', ['+', '-', '(', ')', '^', '*']], ['Solve_this|kata-very\\\\quickly!', ['!', '|', '\\\\', '_', '-']], ['', []], [''], ['some strange string'], ['1_2_3_huhuh_hahaha', ['_']], ['((1+2))*(6-3)^9', ['+', '-', '(', ')', '^', '*']], ['(((1+2)-(3)))', ['...
coding
149
Solve the programming task below in a Python markdown code block. You are given a sequence a_1, a_2, ..., a_n, consisting of integers. You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning, or to the end of a. Note that you have to move a...
{"inputs": ["3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 4 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 5 8 8\n7\n4 2 5 2 6 4...
coding
711
Solve the programming task below in a Python markdown code block. You are given two arrays: an array $a$ consisting of $n$ zeros and an array $b$ consisting of $n$ integers. You can apply the following operation to the array $a$ an arbitrary number of times: choose some subsegment of $a$ of length $k$ and add the arit...
{"inputs": ["1 1\n1\n", "3 3\n5 4 6\n", "6 3\n1 2 3 2 2 3\n", "6 3\n1 2 4 1 2 3\n", "1 1\n1000000000000\n", "3 3\n14159 26535 89793\n", "7 3\n50 17 81 25 42 39 96\n", "7 4\n1 10000 1 1 1 1 10000\n"], "outputs": ["1\n", "5\n", "3\n", "3\n", "1000000000000\n", "29931\n", "92\n", "7500\n"]}
coding
691
Solve the programming task below in a Python markdown code block. Chef has three numbers A, B, and C. He can do the following type of operation: Select two numbers amongst A, B, and C; Add 1 to the selected numbers; Subtract 1 from the remaining number. Determine whether Chef can make all the three numbers equal afte...
{"inputs": ["4\n1 1 2\n3 7 3\n4 4 4\n1 2 3\n"], "outputs": ["-1\n2\n0\n-1\n"]}
coding
482
Solve the programming task below in a Python markdown code block. This problem is a complicated version of D1, but it has significant differences, so read the whole statement. Polycarp has an array of $n$ ($n$ is even) integers $a_1, a_2, \dots, a_n$. Polycarp conceived of a positive integer $k$. After that, Polycarp ...
{"inputs": ["1\n6\n0 2 3 7 14 64\n", "1\n8\n0 0 0 1 1 1 2 2\n", "2\n4\n1 1 1 1\n4\n1 3 5 7\n", "1\n4\n-1000000 1000000 1 2\n", "1\n4\n-1000000 1000000 2 3\n", "1\n4\n1000000 -1000000 1 2\n", "1\n4\n2 3 -1000000 1000000\n", "1\n4\n-1000000 1 2 1000000\n"], "outputs": ["7\n", "2\n", "-1\n6\n", "2000000\n", "2000000\n", "...
coding
474
Solve the programming task below in a Python markdown code block. We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that A follows Z. For example, shifting A by...
{"inputs": ["13\nA\n", "0\nYBCXAZ", "2\nABDXYZ", "0\nYBBXAZ", "2\nZYXDBA", "0\nYABXAZ", "2\nZXXDBA", "0\nZAXBAY"], "outputs": ["N\n", "YBCXAZ\n", "CDFZAB\n", "YBBXAZ\n", "BAZFDC\n", "YABXAZ\n", "BZZFDC\n", "ZAXBAY\n"]}
coding
205
Solve the programming task below in a Python markdown code block. You are given a sequence $A_1, A_2, \ldots, A_N$. You have to split the array into maximum number of non-empty subarrays such that the gcd of elements of each subarray is equal to 1. -----Input:----- - The first line of the input contains a single integ...
{"inputs": ["2\n3\n2 2 3\n4\n2 3 3 2"], "outputs": ["1\n2"]}
coding
272
Solve the programming task below in a Python markdown code block. Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that...
{"inputs": ["3 2 1\n", "1 0 0\n", "1 1 1\n", "0 1 0\n", "0 0 1\n", "1 1 0\n", "0 1 1\n", "4 3 5\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
coding
618
Solve the programming task below in a Python markdown code block. Multiplication of Big Integers Given two integers $A$ and $B$, compute the product, $A \times B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the product in a line. Constraints * $-1 \times 10^{1...
{"inputs": ["1 1", "9 1", "6 1", "6 2", "6 4", "5 8", "5 16", "0 16"], "outputs": ["1\n", "9\n", "6\n", "12\n", "24\n", "40", "80\n", "0\n"]}
coding
195
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, calculate the vertical order traversal of the binary tree. For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col +...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == [[9],[3,15],[20],[7]]\n assert candidate(root = tree_node([1,2,3,4,5,6,7])) == [[4],[2],[1,5,6],[3],[7]]\n assert candidate(root = tree_node([1,2,3,4,6,5,7])) == [[4],[2],[1,5,6],[3],[7]]\n\n\ncheck(Solution(...
coding
247
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. You are given a sequence a_{1}, a_{2}, ..., a_{N}. Count the number of triples (i, j, k) such that 1 ≤ i < j < k ≤ N and GCD(a_{i}, a_{j}, a_{k}) = 1. Here GCD stands for the Greatest Common Di...
{"inputs": ["4\n1 2 3 4"], "outputs": ["4"]}
coding
263
Solve the programming task below in a Python markdown code block. A binary string is called *alternating* if no two adjacent characters of the string are equal. Formally, a binary string T of length M is called alternating if T_{i} \neq T_{i +1} for each 1 ≤ i < M. For example, 0, 1, 01, 10, 101, 010, 1010 are altern...
{"inputs": ["4\n3\n110\n4\n1010\n4\n0000\n7\n1101101\n"], "outputs": ["3\n4\n1\n5\n"]}
coding
590
Solve the programming task below in a Python markdown code block. Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies...
{"inputs": ["6 3 2 4\n", "6 3 1 3\n", "5 2 1 5\n", "6 4 2 5\n", "7 4 2 5\n", "6 5 2 4\n", "5 4 2 4\n", "6 6 3 5\n"], "outputs": ["5\n", "1\n", "0\n", "6\n", "6\n", "5\n", "4\n", "5\n"]}
coding
528
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1. Some nodes initial are initially infected by malware. Wh...
{"functional": "def check(candidate):\n assert candidate(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]) == 0\n assert candidate(graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]) == 1\n assert candidate(graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]) == 1\n\n\ncheck(Solution().minMalw...
coding
231
Solve the programming task below in a Python markdown code block. Given are an N \times N matrix and an integer K. The entry in the i-th row and j-th column of this matrix is denoted as a_{i, j}. This matrix contains each of 1, 2, \dots, N^2 exactly once. Sigma can repeat the following two kinds of operation arbitraril...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "2 5\n1 2\n4 3\n", "3 13\n3 2 7\n4 8 9\n1 6 5\n", "5 26\n14 9 6 21 19\n16 4 8 12 1\n25 5 15 7 18\n20 17 24 10 23\n3 13 11 22 2\n", "6 61\n36 22 23 5 33 27\n12 25 1 3 24 7\n30 8 34 28 26 31\n10 32 14 13 6 9\n17 29 16 20 35 11\n21 18 4 2 15 19\n", "6 61\n36 22 23 5 33 27\n12 25 1 3 24 ...
coding
537
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese]. There are $N$ guests (numbered $1$ through $N$) coming to Chef's wedding. Each guest is part of a family; for each valid $i$, the $i$-th guest is part of fam...
{"inputs": ["3\n5 1\n5 1 3 3 3\n5 14\n1 4 2 4 4\n5 2\n3 5 4 5 1"], "outputs": ["3\n17\n4"]}
coding
708
Solve the programming task below in a Python markdown code block. There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once: * You go through the heaps from the 3-rd heap to the n-th heap, in this order. * Let i be the n...
{"inputs": ["4\n4\n1 2 4 100\n4\n100 000 100 1\n5\n5 1 1 1 8\n6\n1 2 3 4 5 6\n", "4\n4\n1 2 5 100\n4\n100 100 100 1\n5\n5 2 1 1 8\n6\n1 2 3 6 5 6\n", "4\n4\n1 0 6 100\n4\n000 101 100 2\n5\n5 1 1 1 8\n6\n1 1 2 3 0 7\n", "4\n4\n2 2 2 100\n4\n100 101 100 1\n5\n5 1 1 1 2\n6\n1 2 4 1 5 6\n", "4\n4\n1 2 6 100\n4\n100 111 100...
coding
667
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a binary array nums containing only the integers 0 and 1. Return the number of subarrays in nums that have more 1's than 0's. Since the answer may be very large, return it modulo 109 + 7. A subarray is a...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,1,0,1]) == 9\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [1]) == 1\n\n\ncheck(Solution().subarraysWithMoreZerosThanOnes)"}
coding
123
Solve the programming task below in a Python markdown code block. Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $n$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy. The pieces of sushi are of two types: ei...
{"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 1 2\n", "3\n2 1 1\n", "3\n1 1 2\n", "3\n2 1 1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
596