task_type
stringclasses
1 value
problem
stringlengths
333
3.04k
answer
stringlengths
38
3.95k
problem_tokens
int64
69
769
answer_tokens
int64
14
1.46k
coding
Solve the programming task below in a Python markdown code block. You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria. According to the regulation, the immigrant should be allo...
{"inputs": ["3\n2 8 9", "3\n4 3 47", "3\n4 5 47", "3\n4 5 66", "3\n4 5 99", "3\n4 5 69", "3\n2 5 69", "3\n2 8 69"], "outputs": ["DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n"]}
253
125
coding
Solve the programming task below in a Python markdown code block. To give credit where credit is due: This problem was taken from the ACMICPC-Northwest Regional Programming Contest. Thank you problem writers. You are helping an archaeologist decipher some runes. He knows that this ancient society used a Base 10 system...
{"functional": "_inputs = [['123?45*?=?'], ['?*123?45=?'], ['??605*-63=-73???5'], ['123?45+?=123?45'], ['?8?170-1?6256=7?2?14'], ['?38???+595???=833444'], ['123?45-?=123?45'], ['-7715?5--484?00=-28?9?5'], ['50685?--1?5630=652?8?'], ['??+??=??'], ['-?56373--9216=-?47157']]\n_outputs = [[0], [0], [1], [0], [9], [2], [0],...
520
362
coding
Solve the programming task below in a Python markdown code block. Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candle...
{"inputs": ["4 2\n", "6 3\n", "1 2\n", "1 3\n", "1 4\n", "2 2\n", "3 2\n", "3 3\n"], "outputs": ["7\n", "8\n", "1\n", "1\n", "1\n", "3\n", "5\n", "4\n"]}
267
86
coding
Solve the programming task below in a Python markdown code block. At Akabe High School, which is a programmer training school, the roles of competition programmers in team battles are divided into the following three types. C: | Coder | I am familiar with the language and code. --- | --- | --- A: | Algorithm | I am goo...
{"inputs": ["4\n3 0 0\n1 1 1\n9 4 2\n0 1 2", "4\n2 0 0\n1 1 1\n9 4 2\n0 1 2", "4\n3 0 1\n1 1 1\n9 4 1\n0 1 2", "4\n3 0 0\n1 2 1\n0 4 2\n0 1 2", "4\n0 0 0\n1 2 1\n0 4 2\n0 1 3", "4\n2 1 0\n2 2 2\n9 8 2\n0 1 3", "4\n0 1 2\n3 0 2\n9 0 0\n0 2 3", "4\n0 0 0\n1 2 1\n1 4 2\n0 0 3"], "outputs": ["1\n1\n5\n0\n", "0\n1\n5\n0\n",...
415
302
coding
Solve the programming task below in a Python markdown code block. Squid loves painting vertices in graphs. There is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges. Initially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. ...
{"inputs": ["7 7\n1 2\n1 3\n1 4\n4 5\n5 6\n5 7\n2 3\n2\n6 0 1\n1 2 2", "7 7\n1 2\n1 3\n1 4\n4 5\n5 3\n5 7\n2 3\n2\n6 0 1\n1 2 1", "7 7\n1 2\n1 3\n1 4\n4 6\n5 6\n5 7\n2 3\n2\n6 0 1\n1 2 2", "7 7\n1 2\n1 3\n1 3\n4 5\n5 3\n5 7\n2 3\n2\n6 0 1\n1 2 1", "7 7\n1 1\n2 3\n1 4\n4 5\n5 5\n5 7\n2 3\n2\n6 1 1\n1 2 2", "7 7\n1 2\n1 ...
499
651
coding
Solve the programming task below in a Python markdown code block. Sho has an array $a$ consisting of $n$ integers. An operation consists of choosing two distinct indices $i$ and $j$ and removing $a_i$ and $a_j$ from the array. For example, for the array $[2, 3, 4, 2, 5]$, Sho can choose to remove indices $1$ and $3$. ...
{"inputs": ["1\n2\n1 9\n", "4\n6\n2 2 2 3 3 3\n5\n9 1 9 9 1\n4\n15 16 16 15\n4\n10 100 1000 10000\n"], "outputs": ["2\n", "2\n1\n2\n4\n"]}
690
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue sm...
{"functional": "def check(candidate):\n assert candidate(img = [[1,1,1],[1,0,1],[1,1,1]]) == [[0, 0, 0],[0, 0, 0], [0, 0, 0]]\n assert candidate(img = [[100,200,100],[200,50,200],[100,200,100]]) == [[137,141,137],[141,138,141],[137,141,137]]\n\n\ncheck(Solution().imageSmoother)"}
171
155
coding
Solve the programming task below in a Python markdown code block. String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string s. You can perform two different operations on this string: swa...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n10\n", "2\n11\n", "2\n11\n", "2\n10\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "10\n", "1\n", "1\n", "10\n"]}
373
92
coding
Solve the programming task below in a Python markdown code block. Create a function ```python has_two_cube_sums(n) ``` which checks if a given number `n` can be written as the sum of two cubes in two different ways: `n = a³+b³ = c³+d³`. All the numbers `a`, `b`, `c` and `d` should be different and greater than `0`. ...
{"functional": "_inputs = [[1], [1729], [42], [4103], [4102], [4104], [4105], [4106], [0], [46163]]\n_outputs = [[False], [True], [False], [False], [False], [True], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math....
171
234
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [indexi, colori]. For the ith q...
{"functional": "def check(candidate):\n assert candidate(n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]]) == [0,1,1,0,2]\n assert candidate(n = 1, queries = [[0,100000]]) == [0]\n\n\ncheck(Solution().colorTheArray)"}
158
89
coding
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"]}
568
48
coding
Solve the programming task below in a Python markdown code block. Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define the distance between two strings s and...
{"inputs": ["0\n0\n", "0\n1\n", "1\n1\n", "1\n0\n", "1\n0\n", "0\n0\n", "0\n1\n", "1\n1\n"], "outputs": ["0\n", "impossible\n", "1\n", "impossible\n", "impossible\n", "0", "impossible\n", "1"]}
376
88
coding
Solve the programming task below in a Python markdown code block. You are given a matrix of integers $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each element of this matrix is either $0$ or $1$. A move consists of the following steps: - Choose two different rows $r_1$ and $r...
{"inputs": ["1\n3 3\n010\n000\n001"], "outputs": ["1 0 1\n2 1 1\n1 1 0"]}
620
44
coding
Solve the programming task below in a Python markdown code block. A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No. -----Constraints--...
{"inputs": ["2 3 4", "1 4 4", "7 9 6", "4 3 4", "1 4 8", "7 4 6", "4 5 4", "0 4 8"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n", "No\n"]}
162
94
coding
Solve the programming task below in a Python markdown code block. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The ...
{"inputs": ["/\n", "////\n", "/a/b/c\n", "/b/b/c\n", "/c/b/c\n", "/aa//b/aa\n", "/a//aa/a//\n", "////a//b/////g\n"], "outputs": ["/\n", "/\n", "/a/b/c\n", "/b/b/c\n", "/c/b/c\n", "/aa/b/aa\n", "/a/aa/a\n", "/a/b/g\n"]}
214
107
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minim...
{"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]) == [[0,1],[2,3,4,5]]\n assert candidate(n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]) == [[],[0,1,2,3]]\n\n\ncheck(Solution().findCriticalAndPseudoCriticalEdges)"}
228
141
coding
Solve the programming task below in a Python markdown code block. Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: $\sum_{i = 1}^{a} \sum_{j = 1}^{b} \sum_{k = 1}^{c} d(i \cdot j \cdot k)$ Find the sum modulo 107...
{"inputs": ["2 2 2\n", "5 6 7\n", "1 5 1\n", "1 5 1\n", "2 1 2\n", "2 2 2\n", "5 6 7\n", "71 2 1\n"], "outputs": ["20\n", "1520\n", "10\n", "10\n", "8\n", "20\n", "1520\n", "811\n"]}
390
115
coding
Solve the programming task below in a Python markdown code block. Given two integers, $\boldsymbol{l}$ and $\textbf{r}$, find the maximal value of $\boldsymbol{a}$ xor $\boldsymbol{b}$, written $a\oplus b$, where $\boldsymbol{a}$ and $\boldsymbol{b}$ satisfy the following condition: $l\leq a\leq b\leq r$ For exampl...
{"inputs": ["10\n15\n", "11\n100\n"], "outputs": ["7\n", "127\n"]}
686
33
coding
Solve the programming task below in a Python markdown code block. Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure...
{"inputs": ["3 1\n1 1\n2 6\n5 3\n0 0 5 5", "3 1\n0 2\n2 4\n0 6\n0 0 0 5", "3 1\n0 2\n2 4\n0 6\n0 0 1 5", "3 1\n0 1\n2 4\n0 6\n0 0 1 5", "3 1\n0 1\n2 4\n0 6\n0 0 0 5", "3 1\n0 1\n2 8\n0 6\n0 0 0 5", "3 1\n1 1\n2 6\n5 3\n0 0 1 5", "3 1\n1 1\n2 4\n5 3\n0 0 5 5"], "outputs": ["2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"...
655
237
coding
Solve the programming task below in a Python markdown code block. The government of Berland decided to improve network coverage in his country. Berland has a unique structure: the capital in the center and $n$ cities in a circle around the capital. The capital already has a good network coverage (so the government igno...
{"inputs": ["1\n4\n3 3 3 3\n3 3 3 2\n", "1\n4\n3 3 3 3\n3 3 3 2\n", "1\n4\n3 3 3 4\n3 3 3 2\n", "1\n4\n3 3 3 4\n3 3 6 2\n", "1\n4\n3 3 3 4\n3 3 3 3\n", "1\n4\n3 3 3 4\n3 3 4 3\n", "1\n4\n3 3 3 8\n3 3 4 3\n", "1\n4\n3 3 3 15\n3 3 4 3\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n"]}
742
215
coding
Solve the programming task below in a Python markdown code block. Chouti is working on a strange math problem. There was a sequence of $n$ positive integers $x_1, x_2, \ldots, x_n$, where $n$ is even. The sequence was very special, namely for every integer $t$ from $1$ to $n$, $x_1+x_2+...+x_t$ is a square of some int...
{"inputs": ["2\n1\n", "2\n1\n", "2\n780\n", "2\n524\n", "2\n203\n", "2\n9900\n", "2\n9900\n", "4\n35 15\n"], "outputs": ["No\n", "No\n", "Yes\n4 780\n", "Yes\n16900 524\n", "Yes\n121 203\n", "Yes\n100 9900\n", "Yes\n100 9900 ", "Yes\n1 35 13 15\n"]}
690
154
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary tree, determine if it is height-balanced.   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=Non...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == True\n assert candidate(root = tree_node([1,2,2,3,3,None,None,4,4])) == False\n assert candidate(root = tree_node([])) == True\n\n\ncheck(Solution().isBalanced)"}
114
84
coding
Solve the programming task below in a Python markdown code block. To write a research paper, you should definitely follow the structured format. This format, in many cases, is strictly defined, and students who try to write their papers have a hard time with it. One of such formats is related to citations. If you refe...
{"inputs": ["5\n1 1 3 5 6\n3\n7 8 9\n0", "5\n1 1 6 5 6\n3\n7 8 9\n0", "5\n1 1 6 4 6\n3\n7 8 9\n0", "5\n1 1 6 4 9\n3\n7 8 9\n0", "5\n1 1 2 4 9\n3\n7 8 9\n0", "5\n1 2 2 4 9\n3\n7 8 9\n0", "5\n1 2 3 5 6\n3\n3 8 9\n0", "5\n1 1 3 5 6\n3\n8 8 9\n0"], "outputs": ["1 1 3 5-6\n7-9\n", "1 1 6 5-6\n7-9\n", "1 1 6 4 6\n7-9\n", "1 ...
432
320
coding
Solve the programming task below in a Python markdown code block. ### Background We **all** know about "balancing parentheses" (plus brackets, braces and chevrons) and even balancing characters that are identical. Read that last sentence again, I balanced different characters and identical characters twice and you ...
{"functional": "_inputs = [['(Sensei says yes!)', '()'], ['(Sensei says no!', '()'], ['(Sensei [says] yes!)', '()[]'], ['(Sensei [says) no!]', '()[]'], ['Sensei says -yes-!', '--'], ['Sensei -says no!', '--'], ['Hello Mother can you hear me?', '()'], ['(Hello Mother can you hear me?)', '()'], ['(Hello Mother can you he...
351
811
coding
Solve the programming task below in a Python markdown code block. One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (stri...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n1 2\n2 1\n", "2\n1 1\n2 2\n", "2\n2 1\n1 2\n", "2\n2 1\n1 2\n", "2\n1 1\n2 2\n", "2\n1 3\n2 1\n"], "outputs": ["Poor Alex\n", "Poor Alex\n", "Happy Alex\n", "Poor Alex\n", "Happy Alex\n", "Happy Alex\n", "Poor Alex\n", "Happy Alex\n"]}
287
134
coding
Solve the programming task below in a Python markdown code block. The Little Elephant from the Zoo of Lviv likes listening to music. There are N songs, numbered from 1 to N, in his MP3-player. The song i is described by a pair of integers B_{i} and L_{i} - the band (represented as integer) that performed that song and ...
{"inputs": ["2\n3\n1 2\n2 2\n3 2\n3\n2 3\n1 2\n2 4", "2\n3\n1 2\n2 2\n3 2\n3\n2 3\n1 2\n2 8", "2\n3\n1 2\n2 2\n3 2\n3\n2 3\n1 2\n2 2", "2\n3\n1 1\n2 2\n3 2\n3\n2 3\n1 2\n2 2", "2\n3\n1 2\n2 2\n4 2\n3\n2 3\n1 2\n2 4", "2\n3\n1 1\n2 2\n3 2\n3\n2 3\n1 2\n2 8", "2\n3\n1 2\n2 2\n3 2\n3\n2 3\n1 2\n2 3", "2\n3\n1 1\n2 2\n1 2\...
653
316
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR". Plea...
{"functional": "def check(candidate):\n assert candidate(0.625) == \"0.101\"\n assert candidate(0.1) == \"ERROR\"\n\n\ncheck(Solution().printBin)"}
100
51
coding
Solve the programming task below in a Python markdown code block. A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again ...
{"inputs": ["0 1 2\n2 0 0", "0 0 2\n4 0 0", "0 1 2\n1 0 0", "0 1 2\n12 0 0", "0 -1 2\n2 0 0", "7 0 1\n-1 0 0", "-9 0 3\n58 0 1", "0 1 -7\n96 0 0"], "outputs": ["2\n", "4\n", "1\n", "12\n", "3\n", "9\n", "67\n", "96\n"]}
415
149
coding
Solve the programming task below in a Python markdown code block. Simple enough this one - you will be given an array. The values in the array will either be numbers or strings, or a mix of both. You will not get an empty array, nor a sparse one. Your job is to return a single array that has first the numbers sorted i...
{"functional": "_inputs = [[[6, 2, 3, 4, 5]], [[14, 32, 3, 5, 5]], [[1, 2, 3, 4, 5]], [['Banana', 'Orange', 'Apple', 'Mango', 0, 2, 2]], [['C', 'W', 'W', 'W', 1, 2, 0]], [['Hackathon', 'Katathon', 'Code', 'CodeWars', 'Laptop', 'Macbook', 'JavaScript', 1, 5, 2]], [[66, 't', 101, 0, 1, 1]], [[78, 117, 110, 99, 104, 117, ...
131
1,457
coding
Solve the programming task below in a Python markdown code block. Given a positive integer, $n$, find and print the number of pairs of positive integers $(a,b)$, where $a<b$, that exist such that the equation $x\cdot a+y\cdot b=n$ (where $\boldsymbol{x}$ and $y$ are positive integers) has at least one solution. Input ...
{"inputs": ["4\n"], "outputs": ["2\n"]}
166
14
coding
Solve the programming task below in a Python markdown code block. New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wante...
{"inputs": ["3 2\n1 1\n", "3 2\n2 1\n", "3 3\n1 1\n", "3 3\n2 1\n", "3 2\n2 1\n", "3 3\n2 1\n", "3 2\n1 1\n", "3 3\n1 1\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO", "YES", "YES", "YES"]}
614
114
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same. Given a string s consistin...
{"functional": "def check(candidate):\n assert candidate(s = \"aababbb\") == 3\n assert candidate(s = \"abcde\") == 0\n\n\ncheck(Solution().largestVariance)"}
121
48
coding
Solve the programming task below in a Python markdown code block. Problem statement Jota knows only the characters from `a` to` z` and the addition symbol `+`. Jota has an older sister, Tachiko. In addition to that, Tatsuko knows multiplication `*`, parentheses `(`, `)`, and integers (numbers) between `1` and` 9`. How...
{"inputs": ["5\nb+a+a", "5\nb+b+b", "5\na+a+b", "5\na+b+b", "5\nb+b+a", "5\nc+a+a", "5\nb+a+b", "5\nc+a+b"], "outputs": ["5\n", "3\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n"]}
617
94
coding
Solve the programming task below in a Python markdown code block. Call a number stepping if adjacent digits, as well as the first and last digits, differ by one. How many n-digit base 11 stepping numbers are there? Give your answer modulo 4294967143. For example, 8789A9 is a 6-digit base 11 stepping number. 9A0A and 2...
{"inputs": ["4\n2\n4\n6\n10"], "outputs": ["19\n54\n171\n1958"]}
188
34
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays nums1 and nums2 sorted in non-decreasing order and an integer k. Define a pair (u, v) which consists of one element from the first array and one element from the second array. Return t...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,7,11], nums2 = [2,4,6], k = 3) == [[1,2],[1,4],[1,6]]\n assert candidate(nums1 = [1,1,2], nums2 = [1,2,3], k = 2) == [[1,1],[1,1]]\n\n\ncheck(Solution().kSmallestPairs)"}
140
106
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array pairs, where pairs[i] = [xi, yi], and: There are no duplicates. xi < yi Let ways be the number of rooted trees that satisfy the following conditions: The tree consists of nodes whose values a...
{"functional": "def check(candidate):\n assert candidate(pairs = [[1,2],[2,3]]) == 1\n assert candidate(pairs = [[1,2],[2,3],[1,3]]) == 2\n assert candidate(pairs = [[1,2],[2,3],[2,4],[1,5]]) == 0\n\n\ncheck(Solution().checkWays)"}
243
89
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and an integer k, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome are minimized. Return the minimum number of letter changes required. A semi...
{"functional": "def check(candidate):\n assert candidate(s = \"abcac\", k = 2) == 1\n assert candidate(s = \"abcdef\", k = 2) == 2\n assert candidate(s = \"aabbaa\", k = 3) == 0\n\n\ncheck(Solution().minimumChanges)"}
464
73
coding
Solve the programming task below in a Python markdown code block. There are two groups, one of $N$ boys and the other of $N$ girls numbered from $1$ to $N$. You are given two arrays $A$ and $B$ containing $N$ numbers each, denoting the height of boys and girls in the group. You have to form $N$ couples, where each cou...
{"inputs": ["1\n3\n4 5 1\n2 2 2"], "outputs": ["7"]}
482
26
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We are playing the Guessing Game. The game will work as follows: I pick a number between 1 and n. You guess a number. If you guess the right number, you win the game. If you guess the wrong number, then I will tell y...
{"functional": "def check(candidate):\n assert candidate(n = 10) == 16\n assert candidate(n = 1) == 0\n assert candidate(n = 2) == 1\n\n\ncheck(Solution().getMoneyAmount)"}
180
58
coding
Solve the programming task below in a Python markdown code block. You have a tree of $n$ vertices. You are going to convert this tree into $n$ rubber bands on infinitely large plane. Conversion rule follows: For every pair of vertices $a$ and $b$, rubber bands $a$ and $b$ should intersect if and only if there is an ed...
{"inputs": ["3\n1 3\n2 3\n", "3\n1 3\n2 3\n", "3\n1 2\n2 3\n", "4\n1 2\n2 3\n3 4\n", "4\n1 2\n2 4\n3 4\n", "4\n1 3\n2 4\n3 4\n", "4\n1 2\n1 4\n3 4\n", "4\n1 4\n2 4\n3 4\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "3\n"]}
559
154
coding
Solve the programming task below in a Python markdown code block. Chef wants to make a feast. In order to do that, he needs a lot of different ingredients. Each ingredient has a certain tastiness; the tastiness of each ingredient may be any positive integer. Initially, for each tastiness between $K$ and $K+N-1$ (inclus...
{"inputs": ["2\n2 1\n3 3"], "outputs": ["0\n2"]}
556
22
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya was delivered a stri...
{"inputs": ["7\n", "4\n", "5\n", "9\n", "8\n", "2\n", "3\n", "0\n"], "outputs": ["7\n", "4\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
417
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If no such uncommon subsequence exists, return -1. An uncommon subsequence between two strings is a string that is a su...
{"functional": "def check(candidate):\n assert candidate(a = \"aaa\", b = \"bbb\") == 3\n assert candidate(a = \"aaa\", b = \"aaa\") == -1\n\n\ncheck(Solution().findLUSlength)"}
107
55
coding
Solve the programming task below in a Python markdown code block. Faizal and Sultan are having a one-on-one faceoff. Before stepping into the fight, each of them smoked a special kind of weed from Jhalwa. Smoking k grams of this weed grants the smoker the ability to resurrect k times after dying. Sultan smoked M grams ...
{"inputs": ["3\n2 1\n12 6\n6969 8563"], "outputs": ["7\n255\n988402422\n"]}
711
46
coding
Solve the programming task below in a Python markdown code block. ```if:python,php In this kata you will have to write a function that takes `litres` and `price_per_litre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre,...
{"functional": "_inputs = [[10, 21.5], [40, 10], [15, 5.83]]\n_outputs = [[212.5], [390], [83.7]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len...
315
195
coding
Solve the programming task below in a Python markdown code block. [Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not. ### About syllables [Syllables](https://en.wi...
{"functional": "_inputs = [['An old silent pond...\\nA frog jumps into the pond,\\nsplash! Silence again.'], ['An old silent pond...\\nA frog jumps into the pond, splash!\\nSilence again.'], ['An old silent pond...\\nA frog jumps into the pond,\\nsplash!\\nSilence again.'], ['An old silent pond... A frog jumps into the...
571
370
coding
Solve the programming task below in a Python markdown code block. Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one c...
{"inputs": ["1\n3\n", "1\n1\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n4\n", "1\n0\n", "4\n4 1 2 10\n"], "outputs": ["3 0\n", "1 0\n", "1 0\n", "3 0\n", "2 0\n", "4 0\n", "0 0\n", "12 5\n"]}
403
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array pref of size n. Find and return the array arr of size n that satisfies: pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]. Note that ^ denotes the bitwise-xor operation. It can be proven that t...
{"functional": "def check(candidate):\n assert candidate(pref = [5,2,0,3,1]) == [5,7,2,3,2]\n assert candidate(pref = [13]) == [13]\n\n\ncheck(Solution().findArray)"}
111
63
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. You are given a function f which is defined as : Your task is to find the value of where M is given in input. ------ Input Format ------ First line contains T, the number of test ...
{"inputs": ["2\n5 114 1\n2\n50 3874 3\n31\n17\n21"], "outputs": ["72\n3718\n624\n1144"]}
381
56
coding
Solve the programming task below in a Python markdown code block. Given an array A having N elements, a subarray S of A is called good if XOR(S) ≥ K, where XOR(S) denotes the [bitwise XOR] of all the elements of the subarray S. Find the length of the smallest subarray S which is good. If there is no good subarray, pri...
{"inputs": ["3\n5 15\n1 4 2 8 1\n5 7\n1 4 2 8 1\n5 20\n1 4 2 8 1"], "outputs": ["4\n1\n-1"]}
657
61
coding
Solve the programming task below in a Python markdown code block. Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages. At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more t...
{"inputs": ["1 1 1 0 0\n", "4 1 2 2 0\n", "1 5 5 1 1\n", "1 2 3 0 0\n", "1 1 1 1 0\n", "9 1 4 2 0\n", "4 2 2 0 1\n", "8 3 4 2 0\n"], "outputs": ["1\n", "3\n", "1\n", "1\n", "1\n", "4\n", "3\n", "3\n"]}
482
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given n item's value and label as two integer arrays values and labels. You are also given two integers numWanted and useLimit. Your task is to find a subset of items with the maximum sum of their values such ...
{"functional": "def check(candidate):\n assert candidate(values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1) == 9\n assert candidate(values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2) == 12\n assert candidate(values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, ...
145
162
coding
Solve the programming task below in a Python markdown code block. Round any given number to the closest 0.5 step I.E. ``` solution(4.2) = 4 solution(4.3) = 4.5 solution(4.6) = 4.5 solution(4.8) = 5 ``` Round **up** if number is as close to previous and next 0.5 steps. ``` solution(4.75) == 5 ``` Also feel free to re...
{"functional": "_inputs = [[4.2], [4.25], [4.4], [4.6], [4.75], [4.8], [4.5], [4.55], [4.74], [4.74999999999], [4.74999999991]]\n_outputs = [[4], [4.5], [4.5], [4.5], [5], [5], [4.5], [4.5], [4.5], [4.5], [4.5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r...
131
275
coding
Solve the programming task below in a Python markdown code block. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbrevi...
{"inputs": ["1\nIAO'001\n", "1\nIAO'089\n", "1\nIAO'000\n", "1\nIAO'2000\n", "1\nIAO'2015\n", "1\nIAO'1015\n", "1\nIAO'3015\n", "1\nIAO'1014\n"], "outputs": ["3001\n", "3089\n", "3000\n", "12000\n", "12015\n", "11015\n", "13015\n", "11014\n"]}
395
160
coding
Solve the programming task below in a Python markdown code block. It's almost summertime, so Big Cat and Little Cat are getting in shape. They decide the core of their fitness plan is to start jogging every day. Their city consists of $N$ intersections connected by $\mbox{M}$ bidirectional roads. The cats decide that ...
{"inputs": ["4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n"], "outputs": ["3\n"]}
513
40
coding
Solve the programming task below in a Python markdown code block. For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path). Constraints * 1 ≤ |V| ≤ 100000 * 0 ≤ di ≤ 10000 * 0 ≤ |E| ≤ 500000 * There are no parallel edges * Ther...
{"inputs": ["4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n0 2 4\n1 2 0\n2 3 1\n1 3 5", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 1 1\n1 2 5\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 2 1\n0 3 4\n1 2 2\n2 2 2\n1 3 2", "4 5 0\n0 2 2\n0 3 4\n1 3 2\n3 2 2\n1 3 2", ...
426
382
coding
Solve the programming task below in a Python markdown code block. The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the s...
{"inputs": ["1 1 1\nX\n", "1 1 1\nX\n", "1 1 2\nX\n", "1 1 1\nX\n", "1 1 2\nX\n", "1 2 2\nX.\n", "1 2 2\n.X\n", "1 2 2\nX*\n"], "outputs": ["IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "RL\n", "LR\n", "IMPOSSIBLE\n"]}
595
138
coding
Solve the programming task below in a Python markdown code block. There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left. Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares ...
{"inputs": ["39 0", "630 0", "279 0", "328 0", "272 0", "173 0", "218 0", "674 0"], "outputs": ["1369", "394384", "76729", "106276", "72900", "29241", "46656", "451584"]}
419
119
coding
Solve the programming task below in a Python markdown code block. In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of **on** bits they have. E.g Given the array **[7, 6, 15, 8]** - 7 has **3 on** bits (000...0**111**) - 6 has **2 on** bits (000...00**11**) - 15 has *...
{"functional": "_inputs = [[[3, 8, 3, 6, 5, 7, 9, 1]], [[9, 4, 5, 3, 5, 7, 2, 56, 8, 2, 6, 8, 0]]]\n_outputs = [[[1, 8, 3, 3, 5, 6, 9, 7]], [[0, 2, 2, 4, 8, 8, 3, 5, 5, 6, 9, 7, 56]]]\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...
321
277
coding
Solve the programming task below in a Python markdown code block. Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of card...
{"inputs": ["1\n8\n", "1\n8\n", "1\n7\n", "1\n6\n", "2\n5 4\n", "2\n5 4\n", "2\n5 1\n", "2\n5 2\n"], "outputs": ["1", "1", "1\n", "1\n", "2", "2", "2\n", "2\n"]}
520
90
coding
Solve the programming task below in a Python markdown code block. You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the en...
{"inputs": ["1\na\n", "1\ns\n", "1\ns\n", "1\na\n", "1\nt\n", "1\n`\n", "2\naa\n", "2\naa\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]}
322
86
coding
Solve the programming task below in a Python markdown code block. For an array of non-negative integers $a$ of size $n$, we construct another array $d$ as follows: $d_1 = a_1$, $d_i = |a_i - a_{i - 1}|$ for $2 \le i \le n$. Your task is to restore the array $a$ from a given array $d$, or to report that there are multi...
{"inputs": ["1\n2\n5 5\n", "1\n2\n1 1\n", "1\n2\n3 3\n", "1\n2\n2 2\n", "1\n2\n4 4\n", "1\n2\n7 7\n", "1\n2\n2 3\n", "1\n2\n6 6\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "2 5\n", "-1\n"]}
373
121
coding
Solve the programming task below in a Python markdown code block. ------ Problem Statement ------ Write a program that accepts sets of three numbers, and prints the second-maximum number among the three. ------ Input ------ First line contains the number of triples, N. The next N lines which follow each have three...
{"inputs": ["3\n1 2 3\n10 15 5\n100 999 500"], "outputs": ["2\n10\n500"]}
189
45
coding
Solve the programming task below in a Python markdown code block. Gildong has bought a famous painting software cfpaint. The working screen of cfpaint is square-shaped consisting of $n$ rows and $n$ columns of square cells. The rows are numbered from $1$ to $n$, from top to bottom, and the columns are numbered from $1$...
{"inputs": ["1 1\nB\n", "1 1\nW\n", "1 1\nW\n", "1 1\nB\n", "2 2\nBW\nWB\n", "2 1\nWW\nWW\n", "2 1\nBB\nWW\n", "2 1\nBB\nBB\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "4\n", "4\n", "2\n", "0\n"]}
721
110
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. You are given a sequence $a$ consisting of $n$ positive integers. Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements...
{"inputs": ["6\n8\n1 2 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 1 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n3 1\n3\n3 1 2\n", "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 1\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 2...
757
590
coding
Solve the programming task below in a Python markdown code block. We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 who...
{"inputs": ["1 0 1\n4 1 2\n1 0 1", "1 8 6\n2 9 7\n1 7 7", "0 8 8\n0 8 8\n0 0 8", "2 2 2\n2 1 0\n2 2 2", "1 0 1\n4 1 2\n0 0 1", "1 8 6\n4 9 7\n1 7 7", "0 8 2\n0 8 8\n0 0 8", "1 0 1\n4 1 4\n0 0 1"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
347
190
coding
Solve the programming task below in a Python markdown code block. At the store, the salespeople want to make all prices round. In this problem, a number that is a power of $10$ is called a round number. For example, the numbers $10^0 = 1$, $10^1 = 10$, $10^2 = 100$ are round numbers, but $20$, $110$ and $256$ are not ...
{"inputs": ["4\n1\n1\n1\n1\n", "1\n100000000\n", "14\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n2\n178\n20\n999999999\n9000\n987654321\n", "7\n100\n40000000\n89657\n326894\n2325566\n74444\n200055\n"], "outputs": ["0\n0\n0\n0\n", "0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n1\n78\n10\n899999999\n80...
651
284
coding
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 matrix grid consisting of positive integers. You can start at any cell in the first column of the matrix, and traverse the grid in the following way: From a cell (row, col), you can mo...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]) == 3\n assert candidate(grid = [[3,2,4],[2,1,9],[1,1,7]]) == 0\n\n\ncheck(Solution().maxMoves)"}
172
93
coding
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. For example, "Hello World", "HELLO", "hello world hello world" are all sentences. Words consist of only uppercas...
{"functional": "def check(candidate):\n assert candidate(sentence = \"leetcode exercises sound delightful\") == True\n assert candidate(sentence = \"eetcode\") == True\n assert candidate(sentence = \"Leetcode is cool\") == False\n\n\ncheck(Solution().isCircularSentence)"}
222
60
coding
Solve the programming task below in a Python markdown code block. # Story&Task The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all houses in the city were built in one row. Let's enumerate all the houses from left to right, starting with 0. A house is c...
{"functional": "_inputs = [[[1, 2, 3, 1, 2]], [[3, 2, 1, 4]], [[1, 2, 3]], [[3, 2, 1]], [[1, 1, 1]]]\n_outputs = [[[3, 2, 0, 2, 0]], [[2, 3, 4, 0]], [[3, 2, 0]], [[0, 0, 0]], [[1, 1, 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,...
466
257
coding
Solve the programming task below in a Python markdown code block. Chef got his dream seat in F1 and secured a 3^{rd} place in his debut race. He now wants to know the time gap between him and the winner of the race. You are his chief engineer and you only know the time gap between Chef and the runner up of the race, g...
{"inputs": ["4\n1 1\n2 5\n3 2\n5 6\n"], "outputs": ["2\n7\n5\n11\n"]}
500
37
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2, each of length n, and a 1-indexed 2D array queries where queries[i] = [xi, yi]. For the ith query, find the maximum value of nums1[j] + nums2[j] among all in...
{"functional": "def check(candidate):\n assert candidate(nums1 = [4,3,1,2], nums2 = [2,4,9,5], queries = [[4,1],[1,3],[2,5]]) == [6,10,7]\n assert candidate(nums1 = [3,2,5], nums2 = [2,3,4], queries = [[4,4],[3,2],[1,1]]) == [9,9,9]\n assert candidate(nums1 = [2,1], nums2 = [2,3], queries = [[3,3]]) == [-1]\n\...
178
150
coding
Solve the programming task below in a Python markdown code block. In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an ...
{"inputs": ["3\n5\n9\n6\n2\n2\n0", "3\n5\n9\n6\n3\n2\n0", "3\n5\n9\n5\n3\n2\n0", "3\n5\n9\n1\n3\n2\n0", "3\n5\n9\n1\n4\n2\n0", "3\n5\n9\n2\n4\n2\n0", "3\n5\n9\n4\n2\n19\n0", "3\n5\n5\n3\n8\n19\n0"], "outputs": ["Case 1: 3\nCase 2: 5\nCase 3: 9\nCase 4: 6\nCase 5: 2\nCase 6: 2\n", "Case 1: 3\nCase 2: 5\nCase 3: 9\nCase ...
264
482
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef is judging a game called "Broken telephone". There are total N players taking part in the game. They are all sitting in a line. In the start of the game, first player is given a secret mes...
{"inputs": ["3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 1\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 2\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 3\n5\n1 3 1 1 2\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 0 1 1 1\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 2\n4\n9 5 5 5", "3\n7\n1 1 1 3 3 3 3\n5\n1 3 1 1 2\n4\n5 5 9 5", "3\n7\n1 2 1 3...
547
397
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef calls a sequence *good* if it does not contain any two adjacent identical elements. Initially, Chef has a sequence $a_{1}, a_{2}, \ldots, a_{N}...
{"inputs": ["1\n5 2\n1 1 2 5 2\n1 3\n4 2"], "outputs": ["5\n3"]}
435
36
coding
Solve the programming task below in a Python markdown code block. The eval() expression is a very powerful built-in function of Python. It helps in evaluating an expression. The expression can be a Python statement, or a code object. For example: >>> eval("9 + 5") 14 >>> x = 2 >>> eval("x + 3") 5 Here, eval() ca...
{"inputs": ["print(2 + 3)\n"], "outputs": ["5\n"]}
214
20
coding
Solve the programming task below in a Python markdown code block. You have a binary string S of length N. In one operation you can select a substring of S and reverse it. For example, on reversing the substring S[2,4] for S=11000, we change 1 \textcolor{red}{100} 0 \rightarrow 1 \textcolor{red}{001} 0. Find the minimu...
{"inputs": ["4\n3\n000\n4\n1001\n4\n1010\n6\n010101"], "outputs": ["0\n1\n2\n2"]}
577
47
coding
Solve the programming task below in a Python markdown code block. The capital of Berland looks like a rectangle of size n × m of the square blocks of same size. Fire! It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers are know...
{"inputs": ["8 5 1\n3 3\n", "10 5 1\n3 3\n", "10 5 1\n3 5\n", "10 5 1\n3 3\n", "5 1 2\n4 1\n5 1\n", "5 1 2\n4 1\n5 1\n", "5 1 2\n4 1\n1 1\n", "5 1 2\n4 1\n2 1\n"], "outputs": ["2\n", "2\n", "4\n", "2\n", "1\n", "1\n", "1\n", "1\n"]}
445
153
coding
Solve the programming task below in a Python markdown code block. This is a problem that involves adding numbers to items in a list. In a list you will have to add the item's remainder when divided by a given divisor to each item. For example if the item is 40 and the divisor is 3 you would have to add 1 since 40 minu...
{"functional": "_inputs = [[[2, 7, 5, 9, 100, 34, 32, 0], 3], [[], 2], [[1000, 999, 998, 997], 5], [[0, 0, 0, 0], 5], [[4, 3, 2, 1], 5], [[33, 23, 45, 78, 65], 10]]\n_outputs = [[[4, 8, 7, 9, 101, 35, 34, 0]], [[]], [[1000, 1003, 1001, 999]], [[0, 0, 0, 0]], [[8, 6, 4, 2]], [[36, 26, 50, 86, 70]]]\nimport math\ndef _de...
326
359
coding
Solve the programming task below in a Python markdown code block. We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.) Snuke wants to sat...
{"inputs": ["byeybe", "eybcxb", "ebyeyb", "eybeyb", "eybdyb", "eybcyb", "byecxb", "cyebxb"], "outputs": ["1\n", "6\n", "1\n", "1\n", "2\n", "2\n", "6\n", "4\n"]}
242
80
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the size of the input. You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'. You are also given an integer $k$. Your task is to change the minimum number of cha...
{"inputs": ["3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n", "3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBRBR\n", "3\n5 3\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n", "3\n5 2\nBGGGG\n5 4\nRBRGR\n5 5\nBBRBR\n", "3\n5 3\nBGGGG\n5 3\nRBRGR\n5 2\nBBBRR\n", "3\n5 2\nBGGGG\n5 4\nRBRGR\n5 5\nBRBRB\n", "3\n5 1\nBGGGG\n5 2\nRBRGR\n5 5\nBBRBR\n", "3\n5 1...
591
294
coding
Solve the programming task below in a Python markdown code block. You are given three piles of casino chips: white, green and black chips: * the first pile contains only white chips * the second pile contains only green chips * the third pile contains only black chips Each day you take exactly two chips of different ...
{"functional": "_inputs = [[[1, 1, 1]], [[1, 2, 1]], [[4, 1, 1]], [[8, 2, 8]], [[8, 1, 4]], [[7, 4, 10]], [[12, 12, 12]], [[1, 23, 2]]]\n_outputs = [[1], [2], [2], [9], [5], [10], [18], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a,...
482
251
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is ...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5]) == 24\n assert candidate(n = 3, edges = [[0,1],[1,2]], price = [1,1,1]) == 2\n\n\ncheck(Solution().maxOutput)"}
223
103
coding
Solve the programming task below in a Python markdown code block. Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping su...
{"inputs": ["aaa\na\nb\n", "cumurcumur\num\ncur\n", "cumurcumur\nul\ncur\n", "abbbaaccca\nba\naca\n", "cunurcumur\nul\ncur\n", "abbbaaccca\nab\naca\n", "xxxbbbcccoca\nca\ncb\n", "xxxbbbcccoca\nca\nca\n"], "outputs": ["aaa\n", "umumcurcur\n", "curcurmmuu", "babaacabcc", "curcurmnuu", "ababacabcc\n", "cacbcbcboxxx\n", "c...
390
150
coding
Solve the programming task below in a Python markdown code block. There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the ...
{"inputs": ["1\n1000000\n", "1\n1000000\n", "1\n1000001\n", "1\n1000100\n", "1\n0000001\n", "1\n1000110\n", "1\n0001001\n", "1\n1001110\n"], "outputs": ["2 1\n", "2 1\n", "2 1 ", "2 1 ", "2 1 ", "2 1 ", "2 1 ", "2 1 "]}
531
145
coding
Solve the programming task below in a Python markdown code block. There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. Constraints...
{"inputs": ["5 2", "1 2", "1 3", "1 5", "1 4", "1 8", "1 6", "1 9"], "outputs": ["1\n", "2\n", "3\n", "5\n", "4\n", "8\n", "6\n", "9\n"]}
212
78
coding
Solve the programming task below in a Python markdown code block. Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 f...
{"inputs": ["2\nS 1\nH 2", "2\nS 0\nH 1", "2\nS 2\nH 2", "2\nS 1\nH 1", "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2"], "outputs": ["Stable\nS 1\nH 2\n", "Stable\nS 0\nH 1\n", "Stable\nS 2\nH 2\n", "Stable\nS 1\nH 1", "Not stab...
485
325
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit '0' with the letter 'O', and the digit '1' with t...
{"functional": "def check(candidate):\n assert candidate(num = \"257\") == \"IOI\"\n assert candidate(num = \"3\") == \"ERROR\"\n\n\ncheck(Solution().toHexspeak)"}
170
50
coding
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 n characters which are either 'X' or 'O'. A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the chara...
{"functional": "def check(candidate):\n assert candidate(s = \"XXX\") == 1\n assert candidate(s = \"XXOX\") == 2\n assert candidate(s = \"OOOO\") == 0\n\n\ncheck(Solution().minimumMoves)"}
124
57
coding
Solve the programming task below in a Python markdown code block. # Write Number in Expanded Form You will be given a number and you will need to return it as a string in [Expanded Form](https://www.mathplacementreview.com/arithmetic/whole-numbers.php#expanded-form). For example: ```python expanded_form(12) # Should ...
{"functional": "_inputs = [[2], [12], [42], [70304], [4982342]]\n_outputs = [['2'], ['10 + 2'], ['40 + 2'], ['70000 + 300 + 4'], ['4000000 + 900000 + 80000 + 2000 + 300 + 40 + 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_to...
192
250
coding
Solve the programming task below in a Python markdown code block. We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds. Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others. Let S and T be the sum of the numb...
{"inputs": ["3 3 2", "3 3 3", "0 3 2", "2 4 3", "3 4 2", "3 4 2\n", "7 5 5\n", "8 6 0\n"], "outputs": ["8\n", "7\n", "1\n", "4\n", "8", "8\n", "29\n", "9\n"]}
372
97
coding
Solve the programming task below in a Python markdown code block. Much cooler than your run-of-the-mill Fibonacci numbers, the Triple Shiftian are so defined: `T[n] = 4 * T[n-1] - 5 * T[n-2] + 3 * T[n-3]`. You are asked to create a function which accept a base with the first 3 numbers and then returns the nth element....
{"functional": "_inputs = [[[1, 1, 1], 25], [[1, 2, 3], 25], [[3, 2, 1], 25], [[6, 7, 2], 25], [[1, 1, 1], 35], [[1, 2, 3], 35], [[3, 2, 1], 35], [[6, 7, 2], 35], [[3, 2, 1], 0], [[6, 7, 2], 2]]\n_outputs = [[1219856746], [2052198929], [2827228055], [-2575238999], [10127083068293], [17037073417493], [23471258855679], [...
312
396
coding
Solve the programming task below in a Python markdown code block. Given an array a_1, a_2, ..., a_{n} of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y^2. -----Input----- The first line contains a ...
{"inputs": ["1\n2\n", "1\n2\n", "1\n-1\n", "1\n-1\n", "1\n-2\n", "1\n-4\n", "1\n-6\n", "1\n-8\n"], "outputs": ["2\n", "2\n", "-1\n", "-1\n", "-2\n", "-4\n", "-6\n", "-8\n"]}
270
92
coding
Solve the programming task below in a Python markdown code block. The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance: The MEX of [2, 2, 1] is 0 because 0 does not belong to the array. The MEX of [3, 1, 0, 1] is 2 because 0 and 1 belong to the arr...
{"inputs": ["4\n2\n0 0 0 1\n2\n0 0 1 1\n3\n1 3 2 3 3 2\n3\n0 0 1 1 1 2\n"], "outputs": ["NO\nYES\nYES\nNO\n"]}
632
68
coding
Solve the programming task below in a Python markdown code block. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know...
{"inputs": ["1\n1\n", "1\n4\n", "1\n1\n", "1\n4\n", "1\n2\n", "2\n1 1\n", "2\n2 3\n", "2\n1 4\n"], "outputs": ["-1\n", "0\n", "-1\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
424
93
coding
Solve the programming task below in a Python markdown code block. Priyanka works for an international toy company that ships by container. Her task is to the determine the lowest cost way to combine her orders for shipping. She has a list of item weights. The shipping company has a requirement that all items loaded ...
{"inputs": ["8\n1 2 3 21 7 12 14 21\n"], "outputs": ["4\n"]}
554
34
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows: Choose 2 distinct names from ideas, call them idea...
{"functional": "def check(candidate):\n assert candidate(ideas = [\"coffee\",\"donuts\",\"time\",\"toffee\"]) == 6\n assert candidate(ideas = [\"lack\",\"back\"]) == 0\n\n\ncheck(Solution().distinctNames)"}
176
60
coding
Solve the programming task below in a Python markdown code block. The enmity between Logan and Donald Pierce never ceases to exist. However, once Logan and Donald came face to face. Donald got agitated and asked Logan to prove his true mettle by solving a puzzle. Logan is provided an array Arr[] of N integers. ...
{"inputs": ["1\n4\n1 1 1 1"], "outputs": ["0"]}
349
22
coding
Solve the programming task below in a Python markdown code block. Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions ...
{"inputs": ["1 1 2\n1\n2\n", "1 1 1\n1\n1\n", "2 2 1\n1 2\n1 2\n", "2 2 1\n1 2\n2 1\n", "2 2 1\n1 2\n4 1\n", "2 2 1\n1 1\n4 1\n", "2 2 1\n2 1\n4 1\n", "2 2 1\n2 1\n4 2\n"], "outputs": ["0\n", "1\n1 ", "1\n1 ", "1\n1 ", "0\n", "0\n", "0\n", "0\n"]}
341
161
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return a binary string representing its representation in base -2. Note that the returned string should not have leading zeros unless the string is "0".   Please complete the following python code ...
{"functional": "def check(candidate):\n assert candidate(n = 2) == \"110\"\n assert candidate(n = 3) == \"111\"\n assert candidate(n = 4) == \"100\"\n\n\ncheck(Solution().baseNeg2)"}
82
65