task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a string $S$ with length $N$. You may perform the following operation any number of times: choose a non-empty substring of $S$ (possib...
{"inputs": ["4\n6\ncabbac\n7\nacabbad\n18\nfbedfcbdaebaaceeba\n21\nyourcrushlovesyouback"], "outputs": ["YES\nNO\nYES\nNO"]}
483
53
coding
Solve the programming task below in a Python markdown code block. # Introduction and Warm-up (Highly recommended) # [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays) ___ # Task **_Given_** an *array/list [] of integers* , **_Find_** **_The maximum difference_** ...
{"functional": "_inputs = [[[13, 10, 2, 9, 5]], [[13, 3, 5]], [[24, 299, 131, 14, 26, 25]], [[-3, -27, -4, -2]], [[-7, -42, -809, -14, -12]], [[12, -5, -7, 0, 290]], [[-54, 37, 0, 64, -15, 640, 0]], [[130, 30, 50]], [[1, 1, 1]], [[-1, -1, -1]]]\n_outputs = [[4], [8], [168], [23], [767], [278], [576], [80], [0], [0]]\ni...
657
354
coding
Solve the programming task below in a Python markdown code block. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is...
{"inputs": ["1\n0\n", "1\n0\n", "3\n0 1 2\n", "3\n2 1 0\n", "3\n1 2 0\n", "3\n2 1 0\n", "3\n1 2 0\n", "3\n0 1 2\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "1\n", "3\n", "1\n", "3\n"]}
341
110
coding
Solve the programming task below in a Python markdown code block. Chef has closed his restaurant and decided to run a fruit stand instead. His signature dish is a fruit chaat consisting of 2 bananas and 1 apple. He currently has X bananas and Y apples. How many chaats can he make with the fruits he currently has? ---...
{"inputs": ["3\n72 50\n38 93\n51 4"], "outputs": ["36\n19\n4\n"]}
281
36
coding
Solve the programming task below in a Python markdown code block. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 <...
{"inputs": ["3\n0 2 3", "3\n2 3 8", "3\n0 0 8", "3\n0 2 4", "3\n3 3 8", "3\n0 2 8", "3\n6 3 8", "3\n0 4 8"], "outputs": ["2\n", "6\n", "1\n", "2\n", "6\n", "2\n", "6\n", "2\n"]}
435
110
coding
Solve the programming task below in a Python markdown code block. You will receive an uncertain amount of integers in a certain order ```k1, k2, ..., kn```. You form a new number of n digits in the following way: you take one of the possible digits of the first given number, ```k1```, then the same with the given numb...
{"functional": "_inputs = [[23, 17, 89], [22, 22, 22, 22], [230, 15, 8]]\n_outputs = [[[8, 218, 379, 2388]], [[1, 2222]], [[4, 218, 358, 1152]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstan...
535
235
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last i...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,1,4]) == True\n assert candidate(nums = [3,2,1,0,4]) == False\n\n\ncheck(Solution().canJump)"}
96
57
coding
Solve the programming task below in a Python markdown code block. Dothraki are planning an attack to usurp King Robert's throne. King Robert learns of this conspiracy from Raven and plans to lock the single door through which the enemy can enter his kingdom. But, to lock the door he needs a key that is an anagram of a...
{"inputs": ["aaabbbb\n", "cdcdcdcdeeeef\n", "cdefghmnopqrstuvw\n"], "outputs": ["YES\n", "YES\n", "NO\n"]}
388
42
coding
Solve the programming task below in a Python markdown code block. One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by $n$ machines, and the power of the $i$-th machine is $a_i$. ...
{"inputs": ["2\n42 9\n", "2\n42 9\n", "2\n74 1\n", "2\n2 10\n", "2\n2 12\n", "2\n1 12\n", "2\n75 7\n", "2\n42 7\n"], "outputs": ["39\n", "39", "39\n", "9\n", "10\n", "7\n", "46\n", "35\n"]}
595
115
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Consider a function that implements an algorithm similar to Binary Search. The function has two input parameters: sequence is a sequence of integers, and target is an integer value. The purpose of the function is to f...
{"functional": "def check(candidate):\n assert candidate(nums = [7]) == 1\n assert candidate(nums = [-1,5,2]) == 1\n\n\ncheck(Solution().binarySearchableNumbers)"}
264
49
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["3\n2\n3\n4"], "outputs": ["1121\n1222\n112131\n122232\n132333\n11213141\n12223242\n13233343\n14243444"]}
241
83
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a lower case string and your task will be to remove `k` characters from that string using the following rule: ```Python - first remove all letter 'a', followed by letter 'b', then 'c', etc... - remove the leftmost characte...
{"functional": "_inputs = [['abracadabra', 0], ['abracadabra', 1], ['abracadabra', 2], ['abracadabra', 6], ['abracadabra', 8], ['abracadabra', 50], ['hxehmvkybeklnj', 5], ['cccaabababaccbc', 3], ['cccaabababaccbc', 9], ['u', 1], ['back', 3]]\n_outputs = [['abracadabra'], ['bracadabra'], ['brcadabra'], ['rcdbr'], ['rdr'...
308
303
coding
Solve the programming task below in a Python markdown code block. # Task A range-collapse representation of an array of integers looks like this: `"1,3-6,8"`, where `3-6` denotes the range from `3-6`, i.e. `[3,4,5,6]`. Hence `"1,3-6,8"` = `[1,3,4,5,6,8]`. Some other range-collapse representations of `[1,3,4,5,6,8]...
{"functional": "_inputs = [[[1, 3, 4, 5, 6, 8]], [[1, 2, 3]], [[11, 43, 66, 123]], [[3, 4, 5, 8, 9, 10, 11, 23, 43, 66, 67]]]\n_outputs = [[8], [4], [1], [64]]\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...
390
244
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).   Please complete the following python code precisely: ```python class Solution: def countOdds(self, ...
{"functional": "def check(candidate):\n assert candidate(low = 3, high = 7) == 3\n assert candidate(low = 8, high = 10) == 1\n\n\ncheck(Solution().countOdds)"}
75
55
coding
Solve the programming task below in a Python markdown code block. Slime has a sequence of positive integers $a_1, a_2, \ldots, a_n$. In one operation Orac can choose an arbitrary subsegment $[l \ldots r]$ of this sequence and replace all values $a_l, a_{l + 1}, \ldots, a_r$ to the value of median of $\{a_l, a_{l + 1},...
{"inputs": ["1\n5 2\n2 1 5 1 1\n", "1\n5 2\n2 1 5 1 1\n", "1\n5 2\n4 1 5 1 1\n", "1\n5 2\n4 1 5 2 1\n", "1\n6 3\n3 1 1 6 1 6\n", "1\n6 3\n4 1 4 1 1 3\n", "1\n6 2\n3 1 3 1 1 2\n", "1\n6 3\n5 1 5 2 2 3\n"], "outputs": ["yes\n", "yes\n", "no\n", "yes\n", "yes\n", "yes\n", "yes\n", "yes\n"]}
643
190
coding
Solve the programming task below in a Python markdown code block. Given a number $n$, give the last digit of sum of all the prime numbers from 1 to $n$ inclusive. -----Input:----- - First line contains number of testcase $t$. - Each testcase contains of a single line of input, number $n$. -----Output:----- Last digi...
{"inputs": ["1\n10"], "outputs": ["7"]}
134
15
coding
Solve the programming task below in a Python markdown code block. You are a game designer and want to make an obstacle course. The player will walk from left to right. You have $n$ heights of mountains already selected and want to arrange them so that the absolute difference of the heights of the first and last mountai...
{"inputs": ["2\n4\n4 2 1 2\n2\n3 1\n"], "outputs": ["2 4 1 2 \n1 3\n"]}
633
41
coding
Solve the programming task below in a Python markdown code block. # Task Consider the following operation: We take a positive integer `n` and replace it with the sum of its `prime factors` (if a prime number is presented multiple times in the factorization of `n`, then it's counted the same number of times in the s...
{"functional": "_inputs = [[24], [35], [156], [4], [31]]\n_outputs = [[5], [7], [5], [4], [31]]\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...
258
184
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j.   Please complete the following python code precisely: ```python class Solution: def ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1,1,3]) == 4\n assert candidate(nums = [1,1,1,1]) == 6\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().numIdenticalPairs)"}
87
77
coding
Solve the programming task below in a Python markdown code block. There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in ...
{"inputs": ["2 3\n0 1 1\n1 1 1\n1 4 0\n1 2\n3 3", "2 3\n0 1 1\n1 1 1\n2 4 0\n1 2\n3 3", "2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n1 3", "2 3\n0 2 1\n1 1 1\n2 4 0\n1 2\n3 3", "2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n2 3", "2 3\n1 3 1\n1 1 1\n2 4 0\n1 2\n3 3", "2 3\n2 3 1\n2 1 1\n3 4 0\n1 2\n3 3", "2 3\n1 1 1\n1 1 1\n1 4 0\n1 2\n3 3"], "ou...
617
286
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\n1\n", "1\n2\n", "1\n4\n", "2\n1 2\n", "2\n3 2\n", "2\n1 2\n", "2\n3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
578
94
coding
Solve the programming task below in a Python markdown code block. There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can mo...
{"inputs": ["1 1\n0", "1 1\n0\n", "3 2\n10 18 30", "3 2\n10 20 43", "3 2\n10 22 30", "3 2\n10 11 30", "3 3\n12 20 60", "3 3\n5 26 149"], "outputs": ["0", "0\n", "18\n", "20\n", "22\n", "11\n", "60\n", "149\n"]}
334
143
coding
Solve the programming task below in a Python markdown code block. Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants...
{"inputs": ["bbbabb\nbb\n1 6 3 4 2 5\n", "bababc\nbb\n1 6 3 4 2 5\n", "bbbabc\nbb\n1 6 3 4 2 5\n", "cbabbb\nbb\n1 6 3 4 2 5\n", "bbabbb\nbb\n1 6 3 4 2 5\n", "bbbabb\nba\n1 6 3 4 2 5\n", "abbabb\nba\n1 6 3 4 2 5\n", "bbabba\nba\n1 6 3 4 2 5\n"], "outputs": ["4", "2\n", "4\n", "4\n", "4\n", "3\n", "3\n", "2\n"]}
614
192
coding
Solve the programming task below in a Python markdown code block. This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "...
{"inputs": ["((()))\n", "()()()\n", "))))))\n", "((((((\n", "(())()\n", ")))(((\n", ")())))\n", ")())((\n"], "outputs": ["0\n((()))", "0\n()()()", "-1", "-1", "0\n(())()", "-1\n", "-1\n", "-1\n"]}
311
87
coding
Solve the programming task below in a Python markdown code block. Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in ...
{"inputs": ["3\nact dog\nfish fish\nlion tiger", "3\nact god\nfish fith\nlion tiger", "3\nuea goe\ndirh giuh\nnojk tiger", "3\nvea hpg\njrie giug\nnpjk rhget", "3\nv`f ggn\njrhd jgug\njnok ehrug", "3\nact god\nfish fish\nlion tiger", "3\nact god\nfish gith\nlion tiger", "3\nact goe\nfish gith\nlion tiger"], "outputs": ...
243
175
coding
Solve the programming task below in a Python markdown code block. Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2. This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actuall...
{"inputs": ["6\n1\n3\n0", "6\n4\n2\n0", "6\n0\n2\n0", "6\n4\n0\n0", "6\n1\n0\n0", "6\n5\n8\n0", "6\n2\n2\n0", "6\n2\n3\n0"], "outputs": ["1\n0\n0\n", "1\n1\n0\n", "1\n", "1\n1\n", "1\n0\n", "1\n1\n1\n", "1\n0\n0\n", "1\n0\n0\n"]}
290
134
coding
Solve the programming task below in a Python markdown code block. The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n × m rectangular table. Each cell of the table on the map represents some districts of the capital...
{"inputs": ["2 2\n*.\n**\n", "2 2\n**\n.*\n", "2 2\n**\n/*\n", "2 3\n*.*\n..*\n", "3 2\n.*\n..\n**\n", "2 5\n*....\n*...*\n", "3 3\n*.*\n*..\n-..\n", "3 3\n*.*\n*..\n...\n"], "outputs": ["1 2", "2 1", "2 1\n", "2 1", "1 1", "1 5", "2 3\n", "2 3"]}
374
156
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s consisting of lowercase English letters. Perform the following operation: Select any non-empty substring then replace every letter of the substring with the preceding letter of the English alphabet. ...
{"functional": "def check(candidate):\n assert candidate(s = \"cbabc\") == \"baabc\"\n assert candidate(s = \"acbbc\") == \"abaab\"\n assert candidate(s = \"leetcode\") == \"kddsbncd\"\n\n\ncheck(Solution().smallestString)"}
117
67
coding
Solve the programming task below in a Python markdown code block. You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number tha...
{"inputs": ["2 1 1\n0\n", "20 15 1\n6\n", "20 19 2\n16 13\n", "38 19 2\n16 13\n", "7 6 4\n3 5 0 8\n", "57 19 2\n16 13\n", "109 19 2\n16 3\n", "7 6 4\n3 5 0 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n"]}
651
156
coding
Solve the programming task below in a Python markdown code block. You are given a permutation p consisting of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once). Let's call an array a bipartite if the following undirected graph is bipartite: * the graph consists o...
{"inputs": ["4\n3\n1 2 3\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 2 1 6 7 8 5 4\n", "4\n3\n1 2 3\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 0 1 6 7 8 5 4\n", "4\n3\n1 2 3\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 2 1 6 7 1 5 4\n", "4\n3\n1 2 0\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 0 1 6 7 8 5 4\n", "4\n3\n1 2 3\n6\n1 3 2 6 5 1\n4\n4 1 3 2\n8\n3 2...
403
722
coding
Solve the programming task below in a Python markdown code block. Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first. -----Input----- First line of input contains an integer T, d...
{"inputs": ["2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2\n\n"], "outputs": ["2 2\n1 3"]}
269
46
coding
Solve the programming task below in a Python markdown code block. A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbe...
{"inputs": ["6\n", "9\n", "8\n", "4\n", "5\n", "7\n", "2\n", "3\n"], "outputs": ["2 4 1 5 4 ", "2 4 7 2 7 4 2 1 ", "2 4 7 3 8 6 5 ", "2 4 3 ", "2 4 2 1 ", "2 4 7 4 2 1 ", "2 ", "2 1 "]}
433
119
coding
Solve the programming task below in a Python markdown code block. Problem Statement The Animal School is a primary school for animal children. You are a fox attending this school. One day, you are given a problem called "Arithmetical Restorations" from the rabbit teacher, Hanako. Arithmetical Restorations are the pro...
{"inputs": ["3?4\n12?\n5?6\n?1?4\n5?7?\n?9?2\n?????\n?????\n?????\n0", "3?4\n12?\n6?5\n?2?4\n5?7?\n?9?2\n?????\n?????\n?????\n0", "3?4\n12?\n6?5\n?2?4\n5?7?\n2?9?\n?????\n?????\n?????\n0", "3?4\n?21\n6?5\n?2?4\n5?7?\n2?9?\n?????\n?????\n?????\n0", "34?\n?21\n6?5\n4?2?\n5?7?\n2?9?\n?????\n?????\n?????\n0", "3?4\n12?\n5?...
654
453
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete. Given the integer n, return...
{"functional": "def check(candidate):\n assert candidate(n = 5) == 2\n assert candidate(n = 8) == 3\n\n\ncheck(Solution().arrangeCoins)"}
105
44
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is a network engineer at CodeChef. Currently, he has to design a network that connects $N$ computers (numbered $1$ through $N$). The network sh...
{"inputs": ["3\n2 3\n5 6\n3 3"], "outputs": ["2\n2\n2"]}
727
28
coding
Solve the programming task below in a Python markdown code block. You have $a$ coins of value $n$ and $b$ coins of value $1$. You always pay in exact change, so you want to know if there exist such $x$ and $y$ that if you take $x$ ($0 \le x \le a$) coins of value $n$ and $y$ ($0 \le y \le b$) coins of value $1$, then t...
{"inputs": ["1\n2 2 3 55\n", "1\n2 2 3 43\n", "1\n2 2 3 33\n", "1\n2 2 4 33\n", "1\n2 4 4 33\n", "1\n2 4 5 33\n", "1\n2 8 5 33\n", "1\n1 8 5 33\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
398
142
coding
Solve the programming task below in a Python markdown code block. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 ≥ x * a1 + a2 + ... + an ≤ y Input The first line contains three space-separated integ...
{"inputs": ["1 1 1\n", "5 1 4\n", "2 1 1\n", "2 3 2\n", "10 3 8\n", "1 5 10\n", "5 37 10\n", "100 1 1\n"], "outputs": ["1\n", "-1", "-1", "-1\n", "-1", "10\n", "1\n1\n1\n1\n6\n", "-1"]}
255
113
coding
Solve the programming task below in a Python markdown code block. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without reveali...
{"inputs": ["2 1\n4 5 6 7\n4 7\n", "2 1\n1 2 1 3\n1 2\n", "2 1\n3 5 6 7\n4 7\n", "2 1\n1 2 2 3\n1 2\n", "2 2\n1 2 1 3\n1 2 1 3\n", "2 2\n1 2 2 4\n1 2 1 3\n", "2 2\n1 2 2 3\n2 3 3 4\n", "2 2\n1 2 3 4\n1 5 3 4\n"], "outputs": ["-1", "1", "7\n", "2\n", "1", "0", "0", "1"]}
719
193
coding
Solve the programming task below in a Python markdown code block. Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define a pair of integers (a, b) good, if GCD(a, b) ...
{"inputs": ["1 2 1 2\n", "3 3 1 1\n", "2 2 3 3\n", "3 3 3 9\n", "3 3 3 9\n", "3 3 1 1\n", "2 2 3 3\n", "3 3 3 5\n"], "outputs": ["2\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
407
118
coding
Solve the programming task below in a Python markdown code block. Chef has a permutation P of length 2 \cdot N. He can perform the following operation on P: Select an index i (1 ≤ i < 2 \cdot N) and swap P_{i} and P_{i + 1}. Chef would call the permutation P *good*, if the maximum element of the first half of P is les...
{"inputs": ["3\n2\n3 2 1 4\n3\n1 2 3 4 5 6\n3\n6 5 4 3 2 1\n"], "outputs": ["2\n0\n9\n"]}
522
56
coding
Solve the programming task below in a Python markdown code block. Reverse and invert all integer values in a given list. Python: reverse_invert([1,12,'a',3.4,87,99.9,-42,50,5.6]) = [-1,-21,-78,24,-5] Ignore all other types than integer. Also feel free to reuse/extend the following starter code: ```python de...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[-10]], [[-9, -18, 99]], [[1, 12, 'a', 3.4, 87, 99.9, -42, 50, 5.6]], [[]]]\n_outputs = [[[-1, -2, -3, -4, -5]], [[1]], [[9, 81, -99]], [[-1, -21, -78, 24, -5]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
106
272
coding
Solve the programming task below in a Python markdown code block. The Fair Nut likes kvass very much. On his birthday parents presented him $n$ kegs of kvass. There are $v_i$ liters of kvass in the $i$-th keg. Each keg has a lever. You can pour your glass by exactly $1$ liter pulling this lever. The Fair Nut likes this...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "1 2\n1\n", "1 1\n1\n", "1 2\n2\n", "1 1\n2\n", "1 2\n3\n", "1 1\n0\n"], "outputs": ["0\n", "-1\n", "-1\n", "0\n", "0", "1", "1", "-1"]}
480
98
coding
Solve the programming task below in a Python markdown code block. A list of names is taken as input, in which a particular name can occur multiple times. You need to arrange these names as they will appear in the dictionary and also print the number of times the arranged names appear in the list taken as input. Input:...
{"inputs": ["3\nritesh\nsahil\nritesh"], "outputs": ["ritesh 2\nsahil 1"]}
252
31
coding
Solve the programming task below in a Python markdown code block. There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want. To play d...
{"inputs": ["H\nQD KD\n", "D\n9S 8S\n", "H\nTH 8H\n", "D\nAC KS\n", "H\nAH KH\n", "H\nAD KD\n", "D\n8S 6C\n", "H\nAC QC\n"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
443
103
coding
Solve the programming task below in a Python markdown code block. Using his tip-top physique, Kim has now climbed up the mountain where the base is located. Kim has found the door to the (supposedly) super secret base. Well, it is super secret, but obviously no match for Kim's talents. The door is guarded by a row of ...
{"inputs": ["3\n4\n3 5 3 4\n2\n5 7\n1\n4"], "outputs": ["3\n0\n0"]}
751
36
coding
Solve the programming task below in a Python markdown code block. On a weekend, Qingshan suggests that she and her friend Daniel go hiking. Unfortunately, they are busy high school students, so they can only go hiking on scratch paper. A permutation $p$ is written from left to right on the paper. First Qingshan choose...
{"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n0 2\n", "2\n0 1\n", "2\n1 4\n", "2\n1 7\n", "2\n0 7\n", "2\n0 6\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
584
102
coding
Solve the programming task below in a Python markdown code block. Min Element Given the sequence a_1, a_2, .., a_N. Find the minimum number in this sequence. If the minimum value is in more than one place, answer the one with the lowest number. input N a_1 a_2 ... a_N output Output the smallest i such that a_i...
{"inputs": ["6\n8 6 9 0 2 1", "6\n8 6 9 1 2 0", "6\n6 0 9 1 2 1", "6\n1 6 9 1 2 0", "6\n1 6 9 0 2 0", "6\n8 3 9 1 2 1", "6\n6 6 9 0 2 1", "6\n8 6 9 2 2 0"], "outputs": ["4\n", "6\n", "2\n", "6\n", "4\n", "4\n", "4\n", "6\n"]}
171
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed). For example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 +...
{"functional": "def check(candidate):\n assert candidate(nums1 = [5,3,4,2], nums2 = [4,2,2,5]) == 40\n assert candidate(nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]) == 65\n\n\ncheck(Solution().minProductSum)"}
184
88
coding
Solve the programming task below in a Python markdown code block. In Berland recently a new collection of toys went on sale. This collection consists of 10^9 types of toys, numbered with integers from 1 to 10^9. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different ty...
{"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 1\n1 3\n", "2 1\n2 3\n", "2 0\n2 3\n", "2 0\n2 6\n", "2 0\n2 12\n", "3 7\n1 3 4\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "1\n1\n", "0\n\n", "0\n\n", "0\n\n", "2\n2 5 \n"]}
570
134
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a number `n` (`n > 0`) and your task will be to return the smallest square number `N` (`N > 0`) such that `n + N` is also a perfect square. If there is no answer, return `-1` (`nil` in Clojure, `Nothing` in Haskell, `None`...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [7], [8], [9], [10], [11], [13], [17], [88901], [290101]]\n_outputs = [[-1], [-1], [1], [-1], [4], [9], [1], [16], [-1], [25], [36], [64], [5428900], [429235524]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
572
264
coding
Solve the programming task below in a Python markdown code block. Return a new array consisting of elements which are multiple of their own index in input array (length > 1). Some cases: ``` [22, -6, 32, 82, 9, 25] => [-6, 32, 25] [68, -1, 1, -7, 10, 10] => [-1, 10] [-56,-85,72,-26,-14,76,-27,72,35,-21,-67,87,0,2...
{"functional": "_inputs = [[[22, -6, 32, 82, 9, 25]], [[68, -1, 1, -7, 10, 10]], [[11, -11]], [[-56, -85, 72, -26, -14, 76, -27, 72, 35, -21, -67, 87, 0, 21, 59, 27, -92, 68]], [[28, 38, -44, -99, -13, -54, 77, -51]], [[-1, -49, -1, 67, 8, -60, 39, 35]]]\n_outputs = [[[-6, 32, 25]], [[-1, 10]], [[-11]], [[-85, 72, 0, 6...
200
404
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same. In one step, you can delete exactly one character in either string.   Please complete the following pyth...
{"functional": "def check(candidate):\n assert candidate(word1 = \"leetcode\", word2 = \"etco\") == 4\n\n\ncheck(Solution().minDistance)"}
93
39
coding
Solve the programming task below in a Python markdown code block. You are beta testing the new secret Terraria update. This update will add quests to the game! Simply, the world map can be represented as an array of length $n$, where the $i$-th column of the world has height $a_i$. There are $m$ quests you have to te...
{"inputs": ["10 1\n5 5 5 3 5 5 5 5 5 1\n10 7\n", "7 6\n10 8 9 6 8 12 7\n1 2\n1 7\n4 6\n7 1\n3 5\n4 2\n", "8 6\n1 2 3 4 5 6 7 8\n1 8\n7 1\n1 2\n2 3\n4 5\n4 5\n", "10 4\n1 1 1 1 1 1 1 1 1 1\n1 10\n10 1\n10 9\n1 2\n", "38 1\n2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 ...
630
471
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0). Starting from the cell (i, j), you can move to one of the following cells: Cells (i, k) with j < k <= grid[i]...
{"functional": "def check(candidate):\n assert candidate(grid = [[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]) == 4\n assert candidate(grid = [[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]) == 3\n assert candidate(grid = [[2,1,0],[1,0,0]]) == -1\n\n\ncheck(Solution().minimumVisitedCells)"}
185
126
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts. A falling path with non-zero shifts is a choice of exactly one element from each row of grid such that no two elements...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,2,3],[4,5,6],[7,8,9]]) == 13\n assert candidate(grid = [[7]]) == 7\n\n\ncheck(Solution().minFallingPathSum)"}
108
63
coding
Solve the programming task below in a Python markdown code block. In computer science, cycle detection is the algorithmic problem of finding a cycle in a sequence of iterated function values. For any function ƒ, and any initial value x0 in S, the sequence of iterated function values x0,x1=f(x0), x2=f(x1), ...,xi=...
{"functional": "_inputs = [[[2, 3, 4, 2, 3, 4]], [[1, 2, 3, 4, 2, 3, 4]], [[1, 1, 1, 1, 1, 1, 1, 1]], [[]], [[7]], [[1, 2, 3, 4]]]\n_outputs = [[[0, 3]], [[1, 3]], [[0, 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...
508
252
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Limak is a little polar bear, who loves eating cookies and drinking milk. For this reason he often visits Chef's kitchen. Limak is going to spend N minutes in the kitchen. E...
{"inputs": ["4\n7\ncookie milk milk cookie milk cookie milk\n5\ncookie cookie milk milk milk\n4\nmilk milk milk milk\n1\ncookie"], "outputs": ["YES\nNO\nYES\nNO"]}
611
48
coding
Solve the programming task below in a Python markdown code block. Let's play the game using a bag containing several cards with integers written on it. In each game, participants first declare one of their favorite number n. Then, take out an appropriate number of cards from the bag at a time, and if the sum of the num...
{"inputs": ["5\n2 28\n5 4\n5 2\n25 1\n50 2\n4\n228\n714\n100\n168\n7\n1 8\n4 10\n9 10\n17 5\n6 1\n10 15\n110 5\n3\n692\n574\n787\n0", "5\n2 28\n5 4\n5 2\n25 1\n50 2\n4\n228\n714\n100\n168\n7\n1 8\n4 10\n9 10\n17 5\n4 1\n10 15\n110 5\n3\n692\n574\n787\n0", "5\n4 28\n5 4\n5 2\n25 1\n50 2\n4\n228\n714\n100\n168\n7\n1 8\n4...
484
987
coding
Solve the programming task below in a Python markdown code block. You are given a straight line, $a\cdot x+b\cdot y=c$. Find the point closest to the origin that also satisfies the following properties: $\boldsymbol{x}$ and $y$ are integers. $\boldsymbol{x}$ is greater than zero. If more than one solution exist...
{"inputs": ["1\n2 3 1\n"], "outputs": ["2 -1\n"]}
439
22
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. We consider an array good if it is a permutation of an array base[n]. base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 e...
{"functional": "def check(candidate):\n assert candidate(nums = [2, 1, 3]) == False\n assert candidate(nums = [1, 3, 3, 2]) == True\n assert candidate(nums = [1, 1]) == True\n assert candidate(nums = [3, 4, 4, 1, 2, 1]) == False\n\n\ncheck(Solution().isGood)"}
183
96
coding
Solve the programming task below in a Python markdown code block. You are given two strings. In a single move, you can choose any of them, and delete the first (i.e. leftmost) character. For Example: * By applying a move to the string `"where"`, the result is the string `"here"`. * By applying a move to the string `"...
{"functional": "_inputs = [['test', 'west'], ['test', 'yes'], ['b', 'ab'], ['abacabadabacaba', 'abacabadacaba'], ['aaabc', 'bc'], ['dark', 'd'], ['dadc', 'dddc'], ['nogkvcdldfpvlbkpedsecl', 'nogkvcdldfpvlbkpedsecl']]\n_outputs = [[2], [7], [1], [18], [3], [5], [4], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ...
161
253
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible. Return t...
{"functional": "def check(candidate):\n assert candidate(arr = [9,12,3,7,15], target = 5) == 2\n assert candidate(arr = [1000000,1000000,1000000], target = 1) == 999999\n assert candidate(arr = [1,2,4,8,16], target = 0) == 0\n\n\ncheck(Solution().closestToTarget)"}
141
117
coding
Solve the programming task below in a Python markdown code block. Your task is to sort a given string. Each word in the string will contain a single number. This number is the position the word should have in the result. Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0). If the input string is emp...
{"functional": "_inputs = [['is2 Thi1s T4est 3a'], ['4of Fo1r pe6ople g3ood th5e the2'], ['d4o dru7nken sh2all w5ith s8ailor wha1t 3we a6'], [''], ['3 6 4 2 8 7 5 1 9']]\n_outputs = [['Thi1s is2 3a T4est'], ['Fo1r the2 g3ood 4of th5e pe6ople'], ['wha1t sh2all 3we d4o w5ith a6 dru7nken s8ailor'], [''], ['1 2 3 4 5 6 7 8...
197
309
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
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers. For e...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,1,1,1], target = 3) == 5\n assert candidate(nums = [1], target = 1) == 1\n\n\ncheck(Solution().findTargetSumWays)"}
151
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s and t. In one step, you can append any character to either s or t. Return the minimum number of steps to make s and t anagrams of each other. An anagram of a string is a string that contain...
{"functional": "def check(candidate):\n assert candidate(s = \"leetcode\", t = \"coats\") == 7\n assert candidate(s = \"night\", t = \"thing\") == 0\n\n\ncheck(Solution().minSteps)"}
116
54
coding
Solve the programming task below in a Python markdown code block. Let us play a game of cards. As you all know there are 52 cards in a regular deck, but our deck is somewhat different. Our deck consists of N cards. Each card simply contains a unique number from 1 to N. Initially all the cards are kept on the table, fac...
{"inputs": ["3 4\n1 2 3", "5 12\n4 -2 3 -1 5"], "outputs": ["0", "2\n2 3"]}
601
43
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. An isla...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,1,1]]) == 1\n assert candidate(grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]) == 1\n\n\ncheck(Solution().numDistinctIslands2)"}
160
122
coding
Solve the programming task below in a Python markdown code block. Chef bought a huge (effectively infinite) planar island and built $N$ restaurants (numbered $1$ through $N$) on it. For each valid $i$, the Cartesian coordinates of restaurant $i$ are $(X_i, Y_i)$. Now, Chef wants to build $N-1$ straight narrow roads (li...
{"inputs": ["2\n3\n0 0\n0 1\n0 -1\n3\n0 1\n1 0\n-1 0"], "outputs": ["0.5\n0"]}
678
45
coding
Solve the programming task below in a Python markdown code block. You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974". Constraints * 0 \leq N_1, N_2, N_3, N_4 \leq 9 * N_1, N_2, N_3 and N_4 are integers. Input Input is given from Standard Input in t...
{"inputs": ["1 2 3 1", "0 7 9 4", "1 3 3 1", "1 2 3 2", "1 0 3 2", "1 0 4 2", "1 0 0 2", "1 0 0 1"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
226
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an initial array arr, every day you produce a new array using the array of the previous day. On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i: If an element...
{"functional": "def check(candidate):\n assert candidate([6,2,3,4]) == [6,3,3,4]\n assert candidate([1,6,3,4,3,5]) == [1,4,4,4,4,5]\n\n\ncheck(Solution().transformArray)"}
166
73
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array words consisting of distinct strings. The string words[i] can be paired with the string words[j] if: The string words[i] is equal to the reversed string of words[j]. 0 <= i < j < words...
{"functional": "def check(candidate):\n assert candidate(words = [\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"]) == 2\n assert candidate(words = [\"ab\",\"ba\",\"cc\"]) == 1\n assert candidate(words = [\"aa\",\"ab\"]) == 0\n\n\ncheck(Solution().maximumNumberOfStringPairs)"}
134
77
coding
Solve the programming task below in a Python markdown code block. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a...
{"inputs": ["1 2", "1 1", "0 1", "2 3", "3 4", "7 8", "3 3", "5 6"], "outputs": ["20\n", "13\n", "10\n", "30\n", "40\n", "88\n", "38\n", "63\n"]}
351
86
coding
Solve the programming task below in a Python markdown code block. Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice. Given is a string S. Find the minimum number of hugs needed to make S palindromi...
{"inputs": ["f\n", "zz\n", "ax\n", "za\n", "ddr\n", "ntt\n", "lol\n", "xxx\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "0\n", "0\n"]}
173
72
coding
Solve the programming task below in a Python markdown code block. The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it. However, one day, the members somehow entered the sequence into the document at the same time, crea...
{"inputs": ["5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMMTT\n", "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMMTT\n", "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMTTM\n", "5\n3\nTMT\n3\nMTT\n6\nTTTMMT\n6\nTMTTTT\n6\nTTMMTT\n", "5\n3\nTTM\n3\nTTM\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMMTT\n", "5\n3\nTTM\n3\nTMT\n6\nTMTMT...
471
369
coding
Solve the programming task below in a Python markdown code block. Transpose We can generate the transposition of an array using the tool numpy.transpose. It will not affect the original array, but it will create a new array. import numpy my_array = numpy.array([[1,2,3], [4,5,6]]) print nu...
{"inputs": ["2 2\n1 2\n3 4\n"], "outputs": ["[[1 3]\n [2 4]]\n[1 2 3 4]\n"]}
302
45
coding
Solve the programming task below in a Python markdown code block. If `a = 1, b = 2, c = 3 ... z = 26` Then `l + o + v + e = 54` and `f + r + i + e + n + d + s + h + i + p = 108` So `friendship` is twice stronger than `love` :-) The input will always be in lowercase and never be empty. Also feel free to reuse/extend...
{"functional": "_inputs = [['attitude'], ['friends'], ['family'], ['selfness'], ['knowledge']]\n_outputs = [[100], [75], [66], [99], [96]]\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, ...
126
187
coding
Solve the programming task below in a Python markdown code block. AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual number...
{"inputs": ["3\n3 3\n1 1\n3 2", "3\n4 3\n1 1\n3 1", "3\n4 3\n1 2\n3 1", "3\n2 3\n1 1\n1 2", "3\n4 3\n1 1\n1 2", "3\n2 1\n1 1\n3 2", "3\n3 3\n1 2\n3 2", "3\n4 3\n1 2\n2 1"], "outputs": ["10\n", "16\n", "32\n", "9\n", "12\n", "5\n", "15\n", "24\n"]}
381
164
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: - Append a_i to the end of b. - Reverse the order of the elements in b. Find t...
{"inputs": ["3\n1 2 3\n", "4\n1 2 3 4\n", "1\n1000000000\n", "6\n0 6 7 6 7 0\n"], "outputs": ["3 1 2\n", "4 2 1 3\n", "1000000000\n", "0 6 6 0 7 7\n"]}
384
104
coding
Solve the programming task below in a Python markdown code block. A bracket sequence is a string that is one of the following: - An empty string; - The concatenation of (, A, and ) in this order, for some bracket sequence A ; - The concatenation of A and B in this order, for some non-empty bracket sequences A and B ...
{"inputs": ["2\n)\n()(", "2\n)(\n)(", "2\n((\n)(", "2\n((\n()", "2\n)\n(((", "2\n)(\n))", "2\n)\n())", "2\n(\n((("], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
230
98
coding
Solve the programming task below in a Python markdown code block. Cheffina challanges chef to rearrange the given array as arr[i] > arr[i+1] < arr[i+2] > arr[i+3].. and so on…, i.e. also arr[i] < arr[i+2] and arr[i+1] < arr[i+3] and arr[i] < arr[i+3] so on.. Chef accepts the challenge, chef starts coding but his code i...
{"inputs": ["2\n4\n4 1 6 3\n5\n4 5 1 6 3"], "outputs": ["3 1 6 4\n3 1 5 4 6"]}
290
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. A subarray is a contiguous subsequence of the array.   Please complete the following python code precisely: ```pytho...
{"functional": "def check(candidate):\n assert candidate(arr = [1,4,2,5,3]) == 58\n assert candidate(arr = [1,2]) == 3\n assert candidate(arr = [10,11,12]) == 66\n\n\ncheck(Solution().sumOddLengthSubarrays)"}
84
77
coding
Solve the programming task below in a Python markdown code block. There are N piles of stones. The i-th pile has A_i stones. Aoki and Takahashi are about to use them to play the following game: - Starting with Aoki, the two players alternately do the following operation: - Operation: Choose one pile of stones, and re...
{"inputs": ["2\n3 6", "2\n5 5", "2\n7 5", "2\n5 1", "2\n7 7", "2\n3 1", "2\n7 1", "2\n3 2"], "outputs": ["-1\n", "0\n", "1\n", "2\n", "0\n", "1\n", "3\n", "-1\n"]}
402
95
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours. Return the time when the train will arrive at...
{"functional": "def check(candidate):\n assert candidate(arrivalTime = 15, delayedTime = 5 ) == 20 \n assert candidate(arrivalTime = 13, delayedTime = 11) == 0\n\n\ncheck(Solution().findDelayedArrivalTime)"}
117
67
coding
Solve the programming task below in a Python markdown code block. The aim of the kata is to try to show how difficult it can be to calculate decimals of an irrational number with a certain precision. We have chosen to get a few decimals of the number "pi" using the following infinite series (Leibniz 1646–1716): PI / ...
{"functional": "_inputs = [[0.1], [0.01], [0.001], [0.0001], [1e-05], [1e-06]]\n_outputs = [[[10, 3.0418396189]], [[100, 3.1315929036]], [[1000, 3.1405926538]], [[10000, 3.1414926536]], [[100001, 3.1416026535]], [[1000001, 3.1415936536]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isins...
498
311
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. An integer x is said to be a Perfect Power if there exists positive integers a and b (i.e a, and b should be ≥ 1) such that x = a^{b+1}. Given an integer n, ...
{"inputs": ["7\n7\n10\n26\n242\n129\n394857629456789876\n353872815358409997"], "outputs": ["8\n9\n25\n243\n128\n394857628993920400\n353872815358410000"]}
763
117
coding
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"]}
435
44
coding
Solve the programming task below in a Python markdown code block. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column f...
{"inputs": ["2 1\nb\na\n", "2 1\nb\n`\n", "2 2\nfb\nye\n", "2 2\nfb\ney\n", "2 2\nfb\nez\n", "2 2\nfb\nze\n", "2 2\nfc\nez\n", "2 3\naxc\nbxa\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "0\n"]}
379
120
coding
Solve the programming task below in a Python markdown code block. This problem is a simplified version of D2, 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 b...
{"inputs": ["1\n4\n0 0 0 4\n", "1\n4\n1 2 3 4\n", "1\n4\n1 1 1 1\n", "1\n4\n-10 -10 -5 -5\n", "1\n4\n1000000 0 0 0\n", "1\n6\n8 128 -38 -39 19 119\n", "1\n4\n572894 617066 -274175 841676\n", "1\n4\n210452 -553585 -303337 -97565\n"], "outputs": ["4\n", "1\n", "-1\n", "5\n", "1000000\n", "1\n", "1\n", "1\n"]}
452
215
coding
Solve the programming task below in a Python markdown code block. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly a_{i} each hour. Luba can't water any parts ...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 88\n1\n", "1 89\n1\n", "1 88\n1\n", "1 89\n1\n", "1 73\n1\n", "2 6\n5 3\n"], "outputs": ["1\n", "1\n", "88\n", "89\n", "88\n", "89\n", "73\n", "2\n"]}
431
114
coding
Solve the programming task below in a Python markdown code block. Petya is preparing for his birthday. He decided that there would be $n$ different dishes on the dinner table, numbered from $1$ to $n$. Since Petya doesn't like to cook, he wants to order these dishes in restaurants. Unfortunately, all dishes are prepar...
{"inputs": ["4\n4\n3 7 4 2\n2 1 2 0\n4\n1 0 3 8\n3 5 4 3\n2\n1 2\n10 4\n2\n9 10\n0 2\n", "4\n4\n3 7 4 2\n2 1 2 0\n4\n1 0 3 8\n3 5 4 3\n2\n1 2\n10 4\n2\n9 10\n1 2\n", "4\n4\n3 7 4 2\n2 1 2 0\n4\n1 0 3 8\n3 5 4 3\n2\n1 2\n10 10\n2\n9 6\n1 2\n", "4\n4\n3 7 4 2\n2 1 3 0\n4\n1 0 3 4\n3 3 4 3\n2\n1 2\n10 10\n2\n9 10\n1 2\n",...
743
579
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values. We translate one image however we choose by sliding all the 1 bits left, rig...
{"functional": "def check(candidate):\n assert candidate(img1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]) == 3\n assert candidate(img1 = [[1]], img2 = [[1]]) == 1\n assert candidate(img1 = [[0]], img2 = [[0]]) == 0\n\n\ncheck(Solution().largestOverlap)"}
190
109
coding
Solve the programming task below in a Python markdown code block. There are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain two integers, the first one on top, the second one i...
{"inputs": ["1 6\n2\n", "1 6\n7\n", "1 6\n3\n", "1 6\n4\n", "1 7\n2\n", "1 6\n2\n", "1 6\n7\n", "1 24\n10\n"], "outputs": ["11\n", "14\n", "11\n", "14\n", "14\n", " 11\n", " 14\n", "161\n"]}
553
117
coding
Solve the programming task below in a Python markdown code block. There is a strange counter. At the first second, it displays the number $3$. Each second, the number displayed by decrements by $\mbox{1}$ until it reaches $\mbox{1}$. In next second, the timer resets to $2\times\textbf{the initial number for the prior c...
{"inputs": ["4\n"], "outputs": ["6\n"]}
311
14
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. To give credit where credit is due: This problem was taken from the ACMICPC-Northwest Regional Programming Contest. Thank you problem writers. You are helping an archaeologist decipher some runes. He knows that this ancient society used a Base 10 system...
{"functional": "_inputs = [['123?45*?=?'], ['?*123?45=?'], ['??605*-63=-73???5'], ['123?45+?=123?45'], ['?8?170-1?6256=7?2?14'], ['?38???+595???=833444'], ['123?45-?=123?45'], ['-7715?5--484?00=-28?9?5'], ['50685?--1?5630=652?8?'], ['??+??=??'], ['-?56373--9216=-?47157']]\n_outputs = [[0], [0], [1], [0], [9], [2], [0],...
520
362
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two sorted arrays of distinct integers nums1 and nums2. A valid path is defined as follows: Choose array nums1 or nums2 to traverse (from index-0). Traverse the current array from left to right. If you ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]) == 30\n assert candidate(nums1 = [1,3,5,7,9], nums2 = [3,5,100]) == 109\n assert candidate(nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]) == 40\n\n\ncheck(Solution().maxSum)"}
189
126
coding
Solve the programming task below in a Python markdown code block. You are given several queries. In the i-th query you are given a single positive integer n_{i}. You are to represent n_{i} as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittin...
{"inputs": ["1\n4\n", "1\n12\n", "1\n12\n", "2\n6\n8\n", "2\n6\n4\n", "2\n8\n1\n", "2\n8\n4\n", "2\n6\n8\n"], "outputs": ["1\n", "3\n", "3\n", "1\n2\n", "1\n1\n", "2\n-1\n", "2\n1\n", "1\n2\n"]}
352
109
coding
Solve the programming task below in a Python markdown code block. In this exercise, you will have to create a function named tiyFizzBuzz. This function will take on a string parameter and will return that string with some characters replaced, depending on the value: - If a letter is a upper case consonants, replace th...
{"functional": "_inputs = [[' '], ['H'], ['b'], ['A'], ['a'], ['Hello WORLD!'], ['H6H4Na ./?U']]\n_outputs = [[' '], ['Iron'], ['b'], ['Iron Yard'], ['Yard'], ['IronYardllYard IronIron YardIronIronIron!'], ['Iron6Iron4IronYard ./?Iron Yard']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
156
227
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