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. The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he w...
{"inputs": ["4 9\n3 2 4 1", "4 0\n3 2 4 1", "4 0\n3 2 1 1", "4 0\n3 0 4 1", "4 0\n3 1 4 1", "4 5\n3 2 4 1", "4 5\n3 2 4 1\n", "4 16\n3 2 4 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "4", "4\n", "3\n"]}
coding
296
Solve the programming task below in a Python markdown code block. You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{...
{"inputs": ["1\n2 1000000000\n01\n", "3\n4 0\n1010\n7 1\n0010100\n5 2\n00110\n"], "outputs": ["1\n", "21\n22\n12\n"]}
coding
565
Solve the programming task below in a Python markdown code block. Chef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the first miss...
{"inputs": ["2\n9\nsharechat\n4\nchef"], "outputs": ["shizxvzsg\nsxuv"]}
coding
510
Solve the programming task below in a Python markdown code block. Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice! Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. A...
{"inputs": ["4\na\n", "4\nb\n", "4\nb\n", "4\na\n", "4\nc\n", "4\n`\n", "4\nd\n", "4\n_\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
642
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive. In one operation, you can change any integer's value in any of the arrays t...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]) == 3\n assert candidate(nums1 = [1,1,1,1,1,1,1], nums2 = [6]) == -1\n assert candidate(nums1 = [6,6], nums2 = [1]) == 3\n\n\ncheck(Solution().minOperations)"}
coding
163
Solve the programming task below in a Python markdown code block. Chef and Chefina are playing with dice. In one turn, both of them roll their dice at once. They consider a turn to be *good* if the sum of the numbers on their dice is greater than 6. Given that in a particular turn Chef and Chefina got X and Y on the...
{"inputs": ["4\n1 4\n3 4\n4 2\n2 6\n"], "outputs": ["NO\nYES\nNO\nYES\n"]}
coding
410
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Element...
{"functional": "def check(candidate):\n assert candidate(arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]) == [2,2,2,1,4,3,3,9,6,7,19]\n assert candidate(arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6]) == [22,28,8,6,17,44]\n\n\ncheck(Solution().relativeSortArray)"}
coding
131
Solve the programming task below in a Python markdown code block. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: on Mondays, Thursdays and Sundays he eats fish food; on Tuesdays and Saturdays he eats rabbit stew; on other days of week he eats chicken st...
{"inputs": ["2 1 1\n", "3 2 2\n", "4 1 2\n", "2 8 9\n", "3 1 4\n", "3 2 1\n", "5 4 3\n", "1 1 2\n"], "outputs": ["4\n", "7\n", "6\n", "6\n", "6\n", "6\n", "12\n", "4\n"]}
coding
525
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums, which contains distinct elements and an integer k. A subset is called a k-Free subset if it contains no two elements with an absolute difference equal to k. Notice that the empty s...
{"functional": "def check(candidate):\n assert candidate(nums = [5,4,6], k = 1) == 5\n assert candidate(nums = [2,3,5,8], k = 5) == 12\n assert candidate(nums = [10,5,9,11], k = 20) == 16\n\n\ncheck(Solution().countTheNumOfKFreeSubsets)"}
coding
137
Solve the programming task below in a Python markdown code block. JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom. JATC deci...
{"inputs": ["1\n1\n", "1\n5\n", "1\n2\n", "1\n1\n", "1\n5\n", "1\n2\n", "1\n0\n", "1\n8\n"], "outputs": ["0", "0", "0", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
570
Solve the programming task below in a Python markdown code block. You are given an array of `n+1` integers `1` through `n`. In addition there is a single duplicate integer. The array is unsorted. An example valid array would be `[3, 2, 5, 1, 3, 4]`. It has the integers `1` through `5` and `3` is duplicated. `[1, 2, 4...
{"functional": "_inputs = [[[1, 1, 2, 3]], [[1, 2, 2, 3]], [[5, 4, 3, 2, 1, 1]], [[1, 3, 2, 5, 4, 5, 7, 6]], [[8, 2, 6, 3, 7, 2, 5, 1, 4]]]\n_outputs = [[1], [2], [1], [5], [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=t...
coding
149
Solve the programming task below in a Python markdown code block. Pankaj likes to eat Ice cream when he is working late into the night. Today has been yet another long day for Pankaj. So, he wants to eat ice cream now. He opens the fridge and sees that he has 2 types of containers holding the ice cream. The first conta...
{"inputs": ["2\n1.00 1.00 1.00 1.00\n3.02 7.23 5.20 6.00\n\n"], "outputs": ["3.141592654 3.141592654\n126.739919445 509.691992118"]}
coding
401
Solve the programming task below in a Python markdown code block. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. I...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 0 1\n1\n", "1 0 1\n2\n", "2 1 2\n2 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
562
Solve the programming task below in a Python markdown code block. Chef has X 5 rupee coins and Y 10 rupee coins. Chef goes to a shop to buy chocolates for Chefina where each chocolate costs Z rupees. Find the maximum number of chocolates that Chef can buy for Chefina. ------ Input Format ------ - The first line cont...
{"inputs": ["4\n10 10 10\n3 1 8\n8 1 3\n4 4 1000"], "outputs": ["15\n3\n16\n0\n"]}
coding
507
Solve the programming task below in a Python markdown code block. Pak Chanek has $n$ two-dimensional slices of cheese. The $i$-th slice of cheese can be represented as a rectangle of dimensions $a_i \times b_i$. We want to arrange them on the two-dimensional plane such that: Each edge of each cheese is parallel to eit...
{"inputs": ["1\n1\n420 420\n", "3\n4\n4 1\n4 5\n1 1\n2 3\n3\n2 4\n2 6\n2 3\n1\n2 65\n"], "outputs": ["1680\n", "26\n24\n134\n"]}
coding
647
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array ranks and a character array suits. You have 5 cards where the ith card has a rank of ranks[i] and a suit of suits[i]. The following are the types of poker hands you can make from best to...
{"functional": "def check(candidate):\n assert candidate(ranks = [13,2,3,1,9], suits = [\"a\",\"a\",\"a\",\"a\",\"a\"]) == \"Flush\"\n assert candidate(ranks = [4,4,2,4,4], suits = [\"d\",\"a\",\"a\",\"b\",\"c\"]) == \"Three of a Kind\"\n assert candidate(ranks = [10,10,2,12,9], suits = [\"a\",\"b\",\"c\",\"a\...
coding
173
Solve the programming task below in a Python markdown code block. Your task in this Kata is to emulate text justify right in monospace font. You will be given a single-lined text and the expected justification width. The longest word will never be greater than this width. Here are the rules: - Use spaces to fill in t...
{"functional": "_inputs = [['abc def', 10], ['I take up the whole line', 24], ['Two lines, I am', 10]]\n_outputs = [[' abc def'], ['I take up the whole line'], ['Two lines,\\n I am']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a,...
coding
390
Solve the programming task below in a Python markdown code block. Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediate...
{"inputs": ["3\n(a+(b*c))\n((a+b)*(z+x))\n((a+t)*((b+(a+c))^(c+d)))\n"], "outputs": ["abc*+\nab+zx+*\nat+bac++cd+^*\n"]}
coding
224
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 got another sequence as a birthday present. He does not like this sequence very much because it is not sorted. Since you are a good programmer, ...
{"inputs": ["2\n4 1\n1 4 2 3\n4 2\n1 4 2 3"], "outputs": ["yes\nno"]}
coding
505
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b​​​​​​ to be a substring of a after repeating it, return -1. Not...
{"functional": "def check(candidate):\n assert candidate(a = \"abcd\", b = \"cdabcdab\") == 3\n assert candidate(a = \"a\", b = \"aa\") == 2\n assert candidate(a = \"a\", b = \"a\") == 1\n assert candidate(a = \"abc\", b = \"wxyz\") == -1\n\n\ncheck(Solution().repeatedStringMatch)"}
coding
133
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2x.   Please complete the following python code precisely: ...
{"functional": "def check(candidate):\n assert candidate(n = 1) == True\n assert candidate(n = 16) == True\n assert candidate(n = 3) == False\n\n\ncheck(Solution().isPowerOfTwo)"}
coding
92
Solve the programming task below in a Python markdown code block. Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. You are given an integer sequence $A$ with length $N$. In one move, you are allowed to choose one element of this sequence and change it to an arbitrary intege...
{"inputs": ["2\n4\n1 2 3 3\n3\n2 6 2"], "outputs": ["1\n2"]}
coding
393
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists. We define the range [a, b] is smaller than range [c, d] if b - a < d - c...
{"functional": "def check(candidate):\n assert candidate(nums = [[4,10,15,24,26], [0,9,12,20], [5,18,22,30]]) == [20,24]\n assert candidate(nums = [[1,2,3],[1,2,3],[1,2,3]]) == [1,1]\n\n\ncheck(Solution().smallestRange)"}
coding
120
Solve the programming task below in a Python markdown code block. ## Task Create a function that given a sequence of strings, groups the elements that can be obtained by rotating others, ignoring upper or lower cases. In the event that an element appears more than once in the input sequence, only one of them will be...
{"functional": "_inputs = [[['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris', 'Okyot']], [['Tokyo', 'London', 'Rome', 'Donlon']], [['Rome', 'Rome', 'Rome', 'Donlon', 'London']], [['Ab', 'Aa']], [[]]]\n_outputs = [[[['Kyoto', 'Okyot', 'Tokyo'], ['Donlon', 'London'], ['Paris'], ['Rome']]], [[['Donlon', 'London'], [...
coding
282
Solve the programming task below in a Python markdown code block. A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1. Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic perm...
{"inputs": ["8\nabacabac\n1 1 1 1 1 1 1 1\n", "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "8\nabacabca\n1 2 3 4 4 3 2 1\n", "8\ncdcddcda\n4 1 4 1 4 3 9 6\n", "8\ncdcddcda\n4 1 4 1 4 3 9 6\n", "8\ncdcddcda\n4 1 4 1 2 3 9 6\n", "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "8\nabacabac\n1 1 1 1 1 1 1 1\n"], "outputs": ["8\n", "26\n", "17\n", ...
coding
372
Solve the programming task below in a Python markdown code block. You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into? Co...
{"inputs": ["6\n1 2 3 2 0 1", "6\n1 2 3 2 0 0", "6\n0 2 3 2 0 0", "6\n0 2 3 1 0 0", "6\n1 2 3 2 2 1", "6\n0 2 3 1 -1 0", "6\n0 2 3 0 -1 0", "6\n0 2 3 -1 -1 0"], "outputs": ["3\n", "2\n", "2\n", "2\n", "2", "3\n", "3\n", "2\n"]}
coding
238
Solve the programming task below in a Python markdown code block. Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in ...
{"inputs": ["3\n3 2\n3 4\n3 7"], "outputs": ["2\n5\n12\n"]}
coding
641
Solve the programming task below in a Python markdown code block. The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal nota...
{"inputs": ["2 3\n", "1 1\n", "1 2\n", "2 2\n", "7 8\n", "4 7\n", "1 7\n", "1 3\n"], "outputs": ["2\n", "1\n", "2\n", "1\n", "2\n", "4\n", "7\n", "3\n"]}
coding
305
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef invited N of his friends in his birthday party. All the friends are numbered from 1 to N. Some of the friends might know each other. You are given this information by M ...
{"inputs": ["3\n3 2\n1 2\n2 3\n4 3\n1 2\n2 3\n2 4\n6 7\n1 2\n1 3\n2 3\n2 4\n4 5\n4 6\n5 6"], "outputs": ["YES\nNO\nYES"]}
coding
652
Solve the programming task below in a Python markdown code block. Write a function ```python alternate_sort(l) ``` that combines the elements of an array by sorting the elements ascending by their **absolute value** and outputs negative and non-negative integers alternatingly (starting with the negative value, if any)....
{"functional": "_inputs = [[[5, 2, -3, -9, -4, 8]], [[5, -42, 2, -3, -4, 8, 9]], [[5, -42, 8, 2, -3, -4, 9]], [[5, -42, -8, 2, -3, -4, -9]], [[5, 2, 3, 4, 8, 9]], [[-5, -2, -3, -4, -8, -9]], [[-5, -2, 3, 4, -8, 0, -9]], [[-5, -2, 3, 9, 4, -2, -8, 0, 9, -9]]]\n_outputs = [[[-3, 2, -4, 5, -9, 8]], [[-3, 2, -4, 5, -42, 8,...
coding
265
Solve the programming task below in a Python markdown code block. A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are no...
{"inputs": ["(\n", ")\n", ")(()(\n", "()(()\n", "((())\n", "())((\n", "))(((\n", "(())(\n"], "outputs": ["0\n", "0\n", "2\n", "4\n", "4\n", "2\n", "0\n", "4\n"]}
coding
183
Solve the programming task below in a Python markdown code block. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Finish the solution so that it returns the sum of all the multiples of 3 or 5 **below** the number passed in. > Note: If ...
{"functional": "_inputs = [[10], [20], [0], [1], [200]]\n_outputs = [[23], [78], [0], [0], [9168]]\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) != le...
coding
161
Solve the programming task below in a Python markdown code block. You are given an array a of size n, and q queries to it. There are queries of two types: 1 l_{i} r_{i} — perform a cyclic shift of the segment [l_{i}, r_{i}] to the right. That is, for every x such that l_{i} ≤ x < r_{i} new value of a_{x} + 1 becomes ...
{"inputs": ["1 1 1\n474812122\n2 1 1\n1\n", "1 1 1\n474812122\n2 1 1\n1\n", "1 1 1\n474812122\n4 1 1\n1\n", "1 1 1\n474702042\n5 1 1\n1\n", "1 1 1\n474812122\n5 1 1\n1\n", "5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5\n", "5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5\n", "5 2 5\n64 3 1 665 2\n1 1 3\n2 1 5\n1 2 3 4 5\n"...
coding
497
Solve the programming task below in a Python markdown code block. Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking th...
{"inputs": ["y\n", "y\n", "x\n", "w\n", "v\n", "bbb\n", "aba\n", "aba\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "3\n", "3\n"]}
coding
370
Solve the programming task below in a Python markdown code block. Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a...
{"inputs": ["1\n33\n", "1\n09\n", "1\n10\n", "1\n50\n", "1\n13\n", "1\n80\n", "1\n25\n", "1\n24\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
492
Solve the programming task below in a Python markdown code block. Write a function that accepts two parameters, i) a string (containing a list of words) and ii) an integer (n). The function should alphabetize the list based on the nth letter of each word. The letters should be compared case-insensitive. If both lette...
{"functional": "_inputs = [['bill, bell, ball, bull', 2], ['words, wordz, wordy, wording', 5], ['he, hi, ha, ho', 2], ['zephyr, yellow, wax, a, ba, cat', 1], ['hello, how, are, you, doing, today', 3]]\n_outputs = [['ball, bell, bill, bull'], ['wording, words, wordy, wordz'], ['ha, he, hi, ho'], ['a, ba, cat, wax, yello...
coding
220
Solve the programming task below in a Python markdown code block. ------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ At ShareChat, there are are plenty of interesting problems to solve. Here is one of them. Given integers $A$, $B$ and $N$, you should calculate the [GCD...
{"inputs": ["2\n10 1 1\n9 1 5"], "outputs": ["1\n2"]}
coding
468
Solve the programming task below in a Python markdown code block. Rabbits and cats are competing. The rules are as follows. First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Ea...
{"inputs": ["3 2 2 0\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8", "3 2 4 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8", "3 3 4 11\n1 2 3\n8 5 6\n7 8 9\n1 2 3\n8 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n3\n1\n3\n8", "3 5 4 11\n1 2 3\n8 5 6\n7 8 9\n1 2 3\n8 5 4\n7 8 9...
coding
574
Solve the programming task below in a Python markdown code block. Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole per...
{"inputs": ["1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 1 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 2 7 8 9 -7 -3 4 -...
coding
615
Solve the programming task below in a Python markdown code block. Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). ...
{"inputs": ["b\n", "x\n", "a\n", "c\n", "w\n", "d\n", "ba\n", "aa\n"], "outputs": ["b\n", "x\n", "a\n", "c", "w", "d", "ba\n", "aa\n"]}
coding
453
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a digit string s, return the number of unique substrings of s where every digit appears the same number of times.   Please complete the following python code precisely: ```python class Solution: def equalDig...
{"functional": "def check(candidate):\n assert candidate(s = \"1212\") == 5\n assert candidate(s = \"12321\") == 9\n\n\ncheck(Solution().equalDigitFrequency)"}
coding
73
Solve the programming task below in a Python markdown code block. Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a_1, a_2, ..., a_{n}. While Vasya wa...
{"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "3 1 2\n1 2 3\n3 1 2\n", "3 1 2\n1 2 5\n3 1 2\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n", "4 3 4\n1 2 3 4\n2 1 3 4\n", "4 2 2\n2 1 2 2\n1 2 2 2\n"], "outputs": ["TRUTH\n", "TRUTH\n", "LIE\n", "LIE\n", "LIE\n", "TRUTH\n", "LIE\n", "LIE\n"]}
coding
709
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word. For a given query word, the spell checker handles two categories of spelling mistakes: Capitalization: If the quer...
{"functional": "def check(candidate):\n assert candidate(wordlist = [\"KiTe\",\"kite\",\"hare\",\"Hare\"], queries = [\"kite\",\"Kite\",\"KiTe\",\"Hare\",\"HARE\",\"Hear\",\"hear\",\"keti\",\"keet\",\"keto\"]) == [\"kite\",\"KiTe\",\"KiTe\",\"Hare\",\"hare\",\"\",\"\",\"KiTe\",\"\",\"KiTe\"]\n assert candidate(wo...
coding
129
Solve the programming task below in a Python markdown code block. There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n2\n", "2 2\n100 9\n", "2 2\n100 99\n", "2 2\n100 99\n", "2 2\n100 27\n", "2 2\n100 100\n"], "outputs": ["YES\n1 \n", "YES\n1", "YES\n1 ", "YES\n1 2 ", "YES\n1 2 \n", "YES\n1 2", "YES\n1 2 ", "NO\n"]}
coding
469
Solve the programming task below in a Python markdown code block. The weather report of Chefland is *Good* if the number of sunny days in a week is strictly greater than the number of rainy days. Given 7 integers A_{1}, A_{2}, A_{3}, A_{4}, A_{5}, A_{6}, A_{7} where A_{i} = 1 denotes that the i^{th} day of week in Ch...
{"inputs": ["4\n1 0 1 0 1 1 1\n0 1 0 0 0 0 1\n1 1 1 1 1 1 1\n0 0 0 1 0 0 0\n"], "outputs": ["YES\nNO\nYES\nNO"]}
coding
466
Solve the programming task below in a Python markdown code block. Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses...
{"inputs": ["7\n", "9\n", "6\n", "8\n", "5\n", "3\n", "4\n", "2\n"], "outputs": ["3\n", "4\n", "3\n", "4\n", "3\n", "2\n", "2\n", "1\n"]}
coding
446
Solve the programming task below in a Python markdown code block. There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j. Obs. i is said to be good when its ...
{"inputs": ["4 3\n1 2 3 4\n1 3\n3 3\n2 4", "4 2\n2 4 3 5\n1 3\n3 3\n2 4", "4 0\n2 4 3 5\n1 3\n3 3\n4 4", "4 3\n1 6 3 3\n1 3\n2 2\n3 4", "4 3\n1 2 3 5\n1 3\n3 3\n2 4", "4 3\n1 4 3 5\n1 3\n3 3\n2 4", "4 3\n2 4 3 5\n1 3\n3 3\n2 4", "4 2\n2 4 3 5\n1 3\n3 1\n2 4"], "outputs": ["1\n", "2\n", "4\n", "0\n", "1\n", "1\n", "1\n"...
coding
539
Solve the programming task below in a Python markdown code block. DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number x_{i}, DZY will put it into the bucket numbered h(x_{i}), where h(x) is the hash function. ...
{"inputs": ["2 2\n2\n2\n", "2 2\n0\n0\n", "2 2\n0\n0\n", "2 2\n2\n2\n", "2 2\n1\n0\n", "2 2\n0\n2\n", "2 0\n1\n0\n", "2 2\n0\n3\n"], "outputs": ["2\n", "2\n", "2", "2", "-1\n", "2\n", "-1\n", "-1\n"]}
coding
300
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.   Please complete the following python code precisely: ```python class Solution: def m...
{"functional": "def check(candidate):\n assert candidate(matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]) == 6\n assert candidate(matrix = [[\"0\"]]) == 0\n assert candidate(matrix = [[\"1\"]]) == 1\n\n\ncheck(Solution()...
coding
81
Solve the programming task below in a Python markdown code block. A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November l6, l974. The message consisted of l679 bits and was meant to be translated to a rectangular picture ...
{"inputs": ["5 1 7\n99999 999 999\n103 5 21\n973 1 2\n3406 4 4\n0 0 0", "6 1 7\n99999 999 999\n103 5 21\n973 1 2\n3406 4 4\n0 0 0", "7 1 5\n99999 999 999\n710 5 14\n973 1 2\n771 4 11\n0 0 0", "8 1 5\n99999 999 999\n238 8 10\n973 1 2\n771 4 11\n0 0 0", "5 1 4\n99999 999 999\n1680 5 6\n973 1 2\n131 4 11\n0 0 0", "5 1 2\n...
coding
679
Solve the programming task below in a Python markdown code block. We have a tree with N vertices. The vertices are numbered 0 through N - 1, and the i-th edge (0 ≤ i < N - 1) comnnects Vertex a_i and b_i. For each pair of vertices u and v (0 ≤ u, v < N), we define the distance d(u, v) as the number of edges in the path...
{"inputs": ["2\n0 2", "2\n0 4", "2\n0 5", "2\n0 9", "2\n2 8", "2\n0 8", "2\n0 3", "2\n1 3"], "outputs": ["1", "1", "1", "1", "1", "1", "1", "1"]}
coding
512
Solve the programming task below in a Python markdown code block. Akash has his maths test tomorrow. He secretly found out one of the questions from the test. As the test is online, he wants to write a code that solves the question. However, he is not good at coding and thus, wants Chef to help him with that. Chef is ...
{"inputs": ["2\n2\n5"], "outputs": ["1\n3"]}
coding
527
Solve the programming task below in a Python markdown code block. Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the ...
{"inputs": ["2\n", "9\n", "3\n", "1\n", "4\n", "5\n", "8\n", "6\n"], "outputs": ["1\n1 ", "0\n", "0\n", "0\n", "1\n2\n", "0\n\n", "1\n4\n", "1\n3\n"]}
coding
294
Solve the programming task below in a Python markdown code block. Given two integers A and B, find the count of integers X \in [L, R] such that at least one of the following is true: X and A are [coprime] X and B are [coprime] ------ Input Format ------ - The first and only line of input contains four integers A,B,L...
{"inputs": ["6 15 1 10\n", "235714494 193478285 2 100000000000\n"], "outputs": ["6\n", "65435081000\n"]}
coding
268
Solve the programming task below in a Python markdown code block. Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera...
{"inputs": ["1\n2\n", "1\n1\n", "1\n0\n", "1\n4\n", "1\n7\n", "1\n5\n", "1\n10\n", "1\n-1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
473
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can be divided into two stages: Sea...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([5,3,6,2,4,None,7]), key = 3), tree_node([5,4,6,2,None,None,7]))\n\n\ncheck(Solution().deleteNode)"}
coding
170
Solve the programming task below in a Python markdown code block. A boy named Vasya wants to play an old Russian solitaire called "Accordion". In this solitaire, the player must observe the following rules: * A deck of n cards is carefully shuffled, then all n cards are put on the table in a line from left to right;...
{"inputs": ["1\n3C\n", "1\n3D\n", "1\n4C\n", "2\n3S 2C\n", "4\n2C 3D 4D 5C\n", "4\n2C 4D 4D 5C\n", "4\n2D 4D 4D 5C\n", "4\n2S 2S 2C 2C\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]}
coding
646
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string and your task is to return the most valuable character. The value of a character is the difference between the index of its last occurrence and the index of its first occurrence. Return the character that has the ...
{"functional": "_inputs = [['a'], ['aa'], ['bcd'], ['axyzxyz'], ['dcbadcba'], ['aabccc'], ['efgefg'], ['efghijefghi'], ['acefacef'], ['acefacefacef']]\n_outputs = [['a'], ['a'], ['b'], ['x'], ['a'], ['c'], ['e'], ['e'], ['a'], ['a']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance...
coding
174
Solve the programming task below in a Python markdown code block. Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are? Constraints * 1 ≤ N,A,B ≤ 10^9 * A and B are integers. Input Input is given from ...
{"inputs": ["5 5 3", "1 7 7", "4 4 8", "5 4 6", "7 1 2", "5 4 8", "3 0 2", "7 1 4"], "outputs": ["0\n", "1\n", "9\n", "7\n", "6\n", "13\n", "3\n", "16\n"]}
coding
154
Solve the programming task below in a Python markdown code block. This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercas...
{"inputs": ["1\na\n", "1\nr\n", "1\na\n", "1\ns\n", "1\nb\n", "1\nt\n", "2\ntj\n", "2\njt\n"], "outputs": ["YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n01\n", "YES\n00\n"]}
coding
452
Solve the programming task below in a Python markdown code block. Chef is good at making pancakes. Generally he gets requests to serve N pancakes at once. He serves them in the form of a stack. A pancake can be treated as a circular disk with some radius. Chef needs to take care that when he places a pancake on the to...
{"inputs": ["2\n1\n2", "2\n0\n2", "2\n0\n4", "2\n0\n5", "2\n0\n6", "2\n0\n8", "2\n1\n8", "2\n2\n8"], "outputs": ["1\n2", "0\n2\n", "0\n15\n", "0\n52\n", "0\n203\n", "0\n4140\n", "1\n4140\n", "2\n4140\n"]}
coding
272
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \ldots, a_n$ of positive integers. A good pair is a pair of indices $(i, j)$ with $1 \leq i, j \leq n$ such that, for all $1 \leq k \leq n$, the following equality holds: $$ |a_i - a_k| + |a_k - a_j| = |a_i - a_j|, $$ w...
{"inputs": ["3\n3\n5 2 7\n5\n1 4 2 2 3\n1\n2\n"], "outputs": ["2 3\n1 2\n1 1\n"]}
coding
636
Solve the programming task below in a Python markdown code block. You have array a_1, a_2, ..., a_{n}. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if a_{i} = a_{i} - 1 + a_{i} - 2, for all i (l + 2 ≤ i ≤ r). Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l_1, r_1], is longer...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n3\n", "1\n7\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
326
Solve the programming task below in a Python markdown code block. An array $a$ consisting of $k$ integers is strictly increasing if $a_1 < a_2 < \dots < a_k$. For example, the arrays $[1, 3, 5]$, $[1, 2, 3, 4]$, $[3, 5, 6]$ are strictly increasing; the arrays $[2, 2]$, $[3, 7, 5]$, $[7, 4, 3]$, $[1, 2, 2, 3]$ are not. ...
{"inputs": ["1\n4 6\n", "1\n5 6\n", "7\n5 9\n4 12\n3 3\n3 4\n4 4\n4 6\n8 11\n"], "outputs": ["1 3 4 5\n", "1 3 4 5 6\n", "1 3 6 7 8\n1 3 6 10\n1 2 3\n1 3 4\n1 2 3 4\n1 3 4 5\n1 3 6 7 8 9 10 11\n"]}
coding
509
Solve the programming task below in a Python markdown code block. — Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be ...
{"inputs": ["2\n0 0\n", "3\n1 1 1\n", "2\n-1 -1\n", "3\n2 1 1\n", "3\n2 2 1\n", "3\n0 -1 0\n", "3\n0 0 -1\n", "3\n-1 0 -1\n"], "outputs": ["0 0\n", "3 0\n", "-2 0\n", "2 1\n1\n", "4 1\n3\n", "0 1\n2 ", "0 1\n3\n", "-2 0\n"]}
coding
535
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloon...
{"inputs": ["5 3 \n1 2 3 4 5\n1 2 3 4 5"], "outputs": ["15"]}
coding
623
Solve the programming task below in a Python markdown code block. An array $a_1, a_2, \ldots, a_n$ is good if and only if for every subsegment $1 \leq l \leq r \leq n$, the following holds: $a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1)$. You are given an array of integers $a_1, a_2, \ldots...
{"inputs": ["5\n4\n1 2 3 4\n4\n1 1 2 2\n2\n0 -1\n6\n3 -2 4 -1 -4 0\n1\n-100\n"], "outputs": ["0\n2\n0\n3\n0\n"]}
coding
496
Solve the programming task below in a Python markdown code block. There are $n$ children, numbered $1,2,\ldots,n$, sitting around a circle in a clockwise manner. The ${i}$th child has a piece of paper with the number $a_i$ written on it. They play the following game: In the ${1}$st round, the child numbered ${i}$ incr...
{"inputs": ["2\n5 1\n10 20 30 40 50\n3 4\n1 2 1\n"], "outputs": ["80 20 30 40 50\n10 60 30 40 50\n10 20 90 40 50\n10 20 30 120 50\n10 20 30 40 100\n\n23 7 12\n11 21 6\n7 13 24\n"]}
coding
575
Solve the programming task below in a Python markdown code block. Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to cho...
{"inputs": ["1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n9\n", "1\n18\n", "2\n1 1\n", "2\n1 2\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1\n", "1\n", "1", "2"]}
coding
409
Solve the programming task below in a Python markdown code block. In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is th...
{"inputs": ["4 0 12 0 22", "6 -1 15 1 5", "6 -2 15 1 5", "6 -2 16 1 5", "6 -1 16 1 5", "6 -1 16 1 0", "6 -1 27 1 0", "6 -1 51 1 0"], "outputs": ["458\n", "537\n", "538\n", "598\n", "597\n", "602\n", "1262\n", "2702\n"]}
coding
273
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays startTime and endTime and given an integer queryTime. The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i]. Return the number of students do...
{"functional": "def check(candidate):\n assert candidate(startTime = [1,2,3], endTime = [3,2,7], queryTime = 4) == 1\n assert candidate(startTime = [4], endTime = [4], queryTime = 4) == 1\n assert candidate(startTime = [4], endTime = [4], queryTime = 5) == 0\n assert candidate(startTime = [1,1,1,1], endTime...
coding
130
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal. A subarray is a contiguous part of the array.   Please complete the following python code precisely: ```python c...
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,1,0,1], goal = 2) == 4\n assert candidate(nums = [0,0,0,0,0], goal = 0) == 15\n\n\ncheck(Solution().numSubarraysWithSum)"}
coding
89
Solve the programming task below in a Python markdown code block. # Task Mr.Odd is my friend. Some of his common dialogues are “Am I looking odd?” , “It’s looking very odd” etc. Actually “odd” is his favorite word. In this valentine when he went to meet his girlfriend. But he forgot to take gift. Because of this he ...
{"functional": "_inputs = [['oudddbo'], ['ouddddbo'], ['ooudddbd'], ['qoddoldfoodgodnooofostorodrnvdmddddeidfoi']]\n_outputs = [[1], [1], [2], [6]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isins...
coding
271
Please solve the programming task below using a self-contained code snippet in a markdown code block. There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge be...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]]) == 23\n assert candidate(n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]]) == 1\n\n\ncheck(Solution().minimumTotalPrice)"}
coding
266
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Hasan has recently heard about Chef's restaurant, which serves the tastiest dishes. The restaurant has published a list of $N$ dishes (numbered $1$ ...
{"inputs": ["2\n3 6\n5 7\n1 9\n2 5\n3 7\n5 8\n2 5\n5 10"], "outputs": ["16\n15"]}
coding
563
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.   Please complete the following python code preci...
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,11,5]) == True\n assert candidate(nums = [1,2,3,5]) == False\n\n\ncheck(Solution().canPartition)"}
coding
81
Solve the programming task below in a Python markdown code block. Chef is playing a game with his brother Chefu. He asked Chefu to choose a positive integer $N$, multiply it by a given integer $A$, then choose a divisor of $N$ (possibly $N$ itself) and add it to the product. Let's denote the resulting integer by $M$; m...
{"inputs": ["3\n3 35\n5 50\n4 65"], "outputs": ["1\n10\n0\n3\n13 15 16"]}
coding
397
Solve the programming task below in a Python markdown code block. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and lon...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
535
Solve the programming task below in a Python markdown code block. There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number. Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i an...
{"inputs": ["3\n2 0 4", "3\n2 0 6", "3\n2 0 0", "3\n0 0 6", "3\n2 1 5", "3\n2 2 4", "3\n2 2 4\n", "5\n3 8 1 5 5"], "outputs": ["6 -2 2\n", "8 -4 4\n", "2 2 -2\n", "6 -6 6\n", "6 -2 4\n", "4 0 4", "4 0 4\n", "-4 10 6 -4 14\n"]}
coding
493
Solve the programming task below in a Python markdown code block. Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface. Constraints * $-100 \leq ...
{"inputs": ["1\n0.0 0.0 2.0 0.0 2.0 2.0", "1\n0.0 0.0 2.0 0.5127281311709682 2.0 2.0", "1\n0.0 0.0 2.4487612247110815 0.5127281311709682 2.0 2.0", "1\n0.0 0.0 2.4487612247110815 0.5127281311709682 2.0 2.033916337250816", "1\n0.0 0.8678187768154128 2.4487612247110815 0.5127281311709682 2.0 2.033916337250816", "1\n1.3652...
coding
297
Solve the programming task below in a Python markdown code block. Johnny is a farmer and he annually holds a beet farmers convention "Drop the beet". Every year he takes photos of farmers handshaking. Johnny knows that no two farmers handshake more than once. He also knows that some of the possible handshake combinati...
{"functional": "_inputs = [[0], [1], [3], [6], [7]]\n_outputs = [[1], [2], [3], [4], [5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): ret...
coding
151
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef and his little brother are playing with sticks. They have total N sticks. Length of i-th stick is A_{i}. Chef asks his brother to choose any four sticks and to make a r...
{"inputs": ["2\n5\n1 2 3 1 2\n4\n1 2 2 3", "2\n5\n1 2 3 1 1\n4\n1 2 2 3", "2\n5\n1 2 3 1 2\n4\n1 3 2 3", "2\n5\n1 2 3 1 1\n4\n2 2 4 4", "2\n5\n1 3 3 1 1\n4\n0 2 0 3", "2\n5\n1 2 3 1 2\n4\n1 3 1 3", "2\n5\n2 2 3 1 2\n4\n1 3 1 3", "2\n5\n2 2 3 2 2\n1\n2 5 4 3"], "outputs": ["2\n-1", "-1\n-1\n", "2\n-1\n", "-1\n8\n", "3\n...
coding
466
Solve the programming task below in a Python markdown code block. Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly per...
{"inputs": ["4", "0", "8", "7", "14", "26", "-6", "32"], "outputs": ["1\n", "0\n", "2\n", "2", "3\n", "5\n", "-1\n", "6\n"]}
coding
381
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Recently, Chef hosted a strange competition at the Byteland annual fair. There were $N$ participants in the competition (numbered $1$ through $N$); a...
{"inputs": ["1\n5\n5 2 4 6 7"], "outputs": ["5 5"]}
coding
732
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string number representing a positive integer and a character digit. Return the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string i...
{"functional": "def check(candidate):\n assert candidate(number = \"123\", digit = \"3\") == \"12\"\n assert candidate(number = \"1231\", digit = \"1\") == \"231\"\n assert candidate(number = \"551\", digit = \"5\") == \"51\"\n\n\ncheck(Solution().removeDigit)"}
coding
109
Solve the programming task below in a Python markdown code block. A bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person. You have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of n (n ≥ 3) positive distinct integers (i.e. different, no...
{"inputs": ["1\n3\n2 3 1\n", "1\n3\n4 3 1\n", "1\n3\n6 3 2\n", "1\n3\n2 4 1\n", "1\n3\n4 3 2\n", "1\n3\n5 3 1\n", "1\n3\n5 0 1\n", "1\n3\n3 3 0\n"], "outputs": ["3\n1 2 3\n", "3\n1 2 3\n", "2\n1 3\n", "2\n1 2\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n"]}
coding
566
Solve the programming task below in a Python markdown code block. N problems have been chosen by the judges, now it's time to assign scores to them! Problem i must get an integer score A_i between 1 and N, inclusive. The problems have already been sorted by difficulty: A_1 \le A_2 \le \ldots \le A_N must hold. Differe...
{"inputs": ["0 4548", "1 4548", "1 1010", "0 1010", "0 1000", "-1 4548", "2 666010", "2 489029"], "outputs": ["0", "1", "1", "0", "0", "0", "3", "3"]}
coding
331
Solve the programming task below in a Python markdown code block. In English and programming, groups can be made using symbols such as `()` and `{}` that change meaning. However, these groups must be closed in the correct order to maintain correct syntax. Your job in this kata will be to make a program that checks a s...
{"functional": "_inputs = [['({})'], ['[[]()]'], ['[{()}]'], ['()'], ['([])'], ['{}([])'], ['{[{}[]()[]{}{}{}{}{}{}()()()()()()()()]{{{[[[((()))]]]}}}}(())[[]]{{}}[][][][][][][]({[]})'], [''], ['{(})'], ['[{}{}())'], ['{)[}'], ['[[[]])'], ['()[]{]'], ['{([]})'], ['([]'], ['[])'], ['([]))'], ['{{{{{{{{{{{((((((([]))))))...
coding
209
Solve the programming task below in a Python markdown code block. Chef has to work on a project for the next N hours. He is given a work plan to do this, which is given to you as a binary string S of length N. S_{i} = 1 if Chef has to work on the project during the i-th hour, and S_{i} = 0 if Chef is free during the i-...
{"inputs": ["3\n4 1\n1010\n4 2\n0100\n11 3\n00100000001"], "outputs": ["2\n1\n2"]}
coding
518
Solve the programming task below in a Python markdown code block. Positive integer $x$ is called divisor of positive integer $y$, if $y$ is divisible by $x$ without remainder. For example, $1$ is a divisor of $7$ and $3$ is not divisor of $8$. We gave you an integer $d$ and asked you to find the smallest positive inte...
{"inputs": ["2\n1\n2\n", "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n1\n4\n", "2\n2\n1\n"], "outputs": ["6\n15\n", "15\n15\n", "15\n55\n", "55\n55\n", "91\n55\n", "91\n91\n", "6\n55\n", "15\n6\n"]}
coding
400
Solve the programming task below in a Python markdown code block. Mark is cleaning a row of $n$ rooms. The $i$-th room has a nonnegative dust level $a_i$. He has a magical cleaning machine that can do the following three-step operation. Select two indices $i<j$ such that the dust levels $a_i$, $a_{i+1}$, $\dots$, $a_{...
{"inputs": ["4\n3\n2 0 0\n5\n0 2 0 2 0\n6\n2 0 3 0 4 6\n4\n0 0 0 10\n"], "outputs": ["3\n5\n11\n0\n"]}
coding
710
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. Substrings that occur multipl...
{"functional": "def check(candidate):\n assert candidate(s = \"00110011\") == 6\n assert candidate(s = \"10101\") == 4\n\n\ncheck(Solution().countBinarySubstrings)"}
coding
114
Solve the programming task below in a Python markdown code block. Given an amount A, we want you to compute the number of ways in which you can gather A rupees if you have an infinite supply of each of C = {1, 3, 5} valued rupee coins. Input: First line contains T, the number of test-cases. This is followed by T lin...
{"inputs": ["100\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n...
coding
204
Solve the programming task below in a Python markdown code block. "I have only one rule, never submit partially correct code" -Barney Stinson The religious act which Barney and his friends hold most sacred, XORING the natural numbers in the given range. This time Barney is a bit busy with picking up some girls, so he ...
{"inputs": ["4\n1 4\n2 6\n3 3\n2 3"], "outputs": ["Even\nEven\nOdd\nOdd"]}
coding
335
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order. If a folder[i] is located within another folder[j], it is called a sub-folder...
{"functional": "def check(candidate):\n assert candidate(folder = [\"/a\",\"/a/b\",\"/c/d\",\"/c/d/e\",\"/c/f\"]) == [\"/a\",\"/c/d\",\"/c/f\"]\n assert candidate(folder = [\"/a\",\"/a/b/c\",\"/a/b/d\"]) == [\"/a\"]\n\n\ncheck(Solution().removeSubfolders)"}
coding
196
Solve the programming task below in a Python markdown code block. This is a follow up from my kata Insert Dashes. Write a function ```insertDashII(num)``` that will insert dashes ('-') between each two odd numbers and asterisk ('\*') between each even numbers in ```num``` For example: ```insertDashII(454793)``` --> ...
{"functional": "_inputs = [[454793], [123456], [40546793], [1012356895], [0]]\n_outputs = [['4547-9-3'], ['123456'], ['4054*67-9-3'], ['10123-56*89-5'], ['0']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n...
coding
155
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": ["21\n1\n123\n21\n1\n4321\n123\n21\n1"]}
coding
202
Solve the programming task below in a Python markdown code block. Reverse every other word in a given string, then return the string. Throw away any leading or trailing whitespace, while ensuring there is exactly one space between each word. Punctuation marks should be treated as if they are a part of the word in this ...
{"functional": "_inputs = [['Did it work?'], ['I really hope it works this time...'], ['Reverse this string, please!'], ['Have a beer'], [' '], ['This is not a test '], ['This is a test ']]\n_outputs = [['Did ti work?'], ['I yllaer hope ti works siht time...'], ['Reverse siht string, !esaelp'], ['Have a beer']...
coding
87
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers. Return the maximum product you can get.   Please complete the following python code precisely...
{"functional": "def check(candidate):\n assert candidate(n = 2) == 1\n assert candidate(n = 10) == 36\n\n\ncheck(Solution().integerBreak)"}
coding
84
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Chef is playing a game where he has an array $A$ of $N$ integers, and an integer $K$. He looks at every subarray of length $K$, and writes its sum on a piece ...
{"inputs": ["2\n3 3 \n1 2 3\n2 1\n4 6"], "outputs": ["0\n1"]}
coding
477