task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. Your task is to write function ```findSum```. Upto and including ```n```, this function will return the sum of all multiples of 3 and 5. For example: ```findSum(5)``` should return 8 (3 + 5) ```findSum(10)``` should return 33 (3 + 5 + 6 + 9 + 10) Als...
{"functional": "_inputs = [[5], [10], [100], [1000]]\n_outputs = [[8], [33], [2418], [234168]]\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)...
117
186
coding
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"]}
313
81
coding
Solve the programming task below in a Python markdown code block. Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422. Help him to count the sum of goodness of al...
{"inputs": ["1\n1 9", "1\n1 7", "1\n9 16", "1\n9 24", "1\n6 24", "1\n8 24", "1\n8 45", "1\n5 24"], "outputs": ["45\n", "28\n", "191\n", "519\n", "540\n", "527\n", "1997\n", "545\n"]}
292
115
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If there is no answer return an empty string. Since the answer may not f...
{"functional": "def check(candidate):\n assert candidate(digits = [8,1,9]) == \"981\"\n assert candidate(digits = [8,6,7,1,0]) == \"8760\"\n assert candidate(digits = [1]) == \"\"\n assert candidate(digits = [0,0,0,0,0,0]) == \"0\"\n\n\ncheck(Solution().largestMultipleOfThree)"}
120
100
coding
Solve the programming task below in a Python markdown code block. problem AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of $ N $ of dangerous passwords by a friend, decided to create a password that meets all of the following conditions. 1. T...
{"inputs": ["5\npassword\nlogin\nnimda\nroot\nmaster", "5\nbraprswp\nlofho\nojdma\nsnnt\nfuarsm", "5\nbraprsxp\noofhk\nojcma\nsnnt\nfuarsm", "5\napssword\nlogin\nnimda\nroot\nmaster", "5\nopssward\nlogin\nnimda\nroot\nmaster", "5\ndrawsspo\nlogin\nnimda\nroot\nmaster", "5\ndrawsspo\nlogin\nnjmda\nroot\nmaster", "5\ndra...
349
183
coding
Solve the programming task below in a Python markdown code block. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room o...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n1 1\n", "2\n1 2\n", "3\n1 1 3\n", "3\n1 1 3\n", "3\n1 1 2\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "4\n", "8\n", "8\n", "12\n"]}
478
105
coding
Solve the programming task below in a Python markdown code block. **An [isogram](https://en.wikipedia.org/wiki/Isogram)** (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter. It is also used by some to mean a word or phrase in which each letter appears the same numb...
{"functional": "_inputs = [[None], [3], ['Dermatoglyphics'], ['isogram'], ['eleven'], ['moOse'], ['isIsogram'], [''], ['-.-'], ['subdermatoglyphic'], ['Alphabet'], ['thumbscrew-japingly'], ['Hjelmqvist-Gryb-Zock-Pfund-Wax'], ['Emily Jung Schwartzkopf'], ['aabbccddeeffgg']]\n_outputs = [[False], [False], [True], [True],...
218
281
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array cards where cards[i] represents the value of the ith card. A pair of cards are matching if the cards have the same value. Return the minimum number of consecutive cards you have to pick ...
{"functional": "def check(candidate):\n assert candidate(cards = [3,4,2,3,4,7]) == 4\n assert candidate(cards = [1,0,5,3]) == -1\n\n\ncheck(Solution().minimumCardPickup)"}
120
61
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 nums. The array nums is beautiful if: nums.length is even. nums[i] != nums[i + 1] for all i % 2 == 0. Note that an empty array is considered beautiful. You can delete any numb...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,3,5]) == 1\n assert candidate(nums = [1,1,2,2,3,3]) == 2\n\n\ncheck(Solution().minDeletion)"}
171
62
coding
Solve the programming task below in a Python markdown code block. Consider an array of numeric strings where each string is a positive number with anywhere from $\mbox{I}$ to $10^{6}$ digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. Example ...
{"inputs": ["6\n31415926535897932384626433832795\n1\n3\n10\n3\n5\n", "8\n1\n2\n100\n12303479849857341718340192371\n3084193741082937\n3084193741082938\n111\n200\n"], "outputs": ["1\n3\n3\n5\n10\n31415926535897932384626433832795\n", "1\n2\n100\n111\n200\n3084193741082937\n3084193741082938\n12303479849857341718340192371\n...
693
266
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7. The floor() function ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,5,9]) == 10\n assert candidate(nums = [7,7,7,7,7,7,7]) == 49\n\n\ncheck(Solution().sumOfFlooredPairs)"}
118
64
coding
Solve the programming task below in a Python markdown code block. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2^{n} members and coincidentally Natalia Fan Club also has 2^{n} members. Each member of MDC is a...
{"inputs": ["1\n", "0\n", "0\n", "1\n", "11\n", "01\n", "10\n", "01\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "6\n", "2\n", "4\n", "2\n"]}
402
74
coding
Solve the programming task below in a Python markdown code block. Chef has just finished the construction of his new garden. He has sown the garden with patches of the most beautiful carpet grass he could find. He has filled it with patches of different color and now he wants to evaluate how elegant his garden is. Chef...
{"inputs": ["3\n2 2\naa\naA\n3 0\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbbaa", "3\n2 2\naa\naA\n3 3\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbaaa", "3\n2 2\naa\naA\n3 3\naba\nb`b\naba\n4 4\naabb\naabb\nbba`\nbaaa", "3\n2 2\nab\naA\n3 3\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbbaa", "3\n2 2\nab\naA\n3 3\naba\nc`b\naba\n4 0...
445
395
coding
Solve the programming task below in a Python markdown code block. Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees. There are $n$ t...
{"inputs": ["4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5\n"], "outputs": ["2\n13\n36\n33\n"]}
619
63
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a keyboard layout as shown above in the X-Y plane, where each English uppercase letter is located at some coordinate. For example, the letter 'A' is located at coordinate (0, 0), the letter 'B' is located at...
{"functional": "def check(candidate):\n assert candidate(word = \"CAKE\") == 3\n assert candidate(word = \"HAPPY\") == 6\n\n\ncheck(Solution().minimumDistance)"}
230
46
coding
Solve the programming task below in a Python markdown code block. There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N. On this sequence, Snuke can perform the following operation: - Choose K consecutive elements in the sequence. Then, replace the value of each...
{"inputs": ["3 3\n1 2 3\n", "4 3\n2 3 1 4\n", "8 3\n7 3 1 8 4 6 2 5\n"], "outputs": ["1\n", "2\n", "4\n"]}
320
66
coding
Solve the programming task below in a Python markdown code block. There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain. Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not. Constraints You can assume that: * $ -100 \leq x_1, y_1...
{"inputs": ["0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0", "0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.8224818410475855 1.0 4.0 5.0 3.0 -1.0 3.0", "0.4580529168787624 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.8224818410475855 1.0 4.0 5.0 3.0 -1.0 3.0", "0.4580529168787624 0.0 2.0 0.842157591240854 2.0 2.0 1....
349
911
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 grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical) connected group of 1's. The grid is said to be connected if we ha...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]) == 2\n assert candidate(grid = [[1,1]]) == 2\n\n\ncheck(Solution().minDays)"}
144
67
coding
Solve the programming task below in a Python markdown code block. Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ tu...
{"inputs": ["1\n8\n", "1\n2\n", "1\n0\n", "1\n124\n", "2\n2 1\n", "1\n124\n", "2\n2 1\n", "1\n150\n"], "outputs": ["8\n", "2\n", "0\n", "124", "1", "124\n", "1\n", "150\n"]}
330
100
coding
Solve the programming task below in a Python markdown code block. You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |s|). The answer to the query is the number of substrings of string s[li....
{"inputs": ["caaaba\n5\n1 1\n1 4\n2 3\n2 6\n4 5\n", "caaaba\n5\n1 1\n1 4\n1 3\n4 6\n4 5\n", "caaaba\n5\n1 1\n1 1\n2 3\n2 6\n4 5\n", "caaaba\n5\n1 1\n2 4\n1 3\n4 6\n4 5\n", "caaaba\n5\n1 1\n1 1\n3 3\n2 6\n4 5\n", "caaaba\n5\n1 1\n2 2\n1 3\n4 6\n4 5\n", "caaaba\n5\n1 1\n1 4\n2 5\n4 6\n4 5\n", "caaaba\n5\n1 1\n1 4\n2 3\n4...
409
318
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string and two indexes (`a` and `b`). Your task is to reverse the portion of that string between those two indices inclusive. ~~~if-not:fortran ``` solve("codewars",1,5) = "cawedors" -- elements at index 1 to 5 inclusi...
{"functional": "_inputs = [['codewars', 1, 5], ['codingIsFun', 2, 100], ['FunctionalProgramming', 2, 15], ['abcefghijklmnopqrstuvwxyz', 0, 20], ['abcefghijklmnopqrstuvwxyz', 5, 20]]\n_outputs = [['cawedors'], ['conuFsIgnid'], ['FuargorPlanoitcnmming'], ['vutsrqponmlkjihgfecbawxyz'], ['abcefvutsrqponmlkjihgwxyz']]\nimpo...
417
264
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and co...
{"inputs": ["1\n3 3\n2 1 2\n1 1 1\n2 1 2"], "outputs": ["10"]}
661
35
coding
Solve the programming task below in a Python markdown code block. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. -----Input----- The only line contains two integers n and k (1 ≤ n, k ≤ 10^9). -----Output----- Print the smal...
{"inputs": ["5 3\n", "1 1\n", "8 8\n", "8 8\n", "1 1\n", "1 2\n", "4 3\n", "2 2\n"], "outputs": ["6\n", "2\n", "16\n", "16", "2", "2\n", "6\n", "4\n"]}
129
86
coding
Solve the programming task below in a Python markdown code block. Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence. Constraints * $0 < n \leq 10000$ * $-1000000 \leq a_i \leq 1000000$ Input In the first line, an integ...
{"inputs": ["5\n1 1 -3 0 0", "5\n1 1 -5 0 0", "5\n13 1 5 4 17", "5\n13 1 5 7 17", "5\n13 0 5 7 17", "5\n13 0 7 7 17", "5\n23 0 7 7 17", "5\n23 0 0 7 17"], "outputs": ["-3 1 -1\n", "-5 1 -3\n", "1 17 40\n", "1 17 43\n", "0 17 42\n", "0 17 44\n", "0 23 54\n", "0 23 47\n"]}
183
199
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectiv...
{"functional": "def check(candidate):\n assert candidate(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1) == [\"B\",\"C\"] \n assert candidate(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], i...
226
152
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of those operations. Please complete t...
{"functional": "def check(candidate):\n assert candidate(A = 1, B = 10) == 10\n assert candidate(A = 3, B = 4) == 12\n\n\ncheck(Solution().multiply)"}
85
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the value of the bitwise OR of the sum of all possible subsequences in the array. A subsequence is a sequence that can be derived from another sequence by removing zero or more elem...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,0,3]) == 7\n assert candidate(nums = [0,0,0]) == 0\n\n\ncheck(Solution().subsequenceSumOr)"}
103
55
coding
Solve the programming task below in a Python markdown code block. A holiday weekend is coming up, and Hotel Bytelandia needs to find out if it has enough rooms to accommodate all potential guests. A number of guests have made reservations. Each reservation consists of an arrival time, and a departure time. The hotel ma...
{"inputs": ["3\n3\n1 2 3\n4 5 6\n5\n1 2 3 4 2\n2 3 4 5 4\n7\n13 6 5 8 2 9 12\n19 5 6 9 9 11 15", "3\n3\n1 2 0\n4 5 6\n5\n1 2 3 4 2\n2 6 4 5 4\n7\n13 6 5 8 2 9 12\n19 5 6 9 9 11 15", "3\n3\n0 2 3\n4 5 6\n5\n1 2 3 4 2\n2 3 2 8 6\n7\n13 6 5 8 2 9 12\n19 4 6 9 9 22 15", "3\n3\n1 2 3\n4 5 7\n5\n1 2 3 4 1\n2 4 7 5 6\n7\n13 6...
358
665
coding
Solve the programming task below in a Python markdown code block. Concatenation of two integers is obtained as follows: First, convert both integers to strings. Then concatenate both strings into one and convert this concatenated string back to integer. For example, concatenation of 6 and 7 is CONC(6, 7) = 67, concate...
{"inputs": ["4\n2 10 52\n2 5\n3 58 100\n4 2 3\n4 100 1000\n1 10 100 1000\n5 28 102\n3 2 1 9 10\n"], "outputs": ["3\n0\n2\n11\n"]}
681
93
coding
Solve the programming task below in a Python markdown code block. Complete the function that takes two integers (`a, b`, where `a < b`) and return an array of all integers between the input parameters, **including** them. For example: ``` a = 1 b = 4 --> [1, 2, 3, 4] ``` Also feel free to reuse/extend the following st...
{"functional": "_inputs = [[1, 4], [-2, 2], [-10, 10], [5, 100]]\n_outputs = [[[1, 2, 3, 4]], [[-2, -1, 0, 1, 2]], [[-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 3...
99
650
coding
Solve the programming task below in a Python markdown code block. An array is called `zero-balanced` if its elements sum to `0` and for each positive element `n`, there exists another element that is the negative of `n`. Write a function named `ìsZeroBalanced` that returns `true` if its argument is `zero-balanced` arra...
{"functional": "_inputs = [[[3]], [[-3]], [[0, 0, 0, 0, 0, 0]], [[0, 1, -1]], [[]], [[3, -2, -1]], [[0]], [[1, 1, -2]], [[-1, 1, -2, 2, -2, -2, -4, 4]], [[0, 0, 0, 0, 0]]]\n_outputs = [[False], [False], [True], [True], [False], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ...
119
277
coding
Solve the programming task below in a Python markdown code block. You have a string $s$ of length $n$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that...
{"inputs": ["1\n9\n>>>>>>>><\n", "1\n9\n>>>>>>>><\n", "1\n9\n<>>>>>>>>\n", "3\n2\n<>\n3\n><<\n1\n>\n", "3\n2\n<>\n3\n><<\n1\n>\n", "3\n2\n><\n3\n><<\n1\n>\n", "3\n2\n><\n3\n<<>\n1\n>\n", "3\n2\n<>\n3\n<<>\n1\n>\n"], "outputs": ["0\n", "0\n", "1\n", "1\n0\n0\n", "1\n0\n0\n", "0\n0\n0\n", "0\n1\n0\n", "1\n1\n0\n"]}
486
181
coding
Solve the programming task below in a Python markdown code block. You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. -----Input----- The first line contains posit...
{"inputs": ["2\n3 3\n", "2\n3 3\n", "3\n5 6 5\n", "3\n2 1 1\n", "3\n1 1 2\n", "3\n1 1 1\n", "3\n2 1 1\n", "3\n1 1 2\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
225
114
coding
Solve the programming task below in a Python markdown code block. You have $n$ coins, each of the same value of $1$. Distribute them into packets such that any amount $x$ ($1 \leq x \leq n$) can be formed using some (possibly one or all) number of these packets. Each packet may only be used entirely or not used at al...
{"inputs": ["6\n", "2\n", "1\n", "3\n", "8\n", "8\n", "1\n", "3\n"], "outputs": ["3", "2", "1", "2", "4", "4\n", "1\n", "2\n"]}
380
65
coding
Solve the programming task below in a Python markdown code block. ### Combine strings function ```if:coffeescript,haskell,javascript Create a function named `combineNames` that accepts two parameters (first and last name). The function should return the full name. ``` ```if:python,ruby Create a function named (`combine...
{"functional": "_inputs = [['James', 'Stevens'], ['Davy', 'Back'], ['Arthur', 'Dent']]\n_outputs = [['James Stevens'], ['Davy Back'], ['Arthur Dent']]\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 is...
178
184
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n that consists of exactly 3 digits. We call the number n fascinating if, after the following modification, the resulting number contains all the digits from 1 to 9 exactly once and does not c...
{"functional": "def check(candidate):\n assert candidate(n = 192) == True\n assert candidate(n = 100) == False\n\n\ncheck(Solution().isFascinating)"}
162
47
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$, consisting of $n$ positive integers. Let's call a concatenation of numbers $x$ and $y$ the number that is obtained by writing down numbers $x$ and $y$ one right after another without changing the order. For example, a concate...
{"inputs": ["4 2\n2 78 4 2\n", "4 2\n1 78 4 2\n", "4 2\n2 78 4 10\n", "4 4\n1 130 4 2\n", "4 2\n1 130 4 2\n", "4 2\n2 78 4 10\n", "5 2\n3 7 19 3 3\n", "1 2\n1000000000\n"], "outputs": ["12\n", "9\n", "12\n", "3\n", "9\n", "12", "0\n", "0\n"]}
497
168
coding
Solve the programming task below in a Python markdown code block. You are given n points on a plane. All points are different. Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC. The groups of three points are considered unordered, that is, if point B is the m...
{"inputs": ["3\n3 3\n1 2\n1 1\n", "3\n3 3\n0 2\n1 1\n", "3\n1 1\n4 2\n3 3\n", "3\n2 3\n0 2\n1 1\n", "3\n1 1\n4 3\n3 3\n", "3\n2 3\n0 2\n2 1\n", "3\n1 1\n5 2\n3 3\n", "3\n2 3\n0 0\n2 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
237
166
coding
Solve the programming task below in a Python markdown code block. By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the col...
{"inputs": ["100 1\n+ 6\n", "100 1\n+ 51\n", "100 1\n+ 10\n", "101 1\n+ 51\n", "100 1\n+ 16\n", "101 1\n+ 74\n", "100 1\n+ 63\n", "100 1\n+ 25\n"], "outputs": ["Success\n", "Success\n", "Success\n", "Success\n", "Success\n", "Success\n", "Success\n", "Success\n"]}
743
141
coding
Solve the programming task below in a Python markdown code block. In Python, a string of text can be aligned left, right and center. .ljust(width) This method returns a left aligned string of length width. >>> width = 20 >>> print 'HackerRank'.ljust(width,'-') HackerRank---------- .center(width) This method retu...
{"inputs": ["5\n"], "outputs": [" H \n HHH \n HHHHH \n HHHHHHH \nHHHHHHHHH\n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH ...
436
258
coding
Solve the programming task below in a Python markdown code block. We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left. For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are...
{"inputs": ["4", "5", "2", "3", "6", "1", "73", "22"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]}
286
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of s...
{"functional": "def check(candidate):\n assert candidate(s = \"abacaba\") == 4\n assert candidate(s = \"ssssss\") == 6\n\n\ncheck(Solution().partitionString)"}
111
47
coding
Solve the programming task below in a Python markdown code block. A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. Fo...
{"inputs": ["3\n1\n4\n3\n", "0\n0\n0\n0\n", "1\n2\n3\n4\n", "0\n0\n1\n0\n", "4\n3\n2\n1\n", "1\n2\n2\n1\n", "2\n0\n2\n0\n", "1\n0\n1\n1\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n"]}
422
118
coding
Solve the programming task below in a Python markdown code block. Write a function that takes a string which has integers inside it separated by spaces, and your task is to convert each integer in the string into an integer and return their sum. ### Example ```python summy("1 2 3") ==> 6 ``` Good luck! Also feel fre...
{"functional": "_inputs = [['1 2 3'], ['1 2 3 4'], ['1 2 3 4 5'], ['10 10'], ['0 0']]\n_outputs = [[6], [10], [15], [20], [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...
94
205
coding
Solve the programming task below in a Python markdown code block. You are given a chessboard of size NxN. There is a white knight and several black pawns located on the board. The knight can move similarly to the normal knight in the game of chess; however it can only move towards the right of the board (see the below ...
{"inputs": ["1\n5\nK....\n..P..\n.P...\n...P.\n....."], "outputs": ["2"]}
284
31
coding
Solve the programming task below in a Python markdown code block. Indian National Olympiad in Informatics 2013 Calvin wakes up early one morning and finds that all his friends in the hostel are asleep. To amuse himself, he decides to play the following game : he draws a sequence of N squares on the ground, numbered 1 t...
{"inputs": ["and output corresponding to the example above.\nSample input\n5 2\n5 3 -2 1 1\nSample output\n11\nNote : Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous out...
650
84
coding
Solve the programming task below in a Python markdown code block. ----- CHEF N TIMINGS ----- One day chef was working with some random numbers. Then he found something interesting. He observed that no 240, 567, 9999 and 122 and called these numbers nice as the digits in numbers are in increasing order. Also he called ...
{"inputs": ["1\n132"], "outputs": ["129"]}
244
18
coding
Solve the programming task below in a Python markdown code block. Omkar and Akmar are playing a game on a circular board with n (2 ≤ n ≤ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 ≤ i ≤ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty. Omkar...
{"inputs": ["5\n", "4\n", "7\n", "9\n", "3\n", "6\n", "8\n", "2\n"], "outputs": ["240\n", "56\n", "10416\n", "768960\n", "12\n", "1872\n", "109536\n", "\n4\n"]}
452
92
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d]....
{"functional": "def check(candidate):\n assert candidate(num = \"132\", change = [9,8,5,0,3,6,4,2,6,8]) == \"832\"\n assert candidate(num = \"021\", change = [9,4,3,5,7,2,1,9,0,6]) == \"934\"\n assert candidate(num = \"5\", change = [1,4,7,5,3,2,5,6,9,4]) == \"5\"\n\n\ncheck(Solution().maximumNumber)"}
183
135
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Russian here Polo, the Penguin, likes the XOR operation. Please read NOTE if you are not familiar with XOR operation. XOR-sum of a list of numbers is the result of XOR-ing all of them. XOR-sum of (A[1] XOR A[2] XOR ... XOR A...
{"inputs": ["1\n2\n1 2", "1\n2\n1 2"], "outputs": ["6", "6"]}
606
30
coding
Solve the programming task below in a Python markdown code block. Given a sequence of numbers a1, a2, a3, ..., an, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a contiquous subsequence. Input The input consists of multiple datasets. Each data set...
{"inputs": ["7\n-5\n0\n6\n0\n6\n-6\n0\n9\n2\n2\n0\n2\n-4\n-1\n1\n1\n6\n2\n0\n-3\n4\n3\n0000\n-200\n397\n0", "7\n-5\n0\n6\n4\n9\n-6\n0\n13\n1\n2\n1\n2\n-2\n-1\n1\n2\n6\n2\n1\n-3\n2\n3\n0000\n-200\n201\n0", "7\n-5\n0\n6\n4\n6\n-6\n0\n13\n1\n2\n1\n2\n-2\n-1\n1\n2\n6\n2\n1\n-3\n2\n3\n0000\n-200\n201\n0", "7\n-5\n0\n6\n4\n6...
234
653
coding
Solve the programming task below in a Python markdown code block. An n × n table a is defined as follows: The first row and the first column contain ones, that is: a_{i}, 1 = a_{1, }i = 1 for all i = 1, 2, ..., n. Each of the remaining numbers in the table is equal to the sum of the number above it and the number t...
{"inputs": ["1\n", "5\n", "2\n", "3\n", "4\n", "6\n", "7\n", "9\n"], "outputs": ["1", "70", "2", "6", "20", "252", "924", "12870"]}
345
72
coding
Solve the programming task below in a Python markdown code block. You're about to go on a trip around the world! On this trip you're bringing your trusted backpack, that anything fits into. The bad news is that the airline has informed you, that your luggage cannot exceed a certain amount of weight. To make sure you'r...
{"functional": "_inputs = [[[15, 10, 9, 5], [1, 5, 3, 4], 8], [[20, 5, 10, 40, 15, 25], [1, 2, 3, 8, 7, 4], 10], [[19, 8, 6, 20, 3, 16], [8, 2, 3, 10, 1, 5], 17], [[100, 5, 16, 18, 50], [25, 1, 3, 2, 15], 14]]\n_outputs = [[29], [60], [46], [39]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) ...
300
324
coding
Solve the programming task below in a Python markdown code block. Chef has started working at the candy store. The store has 100 chocolates in total. Chef’s daily goal is to sell X chocolates. For each chocolate sold, he will get 1 rupee. However, if Chef exceeds his daily goal, he gets 2 rupees per chocolate for eac...
{"inputs": ["4\n3 1\n5 5\n4 7\n2 3\n"], "outputs": ["1\n5\n10\n4\n"]}
456
37
coding
Solve the programming task below in a Python markdown code block. Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y v...
{"inputs": ["4 4 0\n2 1 2\n", "5 6 1\n2 7 2\n", "3 3 3\n2 2 2\n", "0 0 0\n0 0 0\n", "0 0 0\n0 0 1\n", "0 1 0\n0 0 0\n", "1 0 0\n1 0 0\n", "2 2 1\n1 1 2\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n"]}
366
150
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer st...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 2) == 3\n assert candidate(n = 5, k = 5) == 1\n assert candidate(n = 20, k = 11) == 647427950\n\n\ncheck(Solution().rearrangeSticks)"}
177
83
coding
Solve the programming task below in a Python markdown code block. You are given a sequence $A_1, A_2, \ldots, A_N$. You may perform the following operation an arbitrary number of times (including zero): choose two adjacent elements of this sequence, i.e. $A_i$, $A_{i+1}$ for some valid $i$, and swap them. However, for ...
{"inputs": ["2\n4\n2 1 4 3\n4\n7 6 3 2"], "outputs": ["30\n39"]}
498
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two non-increasing 0-indexed integer arrays nums1​​​​​​ and nums2​​​​​​. A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]....
{"functional": "def check(candidate):\n assert candidate(nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]) == 2\n assert candidate(nums1 = [2,2,2], nums2 = [10,10,1]) == 1\n assert candidate(nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]) == 2\n\n\ncheck(Solution().maxDistance)"}
188
131
coding
Solve the programming task below in a Python markdown code block. Jump is a simple one-player game: You are initially at the first cell of an array of cells containing non-negative integers; At each step you can jump ahead in the array as far as the integer at the current cell, or any smaller number of cells. You win...
{"functional": "_inputs = [[[11, 6, 11, 0, 2, 1, 14, 3, 7, 6, 2, 1, 10, 6, 0, 0, 8, 10, 2, 12, 13, 11, 14, 6, 1, 4, 14, 3, 10, 4, 14, 2, 3, 10, 8, 13, 14, 8, 2, 13, 11, 14, 0, 1, 6, 2, 1, 6, 8, 2, 0, 12, 4, 9, 2, 6, 8, 14, 4, 14, 4, 10, 8, 7, 12, 11, 0, 3, 8, 0, 13, 9, 9, 11, 10, 13, 12, 1, 0, 10, 14, 6, 1, 11, 7, 8, 6...
424
684
coding
Solve the programming task below in a Python markdown code block. A tennis tournament is about to take place with $N$ players participating in it. Every player plays with every other player exactly once and there are no ties. That is, every match has a winner and a loser. With Naman's birthday approaching, he wants to...
{"inputs": ["2\n3\n2"], "outputs": ["YES\n010\n001\n100\nNO"]}
455
30
coding
Solve the programming task below in a Python markdown code block. Chef Zidane likes the number 9. He has a number N, and he wants to turn it into a multiple of 9. He cannot add or remove digits, and he can only change one digit at a time. The only allowed operation is to increment or decrement a digit by one, and doing...
{"inputs": ["4\n1989\n86236\n90210\n99999999999999999999999999999999999999988"], "outputs": ["0\n2\n3\n2"]}
456
77
coding
Solve the programming task below in a Python markdown code block. The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ... Given is a string S representing the weather in the town today. Predict the weather tomorrow. Constraints * S is `Sunny`, `Clou...
{"inputs": ["Rainy", "Sunny"], "outputs": ["Sunny", "Cloudy"]}
141
22
coding
Solve the programming task below in a Python markdown code block. There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some numb...
{"inputs": ["1\n167038488\n", "1\n291933570\n", "1\n329706911\n", "1\n100414917\n", "1\n372302247\n", "1\n184950274\n", "3\n638631659\n929648227\n848163730\n", "3\n123456789\n100000001\n100123456\n"], "outputs": ["1\n", "2\n", "3\n", "1\n", "3\n", "1\n", "5\n2\n0\n", "7\n000\n012\n"]}
524
202
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of positive integers a1, a2, ..., an. Find all such indices i, that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one). Input The first line contains the integer n (2 ≤ ...
{"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n4 5\n", "2\n4 2\n", "2\n0 0\n", "2\n0 2\n", "2\n1 0\n", "2\n7 5\n"], "outputs": ["0\n\n", "2\n1 2\n", "0\n\n", "0\n\n", "2\n1 2\n", "0\n\n", "0\n\n", "0\n\n"]}
236
116
coding
Solve the programming task below in a Python markdown code block. You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$. It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to g...
{"inputs": ["1 2\n", "6 2\n", "5 2\n", "5 11\n", "6 16\n", "5 29\n", "1 30\n", "5 29\n"], "outputs": ["2\n", "1\n", "1\n", "3", "3", "6", "30", "6\n"]}
328
88
coding
Solve the programming task below in a Python markdown code block. Pied Piper is a startup company trying to build a new Internet called Pipernet. Currently, they have $A$ users and they gain $X$ users everyday. There is also another company called Hooli, which has currently $B$ users and gains $Y$ users everyday. Which...
{"inputs": ["3\n3 10 15 5 10 100\n12 15 18\n3 10 15 5 10 100\n5 5 10\n4 40 80 30 30 100\n100 100 100 100"], "outputs": ["4\nRIP\n1"]}
746
101
coding
Solve the programming task below in a Python markdown code block. Some time ago Lesha found an entertaining string $s$ consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows. Lesha chooses an arbitrary (possibly zero)...
{"inputs": ["g\n", "g\n", "h\n", "tt\n", "go\n", "tt\n", "go\n", "ut\n"], "outputs": ["1 g\n", "1 g\n", "1 h\n", "0 \n1 t\n", "2 go\n1 o\n", "0 \n1 t\n", "2 go\n1 o\n", "2 ut\n1 t\n"]}
690
93
coding
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. On the occasion of the birthday, Chef bought a large circular cake and decorated it with k candles placed equally spaced around the circumference of the cake, i.e. the leng...
{"inputs": ["3\n6 1 3\n6 1 4\n10 1 5"], "outputs": ["1\n0\n3"]}
407
35
coding
Solve the programming task below in a Python markdown code block. Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon a...
{"inputs": ["1\n1\n", "1\n2\n", "1\n2\n", "1\n1\n", "4\n1 1 1 1\n", "4\n1 2 1 2\n", "4\n1 1 2 1\n", "4\n2 2 1 2\n"], "outputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "3\n1 4\n2 2\n4 1\n", "0\n", "2\n1 3\n3 1\n", "2\n1 3\n3 1\n"]}
581
154
coding
Solve the programming task below in a Python markdown code block. Given are a positive integer N and a string S of length N consisting of lowercase English letters. Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T. -----Con...
{"inputs": ["1\n{", "1\ny", "1\n|", "1\n}", "1\n~", "1\n\u007f", "1\nz", "1\nz\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No", "No\n"]}
169
81
coding
Solve the programming task below in a Python markdown code block. You are given a simple connected undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Edge i connects Vertex a_i and b_i bidirectionally. Determine if three circuits (see Notes) can...
{"inputs": ["5 3\n1 2\n2 3\n3 1", "5 3\n1 2\n2 3\n5 1", "3 3\n2 2\n2 3\n3 1", "5 3\n1 2\n2 3\n2 1", "5 3\n1 2\n3 3\n5 1", "5 1\n1 2\n3 3\n5 1", "3 3\n1 2\n2 3\n3 1", "7 9\n1 2\n1 3\n2 3\n1 4\n1 5\n4 5\n1 5\n1 7\n6 7"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No", "No\n"]}
404
197
coding
Solve the programming task below in a Python markdown code block. This is the first step to understanding FizzBuzz. Your inputs: a positive integer, n, greater than or equal to one. n is provided, you have NO CONTROL over its value. Your expected output is an array of positive integers from 1 to n (inclusive). You...
{"functional": "_inputs = [[1], [2], [3], [4], [5]]\n_outputs = [[[1]], [[1, 2]], [[1, 2, 3]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5]]]\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, tu...
109
209
coding
Solve the programming task below in a Python markdown code block. Given a certain integer ```n, n > 0```and a number of partitions, ```k, k > 0```; we want to know the partition which has the maximum or minimum product of its terms. The function ```find_spec_partition() ```, will receive three arguments, ```n```, ...
{"functional": "_inputs = [[10, 4, 'max'], [10, 4, 'min']]\n_outputs = [[[3, 3, 2, 2]], [[7, 1, 1, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) ...
458
193
coding
Solve the programming task below in a Python markdown code block. The chef is playing a game of long distance. Chef has a number K and he wants to find the longest distance between the index of the first and the last occurrence of K in a given array of N numbers. -----Input:----- - First-line will contain $T$, the num...
{"inputs": ["2\n2 6\n2 3 4 2 1 6\n4 6\n2 3 4 2 1 6"], "outputs": ["3\n0"]}
318
46
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Reversing an integer means to reverse all its digits. For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained. Given an integer num, reverse num to get reversed1, then...
{"functional": "def check(candidate):\n assert candidate(num = 526) == True\n assert candidate(num = 1800) == False\n assert candidate(num = 0) == True\n\n\ncheck(Solution().isSameAfterReversals)"}
134
61
coding
Solve the programming task below in a Python markdown code block. One important contest will take place on the most famous programming platform (Topforces) very soon! The authors have a pool of $n$ problems and should choose at most three of them into this contest. The prettiness of the $i$-th problem is $a_i$. The au...
{"inputs": ["1\n5\n2 6 10 30 30\n", "1\n5\n2 6 11 30 30\n", "1\n5\n6 7 15 30 30\n", "1\n5\n2 6 10 41 30\n", "1\n5\n30 30 27 7 6\n", "1\n5\n2 9 10 41 30\n", "1\n5\n30 55 27 7 6\n", "1\n5\n30 30 15 10 6\n"], "outputs": ["30\n", "41\n", "37\n", "71\n", "64\n", "80\n", "112\n", "31\n"]}
556
200
coding
Solve the programming task below in a Python markdown code block. You are given a weighted undirected graph consisting of n$n$ nodes and m$m$ edges. The nodes are numbered from 1$1$ to n$n$. The graph does not contain any multiple edges or self loops. A walk W$W$ on the graph is a sequence of vertices (with repetitions...
{"inputs": ["3 3\n1 2 1\n2 3 2\n3 1 3\n3\n1\n2\n3"], "outputs": ["2\n10\n36"]}
712
46
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array colors, in which there are three colors: 1, 2 and 3. You are also given some queries. Each query consists of two integers i and c, return the shortest distance between the given index i and the ...
{"functional": "def check(candidate):\n assert candidate(colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]]) == [3,0,3]\n assert candidate(colors = [1,2], queries = [[0,3]]) == [-1]\n\n\ncheck(Solution().shortestDistanceColor)"}
123
91
coding
Solve the programming task below in a Python markdown code block. Let's call the set of positive integers $S$ correct if the following two conditions are met: $S \subseteq \{1, 2, \dots, n\}$; if $a \in S$ and $b \in S$, then $|a-b| \neq x$ and $|a-b| \neq y$. For the given values $n$, $x$, and $y$, you have to find...
{"inputs": ["3 6 8\n", "3 8 5\n", "9 8 3\n", "10 2 5\n", "21 4 6\n", "21 7 9\n", "3 4 14\n", "5 20 3\n"], "outputs": ["3\n", "3\n", "5\n", "5\n", "9\n", "12\n", "3\n", "3\n"]}
256
108
coding
Solve the programming task below in a Python markdown code block. Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, a...
{"inputs": ["2", "4", "3", "6", "7", "5", "8", "1"], "outputs": ["ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n"]}
168
62
coding
Solve the programming task below in a Python markdown code block. According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the...
{"inputs": ["1 1\n2\n", "3 3\n000\n011\n222\n", "3 3\n001\n000\n111\n", "3 3\n001\n011\n222\n", "3 3\n001\n000\n110\n", "3 3\n011\n000\n110\n", "3 3\n011\n010\n110\n", "3 3\n011\n010\n010\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
272
172
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`. For example: ``` solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit s...
{"functional": "_inputs = [[79320], [99004], [99088], [99737], [29652], [100], [48], [521], [1], [2], [3], [39188], [5], [10], [1000], [10000], [999999999992], [59195], [19930], [110], [1199], [120], [18], [2090], [72694]]\n_outputs = [[78999], [98999], [98999], [98999], [28999], [99], [48], [499], [1], [2], [3], [3899...
177
433
coding
Solve the programming task below in a Python markdown code block. Alice and Bob play ping-pong with simplified rules. During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternatel...
{"inputs": ["1\n85 4\n", "1\n85 50\n", "1\n85 91\n", "1\n85 37\n", "1\n99 531\n", "1\n99 750\n", "1\n99 141\n", "1\n99 107\n"], "outputs": ["84 4\n", "84 50\n", "84 91\n", "84 37\n", "98 531\n", "98 750\n", "98 141\n", "98 107\n"]}
715
156
coding
Solve the programming task below in a Python markdown code block. There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of info...
{"inputs": ["000 0", "100 0", "4 3\n2 1 1\n2 3 3\n3 4 2", "4 3\n1 1 1\n2 3 3\n3 4 2", "4 3\n1 1 1\n2 3 3\n4 4 2", "4 3\n1 1 1\n2 3 3\n4 4 1", "3 3\n1 2 1\n1 3 1\n1 3 5", "3 3\n1 2 1\n1 3 1\n1 3 2"], "outputs": ["Yes\n", "Yes", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
574
189
coding
Solve the programming task below in a Python markdown code block. Two moving objects A and B are moving accross the same orbit (those can be anything: two planets, two satellites, two spaceships,two flying saucers, or spiderman with batman if you prefer). If the two objects start to move from the same point and the orb...
{"functional": "_inputs = [[12, 15, 5], [12, -15, 6], [-14, -5, 5], [23, 16, 5], [0, 0, 7], [12, 0, 10], [0, 15, 17], [-24, 0, 10], [0, -18, 14], [32, -14, 14]]\n_outputs = [['60.00'], ['6.67'], ['7.78'], ['52.57'], ['0.00'], ['12.00'], ['15.00'], ['24.00'], ['18.00'], ['9.74']]\nimport math\ndef _deep_eq(a, b, tol=1e-...
234
323
coding
Solve the programming task below in a Python markdown code block. You're a statistics professor and the deadline for submitting your students' grades is tonight at midnight. Each student's grade is determined by their mean score across all of the tests they took this semester. You've decided to automate grade calculat...
{"functional": "_inputs = [[[92, 94, 99]], [[50, 60, 70, 80, 90]], [[50, 55]]]\n_outputs = [['A'], ['C'], ['F']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n i...
284
198
coding
Solve the programming task below in a Python markdown code block. One day, Twilight Sparkle is interested in how to sort a sequence of integers a_1, a_2, ..., a_{n} in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence ...
{"inputs": ["2\n2 1\n", "2\n1 2\n", "2\n1 1\n", "2\n1 1\n", "2\n1 0\n", "2\n2 2\n", "2\n2 0\n", "2\n0 0\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n"]}
263
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movemen...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 10\n assert candidate(n = 2) == 20\n assert candidate(n = 3131) == 136006598\n\n\ncheck(Solution().knightDialer)"}
217
71
coding
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"]}
691
213
coding
Solve the programming task below in a Python markdown code block. There are n integers b_1, b_2, ..., b_{n} written in a row. For all i from 1 to n, values a_{i} are defined by the crows performing the following procedure: The crow sets a_{i} initially 0. The crow then adds b_{i} to a_{i}, subtracts b_{i} + 1, adds...
{"inputs": ["5\n7 -8 8 0 2\n", "5\n2 0 0 1 12\n", "5\n7 -8 6 0 2\n", "5\n3 0 0 1 12\n", "5\n3 0 0 1 10\n", "5\n3 0 1 1 10\n", "5\n4 0 1 1 10\n", "5\n6 -4 8 -2 3\n"], "outputs": ["-1 0 8 2 2\n", "2 0 1 13 12\n", "-1 -2 6 2 2\n", "3 0 1 13 12\n", "3 0 1 11 10\n", "3 1 2 11 10\n", "4 1 2 11 10\n", "2 4 6 1 3 \n"]}
550
231
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the un...
{"functional": "def check(candidate):\n assert candidate(times = [[1,4],[2,3],[4,6]], targetFriend = 1) == 1\n assert candidate(times = [[3,10],[1,5],[2,6]], targetFriend = 0) == 2\n\n\ncheck(Solution().smallestChair)"}
240
77
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. Chef is playing a game with his childhood friend. He gave his friend a list of N numbers named $a_1, a_2 .... a_N$ (Note: All numbers are unique). Adjust the numbers in the following order: $(i)$ swap every alternate number with it's succeeding number (...
{"inputs": ["1\n10\n5 15 1 66 55 32 40 22 34 11\n38"], "outputs": ["35 41"]}
523
50
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven ...
{"inputs": ["3\n2\n5\n4\n"], "outputs": ["1 3\n4 6 7 9 10\n2 3 5 6\n"]}
448
41
coding
Solve the programming task below in a Python markdown code block. Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals. -----Input----- The first line contains a single integer N. The next N lines denote the matrix's rows, with each line containing N space-separated i...
{"inputs": ["3\n11 2 4\n4 5 6\n10 8 -12"], "outputs": ["15"]}
218
34
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes: At the first minute, color any arbit...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 1\n assert candidate(n = 2) == 5\n\n\ncheck(Solution().coloredCells)"}
148
44
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not. Given a string n that represents a positi...
{"functional": "def check(candidate):\n assert candidate(n = \"32\") == 3\n assert candidate(n = \"82734\") == 8\n assert candidate(n = \"27346209830709182346\") == 9\n\n\ncheck(Solution().minPartitions)"}
135
80
coding
Solve the programming task below in a Python markdown code block. Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a s...
{"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n0\n", "2\n1 2\n", "2\n1 2\n", "2\n3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
676
92
coding
Solve the programming task below in a Python markdown code block. A string $s$ of length $n$, consisting of lowercase letters of the English alphabet, is given. You must choose some number $k$ between $0$ and $n$. Then, you select $k$ characters of $s$ and permute them however you want. In this process, the positions ...
{"inputs": ["1\n20\naaaaaaaaaaaaaaaaaqwq\n", "1\n20\naaaaaaaaaaaaaaaaaqwq\n", "1\n20\naaaaaaabaaaaaaaaaqwq\n", "1\n20\nabaaaaabaaaaaaaaaqwq\n", "1\n20\nqwqaaaaaaaaabaaaaaba\n", "1\n20\nqwqaaaaabaaabaaaaaba\n", "1\n20\nabaaaaabaaabaaaaaqwq\n", "1\n20\nqwqaaaaaaaaabaaaabba\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "9\...
569
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums ar...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1]) == [1,2,1,1,2,1]\n assert candidate(nums = [1,3,2,1]) == [1,3,2,1,1,3,2,1]\n\n\ncheck(Solution().getConcatenation)"}
120
81