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. Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya. Looking at her coins, a question cam...
{"inputs": ["1 79\n79\n", "1 114\n114\n", "3 50\n24 25 50\n", "3 50\n36 25 50\n", "3 50\n25 25 50\n", "5 6\n0 8 7 27 6\n", "5 6\n2 71 7 27 6\n", "5 6\n0 71 7 27 6\n"], "outputs": ["2\n0 79 ", "2\n0 114 ", "2\n0 50\n", "2\n0 50\n", "3\n0 25 50 ", "2\n0 6\n", "2\n0 6 ", "2\n0 6\n"]}
coding
440
Solve the programming task below in a Python markdown code block. A coordinate line has n segments, the i-th segment starts at the position l_{i} and ends at the position r_{i}. We will denote such a segment as [l_{i}, r_{i}]. You have suggested that one of the defined segments covers all others. In other words, there...
{"inputs": ["2\n3 5\n1 2\n", "2\n3 5\n1 2\n", "2\n3 4\n1 2\n", "1\n1 100000\n", "1\n1 100000\n", "3\n1 1\n2 2\n3 3\n", "3\n2 5\n3 4\n2 3\n", "3\n3 6\n2 4\n1 5\n"], "outputs": ["-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n", "-1\n"]}
coding
361
Solve the programming task below in a Python markdown code block. Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, th...
{"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 2 3\n", "3\n2 3 1\n", "3\n3 2 1\n", "3\n1 3 3\n"], "outputs": ["0 0\n", "0 1\n", "0 0\n", "0 1\n", "0 0\n", "0 1\n", "2 1\n", "1 0\n"]}
coding
588
Solve the programming task below in a Python markdown code block. Our fruit guy has a bag of fruit (represented as an array of strings) where some fruits are rotten. He wants to replace all the rotten pieces of fruit with fresh ones. For example, given `["apple","rottenBanana","apple"]` the replaced array should be `["...
{"functional": "_inputs = [[['apple', 'banana', 'kiwi', 'melone', 'orange']], [['rottenApple', 'rottenBanana', 'rottenApple', 'rottenPineapple', 'rottenKiwi']], [[]], [None], [['apple', 'rottenBanana', 'rottenApple', 'pineapple', 'kiwi']]]\n_outputs = [[['apple', 'banana', 'kiwi', 'melone', 'orange']], [['apple', 'bana...
coding
189
Solve the programming task below in a Python markdown code block. Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n8\n", "1\n9\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
445
Solve the programming task below in a Python markdown code block. Cat Snuke is learning to write characters. Today, he practiced writing digits 1 and 9, but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit 1 with 9 and each digit ...
{"inputs": ["191", "111", "199", "111", "199", "191", "119", "999"], "outputs": ["919\n", "999\n", "911\n", "999\n", "911\n", "919\n", "991", "111"]}
coding
219
Solve the programming task below in a Python markdown code block. -----Problem Statement----- Write a program that accepts a number, n, and outputs the same. -----Input----- The only line contains a single integer. -----Output----- Output the answer in a single line. -----Constraints----- - 0 ≤ n ≤ 105 -----Sample...
{"inputs": ["8", "9", "3", "0", "1", "2", "6", "5"], "outputs": ["8\n", "9\n", "3\n", "0\n", "1\n", "2\n", "6\n", "5\n"]}
coding
84
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you...
{"functional": "def check(candidate):\n assert candidate(candies = [2,3,5,1,3], extraCandies = 3) == [True,True,True,False,True] \n assert candidate(candies = [4,2,1,1,2], extraCandies = 1) == [True,False,False,False,False] \n assert candidate(candies = [12,1,12], extraCandies = 10) == [True,False,True]\n\n\nc...
coding
167
Please solve the programming task below using a self-contained code snippet in a markdown code block. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. You are given an array of strings sentences, where each sentences[i] represents a single sentence. Return the maxi...
{"functional": "def check(candidate):\n assert candidate(sentences = [\"alice and bob love leetcode\", \"i think so too\", \"this is great thanks very much\"]) == 6\n assert candidate(sentences = [\"please wait\", \"continue to fight\", \"continue to win\"]) == 3\n\n\ncheck(Solution().mostWordsFound)"}
coding
103
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding windo...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,-1,-3,5,3,6,7], k = 3) == [3,3,5,5,6,7]\n assert candidate(nums = [1], k = 1) == [1]\n\n\ncheck(Solution().maxSlidingWindow)"}
coding
116
Solve the programming task below in a Python markdown code block. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list,...
{"inputs": ["4 4\n1 2 5 9\n1 3 4 7", "4 4\n1 2 5 9\n2 3 4 7", "4 4\n1 2 4 9\n0 3 4 7", "4 4\n1 2 5 9\n0 3 4 7", "4 4\n1 3 5 9\n0 3 4 7", "4 4\n1 2 5 9\n1 2 4 7", "4 4\n1 2 5 9\n1 3 4 8", "4 4\n1 2 7 9\n0 3 4 7"], "outputs": ["1 7\n1\n1\n2\n3\n4\n5\n7\n9\n", "1 7\n2\n1\n2\n3\n4\n5\n7\n9\n", "1 7\n4\n0\n1\n2\n3\n4\n7\n9\...
coding
599
Solve the programming task below in a Python markdown code block. You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i =...
{"inputs": ["1\n4\n", "1\n5\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n97\n", "1\n97\n", "1\n32\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0", "0\n", "0", "0\n"]}
coding
547
Solve the programming task below in a Python markdown code block. Your friend has been out shopping for puppies (what a time to be alive!)... He arrives back with multiple dogs, and you simply do not know how to respond! By repairing the function provided, you will find out exactly how you should respond, depending on...
{"functional": "_inputs = [[26], [8], [14], [80], [100], [50], [10], [101]]\n_outputs = [['More than a handful!'], ['Hardly any'], ['More than a handful!'], [\"Woah that's a lot of dogs!\"], [\"Woah that's a lot of dogs!\"], ['More than a handful!'], ['Hardly any'], ['101 DALMATIONS!!!']]\nimport math\ndef _deep_eq(a, ...
coding
237
Solve the programming task below in a Python markdown code block. At the end of last year, Santa Claus forgot to give Christmas presents to the children in JOI village. Therefore, I decided to deliver the chocolate cake to the children as an apology. The day to deliver is approaching tomorrow, so it's time to come up w...
{"inputs": ["5 4\n3\n1 1\n3 4\n5 6", "6 4\n3\n1 1\n1 4\n5 6", "5 4\n3\n1 1\n3 4\n5 2", "5 4\n3\n1 1\n3 4\n7 6", "6 4\n3\n1 0\n1 4\n5 6", "6 4\n3\n0 1\n1 4\n5 0", "5 4\n3\n1 1\n3 3\n5 2", "5 4\n3\n0 1\n3 4\n7 6"], "outputs": ["13\n3 4\n", "12\n1 4\n", "11\n3 2\n", "16\n3 4\n", "14\n1 4\n", "13\n1 1\n", "9\n3 2\n", "18\n...
coding
680
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s, which contains stars *. In one operation, you can: Choose a star in s. Remove the closest non-star character to its left, as well as remove the star itself. Return the string after all star...
{"functional": "def check(candidate):\n assert candidate(s = \"leet**cod*e\") == \"lecoe\"\n assert candidate(s = \"erase*****\") == \"\"\n\n\ncheck(Solution().removeStars)"}
coding
128
Solve the programming task below in a Python markdown code block. Given is a string S of length N consisting of lowercase English letters. Snuke can do this operation any number of times: remove fox occurring as a substring from s and concatenate the remaining parts of s. What is the minimum possible length of s after ...
{"inputs": ["1\nf\n", "3\nfox\n", "6\nicefox\n", "7\nfirebox\n", "48\nffoxoxuvgjyzmehmopfohrupffoxoxfofofoxffoxoxejffo\n", "2365\nooofxfxxffxxxoffofffoxoxfoffxxooxooxoofxfooxxooxofooofxoxfxofxffoxxfxofffofxffxfofofooxofxoxffxofxfoxxxxooffoxfxxoxxxfffxoffoxoffofofffoofxoofxffoofxxoxxfoxfxfofxxxoxooxxoffxxfoxooxoxoxxffff...
coding
182
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game on a tree. The tree has N vertices numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex b_i. At the beginning of the game, each vertex contains a coin. Starting from Takahashi, he and Aoki wil...
{"inputs": ["3\n2 2\n2 3", "3\n2 1\n2 3", "3\n1 2\n2 3", "6\n1 2\n2 1\n2 4\n4 6\n5 6", "6\n1 2\n2 3\n2 4\n6 6\n5 6", "6\n1 2\n2 1\n2 4\n4 6\n4 6", "6\n1 3\n2 3\n2 4\n6 6\n5 6", "6\n2 2\n2 3\n2 4\n6 6\n5 6"], "outputs": ["First\n", "First\n", "First", "Second\n", "First\n", "First\n", "First\n", "First\n"]}
coding
385
Solve the programming task below in a Python markdown code block. You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there? Here, a Shichi-Go-San number is a positive integer that satisfies the following condition: - Whe...
{"inputs": ["3", "2", "1", "0", "1\n", "60", "91", "79"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
222
Solve the programming task below in a Python markdown code block. There are a number of people who will be attending ACM-ICPC World Finals. Each of them may be well versed in a number of topics. Given a list of topics known by each attendee, presented as binary strings, determine the maximum number of topics a 2-person...
{"inputs": ["4 5\n10101\n11100\n11010\n00101\n"], "outputs": ["5\n2\n"]}
coding
608
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string of digits num, such as "123456579". We can split it into a Fibonacci-like sequence [123, 456, 579]. Formally, a Fibonacci-like sequence is a list f of non-negative integers such that: 0 <= f[i]...
{"functional": "def check(candidate):\n assert candidate(num = \"1101111\") == [11,0,11,11]\n assert candidate(\"0123\") == []\n\n\ncheck(Solution().splitIntoFibonacci)"}
coding
228
Solve the programming task below in a Python markdown code block. You are given a tree T with N vertices. Recall that a tree is a connected graph with N-1 edges. Determine the minimum number of edges you must add to T to get a new graph G such that G has a Hamiltonian path. Note: A graph G is said to have a hamiltoni...
{"inputs": ["2\n5\n1 2\n1 3\n3 4\n5 3\n3\n1 2\n2 3\n", "1\n10\n8 2\n2 5\n5 6\n2 3\n3 7\n7 1\n1 9\n3 4\n7 10\n"], "outputs": ["1\n0", "2"]}
coding
545
Solve the programming task below in a Python markdown code block. Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: ...
{"inputs": ["?0?", "?/?", "??0", "??/", "?.?", "??1", "?-?", "?,?"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
277
Solve the programming task below in a Python markdown code block. Your company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing. Skipping the repair is necessary because ...
{"inputs": ["3\n6 1 1\n9 2 9\n1000000 1 1000000\n", "3\n6 1 2\n9 2 9\n1000000 1 1000000\n", "3\n5 1 2\n9 1 4\n1000001 1 1000100\n", "3\n5 1 2\n9 2 4\n1000001 1 1000100\n", "3\n5 1 1\n9 2 4\n1000000 1 1000000\n", "3\n4 1 1\n8 6 6\n1000001 2 1000000\n", "3\n3 1 2\n9 2 4\n1000001 1 1000100\n", "3\n5 1 1\n9 2 2\n1000000 1 ...
coding
530
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is n...
{"functional": "def check(candidate):\n assert candidate(s = \"YazaAay\") == \"aAa\"\n assert candidate(s = \"Bb\") == \"Bb\"\n assert candidate(s = \"c\") == \"\"\n assert candidate(s = \"dDzeE\") == \"dD\"\n\n\ncheck(Solution().longestNiceSubstring)"}
coding
161
Solve the programming task below in a Python markdown code block. You are given an array of $n$ non-negative integers $a_1, a_2, \ldots, a_n$. You can make the following operation: choose an integer $x \geq 2$ and replace each number of the array by the remainder when dividing that number by $x$, that is, for all $1 \l...
{"inputs": ["4\n4\n2 5 6 8\n3\n1 1 1\n5\n4 1 7 0 8\n4\n5 9 17 5\n"], "outputs": ["YES\nYES\nNO\nYES\n"]}
coding
541
Solve the programming task below in a Python markdown code block. A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Py...
{"inputs": ["1\n3\n", "1\n6\n", "1\n23\n", "1\n32\n", "1\n48\n", "1\n79\n", "1\n86\n", "1\n847\n"], "outputs": ["0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "20\n"]}
coding
542
Solve the programming task below in a Python markdown code block. Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \...
{"inputs": ["5 2", "5 1", "7 2", "5 0", "8 5", "3 3", "1 2", "6 5"], "outputs": ["33\n", "1\n", "129\n", "0\n", "390889\n", "30\n", "3\n", "15697\n"]}
coding
316
Solve the programming task below in a Python markdown code block. HackerLand Enterprise is adopting a new viral advertising strategy. When they launch a new product, they advertise it to exactly $5$ people on social media. On the first day, half of those $5$ people (i.e., $floor(\frac{5}{2})=2$) like the advertisemen...
{"inputs": ["3\n"], "outputs": ["9\n"]}
coding
437
Solve the programming task below in a Python markdown code block. Chef has N empty bottles where each bottle has a capacity of X litres. There is a water tank in Chefland having K litres of water. Chef wants to fill the empty bottles using the water in the tank. Assuming that Chef does not spill any water while fi...
{"inputs": ["3\n5 2 8\n10 5 4\n3 1 4"], "outputs": ["4\n0\n3"]}
coding
375
Solve the programming task below in a Python markdown code block. A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vert...
{"inputs": ["1\n\n6 2\n1 4\n1 6\n3 1\n6 2\n1 5\n", "1\n\n6 2\n1 4\n1 6\n3 1\n6 2\n2 5\n", "1\n\n6 4\n2 4\n1 2\n5 1\n6 1\n3 5\n", "1\n\n6 4\n1 4\n1 6\n3 1\n6 2\n1 5\n", "1\n\n6 2\n1 4\n1 2\n3 1\n6 2\n2 5\n", "1\n\n6 2\n1 4\n1 2\n3 1\n6 1\n2 5\n", "1\n\n6 2\n1 4\n1 2\n3 1\n6 1\n3 5\n", "1\n\n6 2\n1 4\n1 6\n3 1\n1 2\n2 5\...
coding
431
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions: The value of the first element in arr must be 1. The absolute difference between ...
{"functional": "def check(candidate):\n assert candidate(arr = [2,2,1,2,1]) == 2\n assert candidate(arr = [100,1,1000]) == 3\n assert candidate(arr = [1,2,3,4,5]) == 5\n\n\ncheck(Solution().maximumElementAfterDecrementingAndRearranging)"}
coding
222
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Arrays have fallen out of Chef's good books, and he plans to destroy all arrays he possesses. He is left with the last array A, consisting of N positive integers. In order t...
{"inputs": ["3\n2\n1 2\n2\n1 1\n3\n1 2 3", "3\n2\n1 2\n2\n1 1\n3\n1 4 3", "3\n2\n0 2\n2\n1 0\n3\n1 4 3", "3\n2\n1 2\n2\n1 1\n3\n0 0 0", "3\n2\n1 4\n2\n0 1\n3\n0 0 0", "3\n2\n1 0\n2\n1 1\n3\n1 4 3", "3\n2\n1 2\n2\n1 1\n3\n1 2 0", "3\n2\n0 2\n2\n1 1\n3\n1 4 3"], "outputs": ["1\n2\n2", "1\n2\n2\n", "1\n1\n2\n", "1\n2\n3\n...
coding
419
Solve the programming task below in a Python markdown code block. A core idea of several left-wing ideologies is that the wealthiest should *support* the poorest, no matter what and that is exactly what you are called to do using this kata (which, on a side note, was born out of the necessity to redistribute the width ...
{"functional": "_inputs = [[[2, 3, 5, 15, 75], 5], [[2, 3, 5, 15, 75], 20], [[2, 3, 5, 45, 45], 5], [[2, 3, 5, 45, 45], 30], [[24, 48, 22, 19, 37], 30]]\n_outputs = [[[5, 5, 5, 15, 70]], [[20, 20, 20, 20, 20]], [[5, 5, 5, 42, 43]], [[]], [[30, 30, 30, 30, 30]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinst...
coding
669
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1. An uncommon subsequence between an array of strings is...
{"functional": "def check(candidate):\n assert candidate(strs = [\"aba\",\"cdc\",\"eae\"]) == 3\n assert candidate(strs = [\"aaa\",\"aaa\",\"aa\"]) == -1\n\n\ncheck(Solution().findLUSlength)"}
coding
191
Solve the programming task below in a Python markdown code block. Bears love candies and games involving eating them. Limak and Bob play the following game. Limak eats 1 candy, then Bob eats 2 candies, then Limak eats 3 candies, then Bob eats 4 candies, and so on. Once someone can't eat what he is supposed to eat, he l...
{"inputs": ["10\n3 2\n4 2\n1 1\n1 2\n1 3\n9 3\n9 11\n9 12\n9 1000\n8 11"], "outputs": ["Bob\nLimak\nLimak\nBob\nBob\nLimak\nLimak\nBob\nBob\nBob"]}
coding
629
Solve the programming task below in a Python markdown code block. Counting was a difficult task in ancient Rome. The Arabic numerals 0,1,2,3,…, 9 have not yet been disseminated. Instead, the following symbols were used: Arabic numerals | Roman numerals | Arabic numerals | Roman numerals | Arabic numerals | Roman numer...
{"inputs": ["VI\nCCCCLXXXXVIIII\nCDXCIX", "IV\nCCCILXXXXVICII\nCDXCIX", "IV\nCCCCLXXXXVIIII\nCDICXX", "VI\nCXCCLXXCXVIIII\nCDXCIX", "VI\nCCCILXXXXVICII\nCDXCIX", "VI\nCXDCLXXCXVIIII\nCDXCIX", "IV\nCCCILXXXXVIDII\nCDXCIX", "VI\nCCCILXXXXVICII\nDCXCIX"], "outputs": ["6\n499\n499\n", "4\n495\n499\n", "4\n499\n519\n", "6\n...
coding
622
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 a sequence $A_{1}, A_{2}, \ldots, A_{N}$. He needs to find the number of pairs $(i, j)$ ($1 ≤ i < j ≤ N$) such that $A_{i} + A_{j} = A_{i} \...
{"inputs": ["2\n3\n2 4 2\n3\n0 2 3"], "outputs": ["1\n0"]}
coding
385
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland. To keep the land organized, there are designated rectangular areas of hectar...
{"functional": "def check(candidate):\n assert candidate(land = [[1,0,0],[0,1,1],[0,1,1]]) == [[0,0,0,0],[1,1,2,2]]\n assert candidate(land = [[1,1],[1,1]]) == [[0,0,1,1]]\n assert candidate(land = [[0]]) == []\n\n\ncheck(Solution().findFarmland)"}
coding
299
Solve the programming task below in a Python markdown code block. Given an Array of length $N$ containing elements $Ai$ ( i = 1 to n ) . You have to handle $Q$ queries on this array . Each Query is of two types k=(1 or 2). Type 1:- $k$ $l$ $r$ in which you have to tell whether the product of numbers in range l to r ...
{"inputs": ["4\n2 2 3 4\n4\n1 1 2\n1 3 4\n2 3 3\n1 1 4"], "outputs": ["YES\nNO\nYES"]}
coding
665
Solve the programming task below in a Python markdown code block. Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1...
{"inputs": ["3\n2 2 3", "3\n2 4 3", "3\n2 4 5", "3\n2 4 8", "3\n2 6 8", "3\n4 6 8", "3\n4 2 8", "3\n6 2 8"], "outputs": ["2 2 3\n2 2 3\n2 2 3\n", "2 4 3\n2 4 3\n2 3 4\n", "2 4 5\n2 4 5\n2 4 5\n", "2 4 8\n2 4 8\n2 4 8\n", "2 6 8\n2 6 8\n2 6 8\n", "4 6 8\n4 6 8\n4 6 8\n", "4 2 8\n2 4 8\n2 4 8\n", "6 2 8\n2 6 8\n2 6 8\n"]...
coding
353
Solve the programming task below in a Python markdown code block. Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N in...
{"inputs": ["3\n0 2 3", "3\n0 0 3", "3\n0 0 1", "3\n1 1 3", "3\n1 0 3", "3\n0 0 2", "3\n0 1 3", "3\n0 2 5"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n"]}
coding
277
Solve the programming task below in a Python markdown code block. Recall that a permutation of length $n$ is an array where each element from $1$ to $n$ occurs exactly once. For a fixed positive integer $d$, let's define the cost of the permutation $p$ of length $n$ as the number of indices $i$ $(1 \le i < n)$ such th...
{"inputs": ["2\n2\n3\n"], "outputs": ["2\n1 2 \n2\n1 2 3 \n"]}
coding
396
Solve the programming task below in a Python markdown code block. Write a method that will search an array of strings for all strings that contain another string, ignoring capitalization. Then return an array of the found strings. The method takes two parameters, the query string and the array of strings to search, a...
{"functional": "_inputs = [['ab', ['za', 'ab', 'abc', 'zab', 'zbc']], ['aB', ['za', 'ab', 'abc', 'zab', 'zbc']], ['ab', ['za', 'aB', 'Abc', 'zAB', 'zbc']], ['abcd', ['za', 'aB', 'Abc', 'zAB', 'zbc']]]\n_outputs = [[['ab', 'abc', 'zab']], [['ab', 'abc', 'zab']], [['aB', 'Abc', 'zAB']], [['None']]]\nimport math\ndef _dee...
coding
181
Solve the programming task below in a Python markdown code block. Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are described by a grid of characters S. If S_{i,j} is `1`, there is an edge connecting Vertex i and j; otherwise, there is no such edge. ...
{"inputs": ["2\n01\n10", "3\n011\n111\n110", "3\n010\n101\n010", "3\n011\n111\n111", "3\n011\n110\n111", "3\n010\n101\n110", "3\n011\n011\n110", "3\n011\n111\n011"], "outputs": ["2", "-1\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
434
Solve the programming task below in a Python markdown code block. ## Number of people in the bus There is a bus moving in the city, and it takes and drop some people in each bus stop. You are provided with a list (or array) of integer arrays (or tuples). Each integer array has two items which represent number of peopl...
{"functional": "_inputs = [[[[10, 0], [3, 5], [5, 8]]], [[[3, 0], [9, 1], [4, 10], [12, 2], [6, 1], [7, 10]]], [[[3, 0], [9, 1], [4, 8], [12, 2], [6, 1], [7, 8]]], [[[0, 0]]]]\n_outputs = [[5], [17], [21], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n re...
coding
238
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Xenny reverse-engineered all the binaries released by the International Security Agency (ISA) during summer vacation just to pass time. As a reward, the ISA gave him infinite...
{"inputs": ["1\n1 2"], "outputs": ["8"]}
coding
511
Solve the programming task below in a Python markdown code block. Sinchan and his friends loves to eat. They have a 2D rectangular cake which they want to share. Sinchan is very kind and offers his friends to eat the cake first, all friends goes one by one to eat the cake. Each friend will cut cake into two parts. Firs...
{"inputs": ["3\n2\n5 3\n4\n4 8\n1\n1 2"], "outputs": ["Yes 2\nNo\nYes 1"]}
coding
379
Solve the programming task below in a Python markdown code block. Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The co...
{"inputs": ["1\n3 R\n", "1\n3 R\n", "1\n2 R\n", "1\n4 R\n", "1\n5 R\n", "1\n1 R\n", "1\n6 R\n", "1\n0 R\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
453
Solve the programming task below in a Python markdown code block. We take a line segment of length $\textbf{C}$ on a one-dimensional plane and bend it to create a circle with circumference $\textbf{C}$ that's indexed from $0$ to $\boldsymbol{c-1}$. For example, if $c=4$: We denote a pair of points, $a$ and $\boldsymbo...
{"inputs": ["2 1000\n0 10\n10 20\n", "5 8\n0 4\n2 6\n1 5\n3 7\n4 4\n"], "outputs": ["0\n", "2\n"]}
coding
707
Solve the programming task below in a Python markdown code block. Given an integer $n$, find each $\boldsymbol{x}$ such that: $0\leq x\leq n$ $n+x=n\oplus x$ where $\oplus$ denotes the bitwise XOR operator. Return the number of $\boldsymbol{x}$'s satisfying the criteria. Example $n=4$ There are four values tha...
{"inputs": ["5\n", "10\n"], "outputs": ["2\n", "4\n"]}
coding
472
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...
coding
263
Solve the programming task below in a Python markdown code block. Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero)...
{"inputs": ["1\n1\n1\n1\n", "1\n1\n1\n1\n", "1\n1\n0\n1\n", "1\n3\n1 2 1\n2 1 2\n", "1\n3\n8 9 8\n9 8 9\n", "1\n3\n4 5 4\n5 4 5\n", "1\n3\n3 7 3\n7 3 7\n", "1\n3\n1 2 1\n1 1 2\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
718
Solve the programming task below in a Python markdown code block. Some time ago, Chef bought X stocks at the cost of Rs. Y each. Today, Chef is going to sell all these X stocks at Rs. Z each. What is Chef's total profit after he sells them? Chef's profit equals the total amount he received by selling the stocks, minus...
{"inputs": ["3\n2 5 20\n3 1 2\n4 5 6"], "outputs": ["30\n3\n4\n"]}
coding
590
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the number of prime numbers that are strictly less than n.   Please complete the following python code precisely: ```python class Solution: def countPrimes(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 10) == 4\n assert candidate(n = 0) == 0\n assert candidate(n = 1) == 0\n\n\ncheck(Solution().countPrimes)"}
coding
66
Solve the programming task below in a Python markdown code block. # Remove Duplicates You are to write a function called `unique` that takes an array of integers and returns the array with duplicates removed. It must return the values in the same order as first seen in the given array. Thus no sorting should be done, ...
{"functional": "_inputs = [[[]], [[-1]], [[-1, 5, 10, -100, 3, 2]], [[1, 2, 3, 3, 2, 1, 2, 3, 1, 1, 3, 2]], [[1, 3, 2, 3, 2, 1, 2, 3, 1, 1, 3, 2]], [[3, 2, 3, 3, 2, 1, 2, 3, 1, 1, 3, 2]]]\n_outputs = [[[]], [[-1]], [[-1, 5, 10, -100, 3, 2]], [[1, 2, 3]], [[1, 3, 2]], [[3, 2, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e...
coding
246
Solve the programming task below in a Python markdown code block. Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). -----Constraints----- - 1 \leq N \leq 10^4 - 1 \leq A \leq B \leq 36 - All input values are integers. -----Input----- In...
{"inputs": ["4 1 6", "2 0 8", "2 2 2", "3 0 4", "6 2 3", "6 2 5", "4 4 6", "5 1 0"], "outputs": ["10\n", "3\n", "2\n", "6\n", "5\n", "14\n", "4\n", "0\n"]}
coding
223
Please solve the programming task below using a self-contained code snippet in a markdown code block. Let's play the minesweeper game (Wikipedia, online game)! You are given an m x n char matrix board representing the game board where: 'M' represents an unrevealed mine, 'E' represents an unrevealed empty square, 'B' ...
{"functional": "def check(candidate):\n assert candidate(board = [[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"]], click = [3,0]) == [[\"B\",\"1\",\"E\",\"1\",\"B\"],[\"B\",\"1\",\"M\",\"1\",\"B\"],[\"B\",\"1\",\"1\",\"1\",\"B\"],[\"B\"...
coding
324
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again. A neighborhood is a ma...
{"functional": "def check(candidate):\n assert candidate(houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3) == 9\n assert candidate(houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3) == 11\n assert candidate(houses = [0,0,0,0,0],...
coding
268
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and two integers minK and maxK. A fixed-bound subarray of nums is a subarray that satisfies the following conditions: The minimum value in the subarray is equal to minK. The maximu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,2,7,5], minK = 1, maxK = 5) == 2\n assert candidate(nums = [1,1,1,1], minK = 1, maxK = 1) == 10\n\n\ncheck(Solution().countSubarrays)"}
coding
138
Solve the programming task below in a Python markdown code block. Input The only line of input contains three integers a1, a2, a3 (1 ≤ a1, a2, a3 ≤ 20), separated by spaces. Output Output a single integer. Examples Input 2 3 2 Output 5 Input 13 14 1 Output 14 Input 14 5 9 Output 464 Input 17 18 ...
{"inputs": ["5 5 5\n", "8 2 9\n", "1 1 1\n", "4 6 7\n", "5 5 3\n", "5 6 7\n", "7 5 3\n", "7 9 3\n"], "outputs": ["40\n", "236\n", "1\n", "110\n", "15\n", "118\n", "17\n", "25\n"]}
coding
116
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"]}
coding
179
Solve the programming task below in a Python markdown code block. Simple interest on a loan is calculated by simply taking the initial amount (the principal, p) and multiplying it by a rate of interest (r) and the number of time periods (n). Compound interest is calculated by adding the interest after each time perio...
{"functional": "_inputs = [[100, 0.1, 1], [100, 0.1, 2], [100, 0.1, 10], [100, 0, 10], [0, 0.1, 10], [100, 0.1, 0]]\n_outputs = [[[110, 110]], [[120, 121]], [[200, 259]], [[100, 100]], [[0, 0]], [[100, 100]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retu...
coding
309
Solve the programming task below in a Python markdown code block. A Hackerrank number is a magic number that can be used to get sudo permissions on the site. We are going to generate a hackerrank number from two integers A & B. Each number has two parts to it - the left (L) & the right side (R). For eg: for the numb...
{"inputs": ["2 4\n"], "outputs": ["14502\n"]}
coding
745
Solve the programming task below in a Python markdown code block. Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't g...
{"functional": "_inputs = [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]]\n_outputs = [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, 4, 7, 13, ...
coding
451
Solve the programming task below in a Python markdown code block. Polycarp found a rectangular table consisting of $n$ rows and $m$ columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns": cells are numbered starting from one; cells are numbered from left to ri...
{"inputs": ["5\n1 1 1\n2 2 3\n3 6 1\n110 100 498\n1000000 1000000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 6 1\n110 100 498\n1000000 1100000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 6 1\n110 100 507\n1000000 1000000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 6 1\n100 100 498\n1000000 1100000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 ...
coding
654
Solve the programming task below in a Python markdown code block. Chef has a permutation P of length 2 \cdot N. He can perform the following operation on P: Select an index i (1 ≤ i < 2 \cdot N) and swap P_{i} and P_{i + 1}. Chef would call the permutation P *good*, if the maximum element of the first half of P is les...
{"inputs": ["3\n2\n3 2 1 4\n3\n1 2 3 4 5 6\n3\n6 5 4 3 2 1\n"], "outputs": ["2\n0\n9\n"]}
coding
522
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game. At the start of the game, there are N piles of stones, the i-th of which has A_{i} stones. Alice and Bob alternate moves. On their move, a player does the following: Choose one pile of stones, and discard the remaining ...
{"inputs": ["1\n3\n5 7 8"], "outputs": ["Alice"]}
coding
433
Solve the programming task below in a Python markdown code block. Complete the function that counts the number of unique consonants in a string (made up of printable ascii characters). Consonants are letters used in English other than `"a", "e", "i", "o", "u"`. We will count `"y"` as a consonant. Remember, your funct...
{"functional": "_inputs = [['sillystring'], ['aeiou'], ['abcdefghijklmnopqrstuvwxyz'], ['Count my unique consonants!!']]\n_outputs = [[7], [0], [21], [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 i...
coding
246
Solve the programming task below in a Python markdown code block. The goal of this Kata is to return the greatest distance of index positions between matching number values in an array or 0 if there are no matching values. Example: In an array with the values [0, 2, 1, 2, 4, 1] the greatest index distance is between...
{"functional": "_inputs = [[[9, 7, 1, 2, 3, 7, 0, -1, -2]], [[0, 7, 0, 2, 3, 7, 0, -1, -2]], [[1, 2, 3, 4]]]\n_outputs = [[4], [6], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (l...
coding
236
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You work as an engineer. You were given an empty board with $K$ consecutive cells; at any moment, each cell can display one character. You want the board to display a string...
{"inputs": ["3\n6 3\naabbcc\n5 2\nabccc\n4 3\naabb"], "outputs": ["4\n3\n1"]}
coding
716
Solve the programming task below in a Python markdown code block. # Task A range-collapse representation of an array of integers looks like this: `"1,3-6,8"`, where `3-6` denotes the range from `3-6`, i.e. `[3,4,5,6]`. Hence `"1,3-6,8"` = `[1,3,4,5,6,8]`. Some other range-collapse representations of `[1,3,4,5,6,8]...
{"functional": "_inputs = [[[1, 3, 4, 5, 6, 8]], [[1, 2, 3]], [[11, 43, 66, 123]], [[3, 4, 5, 8, 9, 10, 11, 23, 43, 66, 67]]]\n_outputs = [[8], [4], [1], [64]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n...
coding
390
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of 1's connected 4-directionally (horizontal or vertical). Any cells o...
{"functional": "def check(candidate):\n assert candidate(grid1 = [[1,1,1,0,0],[0,1,1,1,1],[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1]], grid2 = [[1,1,1,0,0],[0,0,1,1,1],[0,1,0,0,0],[1,0,1,1,0],[0,1,0,1,0]]) == 3\n assert candidate(grid1 = [[1,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[1,0,1,0,1]], grid2 = [[0,0,0,0,0]...
coding
170
Solve the programming task below in a Python markdown code block. You are teaching students to generate strings consisting of unique lowercase latin characters (a-z). You give an example reference string $s$ to the students. You notice that your students just copy paste the reference string instead of creating their ow...
{"inputs": ["4\nhelowrd 0\nbackground 0\nabcdefghijklmnopqrstuvwxyz 0\nb 1"], "outputs": ["abcfgij\nefhijlmpqs\nNOPE\na"]}
coding
456
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two binary strings a and b, return their sum as a binary string.   Please complete the following python code precisely: ```python class Solution: def addBinary(self, a: str, b: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(a = \"1010\", b = \"1011\") == \"10101\"\n\n\ncheck(Solution().addBinary)"}
coding
67
Solve the programming task below in a Python markdown code block. Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help ...
{"inputs": ["1\nA\n", "1\nD\n", "1\nA\n", "1\nD\n", "2\nDA\n", "2\nDA\n", "2\nDA\n", "2\nAD\n"], "outputs": ["Anton\n", "Danik\n", "Anton\n", "Danik\n", "Friendship\n", "Friendship\n", "Friendship\n", "Friendship\n"]}
coding
381
Solve the programming task below in a Python markdown code block. You are given a sequence $A_1, A_2, \ldots, A_N$. You may perform the following operation an arbitrary number of times (including zero): choose two adjacent elements of this sequence, i.e. $A_i$, $A_{i+1}$ for some valid $i$, and swap them. However, for ...
{"inputs": ["2\n4\n2 1 4 3\n4\n7 6 3 2"], "outputs": ["30\n39"]}
coding
498
Solve the programming task below in a Python markdown code block. Bosky often helps his younger brother Nitin with his home work and also clears his doubts. Today, Nitin learned about proper fractions. He went a step forward and tried to represent the same proper fraction in its decimal form, but runs into problems. H...
{"inputs": ["100\n1 2 1\n1 2 2\n1234 12345 123\n1 9 5\n5 8 6\n5 8 2\n9 10 5\n1 8 6\n2 3 6\n1 6 4\n3 8 10\n9 10 8\n5 7 6\n2 8 3\n7 10 2\n2 3 5\n6 8 7\n2 8 10\n1 3 3\n1 4 8\n15 32 90\n3 89 98\n10 12 13\n37 78 53\n39 55 54\n44 51 42\n52 78 37\n81 89 89\n48 91 35\n38 89 69\n20 91 52\n1 49 12\n62 88 61\n52 99 67\n41 65 67\n...
coding
525
Solve the programming task below in a Python markdown code block. Diana is planning to make a very long journey. Her journey consists of $N$ bus routes, numbered from $1 to N$ in the order she must take them. The buses themselves are very fast but do not run often. The $i-th$ bus route only runs every $Xi$ days. More ...
{"inputs": ["3\n3 10\n3 7 2\n4 100\n11 10 5 50\n1 1\n1"], "outputs": ["6\n99\n1"]}
coding
688
Solve the programming task below in a Python markdown code block. Solve the mystery. Input : First line contains T - No. of test cases. For each test case there are two lines. first line contains N. Second line contains N space separated integers A[1] to A[N]. Output : Print answer of the mystery in separate...
{"inputs": ["10\n10\n9 83 61 91 57 0 89 87 83 68 \n10\n9 41 12 70 73 85 85 79 3 49 \n10\n25 14 34 85 24 19 0 13 72 15 \n10\n24 66 54 97 85 91 45 64 42 39 \n10\n44 39 78 94 54 81 35 18 10 67 \n10\n58 29 36 52 77 34 64 10 3 24 \n10\n8 42 31 40 6 53 66 77 76 58 \n10\n63 55 67 9 91 77 23 30 91 50 \n10\n36 12 34 78 45 18 21...
coding
191
Solve the programming task below in a Python markdown code block. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, ...
{"inputs": ["1 1 0\n1\n", "3 1 2\n1 1 1\n", "10 2 2\n1 1 1 2 1 2 1 2 1 1\n", "10 2 2\n1 2 1 2 1 1 2 1 1 2\n", "10 3 2\n1 2 1 1 3 2 1 1 2 2\n", "20 6 3\n4 1 2 6 3 3 2 5 2 5 2 1 1 4 1 2 2 1 1 4\n", "20 2 5\n2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1\n", "20 3 5\n2 2 3 1 2 2 3 3 3 2 1 2 3 1 1 3 3 3 2 3\n"], "outputs": ["1", ...
coding
359
Solve the programming task below in a Python markdown code block. Janmansh has to submit 3 assignments for Chingari before 10 pm and he starts to do the assignments at X pm. Each assignment takes him 1 hour to complete. Can you tell whether he'll be able to complete all assignments on time or not? ------ Input Format ...
{"inputs": ["2\n7\n9\n"], "outputs": ["Yes\nNo\n"]}
coding
278
Solve the programming task below in a Python markdown code block. Alice (uniformly and independently) randomly picks two integers a, b from the range [1,10^{4}], and writes down the values of a + b, a - b, a \cdot b and \lfloor \frac{a}{b} \rfloor (integer division) in some random order. Unfortunately, she forgot the v...
{"inputs": ["2\n-1 72 0 17\n1 4 5 6"], "outputs": ["8 9\n-1 -1"]}
coding
563
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. The Chef had a box with N numbers arranged inside it: A_{1}, A_{2}, ..., A_{N}. He also had the number N at the front, so that he knows how many numbers are in it. That is, t...
{"inputs": ["3\n1 2 1\n3 1 2 8\n1 5 1 4 3 2"], "outputs": ["1\n8\n4"]}
coding
461
Solve the programming task below in a Python markdown code block. Given an empty array A of infinite length and a positive integer K you have to process Q queries of type: - ! l r x: Fill the value x in all the empty places in the array from index l to r (both inclusive). - ? l r: Print the number of prime factor...
{"inputs": ["20 5\n? 1 5\n! 3 5 4\n? 1 5\n! 1 4 15\n? 1 5"], "outputs": ["0\n1\n2"]}
coding
483
Solve the programming task below in a Python markdown code block. You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. Can you make this graph acyclic by removing at most one edge f...
{"inputs": ["2 2\n1 2\n2 1\n", "2 2\n1 2\n2 1\n", "3 3\n2 3\n2 1\n3 2\n", "3 3\n2 3\n2 1\n3 2\n", "3 4\n1 2\n2 3\n3 2\n3 1\n", "3 4\n1 2\n2 1\n1 3\n3 1\n", "4 4\n1 2\n2 1\n3 4\n4 3\n", "3 4\n3 2\n1 2\n2 3\n1 3\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n"]}
coding
375
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise OR. An array a is a subset of an array b if a can be ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,1]) == 2\n assert candidate(nums = [2,2,2]) == 7\n assert candidate(nums = [3,2,1,5]) == 6\n\n\ncheck(Solution().countMaxOrSubsets)"}
coding
160
Solve the programming task below in a Python markdown code block. Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string valu...
{"functional": "_inputs = [[['one', 'two', 'three', 'four']], [['one']], [['one', '', 'three']], [['', '', 'three']], [['one', 'two', '']], [[]], [None], [['']]]\n_outputs = [['one, two, three and four'], ['one'], ['one and three'], ['three'], ['one and two'], [''], [''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5...
coding
237
Solve the programming task below in a Python markdown code block. A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team ...
{"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n2 2\n", "4\n1 5\n5 2\n3 7\n7 3\n", "4\n5 6\n6 7\n7 8\n8 5\n", "4\n5 6\n6 7\n7 8\n8 5\n", "4\n5 8\n6 7\n7 8\n8 5\n", "4\n5 8\n6 7\n7 3\n8 5\n"], "outputs": ["2\n", "2\n", "1\n", "6\n", "2\n", "2\n", "2\n", "6\n"]}
coding
450
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", "5\nritesh\nritesh\nritesh\nsahil\nsahil"], "outputs": ["ritesh 2\nsahil 1", "ritesh 3\nsahil 2"]}
coding
252
Solve the programming task below in a Python markdown code block. Given the time in numerals we may convert it into words, as shown below: $\begin{array}{l}5.00\rightarrow\:five \quad o'clock\\ 5.01\rightarrow\:one\quad minute \quad past\quad five\\ 5.10\rightarrow\:ten\quad minutes\quad past\quad five\\ 5.15\righ...
{"inputs": ["5\n47\n", "3\n00\n", "7\n15\n"], "outputs": ["thirteen minutes to six\n", "three o' clock\n", "quarter past seven\n"]}
coding
445
Solve the programming task below in a Python markdown code block. Your job is to write function last_digits(n,d) which return the last `d` digits of an integer `n` as a list. `n` will be from 0 to 10^10 Examples: `last_digits(1,1) --> [1]` `last_digits(1234,2) --> [3,4]` `last_digits(637547,6) --> [6,3,7,5,4,...
{"functional": "_inputs = [[1, 1], [123767, 4], [0, 1], [34625647867585, 10], [1234, 0], [24134, -4], [1343, 5]]\n_outputs = [[[1]], [[3, 7, 6, 7]], [[0]], [[5, 6, 4, 7, 8, 6, 7, 5, 8, 5]], [[]], [[]], [[1, 3, 4, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
194
Solve the programming task below in a Python markdown code block. Chef likes cooking. But more than that, he likes to give gifts. And now he wants to give his girlfriend an unforgettable gift. But unfortunately he forgot the password to the safe where the money he saved for the gift is kept. But he knows how to hack t...
{"inputs": ["2\n3\n1 2 3\n1\n9", "2\n3\n2 2 3\n1\n9", "2\n3\n2 1 3\n1\n9", "2\n3\n3 1 3\n1\n9", "2\n3\n3 4 3\n1\n9", "2\n3\n1 2 6\n1\n9", "2\n3\n3 1 3\n1\n6", "2\n3\n3 4 3\n1\n4"], "outputs": ["-4\n9", "-3\n9\n", "-2\n9\n", "-1\n9\n", "-4\n9\n", "-7\n9\n", "-1\n6\n", "-4\n4\n"]}
coding
527
Solve the programming task below in a Python markdown code block. You are given two arrays $a$ and $b$ of length $n$. Array $a$ contains each odd integer from $1$ to $2n$ in an arbitrary order, and array $b$ contains each even integer from $1$ to $2n$ in an arbitrary order. You can perform the following operation on t...
{"inputs": ["3\n2\n3 1\n4 2\n3\n5 3 1\n2 4 6\n5\n7 5 9 1 3\n2 4 6 10 8\n"], "outputs": ["0\n2\n3\n"]}
coding
710
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.   Please complete the following python code precisely: ```python # Definit...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,1,2])), list_node([1,2]))\n assert is_same_list(candidate(head = list_node([1,1,2,3,3])), list_node([1,2,3]))\n\n\ncheck(Solution().deleteDuplicates)"}
coding
119
Solve the programming task below in a Python markdown code block. Snuke has an integer sequence A of length N. He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen. Let P,Q,R,S be the sums of the elements in B,C,D,E, res...
{"inputs": ["5\n3 2 4 2 2", "5\n5 2 4 2 1", "5\n4 3 4 2 1", "5\n2 1 6 0 2", "5\n2 3 6 2 1", "5\n2 1 7 0 2", "5\n2 1 7 0 0", "5\n8 0 2 2 0"], "outputs": ["2\n", "3\n", "1\n", "5\n", "4\n", "6\n", "7\n", "8\n"]}
coding
311
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef has N simple polygons (non self intersecting polygons) in which no two of them intersect with each other. For any two polygons P_{1}, P_{2}, either P_{1} lies inside P_{2} or vice versa. C...
{"inputs": ["1\n3\n6\n0 4 -1 1 4 1 0 -1 1 -2 -3 -2\n2\n0 -1 1 0 1 0\n2\n3 3 0 1 -3 -3 3 -3", "1\n2\n6\n0 4 -1 1 2 1 0 -1 1 0 -3 0\n3\n-2 -1 0 0 1 0\n2\n6 3 -1 1 -1 -3 3 -3", "1\n2\n5\n-1 4 -1 1 2 2 0 -1 1 0 0 0\n3\n-3 -1 0 -1 1 0\n2\n6 3 0 1 -2 -3 6 -3", "1\n2\n6\n0 4 -1 1 2 1 0 -1 0 0 -3 0\n3\n-2 -1 0 0 1 0\n2\n6 3 -1...
coding
534
Solve the programming task below in a Python markdown code block. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-t...
{"inputs": ["BBX", "BXB", "BYB", "CYB", "CYA", "CAY", "CAX", "AYC"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
274
Solve the programming task below in a Python markdown code block. Chef made $N$ pieces of cakes, numbered them $1$ through $N$ and arranged them in a row in this order. There are $K$ possible types of flavours (numbered $1$ through $K$); for each valid $i$, the $i$-th piece of cake has a flavour $A_i$. Chef wants to se...
{"inputs": ["2\n6 2\n1 1 1 2 2 1\n5 3\n1 1 2 2 1"], "outputs": ["3\n5"]}
coding
423
Solve the programming task below in a Python markdown code block. You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side. Let's call...
{"inputs": ["1 1\n*\n", "1 1\n.\n", "1 1\n*\n", "1 1\n.\n", "3 3\n*.*\n.*.\n*.*\n", "1 10\n**********\n", "1 10\n*.***.**.*\n", "1 10\n**********\n"], "outputs": ["1\n", ".\n", "1\n", ".\n", "3.3\n.5.\n3.3\n", "1111111111\n", "2.212.22.2\n", "1111111111\n"]}
coding
523
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge. Return the length of the shortest pa...
{"functional": "def check(candidate):\n assert candidate(graph = [[1,2,3],[0],[0],[0]]) == 4\n assert candidate(graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]) == 4\n\n\ncheck(Solution().shortestPathLength)"}
coding
130