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. Mr Leicester's cheese factory is the pride of the East Midlands, but he's feeling a little blue. It's the time of the year when **the taxman is coming round to take a slice of his cheddar** - and the final thing he has to work out is how much money he's ...
{"functional": "_inputs = [[[750, 750, 750, 750, 600]], [[700, 750, 700, 750, 600]], [[574, 574, 574, 574, 574]], [[1, 1, 1, 1, 1]], [[0, 0, 0, 0, 0]]]\n_outputs = [['L1260'], ['L1225'], ['L1015'], ['L35'], ['L0']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
370
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints. In one step, you can take one card from the beginning or from the end ...
{"functional": "def check(candidate):\n assert candidate(cardPoints = [1,2,3,4,5,6,1], k = 3) == 12\n assert candidate(cardPoints = [2,2,2], k = 2) == 4\n assert candidate(cardPoints = [9,7,7,9,7,7,9], k = 7) == 55\n assert candidate(cardPoints = [1,1000,1], k = 1) == 1\n assert candidate(cardPoints = [1...
coding
145
Solve the programming task below in a Python markdown code block. # Task Find the integer from `a` to `b` (included) with the greatest number of divisors. For example: ``` divNum(15, 30) ==> 24 divNum(1, 2) ==> 2 divNum(0, 0) ==> 0 divNum(52, 156) ==> 120 ``` If there are several numbers that have the sam...
{"functional": "_inputs = [[15, 30], [1, 2], [52, 156], [159, 4], [15, 48]]\n_outputs = [[24], [2], [120], ['Error'], [48]]\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)):...
coding
165
Solve the programming task below in a Python markdown code block. “Jesse, you asked me if I was in the meth business, or the money business… Neither. I’m in the empire business.” Walter’s sold his stack in Gray Matter Technologies, a company which he deserved half a credit, for peanuts. Now this company is worth a bill...
{"inputs": ["2\n5\n6 5 5 5 2\n5\n1 2 3 4 5"], "outputs": ["6 5 4 3 2\n1 2 3 4 5"]}
coding
592
Solve the programming task below in a Python markdown code block. Red John has committed another murder. This time, he doesn't leave a red smiley behind. Instead he leaves a puzzle for Patrick Jane to solve. He also texts Teresa Lisbon that if Patrick is successful, he will turn himself in. The puzzle begins as follows...
{"inputs": ["2\n1\n7\n"], "outputs": ["0\n3\n"]}
coding
585
Solve the programming task below in a Python markdown code block. # Task Given an array `arr` and a number `n`. Call a pair of numbers from the array a `Perfect Pair` if their sum is equal to `n`. Find all of the perfect pairs and return the sum of their **indices**. Note that any element of the array can only b...
{"functional": "_inputs = [[[1, 4, 2, 3, 0, 5], 7], [[1, 3, 2, 4], 4], [[1, 1, 1], 2], [[0, 0, 0, 0, 1, 1], 1], [[15, 1, 1], 5]]\n_outputs = [[11], [1], [1], [10], [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_t...
coding
318
Solve the programming task below in a Python markdown code block. Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would like to greet him slightly different. She added a special case to her function, but she made a mistake. Can you help her? Also feel free to re...
{"functional": "_inputs = [['James'], ['Jane'], ['Jim'], ['Johnny']]\n_outputs = [['Hello, James!'], ['Hello, Jane!'], ['Hello, Jim!'], ['Hello, my love!']]\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
85
Solve the programming task below in a Python markdown code block. A mischievous notice has arrived from the primitive slow-life organization "Akaruda". Akaruda is famous for mischief such as throwing a pie at the face of a VIP, but recently it has become more radical, such as using gunpowder to sprinkle rat fireworks a...
{"inputs": ["4\n02:15\n05:01\n11:55\n10:40", "4\n02:15\n05:01\n11:54\n10:40", "4\n12:15\n05:01\n11:54\n10:40", "4\n02:15\n05:01\n11:55\n11:40", "4\n12:05\n05:01\n11:44\n00:41", "4\n02:15\n10:50\n11:54\n10:40", "4\n03:05\n06:11\n11:55\n10:41", "4\n03:15\n11:60\n11:55\n00:40"], "outputs": ["alert\nsafe\nalert\nwarning\n"...
coding
403
Solve the programming task below in a Python markdown code block. Find the longest substring in alphabetical order. Example: the longest alphabetical substring in `"asdfaaaabbbbcttavvfffffdf"` is `"aaaabbbbctt"`. There are tests with strings up to `10 000` characters long so your code will need to be efficient. The ...
{"functional": "_inputs = [['asd'], ['nab'], ['abcdeapbcdef'], ['asdfaaaabbbbcttavvfffffdf'], ['asdfbyfgiklag'], ['z'], ['zyba']]\n_outputs = [['as'], ['ab'], ['abcde'], ['aaaabbbbctt'], ['fgikl'], ['z'], ['z']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r...
coding
128
Solve the programming task below in a Python markdown code block. Complete the solution so that the function will break up camel casing, using a space between words. ### Example ``` solution("camelCasing") == "camel Casing" ``` Also feel free to reuse/extend the following starter code: ```python def solution(s): `...
{"functional": "_inputs = [['helloWorld'], ['camelCase'], ['breakCamelCase']]\n_outputs = [['hello World'], ['camel Case'], ['break Camel Case']]\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 isinsta...
coding
73
Solve the programming task below in a Python markdown code block. Create a function `close_compare` that accepts 3 parameters: `a`, `b`, and an optional `margin`. The function should return whether `a` is lower than, close to, or higher than `b`. `a` is "close to" `b` if `margin` is higher than or equal to the differen...
{"functional": "_inputs = [[4, 5], [5, 5], [6, 5], [2, 5, 3], [5, 5, 3], [8, 5, 3], [8.1, 5, 3], [1.99, 5, 3]]\n_outputs = [[-1], [0], [1], [0], [0], [0], [1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=...
coding
270
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n and an integer start. Define an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums.   Please complete the following pyt...
{"functional": "def check(candidate):\n assert candidate(n = 5, start = 0) == 8\n assert candidate(n = 4, start = 3) == 8\n assert candidate(n = 1, start = 7) == 7\n assert candidate(n = 10, start = 5) == 2\n\n\ncheck(Solution().xorOperation)"}
coding
98
Solve the programming task below in a Python markdown code block. Chef has an array A of size N and an integer M, such that 1 ≤ A_{i} ≤ M for every 1 ≤ i ≤ N. The *distance* of an array B from array A is defined as: d(A, B) = \sum_{i=1}^N |A_{i} - B_{i}| Chef wants an array B of size N, such that 1 ≤ B_{i} ≤ M and t...
{"inputs": ["4\n2 6\n3 5\n4 1\n1 1 1 1\n5 7\n2 3 4 5 6\n7 24\n23 7 6 16 12 4 24\n"], "outputs": ["7\n0\n21\n127\n"]}
coding
632
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied: t is a subsequence of the string s. The absolute difference in the alphab...
{"functional": "def check(candidate):\n assert candidate(s = \"acfgbd\", k = 2) == 4\n assert candidate(s = \"abcd\", k = 3) == 4\n\n\ncheck(Solution().longestIdealString)"}
coding
185
Solve the programming task below in a Python markdown code block. problem There are n cards with one integer from 1 to n and one blank card. Of these n + 1 cards, k cards are given, but 1 ≤ k ≤ n. You can write one integer from 1 to n on a blank card. I want to make a continuous sequence of integers as long as possibl...
{"inputs": ["7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n1\n7\n0 0", "9 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n1\n4\n7\n0 0", "7 5\n6\n2\n3\n7\n1\n7 5\n6\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n4\n6\n0 0", "9 5\n6\n2\n4\n3\n1\n7 5\n5\n2\n1\n4\n7\n0 0", "9 5\n6\n3\n4\n7\n0\n7 5\n...
coding
382
Solve the programming task below in a Python markdown code block. There are n integers b_1, b_2, ..., b_{n} written in a row. For all i from 1 to n, values a_{i} are defined by the crows performing the following procedure: The crow sets a_{i} initially 0. The crow then adds b_{i} to a_{i}, subtracts b_{i} + 1, adds...
{"inputs": ["5\n7 -8 8 0 2\n", "5\n2 0 0 1 12\n", "5\n7 -8 6 0 2\n", "5\n3 0 0 1 12\n", "5\n3 0 0 1 10\n", "5\n3 0 1 1 10\n", "5\n4 0 1 1 10\n", "5\n6 -4 8 -2 3\n"], "outputs": ["-1 0 8 2 2\n", "2 0 1 13 12\n", "-1 -2 6 2 2\n", "3 0 1 13 12\n", "3 0 1 11 10\n", "3 1 2 11 10\n", "4 1 2 11 10\n", "2 4 6 1 3 \n"]}
coding
550
Solve the programming task below in a Python markdown code block. The MEX of a set of integers is defined as the smallest non-negative integer that does not belong to this set. For example, $\mathrm{MEX}(\{0,2,3\}) = 1$ and $\mathrm{MEX}(\{1,3\}) = 0$. Chef has a tree with $N$ nodes (numbered $1$ through $N$). The tree...
{"inputs": ["2\n3\n1 1\n5\n1 1 2 2\n"], "outputs": ["4\n9"]}
coding
452
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"]}
coding
454
Solve the programming task below in a Python markdown code block. Given an array $A$ of length $N$. We have to find the $maximum$ sum of elements of the subarray between $two$ nearest occurrences of $same$ elements (excluding both). If both the elements are $even$ then the total number of $even$ elements in that subarr...
{"inputs": ["1\n10\n1 2 3 2 1 5 1 2 8 2"], "outputs": ["7"]}
coding
360
Solve the programming task below in a Python markdown code block. R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The...
{"inputs": ["4 1 2\n", "2 1 5\n", "3 1 1\n", "5 5 5\n", "4 0 0\n", "6 0 6\n", "6 6 0\n", "2 1 2\n"], "outputs": ["12\n", "6\n", "5\n", "60\n", "0\n", "30\n", "30\n", "3\n"]}
coding
517
Solve the programming task below in a Python markdown code block. You're playing a game with a friend involving a bag of marbles. In the bag are ten marbles: * 1 smooth red marble * 4 bumpy red marbles * 2 bumpy yellow marbles * 1 smooth yellow marble * 1 bumpy green marble * 1 smooth green marble You can see that th...
{"functional": "_inputs = [['red', 'bumpy'], ['green', 'bumpy'], ['yellow', 'smooth'], ['red', 'smooth'], ['green', 'smooth'], ['yellow', 'bumpy']]\n_outputs = [['0.57'], ['0.14'], ['0.33'], ['0.33'], ['0.33'], ['0.28']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n...
coding
401
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9. You are given a string rings of length 2n that describes the n rings that are placed onto t...
{"functional": "def check(candidate):\n assert candidate(rings = \"B0B6G0R6R0R6G9\") == 1\n assert candidate(rings = \"B0R0G0R9R0B0G0\") == 1\n assert candidate(rings = \"G4\") == 0\n\n\ncheck(Solution().countPoints)"}
coding
234
Solve the programming task below in a Python markdown code block. A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square. For a given string $s$ determine if it is squar...
{"inputs": ["1\nzz\n", "1\nzz\n", "1\n{{\n", "1\nz{\n", "1\n{|\n", "1\n|{\n", "1\n||\n", "1\nz|\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]}
coding
285
Solve the programming task below in a Python markdown code block. One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are e...
{"inputs": ["1 1\n1\n", "1 4\n1\n", "1 1\n0\n", "1 6\n1\n", "1 2\n1\n", "2 1\n1 3\n", "2 8\n1 2\n", "2 6\n1 2\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "0", "0", "0\n"]}
coding
564
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s and t of equal length n. You can perform the following operation on the string s: Remove a suffix of s of length l where 0 < l < n and append it at the start of s. For example, let s = 'a...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\", t = \"cdab\", k = 2) == 2\n assert candidate(s = \"ababab\", t = \"ababab\", k = 1) == 2\n\n\ncheck(Solution().numberOfWays)"}
coding
184
Solve the programming task below in a Python markdown code block. Chef recently started selling a special fruit. He has been selling the fruit for X rupees (X is a multiple of 100). He earns a profit of Y rupees on selling the fruit currently. Chef decided to increase the selling price by 10\%. Please help him cal...
{"inputs": ["4\n100 10\n200 5\n500 10\n100 7\n"], "outputs": ["20\n25\n60\n17\n"]}
coding
543
Solve the programming task below in a Python markdown code block. Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally... Lee has $n$ integers $a_1, a_2, \ldots, a_n$ in his backpack and he h...
{"inputs": ["3\n4 2\n1 13 7 0\n1 3\n6 2\n10 0 10 10 6 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 13 7 1\n1 3\n6 2\n7 10 11 0 11 19\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n0 18 12 1\n1 3\n6 2\n2 11 9 2 11 11\n3 3\n4 4\n1000000000 1000000000 1000...
coding
747
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 of length n, both of which are permutations of [0, 1, ..., n - 1]. A good triplet is a set of 3 distinct values which are present in increasing order by position both...
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,0,1,3], nums2 = [0,1,2,3]) == 1\n assert candidate(nums1 = [4,0,1,3,2], nums2 = [4,1,0,2,3]) == 4\n\n\ncheck(Solution().goodTriplets)"}
coding
219
Solve the programming task below in a Python markdown code block. Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious ...
{"inputs": ["1\n7\n0\n", "1\n10\n0\n", "1\n10\n0\n", "1\n14\n0\n", "1\n11\n0\n", "1\n16\n0\n", "1\n50\n1\n1 2\n", "1\n100\n1\n1 1\n"], "outputs": ["7\n", "10\n", "10\n", "14\n", "11\n", "16\n", "0\n", "0\n"]}
coding
510
Solve the programming task below in a Python markdown code block. Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is $n$. There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains $2$ apartments, every other floor conta...
{"inputs": ["4\n8 3\n1 5\n22 5\n987 5\n", "4\n8 3\n1 5\n22 5\n859 5\n", "4\n8 3\n1 5\n29 5\n859 5\n", "4\n8 3\n1 5\n11 5\n859 5\n", "4\n8 3\n1 5\n29 5\n859 7\n", "4\n6 3\n1 5\n29 5\n859 6\n", "4\n8 3\n1 5\n37 5\n859 7\n", "4\n2 3\n1 5\n29 5\n859 6\n"], "outputs": ["3\n1\n5\n198\n", "3\n1\n5\n173\n", "3\n1\n7\n173\n", "...
coding
471
Solve the programming task below in a Python markdown code block. Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet $a$ dollars and Ronnie has bet $b$ dollars. But the fans seem to be disappointed. The excitement of the fans is given by...
{"inputs": ["4\n8 5\n1 2\n4 4\n3 9\n", "4\n8 5\n1 2\n4 5\n3 9\n", "4\n8 5\n1 2\n1 5\n3 9\n", "4\n8 0\n1 2\n1 5\n3 9\n", "4\n8 0\n1 2\n1 5\n2 9\n", "4\n7 0\n1 2\n1 5\n2 9\n", "4\n6 0\n1 2\n1 5\n2 9\n", "4\n6 0\n2 2\n1 5\n2 9\n"], "outputs": ["3 1\n1 0\n0 0\n6 3\n", "3 1\n1 0\n1 0\n6 3\n", "3 1\n1 0\n4 1\n6 3\n", "8 0\n1...
coding
577
Solve the programming task below in a Python markdown code block. Chef is interested to solve series problems. Chef wants to solve a series problem but he can't solve it till now.Can you help Chef to solve the series problem? - In series problem, the series goes as follows 1,9,31,73,141 . . . . . . . . Your task is t...
{"inputs": ["2\n8\n10"], "outputs": ["561\n1081"]}
coding
271
Solve the programming task below in a Python markdown code block. Define a method that accepts 2 strings as parameters. The method returns the first string sorted by the second. ```python sort_string("foos", "of") == "oofs" sort_string("string", "gnirts") == "gnirts" sort_string("banana", "abn") == "aaabnn" `...
{"functional": "_inputs = [['banana', 'abn'], ['banana', 'xyz'], ['banana', 'an'], ['foos', 'of'], ['string', 'gnirts'], ['banana', 'a'], ['bungholio', 'aacbuoldiiaoh'], ['fumyarhncujlj', 'nsejcwn']]\n_outputs = [['aaabnn'], ['banana'], ['aaannb'], ['oofs'], ['gnirts'], ['aaabnn'], ['buoolihng'], ['njjcfumyarhul']]\nim...
coding
169
Solve the programming task below in a Python markdown code block. This is the easy version of the problem. The difference in the constraints between both versions is colored below in red. You can make hacks only if all versions of the problem are solved. Marin and Gojou are playing hide-and-seek with an array. Gojou ...
{"inputs": ["3\n0 3\n3 2 1 0\n0 3\n4 7 6 5\n0 2\n1 2 3\n"], "outputs": ["0\n4\n3\n"]}
coding
578
Solve the programming task below in a Python markdown code block. A family of kookaburras are in my backyard. I can't see them all, but I can hear them! # How many kookaburras are there? ## Hint The trick to counting kookaburras is to listen carefully * The males go ```HaHaHa```... * The females go ```hahaha`...
{"functional": "_inputs = [[''], ['hahahahaha'], ['hahahahahaHaHaHa'], ['HaHaHahahaHaHa'], ['hahahahahahahaHaHa']]\n_outputs = [[0], [1], [2], [3], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if ...
coding
139
Solve the programming task below in a Python markdown code block. You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n5\n", "1\n8\n", "1\n7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
481
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two positive integers n and k, the binary string Sn is formed as follows: S1 = "0" Si = Si - 1 + "1" + reverse(invert(Si - 1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reve...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 1) == \"0\"\n assert candidate(n = 4, k = 11) == \"1\"\n assert candidate(n = 1, k = 1) == \"0\"\n assert candidate(n = 2, k = 3) == \"1\"\n\n\ncheck(Solution().findKthBit)"}
coding
223
Solve the programming task below in a Python markdown code block. There are N piles of stones. The i-th pile has A_i stones. Aoki and Takahashi are about to use them to play the following game: - Starting with Aoki, the two players alternately do the following operation: - Operation: Choose one pile of stones, and re...
{"inputs": ["2\n3 6", "2\n5 5", "2\n7 5", "2\n5 1", "2\n7 7", "2\n3 1", "2\n7 1", "2\n3 2"], "outputs": ["-1\n", "0\n", "1\n", "2\n", "0\n", "1\n", "3\n", "-1\n"]}
coding
402
Solve the programming task below in a Python markdown code block. A motorcade of n trucks, driving from city «Z» to city «З», has approached a tunnel, known as Tunnel of Horror. Among truck drivers there were rumours about monster DravDe, who hunts for drivers in that tunnel. Some drivers fear to go first, others - to ...
{"inputs": ["1\n1 1 1 1\n", "1\n1 2 1 1\n", "1\n1 2 2 1\n", "1\n1 2 0 1\n", "1\n0 2 0 1\n", "1\n1 2 0 2\n", "1\n0 2 0 2\n", "1\n2 2 0 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
608
Solve the programming task below in a Python markdown code block. In a far away country called AlgoLandia, there are `N` islands numbered `1` to `N`. Each island is denoted by `k[i]`. King Algolas, king of AlgoLandia, built `N - 1` bridges in the country. A bridge is built between islands `k[i]` and `k[i+1]`. Bridges a...
{"functional": "_inputs = [[[True, True, False, True, False]], [[False, False, True, False, False]], [[False, False, False, False, False]], [[False, False, False, False, False, False]], [[False, False]], [[True, False]], [[False, False, False, True, False, False, False, True]], [[False, False, True, False, True, True, ...
coding
364
Solve the programming task below in a Python markdown code block. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along t...
{"inputs": ["555\n1\n8\n4", "555\n2\n6\n6", "555\n3\n6\n6", "555\n9\n6\n6", "555\n2\n28\n4", "555\n0\n28\n4", "555\n1\n11\n0", "555\n1\n11\n1"], "outputs": ["5\n", "8\n", "9\n", "15\n", "6\n", "4\n", "1\n", "2\n"]}
coding
329
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group o...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,0],[0,1]]) == 3\n assert candidate(grid = [[1,1],[1,0]]) == 4\n assert candidate(grid = [[1,1],[1,1]]) == 4\n\n\ncheck(Solution().largestIsland)"}
coding
105
Solve the programming task below in a Python markdown code block. Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a_1, a_2, ..., a_{n} in the non-decreasing order. The pseu...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["-1\n", "-1\n", "3 2 1 ", "4 3 2 1 ", "5 4 3 2 1 ", "6 5 4 3 2 1 ", "7 6 5 4 3 2 1 ", "8 7 6 5 4 3 2 1 "]}
coding
374
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Chefland is holding a virtual marathon for the categories 10 km, 21 km and 42 km having prizes A, B, C (A < B < C) respectively to promote physical fitness. I...
{"inputs": ["3\n1 1 1 2 3\n10 1 1 2 3\n10 3 1 2 3"], "outputs": ["0\n1\n2"]}
coding
494
Solve the programming task below in a Python markdown code block. You have N cards. On the i-th card, an integer A_i is written. For each j = 1, 2, ..., M in this order, you will perform the following operation once: Operation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card wi...
{"inputs": ["3 2\n5 1 1\n2 3\n1 5", "3 2\n5 1 1\n2 3\n1 7", "3 2\n5 1 1\n2 3\n1 6", "3 2\n5 1 1\n2 3\n2 6", "3 2\n5 1 1\n2 3\n1 0", "3 2\n5 1 1\n1 2\n1 5", "3 2\n5 0 0\n1 6\n1 5", "3 2\n5 1 1\n0 3\n2 7"], "outputs": ["13\n", "15\n", "14\n", "17\n", "11\n", "12\n", "16\n", "19\n"]}
coding
315
Solve the programming task below in a Python markdown code block. In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called...
{"inputs": ["9 5", "4 0", "6 5", "8 5", "5 2", "6 9", "2 0", "4 1"], "outputs": ["8\n", "3\n", "5\n", "7\n", "4\n", "6\n", "1\n", "3\n"]}
coding
291
Solve the programming task below in a Python markdown code block. There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divi...
{"inputs": ["5 1", "4 1", "5 2", "7 2", "4 2", "1 2", "1 1", "3 6"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n"]}
coding
237
Solve the programming task below in a Python markdown code block. Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share referenc...
{"inputs": ["340\n5277\n9302\n7274\n3\n5968\n1327\n255\n27\n5665\n8104\n138\n4051\n4168\n507\n7773\n2688\n3497\n4074\n1403\n3599\n2007\n7621\n3124\n1195\n7245\n1979\n3365\n6607\n4816\n9336\n3620\n1557\n3404\n5451\n3739\n2504\n1845\n5533\n8298\n2893\n7814\n2505\n9785\n4709\n7880\n6262\n5135\n2088\n9309\n7259\n9993\n325\...
coding
208
Solve the programming task below in a Python markdown code block. On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also reme...
{"inputs": ["2\n2 3\n1 3\n", "2\n1 3\n1 3\n", "3\n1 2\n2 3\n3 4\n", "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4\n", "10\n2 8\n8 10\n1 6\n1 2\n7 10\n1 9\n6 8\n3 4\n1 3\n5 8\n", "10\n1 4\n1 12\n5 7\n5 5\n2 5\n1 7\n1 10\n7 9\n8 9\n9 11\n", "10\n2 8\n8 10\n1 6\n1 10\n7 10\n1 9\n6 8\n3 4\n1 3\n5 8\n", "10\n1 2\n...
coding
247
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from nums. Return the minimum number of operations to make nums non-decreasing.   Please complete th...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,3,2,1]) == 3\n assert candidate(nums = [1,3,2,1,3,3]) == 2\n assert candidate(nums = [2,2,2,2,3,3]) == 0\n\n\ncheck(Solution().minimumOperations)"}
coding
96
Please solve the programming task below using a self-contained code snippet in a markdown code block. On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that: The north direction is the positive direction of the y-axis. The south direction is the negative direction of the y-axis. The east ...
{"functional": "def check(candidate):\n assert candidate(instructions = \"GGLLGG\") == True\n assert candidate(instructions = \"GG\") == False\n assert candidate(instructions = \"GL\") == True\n\n\ncheck(Solution().isRobotBounded)"}
coding
210
Solve the programming task below in a Python markdown code block. Bob is a dance teacher and he started dance classes recently. He observes a strange attendance pattern among his students. Initially, there are no students. On day i, a new student starts attending the class. The student stops attending the class, if and...
{"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["odd\nodd\nodd\neven\n"]}
coding
572
Solve the programming task below in a Python markdown code block. There are N turkeys. We number them from 1 through N. M men will visit here one by one. The i-th man to visit will take the following action: * If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it. * If either...
{"inputs": ["6 1\n1 2", "7 1\n1 2", "7 0\n1 2", "7 0\n1 4", "7 0\n0 4", "7 0\n0 8", "2 1\n1 2", "6 1\n1 4"], "outputs": ["14\n", "20\n", "21\n", "21\n", "21\n", "21\n", "0\n", "14\n"]}
coding
370
Please solve the programming task below using a self-contained code snippet in a markdown code block. The power of the string is the maximum length of a non-empty substring that contains only one unique character. Given a string s, return the power of s.   Please complete the following python code precisely: ```python...
{"functional": "def check(candidate):\n assert candidate(s = \"leetcode\") == 2\n assert candidate(s = \"abbcccddddeeeeedcba\") == 5\n\n\ncheck(Solution().maxPower)"}
coding
79
Solve the programming task below in a Python markdown code block. The only difference between this problem and D1 is the bound on the size of the tree. You are given an unrooted tree with $n$ vertices. There is some hidden vertex $x$ in that tree that you are trying to find. To do this, you may ask $k$ queries $v_1, ...
{"inputs": ["3\n1\n2\n1 2\n10\n2 4\n2 1\n5 7\n3 10\n8 6\n6 1\n1 3\n4 7\n9 6\n"], "outputs": ["0\n1\n2\n"]}
coding
554
Solve the programming task below in a Python markdown code block. ## Terminal game move function In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice **two times**. ~~~if-not:sql Create a function for the terminal game that takes the current p...
{"functional": "_inputs = [[0, 4], [3, 6], [2, 5]]\n_outputs = [[8], [15], [12]]\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...
coding
306
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.   Please complete the following python code precisely: ```python class Soluti...
{"functional": "def check(candidate):\n assert candidate(s = \"aab\") == [[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]\n assert candidate(s = \"a\") == [[\"a\"]]\n\n\ncheck(Solution().partition)"}
coding
75
Solve the programming task below in a Python markdown code block. This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last char...
{"inputs": ["4 5\nabcd\n", "4 11\nddcd\n", "4 11\nzzaz\n", "5 10\ndcdcd\n", "5 10\ncbcbc\n", "5 10\nbbabb\n", "8 16\ndbcadabc\n", "8 20\nccaccaca\n"], "outputs": ["aaaaa\n", "ddcddcddcdd\n", "zzazzazzazz\n", "dcdcdcdcdc\n", "cbcbcbcbcb\n", "bbabbabbab\n", "dbcadabcdbcadabc\n", "ccaccacaccaccacaccac\n"]}
coding
486
Solve the programming task below in a Python markdown code block. Arkady decided to buy roses for his girlfriend. A flower shop has white, orange and red roses, and the total amount of them is n. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red and whit...
{"inputs": ["1 1\n100\nO\n", "1 1\n780\nO\n", "1 1\n100\nO\n", "1 1\n780\nO\n", "1 1\n486\nO\n", "1 1\n107\nO\n", "1 1\n1059\nO\n", "1 1\n6750\nW\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
574
Solve the programming task below in a Python markdown code block. Chef has an array A of length N. In one operation, Chef can choose any element A_{i} and split it into two positive integers X and Y such that X+Y = A_{i}. Note that the length of array increases by 1 after every operation. Determine the minimum numbe...
{"inputs": ["2\n4\n1 3 5 7\n3\n1 2 3\n"], "outputs": ["0\n1\n"]}
coding
449
Solve the programming task below in a Python markdown code block. Following on from [Part 1](http://www.codewars.com/kata/filling-an-array-part-1/), part 2 looks at some more complicated array contents. So let's try filling an array with... ## ...square numbers The numbers from `1` to `n*n` ## ...a range of numbers ...
{"functional": "_inputs = [[5]]\n_outputs = [[[1, 4, 9, 16, 25]]]\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 retur...
coding
176
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef likes to mix colors a lot. Recently, she was gifted N colors A_{1}, A_{2}, ..., A_{N} by her friend. Chef wants to make the values of all her colors pairwise distinct, ...
{"inputs": ["2\n3\n1 2 3\n3\n2 1 2"], "outputs": ["0\n1"]}
coding
493
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed binary string s which represents the types of buildings along a street where: s[i] = '0' denotes that the ith building is an office and s[i] = '1' denotes that the ith building is a restaura...
{"functional": "def check(candidate):\n assert candidate(s = \"001101\") == 6\n assert candidate(s = \"11100\") == 0\n\n\ncheck(Solution().numberOfWays)"}
coding
209
Solve the programming task below in a Python markdown code block. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It...
{"inputs": ["aatt\n", "atatat\n", "doatdt\n", "taatta\n", "eoatdt\n", "taatua\n", "epatdt\n", "tbatua\n"], "outputs": ["a@t\n", "at@at\n", "do@dt\n", "ta@ta\n", "eo@dt\n", "ta@ua\n", "ep@dt\n", "tb@ua\n"]}
coding
398
Solve the programming task below in a Python markdown code block. You are given a string $s$, consisting only of characters '0' and '1'. You have to choose a contiguous substring of $s$ and remove all occurrences of the character, which is a strict minority in it, from the substring. That is, if the amount of '0's in...
{"inputs": ["1\n00000000000000\n", "4\n01\n1010101010111\n00110001000\n1\n", "1\n00000000000000000011111111111111111111\n", "1\n1101010101111010110101010101001010111010\n", "1\n10101010101010101010101010101001010101010101010101010101010101010101010000\n", "1\n101010101010101010101010101010010101010101010101010101010101...
coding
577
Solve the programming task below in a Python markdown code block. Meliodas and Ban are fighting over chocolates. Meliodas has $X$ chocolates, while Ban has $Y$. Whoever has lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the sam...
{"inputs": ["3\n5 3\n10 10\n4 8"], "outputs": ["2\n20\n8"]}
coding
496
Solve the programming task below in a Python markdown code block. As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase E...
{"inputs": ["ah\n1\nha\n", "bb\n1\naa\n", "aa\n1\naa\n", "bb\n1\nbb\n", "ba\n1\ncc\n", "ha\n1\nha\n", "aa\n1\naa\n", "ez\n1\njl\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n"]}
coding
443
Solve the programming task below in a Python markdown code block. There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that t...
{"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "2 1\n1 1\n1\n", "2 1\n1 1\n2\n", "2 1\n1 1\n2\n", "2 1\n1 1\n1\n", "2 2\n1 2\n1 1\n", "2 2\n2 2\n1 1\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0", "0", "0\n", "-1\n"]}
coding
484
Solve the programming task below in a Python markdown code block. You are given four integers $n$, $B$, $x$ and $y$. You should build a sequence $a_0, a_1, a_2, \dots, a_n$ where $a_0 = 0$ and for each $i \ge 1$ you can choose: either $a_i = a_{i - 1} + x$ or $a_i = a_{i - 1} - y$. Your goal is to build such a seque...
{"inputs": ["1\n200000 1 1 1\n", "1\n200000 9 9 9\n", "1\n200000 8 8 8\n", "1\n200000 7 7 7\n", "1\n200000 10 10 10\n", "1\n1000 100 200 300\n", "1\n2000 100 200 300\n", "1\n3000 100 200 300\n"], "outputs": ["100000\n", "900000\n", "800000\n", "700000\n", "1000000\n", "-100000\n", "-200000\n", "-300000\n"]}
coding
509
Solve the programming task below in a Python markdown code block. # Task The number is considered to be `unlucky` if it does not have digits `4` and `7` and is divisible by `13`. Please count all unlucky numbers not greater than `n`. # Example For `n = 20`, the result should be `2` (numbers `0 and 13`). For `n =...
{"functional": "_inputs = [[20], [100], [1000], [1000000]]\n_outputs = [[2], [7], [40], [20182]]\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(...
coding
197
Solve the programming task below in a Python markdown code block. In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. S...
{"inputs": ["1\ns\n", "1\ns\n", "2\nf\ns\n", "2\ns\ns\n", "2\nf\ns\n", "2\ns\ns\n", "3\nf\nf\ns\n", "3\nf\nf\ns\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1", "1", "1\n", "1"]}
coding
450
Solve the programming task below in a Python markdown code block. Sachin wants to give a love letter to his girlfriend on valentines day. He is having a circular piece of paper of radius "r". He wants to use rectangular piece of paper for letter writing whose length and breadth are integers. In how many ways can he ...
{"inputs": ["12"], "outputs": ["424"]}
coding
159
Solve the programming task below in a Python markdown code block. Let's define a periodic infinite sequence S$S$ (0$0$-indexed) with period K$K$ using the formula Si=(i%K)+1$S_i = (i \% K) + 1$. Chef has found a sequence of positive integers A$A$ with length N$N$ buried underground. He suspects that it is a contiguous ...
{"inputs": ["3\n3\n-1 -1 -1\n5\n1 -1 -1 4 1\n4\n4 6 7 -1"], "outputs": ["inf\n4\nimpossible"]}
coding
568
Solve the programming task below in a Python markdown code block. Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, a...
{"inputs": ["2", "4", "3", "6", "7", "5", "8", "1"], "outputs": ["ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n"]}
coding
168
Solve the programming task below in a Python markdown code block. *** Nova polynomial multiply*** This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e880...
{"functional": "_inputs = [[[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]]\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 ...
coding
363
Solve the programming task below in a Python markdown code block. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of vote...
{"inputs": ["1 2\n1 100\n", "1 2\n1 100\n", "1 3000\n670 56891830\n", "1 3000\n918 548706881\n", "1 3000\n918 548706881\n", "1 3000\n670 548706881\n", "1 3000\n670 141077449\n", "1 3000\n2006 226621946\n"], "outputs": ["0\n", "0\n", "56891830\n", "548706881\n", "548706881\n", "548706881\n", "141077449\n", "226621946\n"...
coding
561
Solve the programming task below in a Python markdown code block. You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are als...
{"inputs": ["6\n9 2\n010001010\n9 3\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n1\n1 1\n0\n", "6\n9 2\n010001010\n9 3\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n0\n1 1\n0\n", "6\n9 2\n010001010\n9 5\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n0\n1 1\n0\n", "6\n9 2\n011001010\n9 3\n111100000\n7 4\n111111...
coding
589
Solve the programming task below in a Python markdown code block. You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the...
{"inputs": ["1 8 9\n1", "1 8 3\n1", "1 8 5\n1", "1 8 10\n1", "1 12 10\n1", "1 10 10\n1", "3 4 11\n3 1 2", "3 26 30\n3 1 2"], "outputs": ["0", "0", "0", "0", "0", "0", "4", "26"]}
coding
522
Solve the programming task below in a Python markdown code block. Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible product of digits among all integers from $1$ to $n$. -----Input-----...
{"inputs": ["7\n", "1\n", "9\n", "2\n", "3\n", "4\n", "1\n", "9\n"], "outputs": ["7\n", "1\n", "9\n", "2\n", "3\n", "4\n", "1", "9"]}
coding
267
Solve the programming task below in a Python markdown code block. Your teacher gave you an assignment — given an integer N, construct a binary string B = b_{1b}_2b_{3}\ldots b_{N} of length N such that: \max(b_{i}, b_{i+1}) = 1 for every i from 1 to N-1. What is the minimum number of 1's such a binary string can con...
{"inputs": ["6\n6\n8\n2\n3\n5\n100"], "outputs": ["3\n4\n1\n1\n2\n50"]}
coding
482
Solve the programming task below in a Python markdown code block. Thanos sort is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process. Given an input array, what is the size of the longest so...
{"inputs": ["1\n100\n", "1\n100\n", "1\n101\n", "1\n111\n", "1\n011\n", "1\n010\n", "1\n000\n", "1\n110\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
382
Solve the programming task below in a Python markdown code block. In some ranking people collects points. The challenge is sort by points and calulate position for every person. But remember if two or more persons have same number of points, they should have same position number and sorted by name (name is unique). Fo...
{"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...
coding
93
Solve the programming task below in a Python markdown code block. You are given a tree rooted at node $1$ with $N$ vertices. The $i$$th$ vertex initially has value $A_i (1 \leq i \leq N)$. You are also given $Q$ queries. In each query you are given a vertex $V$. Let $S = \{ S_1 , S_2 , ... S_x \} $ denote the set of ...
{"inputs": ["1\n4 3\n6 2 7 3\n1 2\n2 3\n3 4\n3\n2\n1"], "outputs": ["13 5 0 0"]}
coding
713
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 has always been fond of girls, but he could not make any girl his friend. In order to finally make one, he was asked to solve the following prob...
{"inputs": ["1\n4\nanxa"], "outputs": ["1"]}
coding
534
Solve the programming task below in a Python markdown code block. You are going to eat X red apples and Y green apples. You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C. Before eating a colorles...
{"inputs": ["1 2 2 2 1\n3 4\n5 1\n3", "1 2 2 4 1\n3 3\n1 1\n3", "1 0 4 4 1\n3 3\n1 1\n3", "1 1 4 4 1\n3 3\n1 1\n3", "1 1 4 4 1\n6 3\n1 1\n3", "1 2 4 8 1\n6 3\n1 1\n3", "2 2 4 8 1\n6 3\n1 1\n3", "1 2 2 2 1\n2 4\n9 1\n3"], "outputs": ["12\n", "7\n", "3\n", "6\n", "9\n", "10\n", "13\n", "16\n"]}
coding
439
Solve the programming task below in a Python markdown code block. Watson gives an integer $N$ to Sherlock and asks him: What is the number of divisors of $N$ that are divisible by 2?. Input Format First line contains $\mathbf{T}$, the number of testcases. This is followed by $\mathbf{T}$ lines each containing an...
{"inputs": ["2\n9\n8\n"], "outputs": ["0\n3\n"]}
coding
195
Solve the programming task below in a Python markdown code block. An array is defined to be `odd-heavy` if it contains at least one odd element and every element whose value is `odd` is greater than every even-valued element. eg. ``` Array [11,4,9,2,8] is odd-heavy because:- its odd elements [11,9] are greater than...
{"functional": "_inputs = [[[0, 2, 19, 4, 4]], [[1, -2, -1, 2]], [[-3, 2, 1, 3, -1, -2]], [[3, 4, -2, -3, -2]], [[-1, 1, -2, 2, -2, -2, -4, 4]], [[-1, -2, 21]], [[0, 0, 0, 0]], [[0, -1, 1]], [[0, 2, 3]], [[0]], [[]], [[1]], [[0, 1, 2, 3, 4, 0, -2, -1, -4, -3]], [[1, -1, 3, -1]], [[1, -1, 2, -2, 3, -3, 0]], [[3]], [[2, ...
coding
225
Solve the programming task below in a Python markdown code block. We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. ...
{"inputs": ["1 5\n6\n", "1 5\n6\n", "1 3\n6\n", "1 0\n6\n", "1 0\n22\n", "1 0\n22\n", "1 1\n22\n", "1 1\n42\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
424
Solve the programming task below in a Python markdown code block. Chef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if he has at...
{"inputs": ["1\n9\nPAAPPAPPP"], "outputs": ["1"]}
coding
681
Solve the programming task below in a Python markdown code block. You are given an array consisting of all integers from $[l, r]$ inclusive. For example, if $l = 2$ and $r = 5$, the array would be $[2, 3, 4, 5]$. What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero? A bitw...
{"inputs": ["5\n1 2\n2 8\n4 5\n1 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n100000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n110000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100100 200000\n", "5\n1 2\n2 8\n4 5\n1 5\n100001 200000\n", "5\n1 2\n2 8\n...
coding
486
Solve the programming task below in a Python markdown code block. Jack and Jill are playing a game. They have balls numbered from `0` to `n - 1`. Jack looks the other way and asks Jill to reverse the position of the balls, for instance, to change the order from say, `0,1,2,3` to `3,2,1,0`. He further asks Jill to rever...
{"functional": "_inputs = [[4, 1], [4, 2], [4, 3], [20, 8], [20, 9], [20, 10]]\n_outputs = [[3], [2], [0], [17], [19], [18]]\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))...
coding
323
Solve the programming task below in a Python markdown code block. In 21XX, humanity finally began a plan to relocate to Mars. Selected as the first group of immigrants to Mars, you are assigned to the Administrative Center of Mars to deal with various problems that occur on Mars. The biggest problem at the moment of th...
{"inputs": ["4 5 1 3 4\n1 2 5\n2 3 9\n2 4 5\n1 3 8\n1 4 8\n0 0 0 0 0", "4 5 1 3 4\n1 2 5\n2 3 9\n2 4 5\n1 3 3\n1 4 8\n0 0 0 0 0", "6 5 1 3 4\n1 2 5\n4 3 5\n2 3 5\n1 3 8\n1 4 8\n0 0 0 0 0", "4 5 1 3 4\n1 2 5\n2 3 5\n2 4 5\n1 3 8\n2 4 8\n0 0 0 0 0", "4 5 1 3 4\n0 2 5\n2 3 9\n2 4 5\n1 2 3\n1 4 8\n0 0 0 0 0", "4 5 1 3 4\n0...
coding
698
Solve the programming task below in a Python markdown code block. You are given three positive integers $n$, $a$ and $b$. You have to construct a string $s$ of length $n$ consisting of lowercase Latin letters such that each substring of length $a$ has exactly $b$ distinct letters. It is guaranteed that the answer exist...
{"inputs": ["1\n2 1 1\n", "1\n1 1 1\n", "1\n3 1 1\n", "1\n3 1 2\n", "1\n2 2 1\n", "1\n1 0 1\n", "1\n27 1 1\n", "1\n30 1 1\n"], "outputs": ["aa\n", "a\n", "aaa\n", "aba\n", "aa\n", "a\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"]}
coding
500
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that consists of only digits. Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between ...
{"functional": "def check(candidate):\n assert candidate(s = \"1234\") == False\n assert candidate(s = \"050043\") == True\n assert candidate(s = \"9080701\") == False\n assert candidate(s = \"10009998\") == True\n\n\ncheck(Solution().splitString)"}
coding
277
Solve the programming task below in a Python markdown code block. The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a l...
{"inputs": ["1\n1234 0 0\n", "1\n1234 2 2\n", "1\n0714 1 1\n", "1\n1234 3 1\n", "1\n1234 0 1\n", "1\n1234 1 2\n", "1\n0714 1 2\n", "1\n1234 3 0\n"], "outputs": ["Need more data", "Need more data", "Need more data", "Incorrect data\n", "Need more data\n", "Need more data\n", "Need more data\n", "Need more data\n"]}
coding
667
Solve the programming task below in a Python markdown code block. There is a grass field that stretches infinitely. In this field, there is a negligibly small cow. Let (x, y) denote the point that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0)...
{"inputs": ["3 1\n-3 -1 0\n-3 0 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0", "3 1\n-3 -1 0\n-6 0 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0", "3 1\n-3 -1 0\n-6 1 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0", "3 1\n-3 -1 0\n-6 1 1\n-2 0 2\n1 4 -2\n1 2 -1\n1 4 1\n3 1 0", "3 0\n-3 -1 0\n-3 0 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0"...
coding
514
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are $N$ seats in a row. You are given a string $S$ with length $N$; for each valid $i$, the $i$-th character of $S$ is '0' if the $i$-th seat is empty o...
{"inputs": ["4\n000\n010\n101\n01011011011110"], "outputs": ["0\n1\n2\n4"]}
coding
481
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Ujan is a software developer. He is developing a software that takes two integers L and R and outputs the count of integers in the sequence L,L+1,\ldots,R-1,R whose s...
{"inputs": ["5\n139 141\n100 1235\n1000 2537\n998244353 1000000007\n27182818284 31415926535897"], "outputs": ["1\n378\n512\n585218\n10462914572538"]}
coding
485
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have some coins.  The i-th coin has a probability prob[i] of facing heads when tossed. Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.   Please compl...
{"functional": "def check(candidate):\n assert candidate(prob = [0.4], target = 1) == 0.40000\n assert candidate(prob = [0.5,0.5,0.5,0.5,0.5], target = 0) == 0.03125\n\n\ncheck(Solution().probabilityOfHeads)"}
coding
98
Solve the programming task below in a Python markdown code block. A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible. INPUT First line is T,...
{"inputs": ["6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii"], "outputs": ["38\n51\n9\n1\n77\n95"]}
coding
219