problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. In this Kata, you will remove the left-most duplicates from a list of integers and return the result. ```python # Remove the 3's at indices 0 and 3 # followed by removing a 4 at index 1 solve([3, 4, 4, 3, 6, 3]) # => [4, 6, 3] ``` More examples can be ...
{"functional": "_inputs = [[[3, 4, 4, 3, 6, 3]], [[1, 2, 1, 2, 1, 2, 3]], [[1, 2, 3, 4]], [[1, 1, 4, 5, 1, 2, 1]]]\n_outputs = [[[4, 6, 3]], [[1, 2, 3]], [[1, 2, 3, 4]], [[4, 5, 2, 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, r...
coding
129
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, determine if it is valid. A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times: Insert string "abc" i...
{"functional": "def check(candidate):\n assert candidate(s = \"aabcbc\") == True\n assert candidate(s = \"abcabcababcc\") == True\n assert candidate(s = \"abccba\") == False\n\n\ncheck(Solution().isValid)"}
coding
148
Solve the programming task below in a Python markdown code block. Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0. There are also n cards, each card has 2 attributes: length l_{i} and co...
{"inputs": ["1\n1\n1\n", "1\n2\n2\n", "1\n1\n1\n", "1\n2\n2\n", "1\n1\n2\n", "1\n4\n2\n", "1\n6\n2\n", "1\n5\n2\n"], "outputs": ["1\n", "-1\n", "1\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]}
coding
628
Solve the programming task below in a Python markdown code block. Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls ar...
{"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "3 2\n2 1 2\n1 3\n", "3 2\n1 2\n2 1 3\n", "3 2\n1 2\n2 1 3\n", "3 2\n2 1 2\n1 3\n", "5 3\n1 4\n3 1 2 3\n1 5\n", "5 3\n1 4\n3 1 2 3\n1 5\n"], "outputs": ["0\n", "0", "1\n", "3\n", "3", "1", "2\n", "2"]}
coding
742
Solve the programming task below in a Python markdown code block. Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n. s = f (1) + f (2) + ... + f (n) Create a program that reads a, b, n, outp...
{"inputs": ["1 2 1\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n7 4 2", "1 2 1\n2 3 2\n5 4 3\n7 3 2", "1 2 1\n2 3 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 1", "1 2 1\n2 4 3\n5 1 3\n7 3 1", "2 2 1\n2 4 3\n5 1 3\n7 3 1"], "outputs": ["5\n24\n7\n6\n", "5\n24\n7\n12\n", "5\n12\n7\n6\n", "5\...
coding
234
Solve the programming task below in a Python markdown code block. # Story&Task There are three parties in parliament. The "Conservative Party", the "Reformist Party", and a group of independants. You are a member of the “Conservative Party” and you party is trying to pass a bill. The “Reformist Party” is trying to b...
{"functional": "_inputs = [[8, 3, 3], [13, 4, 7], [7, 4, 3], [11, 4, 1], [11, 5, 1], [11, 6, 1], [11, 4, 4], [11, 5, 4], [11, 5, 5], [11, 4, 6], [11, 4, 5], [15, 9, 3], [16, 7, 8], [16, 8, 7], [16, 1, 8]]\n_outputs = [[2], [-1], [0], [2], [1], [0], [2], [1], [1], [-1], [2], [0], [-1], [1], [-1]]\nimport math\ndef _deep...
coding
657
Solve the programming task below in a Python markdown code block. Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island wit...
{"inputs": ["1 1 1\n1\n1\n", "2 1 1\n1\n1\n", "2 1 1\n1\n0\n", "2 1 1\n2\n0\n", "2 2 1\n2 1\n1\n", "3 2 2\n2 4\n3 2\n", "3 2 2\n2 4\n3 3\n", "5 3 5\n2 3 4\n1 1 3 4 5\n"], "outputs": ["1\n1 ", "1\n1 ", "1\n1 ", "1\n1 ", "1\n1 ", "1\n2 ", "2\n1 2 ", "3\n1 2 3 "]}
coding
591
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure : let x be the sum of all elements currently in your array. choose index i, such tha...
{"functional": "def check(candidate):\n assert candidate(target = [9,3,5]) == True\n assert candidate(target = [1,1,1,2]) == False\n assert candidate(target = [8,5]) == True\n\n\ncheck(Solution().isPossible)"}
coding
144
Solve the programming task below in a Python markdown code block. Sereja has two sequences a and b and number p. Sequence a consists of n integers a_1, a_2, ..., a_{n}. Similarly, sequence b consists of m integers b_1, b_2, ..., b_{m}. As usual, Sereja studies the sequences he has. Today he wants to find the number of ...
{"inputs": ["1 1 1\n1\n1\n", "1 1 2\n1\n2\n", "1 1 2\n1\n2\n", "1 1 1\n1\n1\n", "1 1 2\n1\n3\n", "2 2 1\n1 2\n2 1\n", "2 2 1\n1 2\n1 2\n", "2 2 1\n1 2\n2 1\n"], "outputs": ["1\n1\n", "0\n", "0\n", "1\n1 ", "0\n\n", "1\n1\n", "1\n1\n", "1\n1 "]}
coding
380
Solve the programming task below in a Python markdown code block. At Akabe High School, which is a programmer training school, the roles of competition programmers in team battles are divided into the following three types. C: | Coder | I am familiar with the language and code. --- | --- | --- A: | Algorithm | I am goo...
{"inputs": ["4\n3 0 0\n1 1 1\n9 4 2\n0 1 2", "4\n2 0 0\n1 1 1\n9 4 2\n0 1 2", "4\n3 0 1\n1 1 1\n9 4 1\n0 1 2", "4\n3 0 0\n1 2 1\n0 4 2\n0 1 2", "4\n0 0 0\n1 2 1\n0 4 2\n0 1 3", "4\n2 1 0\n2 2 2\n9 8 2\n0 1 3", "4\n0 1 2\n3 0 2\n9 0 0\n0 2 3", "4\n0 0 0\n1 2 1\n1 4 2\n0 0 3"], "outputs": ["1\n1\n5\n0\n", "0\n1\n5\n0\n",...
coding
415
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times. The Fibonacci numbers are defined as: F1 = 1 F2 = 1 Fn = Fn-1 + Fn-2 f...
{"functional": "def check(candidate):\n assert candidate(k = 7) == 2 \n assert candidate(k = 10) == 2 \n assert candidate(k = 19) == 3 \n\n\ncheck(Solution().findMinFibonacciNumbers)"}
coding
136
Solve the programming task below in a Python markdown code block. Given an array, return the reversed version of the array (a different kind of reverse though), you reverse portions of the array, you'll be given a length argument which represents the length of each portion you are to reverse. E.g if after reversi...
{"functional": "_inputs = [[[2, 4, 6, 8, 10, 12, 14, 16], 3], [[2, 4, 6, 8, 10, 12, 14, 16], 2], [[1, 2, 3, 4, 5, 6], 2], [[1, 2, 3, 4, 5, 6], 0], [[1, 2, 3, 4, 5, 6], 10]]\n_outputs = [[[6, 4, 2, 12, 10, 8, 16, 14]], [[4, 2, 8, 6, 12, 10, 16, 14]], [[2, 1, 4, 3, 6, 5]], [[1, 2, 3, 4, 5, 6]], [[6, 5, 4, 3, 2, 1]]]\nimp...
coding
168
Solve the programming task below in a Python markdown code block. Do you know Professor Saeed? He is the algorithms professor at Damascus University. Yesterday, he gave his students hard homework (he is known for being so evil) - for a given binary string $S$, they should compute the sum of $F(S, L, R)$ over all pairs ...
{"inputs": ["1\n001"], "outputs": ["6"]}
coding
630
Solve the programming task below in a Python markdown code block. ## Task Given a positive integer `n`, calculate the following sum: ``` n + n/2 + n/4 + n/8 + ... ``` All elements of the sum are the results of integer division. ## Example ``` 25 => 25 + 12 + 6 + 3 + 1 = 47 ``` Also feel free to reuse/extend th...
{"functional": "_inputs = [[25], [127], [38], [1], [320], [13], [15], [47], [101], [257]]\n_outputs = [[47], [247], [73], [1], [638], [23], [26], [89], [198], [512]]\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=...
coding
115
Solve the programming task below in a Python markdown code block. For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_...
{"inputs": ["2\n2\n3"], "outputs": ["NO\nYES\n1 3 2"]}
coding
645
Solve the programming task below in a Python markdown code block. Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the ...
{"inputs": ["1 1\n1 1\n", "9 1\n1 1\n", "2 1\n2 2\n", "6 2\n4 6\n2 5\n", "4 2\n1 4\n2 4\n", "4 2\n1 4\n2 3\n", "4 2\n2 4\n2 4\n", "4 2\n1 2\n2 3\n"], "outputs": ["1\n0\n", "1\n0 0 0 0 0 0 0 0 0\n", "1\n0 0\n", "3\n0 1 2 0 1 2\n", "3\n0 1 2 0\n", "2\n0 1 0 1 \n", "3\n0 1 2 0 \n", "2\n0 1 0 1 \n"]}
coding
505
Solve the programming task below in a Python markdown code block. Gildong's town has a train system that has $100$ trains that travel from the bottom end to the top end and $100$ trains that travel from the left end to the right end. The trains starting from each side are numbered from $1$ to $100$, respectively, and a...
{"inputs": ["3\n1 2\n1\n1 4\n3 2\n2 3 4\n3 4\n9 14\n2 7 9 28 33 12 59 92 99\n6 9 14 19 8 26 5 35 41 68 85 87 99 100\n", "3\n1 2\n1\n1 4\n3 2\n2 3 4\n3 4\n9 14\n2 7 9 28 33 12 59 92 99\n6 9 14 19 8 45 5 35 41 68 85 87 99 100\n", "3\n1 2\n1\n1 4\n3 2\n2 3 4\n3 4\n9 14\n2 7 9 28 33 12 59 92 99\n6 9 14 19 8 45 5 35 41 61 8...
coding
730
Solve the programming task below in a Python markdown code block. ## Task An `ATM` ran out of 10 dollar bills and only has `100, 50 and 20` dollar bills. Given an amount between `40 and 10000 dollars (inclusive)` and assuming that the ATM wants to use as few bills as possible, determinate the minimal number of 100,...
{"functional": "_inputs = [[40], [250], [260], [230], [60]]\n_outputs = [[[0, 0, 2]], [[2, 1, 0]], [[2, 0, 3]], [[1, 1, 4]], [[0, 0, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (...
coding
292
Please solve the programming task below using a self-contained code snippet in a markdown code block. A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free. The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than ...
{"functional": "def check(candidate):\n assert candidate(cost = [1,2,3]) == 5\n assert candidate(cost = [6,5,7,9,2,2]) == 23\n assert candidate(cost = [5,5]) == 10\n\n\ncheck(Solution().minimumCost)"}
coding
198
Solve the programming task below in a Python markdown code block. Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда В...
{"inputs": ["3\n4 5 4\n", "3\n4 5 1\n", "4\n5 4 3 5\n", "6\n4 5 4 5 4 4\n", "6\n4 5 3 4 5 4\n", "6\n3 3 3 4 5 5\n", "7\n4 5 3 4 5 4 1\n", "8\n4 4 4 4 5 5 5 5\n"], "outputs": ["1\n", "0\n", "0\n", "2\n", "1\n", "1\n", "1\n", "2\n"]}
coding
518
Solve the programming task below in a Python markdown code block. Today, Chef decided to cook some delicious meals from the ingredients in his kitchen. There are $N$ ingredients, represented by strings $S_1, S_2, \ldots, S_N$. Chef took all the ingredients, put them into a cauldron and mixed them up. In the cauldron, t...
{"inputs": ["3\n6\ncplusplus\noscar\ndeck\nfee\nhat\nnear\n5\ncode\nhacker\nchef\nchaby\ndumbofe\n5\ncodechef\nchefcode\nfehcedoc\ncceeohfd\ncodechef"], "outputs": ["1\n2\n5"]}
coding
570
Solve the programming task below in a Python markdown code block. How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b. Constraints * 1 ≤ a, b, c ≤ 10000 * a ≤ b Input Three integers a, b and c are given in a line separated by a single spa...
{"inputs": ["6 2 4", "6 2 1", "6 1 1", "6 0 1", "4 0 0", "1 0 0", "2 0 0", "1 1 0"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
coding
116
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n represented as a string, return the smallest good base of n. We call k >= 2 a good base of n, if all digits of n base k are 1's.   Please complete the following python code precisely: ```python clas...
{"functional": "def check(candidate):\n assert candidate(n = \"13\") == \"3\"\n assert candidate(n = \"4681\") == \"8\"\n assert candidate(n = \"1000000000000000000\") == \"999999999999999999\"\n\n\ncheck(Solution().smallestGoodBase)"}
coding
89
Solve the programming task below in a Python markdown code block. A binary string is a string consisting only of the characters 0 and 1. You are given a binary string $s$. For some non-empty substring$^\dagger$ $t$ of string $s$ containing $x$ characters 0 and $y$ characters 1, define its cost as: $x \cdot y$, if $x ...
{"inputs": ["1\n7\n0111111\n", "6\n5\n11100\n7\n1100110\n6\n011110\n7\n1001010\n4\n1000\n1\n0\n"], "outputs": ["36\n", "9\n12\n16\n12\n9\n1\n"]}
coding
692
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with index 0, or the step with...
{"functional": "def check(candidate):\n assert candidate(cost = [10,15,20]) == 15\n assert candidate(cost = [1,100,1,1,1,100,1,1,100,1]) == 6\n\n\ncheck(Solution().minCostClimbingStairs)"}
coding
121
Solve the programming task below in a Python markdown code block. There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.) Takahashi remembers (x_...
{"inputs": ["2 1 6 6", "2 2 6 6", "2 2 6 2", "2 2 6 1", "3 2 6 2", "6 2 6 2", "6 2 6 3", "2 2 6 3"], "outputs": ["1 10 -3 5\n", "2 10 -2 6\n", "6 6 2 6\n", "7 5 3 6\n", "6 5 3 5\n", "6 2 6 2\n", "5 3 5 2\n", "5 7 1 6\n"]}
coding
386
Solve the programming task below in a Python markdown code block. One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow. A positive integer $a$ is initially on the screen. The player can put a coin into the machine and then add $1$ to or subtract $1$ from ...
{"inputs": ["2\n20\n42\n", "2\n35\n44\n", "2\n99\n11\n", "2\n85\n96\n", "2\n37\n97\n", "2\n28\n94\n", "2\n85\n96\n", "2\n37\n97\n"], "outputs": ["2\n1 1\n1 1\n", "-1\n", "8\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n1 -1\n", "1\n1 1\n", "-1\n", "-1\n", " 1\n...
coding
715
Solve the programming task below in a Python markdown code block. In this task, we would like for you to appreciate the usefulness of the groupby() function of itertools . To read more about this function, Check this out . You are given a string $\mbox{S}$. Suppose a character '$\textbf{C}$' occurs consecutively $\mbo...
{"inputs": ["1222311\n"], "outputs": ["(1, 1) (3, 2) (1, 3) (2, 1)\n"]}
coding
312
Solve the programming task below in a Python markdown code block. # Task Given string `s`, which contains only letters from `a to z` in lowercase. A set of alphabet is given by `abcdefghijklmnopqrstuvwxyz`. 2 sets of alphabets mean 2 or more alphabets. Your task is to find the missing letter(s). You may need t...
{"functional": "_inputs = [['abcdefghijklmnopqrstuvwxy'], ['abcdefghijklmnopqrstuvwxyz'], ['aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy'], ['abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy'], ['codewars']]\n_outputs = [['z'], [''], ['zz'], ['ayzz'], ['bfghijklmnpqtuvxyz']]\nimport math\ndef _deep_eq(a, b, tol=1...
coding
358
Solve the programming task below in a Python markdown code block. Problem statement Given the string $ S $. Find the number of all anagrams in $ S $ that are palindromic. An anagram of the string $ X $ is an anagram of $ Y $, which means that $ X $ is equal to $ Y $, or that the rearranged characters of $ X $ are equ...
{"inputs": ["ac", "cc", "bc", "cb", "ca", "db", "bd", "be"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
271
Solve the programming task below in a Python markdown code block. There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or m...
{"inputs": ["2\n0\n2", "2\n1\n0", "2\n1\n1", "2\n2\n1", "2\n2\n2", "2\n2\n3", "2\n1\n3", "2\n1\n6"], "outputs": ["second\n", "first\n", "first\n", "first\n", "second\n", "first\n", "first\n", "first\n"]}
coding
259
Please solve the programming task below using a self-contained code snippet in a markdown code block. We have two special characters: The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Given a binary array bits that ends with 0, return true if the las...
{"functional": "def check(candidate):\n assert candidate(bits = [1,1,1,0]) == False\n\n\ncheck(Solution().isOneBitCharacter)"}
coding
109
Solve the programming task below in a Python markdown code block. It's March and you just can't seem to get your mind off brackets. However, it is not due to basketball. You need to extract statements within strings that are contained within brackets. You have to write a function that returns a list of statements that...
{"functional": "_inputs = [[[1, 2, 3]], [{'3': 4}], [False], [23.45], ['arc.tic.[circle]?[?]'], ['Big [L][e][B][r][o][n]!][['], ['[][]]]][[[[[[][]'], ['logger?]?system...12.12.133333 at [12-32-1432-16]']]\n_outputs = [['Take a seat on the bench.'], ['Take a seat on the bench.'], ['Take a seat on the bench.'], ['Take a ...
coding
120
Solve the programming task below in a Python markdown code block. A string is said to be a child of a another string if it can be formed by deleting 0 or more characters from the other string. Letters cannot be rearranged. Given two strings of equal length, what's the longest string that can be constructed such that...
{"inputs": ["AA\nBB\n", "HARRY\nSALLY\n", "ABCDEF\nFBDAMN\n", "SHINCHAN\nNOHARAAA\n"], "outputs": ["0\n", " 2\n", "2\n", "3\n"]}
coding
493
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return 0 if the sum of the digits of the minimum integer in nums is odd, or 1 otherwise.   Please complete the following python code precisely: ```python class Solution: def sumOfDigit...
{"functional": "def check(candidate):\n assert candidate([34,23,1,24,75,33,54,8]) == 0\n assert candidate([99,77,33,66,55]) == 1\n\n\ncheck(Solution().sumOfDigits)"}
coding
78
Solve the programming task below in a Python markdown code block. An expression is formed by taking the digits 1 to 9 in numerical order and then inserting into each gap between the numbers either a plus sign or a minus sign or neither. Your task is to write a method which takes one parameter and returns the **smalles...
{"functional": "_inputs = [[11], [100], [766], [160], [70], [389]]\n_outputs = [[5], [3], [4], [None], [6], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n i...
coding
411
Solve the programming task below in a Python markdown code block. Chef is given two integers A and C such that A ≤ C. Chef wants to find whether there exists any integer B such that A, B, and C are in [arithmetic progression]. ------ Input Format ------ - The first line of input will contain a single integer T, de...
{"inputs": ["4\n3 5\n6 6\n2 7\n1 9\n"], "outputs": ["4\n6\n-1\n5\n"]}
coding
331
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon. Alice wants the rope to be colorful. She does not want two consecutive balloons to be o...
{"functional": "def check(candidate):\n assert candidate(colors = \"abaac\", neededTime = [1,2,3,4,5]) == 3\n assert candidate(colors = \"abc\", neededTime = [1,2,3]) == 0\n assert candidate(colors = \"aabaa\", neededTime = [1,2,3,4,1]) == 2\n\n\ncheck(Solution().minCost)"}
coding
174
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of string words and two integers left and right. A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e...
{"functional": "def check(candidate):\n assert candidate(words = [\"are\",\"amy\",\"u\"], left = 0, right = 2) == 2\n assert candidate(words = [\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"], left = 1, right = 4) == 3\n\n\ncheck(Solution().vowelStrings)"}
coding
136
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them. A string s is a subsequence of string t if deleting som...
{"functional": "def check(candidate):\n assert candidate(str1 = \"abac\", str2 = \"cab\") == \"cabac\"\n assert candidate(str1 = \"aaaaaaaa\", str2 = \"aaaaaaaa\") == \"aaaaaaaa\"\n\n\ncheck(Solution().shortestCommonSupersequence)"}
coding
121
Solve the programming task below in a Python markdown code block. Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question: Given two binary numbers $a$ and $b$ of length $n$. How many different ways of swapping two digits in $a$ (only in $a$, not $b$) so that bitwise...
{"inputs": ["2\n00\n00\n", "2\n00\n11\n", "2\n00\n11\n", "2\n00\n00\n", "5\n01011\n11001\n", "5\n01011\n11011\n", "5\n01011\n10011\n", "5\n11001\n10111\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "4\n", "3\n", "4\n", "2\n"]}
coding
516
Solve the programming task below in a Python markdown code block. A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registr...
{"inputs": ["1\nn\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\no\n", "1\np\n", "2\nu\nu\n", "2\nv\nu\n"], "outputs": ["OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\nu1\n", "OK\nOK\n"]}
coding
378
Solve the programming task below in a Python markdown code block. Abhiram needs to search for an antidote. He comes to know that clue for finding the antidote is carefully hidden by KrishnaMurthy in the form of a puzzle. The puzzle consists of a string S and a keywordK. Abhiram needs to find the string of position of ...
{"inputs": ["cat is the act of tac\ncat"], "outputs": ["The antidote is found in 46."]}
coding
269
Solve the programming task below in a Python markdown code block. Given $n$ two-dimensional points in space, determine whether they lie on some vertical or horizontal line. If yes, print YES; otherwise, print NO. Input Format The first line contains a single positive integer, $n$, denoting the number of points. Eac...
{"inputs": ["5\n0 1\n0 2\n0 3\n0 4\n0 5\n", "5\n0 1\n0 2\n1 3\n0 4\n0 5\n"], "outputs": ["YES\n", "NO\n"]}
coding
268
Solve the programming task below in a Python markdown code block. Construct a function 'coordinates', that will return the distance between two points on a cartesian plane, given the x and y coordinates of each point. There are two parameters in the function, ```p1``` and ```p2```. ```p1``` is a list ```[x1,y1]``` whe...
{"functional": "_inputs = [[[3, 6], [14, 6]], [[-2, 5], [-2, -10], 2], [[1, 2], [4, 6]], [[5, 3], [10, 15], 2], [[-2, -10], [6, 5]], [[4, 7], [6, 2], 3], [[-4, -5], [-5, -4], 1], [[3, 8], [3, 8]], [[-3, 8], [3, 8]], [[3, 8], [3, -8]]]\n_outputs = [[11], [15], [5], [13], [17], [5.385], [1.4], [0], [6], [16]]\nimport mat...
coding
185
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only.   Please complete the following python code pre...
{"functional": "def check(candidate):\n assert candidate(s = \"Hello World\") == 5\n assert candidate(s = \" fly me to the moon \") == 4\n assert candidate(s = \"luffy is still joyboy\") == 6\n\n\ncheck(Solution().lengthOfLastWord)"}
coding
83
Solve the programming task below in a Python markdown code block. problem Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions. Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $. Example Input 8 5 2 4 9 4 9...
{"inputs": ["8\n5 2 4 4 4 9 2 5", "8\n6 2 7 4 2 7 2 0", "8\n5 2 4 9 4 9 2 5", "8\n5 2 4 4 4 14 2 0", "8\n5 2 4 4 4 14 2 5", "8\n5 2 4 4 4 11 2 0", "8\n5 2 6 4 4 11 2 0", "8\n6 2 6 4 4 11 2 0"], "outputs": ["1 2 6 7 8\n", "8\n", "1 2 4 6 7 8", "8\n", "1 2 6 7 8\n", "8\n", "8\n", "8\n"]}
coding
118
Solve the programming task below in a Python markdown code block. You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. Input The first line contai...
{"inputs": ["1 2\n95\n", "1 2\n96\n", "1 2\n54\n", "1 3\n289\n", "1 3\n250\n", "2 1\n2\n0\n", "2 1\n2\n1\n", "3 1\n1\n2\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "1\n", "1\n"]}
coding
372
Solve the programming task below in a Python markdown code block. You are given a positive integer $n$. Let $S(x)$ be sum of digits in base 10 representation of $x$, for example, $S(123) = 1 + 2 + 3 = 6$, $S(0) = 0$. Your task is to find two integers $a, b$, such that $0 \leq a, b \leq n$, $a + b = n$ and $S(a) + S(b...
{"inputs": ["1\n", "8\n", "9\n", "5\n", "5\n", "1\n", "8\n", "9\n"], "outputs": ["1\n", "8\n", "9\n", "5\n", "5\n", "1\n", "8\n", "9\n"]}
coding
405
Solve the programming task below in a Python markdown code block. Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thin...
{"inputs": ["1\n5\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n3\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n"]}
coding
566
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a perfect binary tree, reverse the node values at each odd level of the tree. For example, suppose the node values at level 3 are [2,1,3,4,7,11,29,18], then it should become [18,29,11,7,4,3,1,2]. R...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([2,3,5,8,13,21,34])), tree_node([2,5,3,8,13,21,34]))\n assert is_same_tree(candidate(root = tree_node([7,13,11])), tree_node([7,11,13]))\n assert is_same_tree(candidate(root = tree_node([0,1,2,0,0,0,0,1,1,1,1,2,2,2,2])), tre...
coding
229
Please solve the programming task below using a self-contained code snippet in a markdown code block. Hercy wants to save money for his first car. He puts money in the Leetcode bank every day. He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day bef...
{"functional": "def check(candidate):\n assert candidate(n = 4) == 10\n assert candidate(n = 10) == 37\n assert candidate(n = 20) == 96\n\n\ncheck(Solution().totalMoney)"}
coding
147
Solve the programming task below in a Python markdown code block. In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing...
{"inputs": ["3 2 3", "5 4 1", "0 2 3", "8 4 1", "0 0 3", "8 4 2", "3 3 3", "5 4 2"], "outputs": ["1 2\n", "2 6\n", "0 1\n", "4 8\n", "0 0\n", "8 4\n", "1 3", "5 3"]}
coding
276
Solve the programming task below in a Python markdown code block. Ayu loves distinct letter sequences ,a distinct letter sequence is defined by a sequence of small case english alphabets such that no character appears more then once. But however there are two phrases that she doesn't like these phrases are "kar" and "s...
{"inputs": ["2\nkarp\nabcd"], "outputs": ["22\n24"]}
coding
280
Solve the programming task below in a Python markdown code block. Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV sets with...
{"inputs": ["4 2 6 4\n", "1 1 1 1\n", "3 3 2 4\n", "3 3 2 6\n", "4 2 4 3\n", "5 5 1 1\n", "3 3 2 4\n", "4 2 4 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "5\n", "1\n", "0\n"]}
coding
628
Solve the programming task below in a Python markdown code block. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 3...
{"inputs": ["1\n8\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n6\n", "1\n7\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
610
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 wants to give a gift to Chefina to celebrate their anniversary. Of course, he has a sequence $a_{1}, a_{2}, \ldots, a_{N}$ ready for this occasi...
{"inputs": ["1\n4\n2 3 4 5"], "outputs": ["3"]}
coding
531
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer array nums. Partition nums into two arrays, nums1 and nums2, such that: Each element of the array nums belongs to either the array nums1 or the array nums2. Both arrays are non-empty....
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,4]) == 1\n assert candidate(nums = [100,1,10]) == 9\n\n\ncheck(Solution().findValueOfPartition)"}
coding
167
Solve the programming task below in a Python markdown code block. Madoka wants to enter to "Novosibirsk State University", but in the entrance exam she came across a very difficult task: Given an integer $n$, it is required to calculate $\sum{\operatorname{lcm}(c, \gcd(a, b))}$, for all triples of positive integers $(...
{"inputs": ["3\n", "5\n", "4\n", "6\n", "7\n", "8\n", "9\n", "47\n"], "outputs": ["1\n", "11\n", "4\n", "20\n", "42\n", "60\n", "100\n", "32596\n"]}
coding
539
Solve the programming task below in a Python markdown code block. For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * pushBack($x$): add element $x$ at the end of $A$ * randomAccess($p$):print element $a_p$ * popBack(): delete the last element of $A$ $A$ is a...
{"inputs": ["8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 1", "8\n0 0\n0 2\n0 3\n2\n1 0\n1 0\n1 1\n1 1", "8\n0 1\n0 2\n0 4\n2\n0 4\n1 0\n1 1\n1 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n0 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 0", "8\n0 0\n0 3\n0 3\n2\n0 0\n1 0\n1 1\n1 1", "8\n0 1...
coding
331
Solve the programming task below in a Python markdown code block. HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of HDD hard drives is the following: ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "3\n3 1 2\n", "3\n3 2 1\n", "3\n2 3 1\n", "3\n1 2 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "3\n", "2\n", "3\n", "2\n"]}
coding
501
Please solve the programming task below using a self-contained code snippet in a markdown code block. A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Every adjacent pair of words differs by a single letter. ...
{"functional": "def check(candidate):\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]) == [[\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],[\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]]\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordLis...
coding
204
Solve the programming task below in a Python markdown code block. As the Rohan is also taking part in the CodeWealth Series, this week he learned about hashing. Now he wants to practice some problems. So he came up with a simple problem. Firstly, he made a hash function F such that: F(x) = x % 10 Now using this funct...
{"inputs": ["2\n3\n1 2 3\n4\n1 1 2 3", "5\n5\n5 5 5 5 5\n1\n1\n2\n0 0\n4\n0 0 0 0\n5\n0 1 0 1 0"], "outputs": ["0\n1", "4\n0\n1\n3\n3"]}
coding
326
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicogr...
{"inputs": ["1 1\n", "2 3\n", "2 4\n", "7 1\n", "3 7\n", "1 2\n", "6 1\n", "2 2\n"], "outputs": ["0", "-1", "-1", "2", "-1", "-1", "1\n", "0\n"]}
coding
425
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of unique integers salary where salary[i] is the salary of the ith employee. Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5 of the actual an...
{"functional": "def check(candidate):\n assert candidate(salary = [4000,3000,1000,2000]) == 2500.00000\n assert candidate(salary = [1000,2000,3000]) == 2000.00000\n assert candidate(salary = [6000,5000,4000,3000,2000,1000]) == 3500.00000\n assert candidate(salary = [8000,9000,2000,3000,6000,1000]) == 4750.0...
coding
96
Solve the programming task below in a Python markdown code block. An array is said to be `hollow` if it contains `3` or more `0`s in the middle that are preceded and followed by the same number of non-zero elements. Furthermore, all the zeroes in the array must be in the middle of the array. Write a function named `i...
{"functional": "_inputs = [[[-1, 0, 0, 0, 3]], [[1, 0, 0, 0, 0]]]\n_outputs = [[True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b...
coding
133
Solve the programming task below in a Python markdown code block. A binary string A is called *good* if it can be sorted (in non-decreasing order) using the following operation: Select an i (1 ≤ i ≤ |A| - 1) and swap A_{i} with A_{i + 1}. This operation can be performed on any i at most once. For example, A = 10110 ...
{"inputs": ["2\n4\n0011\n6\n111000\n"], "outputs": ["10\n17\n"]}
coding
540
Solve the programming task below in a Python markdown code block. As you may know, once some people pass their teens, they jokingly only celebrate their 20th or 21st birthday, forever. With some maths skills, that's totally possible - you only need to select the correct number base! For example, if they turn 32, that'...
{"functional": "_inputs = [[32], [39], [22], [65], [83]]\n_outputs = [[\"32? That's just 20, in base 16!\"], [\"39? That's just 21, in base 19!\"], [\"22? That's just 20, in base 11!\"], [\"65? That's just 21, in base 32!\"], [\"83? That's just 21, in base 41!\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isi...
coding
323
Solve the programming task below in a Python markdown code block. Three numbers A, B and C are the inputs. Write a program to find second largest among them. -----Input----- The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers A, B and C. -----O...
{"inputs": ["3 \n0 7 27\n11308 32 23\n0 1 39", "3 \n0 5 766\n5757 312 12\n6 0 40", "3 \n0 5 766\n5757 317 12\n6 0 40", "3 \n0 7 766\n5757 317 12\n6 0 40", "3 \n0 7 766\n5757 596 16\n6 0 40", "3 \n1 5 766\n5352 312 19\n1 0 40", "3 \n9 10 68\n10213 56 13\n10 0 3", "3 \n0 7 27\n11308 317 23\n0 1 39"], "outputs": ["7\n32\n...
coding
177
Solve the programming task below in a Python markdown code block. Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing. A subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$. A subarray $A[i, j]$ is non-decreasing if $A_i ≤ A_i+...
{"inputs": ["2\n4\n1 4 2 3\n1\n5", "2\n4\n1 2 2 3\n1\n5", "2\n4\n1 4 2 2\n1\n5", "2\n4\n2 1 2 2\n1\n5", "2\n4\n2 1 3 2\n1\n5", "2\n4\n6 5 3 2\n1\n2", "2\n4\n1 4 2 2\n1\n3", "2\n4\n2 4 2 2\n1\n5"], "outputs": ["6\n1", "10\n1\n", "6\n1\n", "7\n1\n", "5\n1\n", "4\n1\n", "6\n1\n", "6\n1\n"]}
coding
459
Solve the programming task below in a Python markdown code block. Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be ava...
{"inputs": ["2\n4 6\n1 1\n2 1 2\n3 1 2 3\n4 1 2 3 4\n2 2 3\n1 3\n2 2\n1 1\n1 1\n"], "outputs": ["YES\n1 2 1 1 2 3 \nNO\n"]}
coding
645
Solve the programming task below in a Python markdown code block. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix $M$ of size $n \times n$ contains only 'X' and '.' (without quotes). The element in the $i$-th row and the $j$-th column $(i, j)$ is defined as $M(i, j)$, where $...
{"inputs": ["1\nX\n", "1\n.\n", "1\n.\n", "1\nX\n", "1\n/\n", "1\nY\n", "1\n0\n", "1\nZ\n"], "outputs": ["0\n", "0\n", "0", "0", "0\n", "0\n", "0\n", "0\n"]}
coding
558
Solve the programming task below in a Python markdown code block. The weight of a sequence is defined as the number of unordered pairs of indexes $(i,j)$ (here $i \lt j$) with same value ($a_{i} = a_{j}$). For example, the weight of sequence $a = [1, 1, 2, 2, 1]$ is $4$. The set of unordered pairs of indexes with same ...
{"inputs": ["2\n4\n1 2 1 1\n4\n1 2 3 4\n", "2\n4\n1 2 2 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 1\n4\n1 2 3 4\n", "2\n4\n2 2 1 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 1\n4\n1 3 3 4\n", "2\n4\n1 2 2 1\n4\n1 4 3 4\n", "2\n4\n2 2 4 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 2\n4\n1 3 3 4\n"], "outputs": ["6\n0\n", "5\n0\n", "9\n0\n", "6\n0\n", "9\n4\n...
coding
587
Solve the programming task below in a Python markdown code block. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d m...
{"inputs": ["1\n3\n1\n3\n", "1\n3\n1\n3\n", "1\n3\n1\n1\n", "1\n1\n2\n1 2\n", "1\n1\n2\n1 1\n", "1\n1\n2\n1 2\n", "1\n1\n2\n1 1\n", "2\n2 2\n2\n2 2\n"], "outputs": ["3:3\n", "3:3", "3:2\n", "2:4\n", "2:4\n", "2:4", "2:4", "6:6\n"]}
coding
378
Solve the programming task below in a Python markdown code block. Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d. Johnny's truck has a gas tank that holds exactly n liters,...
{"inputs": ["16 5 2\n8 2\n5 1\n", "153 105 1\n96 83995\n", "10 4 4\n3 5\n5 8\n6 3\n8 4\n", "229 79 2\n27 270968\n76 284309\n", "229 79 2\n27 349050\n76 284309\n", "229 79 2\n27 349050\n16 284309\n", "229 79 2\n53 349050\n16 284309\n", "229 123 2\n6 270968\n76 284309\n"], "outputs": ["-1\n", "4031760\n", "22\n", "-1\n",...
coding
497
Solve the programming task below in a Python markdown code block. Madoka is going to enroll in "TSUNS PTU". But she stumbled upon a difficult task during the entrance computer science exam: A number is called good if it is a multiple of $d$. A number is called beatiful if it is good and it cannot be represented as a ...
{"inputs": ["8\n6 2\n12 2\n36 2\n8 2\n1000 10\n2376 6\n128 4\n16384 4\n"], "outputs": ["NO\nNO\nYES\nNO\nYES\nYES\nNO\nYES\n"]}
coding
578
Solve the programming task below in a Python markdown code block. Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibl...
{"inputs": ["3 1\n0", "6 1\n0", "5 1\n0", "4 1\n1", "8 1\n0", "2 1\n0", "7 1\n1", "1 1\n0"], "outputs": ["3\n", "6\n", "5\n", "4\n", "8\n", "2\n", "7\n", "1\n"]}
coding
324
Please solve the programming task below using a self-contained code snippet in a markdown code block. A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w, where w is divisible by 32 (that is, no byte will be split across rows). The heig...
{"functional": "def check(candidate):\n assert candidate(length = 1, w = 32, x1 = 30, x2 = 31, y = 0) == [3]\n assert candidate(length = 3, w = 96, x1 = 0, x2 = 95, y = 0) == [-1, -1, -1]\n\n\ncheck(Solution().drawLine)"}
coding
216
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer n, an array languages, and an array frie...
{"functional": "def check(candidate):\n assert candidate(n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]) == 1\n assert candidate(n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]) == 2\n\n\ncheck(Solution().minimumTeachings)"}
coding
245
Solve the programming task below in a Python markdown code block. Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$. Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$. Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if: $a$ i...
{"inputs": ["1\n122520 -643096130 7376743\n", "1\n27154 -643096130 65152507\n", "1\n200000 -926527577 99824348\n", "1\n167208 -356488738 91840074\n", "1\n45288 -643096130 139364119\n", "1\n167208 -356488738 34429628\n", "1\n122520 -643096130 24457044\n", "1\n27154 -643096130 139364119\n"], "outputs": ["862272722\n", "7...
coding
481
Solve the programming task below in a Python markdown code block. In all schools in Buryatia, in the $1$ class, everyone is told the theory of Fibonacci strings. "A block is a subsegment of a string where all the letters are the same and are bounded on the left and right by the ends of the string or by letters other t...
{"inputs": ["6\n1\n1\n2\n1 1\n2\n1 2\n3\n3 1 3\n2\n7 5\n6\n26 8 3 4 13 34\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\nYES\n"]}
coding
725
Solve the programming task below in a Python markdown code block. Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then ...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "2 1\n1\n", "5 4\n4 3 1 2\n", "5 4\n2 3 4 1\n", "5 4\n2 3 4 1\n", "5 4\n3 3 4 1\n", "35 3\n6 1 11\n"], "outputs": ["1 \n", "1\n", "1 1 ", "1 1 3 4 4 \n", "1 2 2 2 2 \n", "1 2 2 2 2\n", "1 1 3 3 3 ", "1 1 1 1 1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 "]}
coding
507
Solve the programming task below in a Python markdown code block. Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi need...
{"inputs": ["4 4\n0 1 2 2", "4 4\n0 1 2 4", "4 4\n1 1 4 2", "4 4\n0 2 2 4", "4 4\n1 0 4 2", "4 7\n0 2 2 4", "4 4\n1 2 2 2", "4 4\n0 1 3 2"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
237
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums consisting of positive integers. You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers...
{"functional": "def check(candidate):\n assert candidate(nums = [1,13,10,12,31]) == 6\n assert candidate(nums = [2,2,2]) == 1\n\n\ncheck(Solution().countDistinctIntegers)"}
coding
108
Solve the programming task below in a Python markdown code block. Find the greatest common divisor of two positive integers. The integers can be large, so you need to find a clever solution. The inputs `x` and `y` are always greater or equal to 1, so the greatest common divisor will always be an integer that is also ...
{"functional": "_inputs = [[1, 3], [60, 12], [2672, 5678], [10927782, 6902514], [1590771464, 1590771620]]\n_outputs = [[1], [12], [334], [846], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isin...
coding
99
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Compute: floor[1*e] + floor[2*e] + floor[3*e] + ... + floor[n*e], where floor[x] is the largest integer that is not greater than x, and e is Euler's number: 2.7182818284... ...
{"inputs": ["3"], "outputs": ["15"]}
coding
296
Solve the programming task below in a Python markdown code block. We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the sq...
{"inputs": ["3\n7\n15", "3\n7\n45", "3\n7\n76", "3\n7\n54", "3\n0\n76", "3\n2\n43", "3\n2\n59", "3\n1\n34"], "outputs": ["3\n", "7\n", "11\n", "8\n", "26\n", "15\n", "20\n", "12\n"]}
coding
266
Solve the programming task below in a Python markdown code block. You are making your very own boardgame. The game is played by two opposing players, featuring a 6 x 6 tile system, with the players taking turns to move their pieces (similar to chess). The design is finished, now it's time to actually write and implemen...
{"functional": "_inputs = [['K', 'A'], ['S', 'A'], ['k', 's'], ['a', 'a'], ['k', 'A'], ['K', 'a']]\n_outputs = [[-1], [-1], [-1], [-1], ['k'], ['K']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isi...
coding
681
Solve the programming task below in a Python markdown code block. For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The...
{"inputs": ["3\n0 0 3 0 1 1 2 0\n0 0 0 0 3 1 3 -1\n0 0 6 1 1 -2 5 0", "3\n0 0 3 0 1 1 2 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 3 -2 5 0", "3\n0 0 3 0 1 1 2 -1\n0 0 0 0 3 1 3 -1\n0 0 6 0 1 -2 5 0", "3\n1 0 3 0 1 1 0 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 2 -4 5 0", "3\n-1 -1 4 0 2 1 4 1\n2 1 0 0 0 0 3 0\n0 2 6 2 1 -2 5 0", "3\n0 0 3 0 1 ...
coding
252
Please solve the programming task below using a self-contained code snippet in a markdown code block. In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position. You are given an integer n. There is originally an array consisting of n in...
{"functional": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 2) == 1\n\n\ncheck(Solution().findDerangement)"}
coding
131
Solve the programming task below in a Python markdown code block. There are total N friends went to Chef's Pizza shop. There they bought a pizza. Chef divided the pizza into K equal slices. Now you have to check whether these K pizza slices can be distributed equally among the friends. Also given that every person shou...
{"inputs": ["2\n10\n20\n12\n5"], "outputs": ["YES\nNO"]}
coding
309
Solve the programming task below in a Python markdown code block. You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same. Constraints * 1 \leq N,K \leq...
{"inputs": ["4 3", "3 2", "5 3", "56 6", "20 6", "25 4", "25 7", "74 1"], "outputs": ["1\n", "9", "1", "1458\n", "54\n", "432\n", "27\n", "405224\n"]}
coding
211
Solve the programming task below in a Python markdown code block. Given two strings, $a$ and $\boldsymbol{b}$, find and print the total number of ways to insert a character at any position in string $\class{ML__boldsymbol}{\boldsymbol{a}}$ such that the length of the Longest Common Subsequence of characters in the two ...
{"inputs": ["aa\nbaaa\n"], "outputs": ["4\n"]}
coding
568
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": ["5\n1\n2\n3\n4\n5"], "outputs": ["1\n1\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112"]}
coding
229
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard versions is the maximum value of $k$. You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first...
{"inputs": ["1\n9124\n", "1\n9124\n", "1\n3621\n", "1\n4320\n", "1\n2836\n", "1\n6961\n", "1\n3722\n", "1\n6297\n"], "outputs": ["4\n", "4\n", "1\n", "2\n", "7\n", "3\n", "5\n", "2\n"]}
coding
587
Solve the programming task below in a Python markdown code block. You are given a permutation $a$ consisting of $n$ numbers $1$, $2$, ..., $n$ (a permutation is an array in which each element from $1$ to $n$ occurs exactly once). You can perform the following operation: choose some subarray (contiguous subsegment) of ...
{"inputs": ["1\n8\n6 2 3 1 8 4 5 7\n", "1\n8\n6 2 3 1 8 4 5 7\n", "1\n8\n6 0 3 1 8 4 5 7\n", "1\n8\n5 2 2 1 0 0 2 8\n", "1\n6\n6 0 3 1 8 4 5 7\n", "1\n8\n6 2 6 1 8 4 5 7\n", "1\n8\n6 0 3 1 8 6 5 7\n", "1\n6\n6 0 3 1 8 5 5 7\n"], "outputs": ["2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n"]}
coding
606
Solve the programming task below in a Python markdown code block. Chef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to successfully ...
{"inputs": ["1\n2 2"], "outputs": ["Yes"]}
coding
429
Solve the programming task below in a Python markdown code block. B: Twice as own problem You will be given Q queries. Since one positive integer N is given for each query, find the number of positive integers M that satisfy the following two conditions. * 2 Satisfy \ leq M \ leq N * Of the divisors of M, excluding ...
{"inputs": ["3\n73\n8\n9", "3\n7\n24\n1", "3\n7\n45\n2", "3\n7\n59\n2", "3\n7\n33\n1", "3\n7\n80\n2", "3\n7\n52\n2", "3\n7\n94\n1"], "outputs": ["25\n0\n0\n", "0\n5\n0\n", "0\n13\n0\n", "0\n18\n0\n", "0\n8\n0\n", "0\n29\n0\n", "0\n16\n0\n", "0\n34\n0\n"]}
coding
305
Solve the programming task below in a Python markdown code block. You are given a string S, each of whose characters is either '0', '1', or '?'. The *badness* of a binary string is defined to be the (absolute) difference between the number of 1s and the number of 0s present in it. For example, 001 has badness |1-2| = ...
{"inputs": ["4\n4\n?101\n4\n??10\n6\n???111\n5\n1?0?1\n"], "outputs": ["0101\n1010\n000111\n11001\n"]}
coding
688
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is n...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 2), list_node([2,1,4,3,5]))\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 3), list_node([3,2,1,4,5]))\n\n\ncheck(Solution().reverseKGroup)"}
coding
185