task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job. There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The workin...
{"functional": "def check(candidate):\n assert candidate(jobs = [3,2,3], k = 3) == 3\n assert candidate(jobs = [1,2,4,7,8], k = 2) == 11\n\n\ncheck(Solution().minimumTimeRequired)"}
153
69
coding
Solve the programming task below in a Python markdown code block. The only difference between the easy and hard versions is that the given string $s$ in the easy version is initially a palindrome, this condition is not always true for the hard version. A palindrome is a string that reads the same left to right and rig...
{"inputs": ["2\n4\n1001\n1\n0\n"], "outputs": ["BOB\nBOB\n"]}
656
29
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of $n$ integers $a_1$, $a_2$, ..., $a_n$. Let us call an index $j$ ($2 \le j \le {{n-1}}$) a hill if $a_j > a_{{j+1}}$ and $a_j > a_{{j-1}}$; and let us call it a valley if $a_j < a_{{j+1}}$ and $a_j < a_{{j-1}}$. Let us define ...
{"inputs": ["4\n3\n2 5 3\n5\n3 3 2 2 2\n6\n1 6 2 5 2 3\n5\n1 6 2 4 1\n", "4\n3\n2 5 3\n5\n3 3 2 2 2\n6\n1 6 0 5 2 3\n5\n1 6 2 4 1\n", "4\n3\n2 5 3\n5\n3 3 3 2 2\n6\n1 6 2 5 2 3\n5\n1 6 2 4 1\n", "4\n3\n2 5 3\n5\n3 3 2 0 2\n6\n1 6 0 5 2 3\n5\n1 6 2 4 1\n", "4\n3\n0 5 3\n5\n3 3 2 2 2\n6\n1 6 2 5 2 3\n5\n1 6 2 4 1\n", "4\...
516
486
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string text and an array of strings words, return an array of all index pairs [i, j] so that the substring text[i...j] is in words. Return the pairs [i, j] in sorted order (i.e., sort them by their first coord...
{"functional": "def check(candidate):\n assert candidate(text = \"thestoryofleetcodeandme\", words = [\"story\",\"fleet\",\"leetcode\"]) == [[3,7],[9,13],[10,17]]\n assert candidate(text = \"ababa\", words = [\"aba\",\"ab\"]) == [[0,1],[0,2],[2,3],[2,4]]\n\n\ncheck(Solution().indexPairs)"}
124
100
coding
Solve the programming task below in a Python markdown code block. Complete the function that takes a string as an input, and return a list of all the unpaired characters (i.e. they show up an odd number of times in the string), in the order they were encountered as an array. In case of multiple appearances to choose ...
{"functional": "_inputs = [['Hello World'], ['Codewars'], ['woowee'], ['wwoooowweeee'], ['racecar'], ['Mamma'], ['Mama'], ['\u00bc x 4 = 1'], ['\u00bc x 4 = 1 and \u00bd x 4 = 2']]\n_outputs = [[['H', 'e', ' ', 'W', 'r', 'l', 'd']], [['C', 'o', 'd', 'e', 'w', 'a', 'r', 's']], [[]], [[]], [['e']], [['M']], [['M', 'm']],...
262
329
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries: For a query of type 1, queries[i] = [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nu...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]) == [3]\n assert candidate(nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]) == [5]\n\n\ncheck(Solution().handleQuery)"}
249
103
coding
Solve the programming task below in a Python markdown code block. There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the foll...
{"inputs": ["1\n1\n10", "4\n3 1 3 2\n6 6 0 7", "4\n3 1 4 2\n15 6 2 64", "4\n3 1 4 2\n18 5 0 24", "4\n3 1 3 2\n20 6 0 37", "4\n3 1 4 2\n18 5 0 35", "4\n3 1 3 2\n6 12 0 37", "4\n3 1 3 2\n5 22 2 37"], "outputs": ["10", "13\n", "70\n", "29\n", "43\n", "40\n", "49\n", "59\n"]}
428
198
coding
Solve the programming task below in a Python markdown code block. D: Shiritori Compression problem Ebi-chan and Kana-chan did a shiritori. Ebi-chan is looking at the memo of the word that came out in Shiritori. Ebi-chan wants to remove redundant continuous subsequences from this word sequence w_1, w_2, ..., w_N unti...
{"inputs": ["7\nbanana\nta\ntomb\nbus\nsound\ndoes\nsome", "7\nananab\nta\nsomb\nbus\nsound\ndoes\nsemo", "7\nbanaoa\nta\ntomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nta\nuomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\nspund\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\...
684
211
coding
Solve the programming task below in a Python markdown code block. You have been assigned to develop a filter for bad messages in the in-game chat. A message is a string $S$ of length $n$, consisting of lowercase English letters and characters ')'. The message is bad if the number of characters ')' at the end of the str...
{"inputs": ["1\n1\nk\n", "1\n1\ng\n", "1\n1\na\n", "1\n4\naaaa\n", "1\n5\naaaaa\n", "1\n7\nabcd)))\n", "1\n10\nsa)ttttttt\n", "2\n6\naaaaa)\n6\n))))))\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\nYes\n"]}
290
121
coding
Solve the programming task below in a Python markdown code block. Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing the...
{"inputs": ["1 1\na1\na1\n", "1 1\na1\na1\n", "1 2\na1\na1\n", "1 100\na1\na1\n", "2 1\n1\n12\n12\n", "2 1\na\nab\nab\n", "2 1\n1\n12\n12\n", "2 1\na\nab\nab\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "7 7\n", "7 7\n", "7 7\n", "7 7\n"]}
709
156
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries. Th...
{"functional": "def check(candidate):\n assert candidate(s = \"babacc\", queryCharacters = \"bcb\", queryIndices = [1,3,3]) == [3,3,4]\n assert candidate(s = \"abyzz\", queryCharacters = \"aa\", queryIndices = [2,1]) == [2,3]\n\n\ncheck(Solution().longestRepeating)"}
166
86
coding
Solve the programming task below in a Python markdown code block. The Chef has a huge square napkin of size 2n X 2n. He folds the napkin n-3 times. Each time he folds its bottom side over its top side, and then its right side over its left side. After each fold, the side length of the napkin is reduced by half. The Che...
{"inputs": ["3\n3\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n4\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n1000000000\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n\n"], "outputs": ["6\n22\n1"]}
771
250
coding
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"]}
372
117
coding
Solve the programming task below in a Python markdown code block. You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: - Choose two among A, B and C, then increase both by 1. - ...
{"inputs": ["2 5 4\n", "2 6 3\n", "0 0 0\n", "0 0 1\n", "0 0 50\n", "31 41 5\n", "0 50 50\n", "0 49 49\n"], "outputs": ["2\n", "5\n", "0\n", "1\n", "50\n", "23\n", "25\n", "26\n"]}
259
113
coding
Solve the programming task below in a Python markdown code block. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to ...
{"inputs": ["1 2\n1\n4", "1 4\n1\n4", "1 3\n1\n3", "1 4\n1\n1", "1 3\n1\n5", "1 4\n1\n2", "1 3\n1\n9", "1 1\n1\n4"], "outputs": ["30\n", "354\n", "36\n", "1\n", "225\n", "17\n", "2025\n", "10\n"]}
622
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the last substring of s in lexicographical order.   Please complete the following python code precisely: ```python class Solution: def lastSubstring(self, s: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"abab\") == \"bab\"\n assert candidate(s = \"leetcode\") == \"tcode\"\n\n\ncheck(Solution().lastSubstring)"}
64
47
coding
Solve the programming task below in a Python markdown code block. Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous chef, Dexte...
{"inputs": ["3\n4\n1 2 2 3\n2\n1 2\n7\n1 2 3 4 5 6 7", "3\n4\n1 2 2 3\n2\n1 2\n7\n1 0 3 4 5 6 7", "3\n4\n1 4 2 3\n2\n1 2\n7\n1 0 3 4 5 6 7", "3\n4\n0 2 2 3\n2\n1 2\n7\n1 2 3 4 5 6 7", "3\n4\n1 1 1 1\n2\n1 2\n7\n1 4 0 1 6 6 7", "3\n4\n1 4 2 3\n2\n1 2\n7\n1 0 4 4 6 6 7", "3\n4\n1 2 2 3\n2\n1 2\n7\n1 4 3 2 5 6 7", "3\n4\n...
774
360
coding
Solve the programming task below in a Python markdown code block. A list of names is taken as input, in which a particular name can occur multiple times. You need to arrange these names as they will appear in the dictionary and also print the number of times the arranged names appear in the list taken as input. Input:...
{"inputs": ["3\nritesh\nsahil\nritesh"], "outputs": ["ritesh 2\nsahil 1"]}
252
31
coding
Solve the programming task below in a Python markdown code block. Being a crewmate in the Among Us game, you will have to solve a task to win against the imposter. The task : You are given a certain number of bulbs(Say n) which are initially in OFF position. The bulbs are numbered from 1 to n. There will be n current...
{"inputs": ["2\n2\n20"], "outputs": ["1\n3"]}
341
19
coding
Solve the programming task below in a Python markdown code block. White Falcon was amazed by what she can do with heavy-light decomposition on trees. As a resut, she wants to improve her expertise on heavy-light decomposition. Her teacher gave her an another assignment which requires path updates. As always, White Falc...
{"inputs": ["3 2\n0 1\n1 2\n1 0 2 1\n2 1 2\n"], "outputs": ["5\n"]}
475
38
coding
Solve the programming task below in a Python markdown code block. Walter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called some of th...
{"inputs": ["1\n5\n1 2 3 4 5\n2 7 8 9 9\n"], "outputs": ["YES"]}
724
35
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game. They start with a positive integer $n$ and take alternating turns doing operations on it. Each turn a player can subtract from $n$ one of its divisors that isn't $1$ or $n$. The player who cannot make a move on his/her ...
{"inputs": ["4\n1\n4\n12\n69\n"], "outputs": ["Bob\nAlice\nAlice\nBob\n"]}
363
30
coding
Solve the programming task below in a Python markdown code block. Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements f_0 and f_1 are arbitrary f_{n} + 2 = f_{n} + 1 + f_{n} for all n ≥ 0. You are g...
{"inputs": ["2\n2 2\n", "2\n0 0\n", "2\n0 0\n", "2\n2 2\n", "2\n2 4\n", "2\n4 4\n", "2\n1 4\n", "2\n1 3\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
328
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. Swaps of adjacent elements are able to be performed on nums. A valid array meets the following conditions: The largest element (any of the largest elements if there are m...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,5,5,3,1]) == 6\n assert candidate(nums = [9]) == 0\n\n\ncheck(Solution().minimumSwaps)"}
142
54
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef Anup is making dishes. Each dish consists of N ingredients, and quantity of each ingredient is an integer between 1 and K inclusive. Relative quality of 2 dishes is determined by their lex...
{"inputs": ["4\n3 3 1\n3 3 2\n3 3 3\n3 3 4", "4\n4 3 1\n4 3 2\n4 3 3\n4 3 4"], "outputs": ["1 1 1\n1 1 2\n1 1 3\n1 2 1", "1 1 1 1\n1 1 1 2\n1 1 1 3\n1 1 2 1"]}
631
118
coding
Solve the programming task below in a Python markdown code block. Given an array of n$n$ integers : A1,A2,...,An$ A_1, A_2,... , A_n$, find the longest size subsequence which satisfies the following property: The xor of adjacent integers in the subsequence must be non-decreasing. -----Input:----- - First line contains...
{"inputs": ["8\n1 200 3 0 400 4 1 7"], "outputs": ["6"]}
275
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset. A set x is a subset of a set y if all el...
{"functional": "def check(candidate):\n assert candidate(strs = [\"10\", \"0001\", \"111001\", \"1\", \"0\"], m = 5, n = 3) == 4\n assert candidate(strs = [\"10\", \"0\", \"1\"], m = 1, n = 1) == 2\n\n\ncheck(Solution().findMaxForm)"}
122
98
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is teaching a cooking course. There are $N$ students attending the course, numbered $1$ through $N$. Before each lesson, Chef has to take atten...
{"inputs": ["1\n4\nhasan jaddouh\nfarhod khakimiyon\nkerim kochekov\nhasan khateeb"], "outputs": ["hasan jaddouh\nfarhod\nkerim\nhasan khateeb"]}
512
61
coding
Solve the programming task below in a Python markdown code block. Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. An array is Rainbow if it has the following structure: - First a1 elements equal 1. - Next a2 elements equal 2. - Next a3 element...
{"inputs": ["3\n19\n1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1\n14\n1 2 3 4 5 6 7 6 5 4 3 2 1 1\n13\n1 2 3 4 5 6 8 6 5 4 3 2 1"], "outputs": ["yes\nno\nno"]}
552
117
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef went to Australia and saw the destruction caused by bushfires, which made him sad, so he decided to help the animals by feeding them fruits. Fir...
{"inputs": ["1\n6 4\n1 2 3 3 2 2\n7 3 9 1 1 1"], "outputs": ["5"]}
628
40
coding
Solve the programming task below in a Python markdown code block. Chef has recently learnt some new facts about the famous number π. For example, he was surprised that ordinary fractions are sometimes used to represent this number approximately. For example, 22/7, 355/113 or even 103993/33102. Soon, by calculating the ...
{"inputs": ["3\n1\n0\n0", "3\n1\n1\n0", "3\n2\n1\n0", "3\n2\n1\n1", "3\n0\n1\n1", "3\n1\n1\n1", "3\n1\n1\n2", "3\n1\n0\n1"], "outputs": ["3.1\n3\n3\n", "3.1\n3.1\n3\n", "3.14\n3.1\n3\n", "3.14\n3.1\n3.1\n", "3\n3.1\n3.1\n", "3.1\n3.1\n3.1\n", "3.1\n3.1\n3.14\n", "3.1\n3\n3.1\n"]}
566
181
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. N...
{"inputs": ["2\n2\n3 5\n8 100\n3\n5 100 1\n2\n5 100"], "outputs": ["4\n4"]}
411
44
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two numbers arr1 and arr2 in base -2, return the result of adding them together. Each number is given in array format:  as an array of 0s and 1s, from most significant bit to least significant bit.  For example,...
{"functional": "def check(candidate):\n assert candidate(arr1 = [1,1,1,1,1], arr2 = [1,0,1]) == [1,0,0,0,0]\n assert candidate(arr1 = [0], arr2 = [0]) == [0]\n assert candidate(arr1 = [0], arr2 = [1]) == [1]\n\n\ncheck(Solution().addNegabinary)"}
210
101
coding
Solve the programming task below in a Python markdown code block. Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every...
{"inputs": ["a\na\na\n", "a\na\n`\n", "ab\nb\na\n", "aab\nb\naa\n", "`ab\nb\naa\n", "atob\na\na\n", "`ab\nb\n`a\n", "atnb\na\na\n"], "outputs": ["fantasy\n", "fantasy\n", "backward\n", "backward\n", "fantasy\n", "fantasy\n", "fantasy\n", "fantasy\n"]}
583
111
coding
Solve the programming task below in a Python markdown code block. Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \ldots, a_n$. For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $a$ to ...
{"inputs": ["1\n5\n", "1\n1\n", "1\n5\n", "1\n1\n", "1\n8\n", "1\n14\n", "2\n1 2\n", "2\n1 3\n"], "outputs": ["4 0\n", "1 0\n", "4 0\n", "1 0\n", "7 0\n", "13 0\n", "1 0\n", "2 0\n"]}
478
108
coding
Solve the programming task below in a Python markdown code block. The Fair Nut found a string $s$. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences $p_1, p_2, \ldots, p_k$, such that: For each $i$ ($1 \leq i \leq k$), $s_{p_i} =$...
{"inputs": ["agaa\n", "bgaa\n", "aagb\n", "agab\n", "agbb\n", "bgbb\n", "bbbg\n", "gbbb\n"], "outputs": ["3", "2\n", "2\n", "2\n", "1\n", "0\n", "0\n", "0\n"]}
396
78
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. -----...
{"inputs": ["1\n3\n4 4 4", "1\n3\n2 5 1", "1\n3\n4 6 4", "1\n3\n4 6 0", "1\n3\n4 6 3", "1\n3\n2 2 3", "1\n3\n4 4 0", "1\n3\n7 6 3"], "outputs": ["3\n1 2 3 \n", "2\n2 3 \n", "1\n2 \n", "1\n2 \n", "1\n2 \n", "1\n3 \n", "1\n3 \n", "1\n2 \n"]}
377
164
coding
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...
323
268
coding
Solve the programming task below in a Python markdown code block. In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And d...
{"inputs": ["2\n2 3\n", "2\n2 3\n", "3\n2 3 5\n", "3\n2 3 5\n", "3\n2 3 4\n", "4\n2 4 4 2\n", "4\n2 2 3 5\n", "1\n1000000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "0\n", "0\n"]}
515
120
coding
Solve the programming task below in a Python markdown code block. Alex, Bob, and, Chef are standing on the coordinate plane. Chef is standing at the origin (coordinates (0, 0)) while the location of Alex and Bob are (X_{1}, Y_{1}) and (X_{2}, Y_{2}) respectively. Amongst Alex and Bob, find out who is at a farther dist...
{"inputs": ["3\n-1 0 3 4\n3 4 -4 -3\n8 -6 0 5\n"], "outputs": ["BOB\nEQUAL\nALEX"]}
458
44
coding
Solve the programming task below in a Python markdown code block. Kundu is true tree lover. Tree is a connected graph having N vertices and N-1 edges. Today when he got a tree, he colored each edge with one of either red(r) or black(b) color. He is interested in knowing how many triplets(a,b,c) of vertices are there ,...
{"inputs": ["5\n1 2 b\n2 3 r\n3 4 r\n4 5 b\n"], "outputs": ["4\n"]}
432
34
coding
Solve the programming task below in a Python markdown code block. At the start of each season, every player in a football team is assigned their own unique squad number. Due to superstition or their history certain numbers are more desirable than others. Write a function generateNumber() that takes two arguments, an a...
{"functional": "_inputs = [[[1, 2, 3, 4, 6, 9, 10, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 38, 47, 56, 65, 69, 74, 83, 92], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 18, 23, 69], 18], [[1, 2, 3, 4, 6, 9, 10, 15, 69], 34], [[1, ...
235
733
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.   Please complete the following python code precisely: ```python clas...
{"functional": "def check(candidate):\n assert candidate( nums = [4, 3, 2, 3, 5, 2, 1], k = 4) == True\n\n\ncheck(Solution().canPartitionKSubsets)"}
86
58
coding
Solve the programming task below in a Python markdown code block. Three guys play a game: first, each person writes down $n$ distinct words of length $3$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of...
{"inputs": ["1\n1\niiy\niiy\niiy\n", "3\n1\nabc\ndef\nabc\n3\norz for qaq\nqaq orz for\ncod for ces\n5\niat roc hem ica lly\nbac ter iol ogi sts\nbac roc lly iol iat\n"], "outputs": ["0 0 0 \n", "1 3 1 \n2 2 6 \n9 11 5 \n"]}
417
111
coding
Solve the programming task below in a Python markdown code block. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 dis...
{"inputs": ["ayvguplhjsoiencbkxdrfwmqtz\nkhzvtbspcndierqumlojyagfwx\n3\n", "ayvguplhjsoiencbkxdrfwmqtz\nkhzvtbspcndierqumlojyagfwx\n3\n", "ayvguplhjsoiebcnkxdrfwmqtz\nkhzvtbspcndierqumlojyagfwx\n3\n", "ayvguplhjsoiebcnkxdrfwmqtz\nkhzvtbspcndierqumlojyagfwx\n1\n", "ayvguplhjsoiebcnkxdrfwmqtz\nkhzvtbspcndierqumlojyagfwx\...
389
325
coding
Solve the programming task below in a Python markdown code block. The well-known Fibonacci sequence $F_0, F_1, F_2,\ldots $ is defined as follows: $F_0 = 0, F_1 = 1$. For each $i \geq 2$: $F_i = F_{i - 1} + F_{i - 2}$. Given an increasing arithmetic sequence of positive integers with $n$ elements: $(a, a + d, a + ...
{"inputs": ["3 1 1\n", "5 1 2\n", "2 1 1\n", "2 2 1\n", "2 2 1\n", "5 1 2\n", "2 1 1\n", "3 1 1\n"], "outputs": ["4417573500000000001 4417573500000000000\n", "4417573500000000001 8835147000000000000\n", "4417573500000000001 4417573500000000000\n", "8835147000000000001 4417573500000000000\n", "8835147000000000001 441757...
585
406
coding
Solve the programming task below in a Python markdown code block. Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $i$ ($1 \le i \le n-1$), this condition must be satisfied: $$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \l...
{"inputs": ["6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n1 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 34 46 42 16 3 16\n", "6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n2 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 34 46 42 16 3 16\n", "6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n2 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 54 46 42 16 3 16\n", "6\n4\n4 3 10 1\n...
688
782
coding
Solve the programming task below in a Python markdown code block. The brothers Hiroshi and Kenjiro came to Lake Inawashiro for fishing. The two decided to score as follows and compete with the total score of the fish they caught. * One char is a point * One yamame trout b points * Add c points for every 10 chars * Add...
{"inputs": ["9 1\n3 1\n1 2 5 5", "5 1\n4 1\n1 2 5 5", "9 1\n3 1\n1 2 5 3", "5 1\n4 1\n1 2 5 1", "9 2\n3 1\n1 2 5 3", "5 1\n4 1\n1 2 5 0", "9 2\n2 1\n1 2 5 3", "5 1\n4 1\n1 0 5 0"], "outputs": ["hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n"]}
430
182
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra chara...
{"functional": "def check(candidate):\n assert candidate(s = \"leetscode\", dictionary = [\"leet\",\"code\",\"leetcode\"]) == 1\n assert candidate(s = \"sayhelloworld\", dictionary = [\"hello\",\"world\"]) == 3\n\n\ncheck(Solution().minExtraChar)"}
129
68
coding
Solve the programming task below in a Python markdown code block. Suppose you have a string S which has length N and is indexed from 0 to N−1. String R is the reverse of the string S. The string S is funny if the condition |Si−Si−1|=|Ri−Ri−1| is true for every i from 1 to N−1. (Note: Given a string str, stri denotes t...
{"inputs": ["2\nacxz\nbcxz", "2\nivvkxq\nivvkx", "10\njkotzxzxrxtzytlruwrxytyzsuzytwyzxuzytryzuzysxvsmupouysywywqlhg\neklrywzvpxtvoptlrskmskszvwzsuzxrtvyzwruqvyxusqwupnurqmtltnltsmuyxqoksyurpwqpv\nefhpuvqvnuwpvwysvnunostvpqvxtxsvqwqvsxtxvqpvtsonunvsywvpwunvqvupxzy\notytmpszumnryqvxpvnvxyvpvprumnvsqwqwtsqyqksqvnuqpxszwz...
188
400
coding
Solve the programming task below in a Python markdown code block. A sequence of positive integers is called great for a positive integer $x$, if we can split it into pairs in such a way that in each pair the first number multiplied by $x$ is equal to the second number. More formally, a sequence $a$ of size $n$ is great...
{"inputs": ["1\n2 42951\n100000 132704\n", "1\n2 8\n600349032 507824960\n", "1\n2 50000\n90000 205032704\n", "1\n2 70000\n70000 605032704\n", "1\n2 800000\n800000 49872896\n", "1\n2 5\n705032704 1000000000\n", "1\n2 444\n902178848 98765432\n", "1\n2 500\n10000000 705032704\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "...
630
264
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list with n nodes. For each node in the list, find the value of the next greater node. That is, for each node, find the value of the first node that is next to it and has a strictly ...
{"functional": "def check(candidate):\n assert candidate(head = list_node([2,1,5])) == [5,5,0]\n assert candidate(head = list_node([2,7,4,3,5])) == [7,0,5,5,0]\n\n\ncheck(Solution().nextLargerNodes)"}
195
75
coding
Solve the programming task below in a Python markdown code block. Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 3. If any of the permutations is divisible by 3 then print 1 else print 0. -----Input:----- - First-line will contain $T$, the number of test case...
{"inputs": ["2\n18\n308"], "outputs": ["1\n0"]}
179
21
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s. Return all the words vertically in the same order in which they appear in s. Words are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed). Each...
{"functional": "def check(candidate):\n assert candidate(s = \"HOW ARE YOU\") == [\"HAY\",\"ORO\",\"WEU\"]\n assert candidate(s = \"TO BE OR NOT TO BE\") == [\"TBONTB\",\"OEROOE\",\" T\"]\n assert candidate(s = \"CONTEST IS COMING\") == [\"CIC\",\"OSO\",\"N M\",\"T I\",\"E N\",\"S G\",\"T\"]\n\n\ncheck(Solut...
118
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return true if s is a good string, or false otherwise. A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).   Please complete the ...
{"functional": "def check(candidate):\n assert candidate(s = \"abacbc\") == True\n assert candidate(s = \"aaabb\") == False\n\n\ncheck(Solution().areOccurrencesEqual)"}
93
45
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. You are given a sequence of integers A_{1}, A_{2}, \ldots, A_{N} and an integer K. Find the number of contiguous subsequences A_{L}, A_{L+1}, \ldots, A_{R} such that R-L+1 ≥ K a...
{"inputs": ["1\n5 3\n1 2 3 4 5"], "outputs": ["1"]}
425
26
coding
Solve the programming task below in a Python markdown code block. For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows: * f(b,n) = n, when n < b * f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b Here, {\rm floor}(n / b) denotes the largest integer not exc...
{"inputs": ["87654\n9", "87654\n8", "87654\n1", "87654\n2", "87654\n3", "87654\n4", "87654\n7", "87654\n5"], "outputs": ["2\n", "3\n", "87654\n", "43827\n", "29218\n", "43826\n", "12522\n", "87650\n"]}
468
134
coding
Solve the programming task below in a Python markdown code block. Almir had a small sequence $A_1, A_2, \ldots, A_N$. He decided to make $K$ copies of this sequence and concatenate them, forming a sequence $X_1, X_2, \ldots, X_{NK}$; for each valid $i$ and $j$ ($0 \le j < K$), $X_{j \cdot N + i} = A_i$. For example, if...
{"inputs": ["2\n3 3\n2 1 3\n4 100\n99 2 1000 24\n"], "outputs": ["12\n30000"]}
459
49
coding
Solve the programming task below in a Python markdown code block. $2^n$ teams participate in a playoff tournament. The tournament consists of $2^n - 1$ games. They are held as follows: in the first phase of the tournament, the teams are split into pairs: team $1$ plays against team $2$, team $3$ plays against team $4$,...
{"inputs": ["1\n1\n", "1\n0\n", "2\n01\n", "2\n00\n", "2\n11\n", "3\n101\n", "3\n000\n", "3\n010\n"], "outputs": ["2 ", "1 ", "2 3 ", "1 ", "4 ", "4 5 6 7 ", "1 ", "2 3 4 5 "]}
574
102
coding
Solve the programming task below in a Python markdown code block. Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started ...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n0\n", "1 0 1\n2\n", "1 2 1\n1\n", "1 0 1\n1\n", "2 5 1\n5 8\n", "2 5 1\n8 8\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "3\n", "1\n", "9\n", "10\n"]}
451
123
coding
Solve the programming task below in a Python markdown code block. Welcome to the exciting class of Professor Manasa. In each lecture she used to play some game while teaching a new concept. Today's topic is Set Theory. For today's game, she had given a set A = {a_{1}, a_{2}, ...a_{N}} of N integers to her students and ...
{"inputs": ["3\n1 2 2\n", "4\n2 4 6 1\n"], "outputs": ["3\n", "7\n"]}
656
36
coding
Solve the programming task below in a Python markdown code block. Let's define $f(x)$ for a positive integer $x$ as the length of the base-10 representation of $x$ without leading zeros. I like to call it a digital logarithm. Similar to a digital root, if you are familiar with that. You are given two arrays $a$ and $b...
{"inputs": ["4\n1\n1\n1000\n4\n1 2 3 4\n3 1 4 2\n3\n2 9 3\n1 100 9\n10\n75019 709259 5 611271314 9024533 81871864 9 3 6 4865\n9503 2 371245467 6 7 37376159 8 364036498 52295554 169\n"], "outputs": ["2\n0\n2\n18\n"]}
646
175
coding
Solve the programming task below in a Python markdown code block. Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the di...
{"inputs": ["04:50\n", "02:17\n", "12:14\n", "03:44\n", "00:17\n", "15:51\n", "23:31\n", "07:56\n"], "outputs": ["05:50\n", "02:20\n", "12:21\n", "04:40\n", "01:10\n", "20:02\n", "23:32\n", "10:01\n"]}
320
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n. For each index i, names[i] and heights[i] denote the name and height of the ith p...
{"functional": "def check(candidate):\n assert candidate(names = [\"Mary\",\"John\",\"Emma\"], heights = [180,165,170]) == [\"Mary\",\"Emma\",\"John\"]\n assert candidate(names = [\"Alice\",\"Bob\",\"Bob\"], heights = [155,185,150]) == [\"Bob\",\"Alice\",\"Bob\"]\n\n\ncheck(Solution().sortPeople)"}
115
99
coding
Solve the programming task below in a Python markdown code block. Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to pla...
{"inputs": ["1 3\n", "5 3\n", "2 1\n", "8 5\n", "5 2\n", "3 5\n", "1 2\n", "3 3\n"], "outputs": ["2B", "1A1B1A", "1A", "1A1B1A1B", "2A1B", "1B1A1B\n", "1B\n", "Impossible\n"]}
664
104
coding
Solve the programming task below in a Python markdown code block. To make Yalalovichik even more satisfied and happy, Jafar decided to invent Yalalovichik strings. A string is called a Yalalovichik string if the set of all of its distinct non-empty substrings is equal to the set of all of its distinct non-empty subsequ...
{"inputs": ["1\n3\nxxx"], "outputs": ["3"]}
456
16
coding
Solve the programming task below in a Python markdown code block. So you've found a meeting room - phew! You arrive there ready to present, and find that someone has taken one or more of the chairs!! You need to find some quick.... check all the other meeting rooms to see if all of the chairs are in use. Your meeting ...
{"functional": "_inputs = [[[['XXX', 3], ['XXXXX', 6], ['XXXXXX', 9]], 4], [[['XXX', 1], ['XXXXXX', 6], ['X', 2], ['XXXXXX', 8], ['X', 3], ['XXX', 1]], 5], [[['XX', 2], ['XXXX', 6], ['XXXXX', 4]], 0], [[['XX', 2], ['XXXX', 6], ['XXXXX', 4]], 8], [[['XX', 2], ['XXXX', 6], ['XXXXX', 4]], 2]]\n_outputs = [[[0, 1, 3]], [[0...
486
322
coding
Solve the programming task below in a Python markdown code block. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the w...
{"inputs": ["2 2\n2 1\n2\n", "8 9\n2 2\n3\n", "5 5\n8 8\n7\n", "5 7\n9 1\n8\n", "4 1\n5 3\n8\n", "2 1\n3 4\n2\n", "5 1\n6 3\n5\n", "2 1\n3 4\n2\n"], "outputs": ["0\n", "8\n", "40\n", "5\n", "6\n", "7\n", "11\n", "7\n"]}
324
136
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr. We want to select three indices i, j and k where (0 <= i < j <= k < arr.length). Let's define a and b as follows: a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1] b = arr[j] ^ arr[j + 1] ^ ....
{"functional": "def check(candidate):\n assert candidate(arr = [2,3,1,6,7]) == 4\n assert candidate(arr = [1,1,1,1,1]) == 10\n assert candidate(arr = [2,3]) == 0\n assert candidate(arr = [1,3,5,7,9]) == 3\n assert candidate(arr = [7,11,12,9,5,2,7,17,22]) == 8\n\n\ncheck(Solution().countTriplets)"}
156
127
coding
Solve the programming task below in a Python markdown code block. Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself. For example, the proper diviso...
{"functional": "_inputs = [[220, 284], [220, 280], [1184, 1210], [220221, 282224], [10744, 10856], [299920, 9284], [999220, 2849], [122265, 139815]]\n_outputs = [[True], [False], [True], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
283
280
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given $N$ sets of integers $A_{1}, A_{2}, \ldots, A_{N}$. For each valid $i$, let's denote the elements of the set $A_{i}$ by $\{c_{i,1}, c_{...
{"inputs": ["3\n3 1 2 3\n2 1 2\n2 2 3"], "outputs": ["3"]}
578
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges ...
{"functional": "def check(candidate):\n assert candidate(scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]) == 24\n assert candidate(scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]) == -1\n\n\ncheck(Solution().maximumScore)"}
217
111
coding
Solve the programming task below in a Python markdown code block. We define the "unfairness" of a list/array as the *minimal* difference between max(x1,x2,...xk) and min(x1,x2,...xk), for all possible combinations of k elements you can take from the list/array; both minimum and maximum of an empty list/array are consid...
{"functional": "_inputs = [[[30, 100, 1000, 150, 60, 250, 10, 120, 20], 3], [[30, 100, 1000, 150, 60, 250, 10, 120, 20], 5], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 10], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 9], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10], [[1, 1, -1], 2], [[1, 1],...
639
546
coding
Solve the programming task below in a Python markdown code block. Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B. -----Input----- The first line of the input contains an integer T denoting the number o...
{"inputs": ["3\n1\n2\n3", "3\n1\n2\n3"], "outputs": ["1/1\n3/4\n5/9", "1/1\n3/4\n5/9"]}
163
50
coding
Solve the programming task below in a Python markdown code block. Sumit and Dhiraj are roommates in a hostel of NIT Jamshedpur,One day after completing there boring assignments of Artificial Intelligence, they decided to play a game as it was dhiraj,s idea to play a game so he started explaining the rules of the game t...
{"inputs": ["2\n4\n5"], "outputs": ["YES\nNO"]}
360
18
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly conne...
{"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4) == 0.16666666666666666 \n assert candidate(n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7) == 0.3333333333333333\n\n\ncheck(Solution().frogPosition)"}
229
153
coding
Solve the programming task below in a Python markdown code block. Every Friday and Saturday night, farmer counts amount of sheep returned back to his farm (sheep returned on Friday stay and don't leave for a weekend). Sheep return in groups each of the days -> you will be given two arrays with these numbers (one for F...
{"functional": "_inputs = [[[1, 2], [3, 4], 15], [[3, 1, 2], [4, 5], 21], [[5, 1, 4], [5, 4], 29], [[11, 23, 3, 4, 15], [7, 14, 9, 21, 15], 300], [[2, 7, 13, 17], [23, 56, 44, 12, 1, 2, 1], 255], [[2, 5, 8], [11, 23, 3, 4, 15, 112, 12, 4], 355], [[1, 1, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1], 30], [[5, 10, 15], [11, 23, 3, 4,...
209
475
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the maximum number of unique substrings that the given string can be split into. You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms t...
{"functional": "def check(candidate):\n assert candidate(s = \"ababccc\") == 5\n assert candidate(s = \"aba\") == 2\n assert candidate(s = \"aa\") == 1\n\n\ncheck(Solution().maxUniqueSplit)"}
131
58
coding
Solve the programming task below in a Python markdown code block. There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball re...
{"inputs": ["2\n1 2\n2 2", "2\n2 1\n2 2", "2\n1 2\n2 4", "2\n1 1\n2 2", "3\n1 4\n3 6\n7 8", "3\n1 4\n4 6\n8 8", "3\n1 4\n4 6\n7 8", "3\n1 4\n4 6\n11 8"], "outputs": ["1\n", "1\n", "1\n", "1", "2\n", "2\n", "1", "2\n"]}
342
141
coding
Solve the programming task below in a Python markdown code block. One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won....
{"inputs": ["1 1\n4\n", "1 1\n*\n", "1 1\n8\n", "1 1\n.\n", "1 1\n*\n", "1 1\n.\n", "1 1\n4\n", "1 1\n8\n"], "outputs": ["NO", "YES", "NO", "YES", "YES", "YES", "NO", "NO"]}
449
94
coding
Solve the programming task below in a Python markdown code block. Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy. Pressing th...
{"inputs": ["3\n10 2\n8 5\n6 1"], "outputs": ["12\n3\n9"]}
489
30
coding
Solve the programming task below in a Python markdown code block. There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that ...
{"inputs": ["3\n1 1 3", "3\n0 2 2", "3\n4 2 2", "3\n1 0 3", "3\n0 2 4", "3\n4 0 2", "3\n0 2 8", "3\n0 0 2"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
260
110
coding
Solve the programming task below in a Python markdown code block. Given the triangle of consecutive odd numbers: ``` 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... ``` Calculate the row sums of this triangle from the row index (starting at index 1) e.g.: ...
{"functional": "_inputs = [[1], [2], [13], [19], [41], [42], [74], [86], [93], [101]]\n_outputs = [[1], [8], [2197], [6859], [68921], [74088], [405224], [636056], [804357], [1030301]]\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...
174
254
coding
Solve the programming task below in a Python markdown code block. Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have $n$...
{"inputs": ["1\n0\n", "1\n8\n", "1\n8\n", "1\n0\n", "1\n1\n", "1\n2\n", "8\n12345678\n", "8\n12345678\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
465
100
coding
Solve the programming task below in a Python markdown code block. Assume you are creating a webshop and you would like to help the user in the search. You have products with brands, prices and name. You have the history of opened products (the most recently opened being the first item). Your task is to create a list o...
{"functional": "_inputs = [[[]]]\n_outputs = [[[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq...
184
155
coding
Solve the programming task below in a Python markdown code block. Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are n mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in on...
{"inputs": ["5\n", "6\n", "4\n", "1\n", "8\n", "7\n", "3\n", "2\n"], "outputs": ["1 5 2 4 3", "1 6 2 5 3 4 ", "1 4 2 3 ", "1", "1 8 2 7 3 6 4 5\n", "1 7 2 6 3 5 4\n", "1 3 2", "1 2 "]}
282
121
coding
Solve the programming task below in a Python markdown code block. Kuro and Shiro are playing with a board composed of n squares lining up in a row. The squares are numbered 1 to n from left to right, and Square s has a mark on it. First, for each square, Kuro paints it black or white with equal probability, independent...
{"inputs": ["3\n", "1\n", "2\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["499122178\n499122178\n499122178\n", "499122177\n", "1\n1\n", "2\n2\n2\n2\n", "499122179\n499122179\n311951363\n499122179\n499122179\n", "3\n3\n904658948\n904658948\n3\n3\n", "499122180\n499122180\n452329476\n140378116\n452329476\n49912218...
722
302
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting of exactly $n$ characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings. Your task is to replace minimum number of characters in this string with other characters to obtain a...
{"inputs": ["3\n121\n", "3\n111\n", "3\n002\n", "3\n000\n", "3\n001\n", "3\n022\n", "3\n211\n", "3\n020\n"], "outputs": ["021\n", "012\n", "012\n", "012\n", "021\n", "012\n", "201\n", "021\n"]}
419
118
coding
Solve the programming task below in a Python markdown code block. Gohan has found his way into Dr. Gero's lab. There, he finds a circuit. He starts to toy with it. He finds the inverse transverse function $(V_{in}/V_{out})$ i.e (itf) of the circuit. Dr. Gero finds out about this. He gives Gohan an $s$-controller, thr...
{"inputs": ["2\n4 5 78 60\n4 5 6 3"], "outputs": ["-61.4\n-3.8"]}
478
39
coding
Solve the programming task below in a Python markdown code block. There are n stone quarries in Petrograd. Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last f...
{"inputs": ["2\n2 0\n3 2\n", "2\n2 0\n5 2\n", "2\n2 0\n1 2\n", "2\n2 0\n2 2\n", "2\n2 0\n4 2\n", "2\n3 0\n4 2\n", "2\n2 1\n3 2\n", "4\n1 1\n1 1\n1 1\n1 1\n"], "outputs": ["tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "tolik\n", "bolik\n"]}
364
150
coding
Solve the programming task below in a Python markdown code block. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where a_{i}, j = 1 if the i-th switch turns on the j-th lamp and a_{i}, j = 0 if the i-t...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "2 1\n0\n1\n", "2 1\n0\n1\n", "2 1\n1\n1\n", "1 5\n11111\n", "2 2\n10\n11\n", "2 2\n01\n11\n"], "outputs": ["NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n"]}
454
120
coding
Solve the programming task below in a Python markdown code block. There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters `R`, `G`, and `B`. Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adj...
{"functional": "_inputs = [['RRGGBB'], ['RGBRGB'], ['BGRBBGGBRRR'], ['GBBBGGRRGRB'], ['GBRGGRBBBBRRGGGB']]\n_outputs = [[3], [0], [4], [4], [7]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstan...
144
198
coding
Solve the programming task below in a Python markdown code block. You are given three integers $x, y$ and $n$. Your task is to find the maximum integer $k$ such that $0 \le k \le n$ that $k \bmod x = y$, where $\bmod$ is modulo operation. Many programming languages use percent operator % to implement it. In other word...
{"inputs": ["1\n13 2 61\n", "1\n13 0 61\n", "1\n13 0 39\n", "1\n31 2 104\n", "1\n33 6 100\n", "1\n31 2 104\n", "1\n33 6 100\n", "1\n23 2 104\n"], "outputs": ["54\n", "52\n", "39\n", "95\n", "72\n", "95\n", "72\n", "94\n"]}
531
147
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a year year and a month month, return the number of days of that month.   Please complete the following python code precisely: ```python class Solution: def numberOfDays(self, year: int, month: int) -> int: ...
{"functional": "def check(candidate):\n assert candidate(year = 1992, month = 7) == 31\n assert candidate(year = 2000, month = 2) == 29\n assert candidate(year = 1900, month = 2) == 28\n\n\ncheck(Solution().numberOfDays)"}
69
82
coding
Solve the programming task below in a Python markdown code block. You are given two binary strings A and B, each of length N. You can perform the following operation on string A any number of times: Select a [prime number] X. Choose any substring of string A having length X and reverse the substring. Determine whether...
{"inputs": ["4\n2\n00\n00\n4\n1001\n0111\n5\n11000\n10010\n5\n11000\n11010\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
533
68
coding
Solve the programming task below in a Python markdown code block. For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise. s1 crosses points p0 and p1, and s2 crosses points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. I...
{"inputs": ["3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", "3\n0 0 3 1 0 2 3 2\n0 0 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", "3\n0 0 3 1 0 2 3 2\n0 1 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", "3\n0 0 3 1 0 2 3 2\n0 1 3 0 1 0 1 7\n0 0 3 0 1 1 2 1", "3\n0 0 3 0 0 2 3 2\n0 0 3 0 2 0 2 7\n0 0 1 0 1 1 1 2", "3\n1 0 3 1 0 2 3 2\n0 0 3 0...
263
478
coding
Solve the programming task below in a Python markdown code block. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and re...
{"inputs": ["2\n1 1", "2\n2 1", "2\n2 2", "2\n1 0", "2\n1 2", "2\n1 -1", "4\n1 2 1 1", "4\n1 2 2 1"], "outputs": ["6\n", "9\n", "12\n", "3\n", "9", "0\n", "268\n", "324\n"]}
388
106
coding
Solve the programming task below in a Python markdown code block. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. Y...
{"inputs": ["1\n2\n", "1\n1\n", "2\n1 1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 1\n", "3\n1 1 1\n", "3\n1 2 2\n"], "outputs": ["2\n\n", "1\n\n", "1 1\n\n", "2 1\n", "2 2\n\n", "2 1\n", "1 1 1\n\n", "2 1 2\n"]}
508
123
coding
Solve the programming task below in a Python markdown code block. itertools.combinations(iterable, r) This tool returns the $\textbf{r}$ length subsequences of elements from the input iterable. Combinations are emitted in lexicographic sorted order. So, if the input iterable is sorted, the combination tuples will be...
{"inputs": ["HACK 2\n"], "outputs": ["A\nC\nH\nK\nAC\nAH\nAK\nCH\nCK\nHK\n"]}
393
35
coding
Solve the programming task below in a Python markdown code block. A Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding ${1}$). The first few such numbers are ${4}$, $22$, $27$, $58$, $85$, ${94}$, and ${121}$. ...
{"inputs": ["378\n"], "outputs": ["1\n"]}
450
16