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. problem Cryptography is all the rage at xryuseix's school. Xryuseix, who lives in a grid of cities, has come up with a new cryptography to decide where to meet. The ciphertext consists of the $ N $ character string $ S $, and the $ S_i $ character dete...
{"inputs": ["5\nAzaNA", "5\nAMazA", "5\nzAaNA", "5\nAzaAN", "5\nzAaNB", "5\nAMAza", "5\nAzaBN", "5\nzAaNC"], "outputs": ["1\nA\n", "3\nAAA\n", "1\nA\n", "1\nA\n", "1\nA\n", "3\nAAA\n", "1\nA\n", "1\nA\n"]}
coding
375
Solve the programming task below in a Python markdown code block. Richik$Richik$ has just completed his engineering and has got a job in one of the firms at Sabrina$Sabrina$ which is ranked among the top seven islands in the world in terms of the pay scale. Since Richik$Richik$ has to travel a lot to reach the firm, t...
{"inputs": ["1\n3 10"], "outputs": ["18"]}
coding
441
Solve the programming task below in a Python markdown code block. You are given a string, and you have to validate whether it's a valid Roman numeral. If it is valid, print True. Otherwise, print False. Try to create a regular expression for a valid Roman numeral. Input Format A single line of input containing a stri...
{"inputs": ["CDXXI\n"], "outputs": ["True\n"]}
coding
181
Solve the programming task below in a Python markdown code block. Chef recently took a course in linear algebra and learned about linear combinations of vectors. Therefore, in order to test his intelligence, Raj gave him a "fuzzy" problem to solve. A sequence of integers $B_1, B_2, \ldots, B_M$ generates an integer $K$...
{"inputs": ["2\n2 4\n3\n1\n2\n8"], "outputs": ["0\n2\n3"]}
coding
614
Solve the programming task below in a Python markdown code block. A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. ...
{"inputs": ["1\n0\n", "2\n0 1\n", "2\n0 0\n", "5\n0 0 0 1 3\n", "5\n0 0 0 2 3\n", "5\n0 1 0 1 3\n", "7\n0 1 0 0 0 0 0\n", "7\n0 1 0 0 0 0 1\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "3\n", "3\n", "6\n", "6\n"]}
coding
478
Solve the programming task below in a Python markdown code block. The executive chef is trying to bring some competitive spirit into his kitchen. He wants to split the chefs into two teams based on their age - he'll form the young and the old team. To make it fair, he will split them evenly or give the young team one p...
{"inputs": ["5\n2 3\n1 7\n5 5\n3 1\n8 15", "5\n2 3\n1 7\n4 5\n3 1\n8 15", "5\n2 3\n1 7\n4 6\n4 1\n8 15", "5\n1 3\n1 7\n4 6\n4 1\n8 25", "5\n2 3\n1 7\n4 6\n4 1\n3 15", "5\n1 3\n1 7\n0 6\n4 1\n8 15", "5\n1 3\n1 7\n4 9\n4 1\n8 25", "5\n2 1\n2 1\n8 18\n5 1\n2 1"], "outputs": ["3\n4\n5\n4\n9", "3\n4\n5\n4\n9\n", "3\n4\n4\n3...
coding
333
Solve the programming task below in a Python markdown code block. In Math, an improper fraction is a fraction where the numerator (the top number) is greater than or equal to the denominator (the bottom number) For example: ```5/3``` (five third). A mixed numeral is a whole number and a fraction combined into one "mix...
{"functional": "_inputs = [['74/3'], ['9999/24'], ['74/30'], ['13/5'], ['5/3'], ['1/1'], ['10/10'], ['900/10'], ['9920/124'], ['6/2'], ['9/77'], ['96/100'], ['12/18'], ['6/36'], ['1/18'], ['-64/8'], ['-6/8'], ['-9/78'], ['-504/26'], ['-47/2'], ['-21511/21']]\n_outputs = [['24 2/3'], ['416 15/24'], ['2 14/30'], ['2 3/5'...
coding
275
Solve the programming task below in a Python markdown code block. Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length a_{i}. Mishka can put a box i into another box j if the following conditions are met: i-th box is not put into another box; j-th box doesn't contain any other...
{"inputs": ["1\n1\n", "1\n9\n", "1\n5\n", "1\n2\n", "1\n2\n", "1\n1\n", "1\n5\n", "1\n9\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
334
Solve the programming task below in a Python markdown code block. Stephanie just learned about a game called Nim in which there are two players and $n$ piles of stones. During each turn, a player must choose any non-empty pile and take as many stones as they want. The first player who cannot complete their turn (i.e., ...
{"inputs": ["2 2\n"], "outputs": ["6\n"]}
coding
393
Solve the programming task below in a Python markdown code block. IIST is thinking of acquiring some land nearby to build its new state of the art labs. The land it has chosen incidentaly has some abandoned college buildings which IIST wants to use. The administration decide the value of the building based on the amoun...
{"inputs": ["2\n6\n0 0 8 3\n1 4 3 2\n2 1 7 1\n4 1 2 3\n3 5 4 6\n2 3 9 8\n3\n3 0 10 2\n5 5 20 25\n7 -3 30 32"], "outputs": ["2 4 5\n3.16\n2\n15.00"]}
coding
494
Solve the programming task below in a Python markdown code block. Today's Random Number E869120 You ran a campaign called "Today's Random Numbers" for N days. This is a project to generate a random number once a day and post the value on Twitter. The "random numbers of the day" on day $ 1, 2, 3, \ dots, N $ were $ A_...
{"inputs": ["5\n1 1 0 0 0", "5\n0 0 0 2 1", "5\n0 0 1 2 1", "5\n0 0 1 2 2", "5\n0 0 1 4 2", "5\n0 0 2 4 2", "5\n0 0 2 4 1", "5\n0 0 0 4 1"], "outputs": ["0\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n"]}
coding
478
Solve the programming task below in a Python markdown code block. The male gametes or sperm cells in humans and other mammals are heterogametic and contain one of two types of sex chromosomes. They are either X or Y. The female gametes or eggs however, contain only the X sex chromosome and are homogametic. The sperm c...
{"functional": "_inputs = [['XY'], ['XX']]\n_outputs = [[\"Congratulations! You're going to have a son.\"], [\"Congratulations! You're going to have a daughter.\"]]\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=t...
coding
215
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 and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answe...
{"functional": "def check(candidate):\n assert candidate(nums = [3,5,6,7], target = 9) == 4\n assert candidate(nums = [3,3,6,8], target = 10) == 6\n assert candidate(nums = [2,3,3,4,6,7], target = 12) == 61\n\n\ncheck(Solution().numSubseq)"}
coding
114
Solve the programming task below in a Python markdown code block. Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on. On every working day (from Monday to Saturday, inclusi...
{"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n6\n", "1\n8\n", "1\n10\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
737
Solve the programming task below in a Python markdown code block. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands a...
{"inputs": ["L\nq\n", "L\no\n", "L\n,\n", "L\nz\n", "R\n.\n", "R\no\n", "R\nw\n", "R\nx\n"], "outputs": ["w\n", "p\n", ".\n", "x\n", ",\n", "i\n", "q\n", "z\n"]}
coding
282
Solve the programming task below in a Python markdown code block. We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i). Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there? We remind you that the distan...
{"inputs": ["4 5\n0 5\n-2 4\n3 4\n4 -2", "4 5\n1 5\n-2 4\n3 1\n4 -1", "3 5\n0 5\n-2 4\n5 1\n4 -2", "1 5\n0 5\n-2 4\n3 1\n4 -2", "4 5\n0 5\n-2 4\n3 1\n4 -2", "4 5\n0 5\n-2 4\n3 1\n4 -1", "3 5\n0 5\n-2 4\n3 1\n4 -2", "4 5\n0 5\n-2 4\n3 4\n4 -5"], "outputs": ["4\n", "3\n", "2\n", "1\n", "4\n", "4\n", "3\n", "3\n"]}
coding
591
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Mike is fond of collecting stamps. He has a lot of rare and unusual ones in his collection. Unfortunately, a few days ago he was fired from his well-paid job. But he doesn't complain about tha...
{"inputs": ["4 3\n2 1 2\n2 2 3\n2 3 4\n"], "outputs": ["2"]}
coding
434
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Alexandra has some distinct integer numbers a_{1},a_{2}...a_{n}. Count number of pairs (i,j) such that: 1≤ i ≤ n 1≤ j ≤ n a_{i} < a_{j}   ------ Input ------ The first line of the input contai...
{"inputs": ["2\n2\n12 11\n3\n13 11 12"], "outputs": ["1\n3"]}
coding
329
Solve the programming task below in a Python markdown code block. Nobody knows, but $N$ frogs live in Chef's garden. Now they are siting on the X-axis and want to speak to each other. One frog can send a message to another one if the distance between them is less or equal to $K$. Chef knows all $P$ pairs of frogs, whic...
{"inputs": ["5 0 2\n0 2 9 3 7\n2 2\n1 4\n2 5", "5 1 2\n0 2 8 4 0\n1 2\n1 3\n4 5", "5 1 2\n0 2 8 4 0\n1 2\n1 1\n1 5", "5 0 3\n0 2 8 5 0\n1 2\n1 3\n4 5", "5 0 3\n0 2 3 5 0\n1 2\n1 3\n4 5", "5 6 3\n0 3 8 8 7\n1 2\n1 3\n2 5", "5 1 3\n0 2 8 5 0\n1 2\n1 3\n4 5", "5 0 3\n0 2 3 7 0\n1 2\n1 3\n4 5"], "outputs": ["Yes\nNo\n", "N...
coding
431
Solve the programming task below in a Python markdown code block. Chef is the financial incharge of Chefland and one of his duties is identifying if any company has gained a monopolistic advantage in the market. There are exactly 3 companies in the market each of whose revenues are denoted by R_{1}, R_{2} and R_{3} re...
{"inputs": ["4\n1 1 1\n1 2 4\n2 10 3\n1 2 3\n"], "outputs": ["No\nYes\nYes\nNo\n"]}
coding
437
Solve the programming task below in a Python markdown code block. Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers. You can assume that a word consists of at most 30 characters, and the page number is less than ...
{"inputs": ["mtzse 6\nveen 1\nnntroductioi 0\nsf_z 1\nstyle 32\ntndmucod 0\nstyld 5\nnuee 0", "mtzse 6\nveen 0\nnntroductioi 0\nsf_y 1\nstyle 17\ntndmucod 13\nstyld 7\nnuee 0", "mtzse 6\nveen 0\nnntroductioi 0\nsf_y 1\nstyle 32\ntndmucod 13\nstyld 7\nnuee 0", "mtzse 6\nveen 0\nnntroductioi 0\nsf_y 1\nstyle 32\ntndmucod...
coding
237
Solve the programming task below in a Python markdown code block. There are $n$ warriors in a row. The power of the $i$-th warrior is $a_i$. All powers are pairwise distinct. You have two types of spells which you may cast: Fireball: you spend $x$ mana and destroy exactly $k$ consecutive warriors; Berserk: you spen...
{"inputs": ["1 1\n2 1 2\n1\n1\n", "1 1\n2 1 2\n1\n1\n", "1 1\n2 2 2\n1\n1\n", "1 1\n2 1 0\n1\n1\n", "1 1\n2 4 2\n1\n1\n", "1 1\n2 4 1\n1\n1\n", "1 1\n2 7 1\n1\n1\n", "1 1\n2 2 1\n1\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
650
Solve the programming task below in a Python markdown code block. The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they can...
{"inputs": ["3\n1\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n1\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 3\n2 1", "3\n2\n0 0\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n1\n0 1\n0 0\n1 0\n4\n0 1\n0 0\n1 0\n2\n0 0\n0 3\n2 1", "3\n2\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n1\n0 1\n0...
coding
485
Solve the programming task below in a Python markdown code block. Complete the function solveMeFirst to compute the sum of two integers. Example $a=7$ $b=3$ Return $10$. Function Description Complete the solveMeFirst function in the editor below. solveMeFirst has the following parameters: int a: the fir...
{"inputs": ["2\n3\n"], "outputs": ["5\n"]}
coding
140
Solve the programming task below in a Python markdown code block. A common problem in number theory is to find x given a such that: a * x = 1 mod [n] Then x is called the inverse of a modulo n. Your goal is to code a function inverseMod wich take a and n as parameters and return x. You may be interested by these ...
{"functional": "_inputs = [[2, 5], [48, 101], [7, 733], [48, 733], [2, 733], [229, 101], [229, 103], [229, 105], [5, 5], [61965, 17408], [101014, 125445], [156435434, 3543432125]]\n_outputs = [[3], [40], [419], [168], [367], [15], [9], [94], [None], [None], [7969], [1056765589]]\nimport math\ndef _deep_eq(a, b, tol=1e-...
coding
195
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n. The sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])2 for each 0 <= i < n. You a...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0) == 579\n assert candidate(nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1) == 43\n\n\ncheck(Solution().minSumSquareDiff)"}
coding
229
Solve the programming task below in a Python markdown code block. You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and...
{"inputs": ["3\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n", "3\n3\n2 1 1\n3\n1 1 1\n3\n1 1 1\n", "3\n3\n2 1 1\n3\n1 2 1\n3\n1 1 1\n", "3\n3\n1 1 1\n3\n1 1 2\n3\n1 1 1\n", "3\n3\n2 1 2\n3\n2 1 1\n3\n1 2 1\n", "3\n3\n1 1 1\n3\n1 1 2\n3\n2 1 1\n", "3\n3\n2 1 1\n3\n2 2 2\n3\n1 2 1\n", "3\n3\n1 1 1\n3\n1 1 1\n3\n1 1 2\n"], "outputs": ...
coding
602
Solve the programming task below in a Python markdown code block. In my town ,there live a coder named Chef . He is a cool programmer . One day , he participate in a programming contest ,the contest give him only one problem . If he can’t solve the problem ,the problem setter will kill him . But the round allow you to ...
{"inputs": ["2\n3 5 6 5\n2\n4 5\n6 8\n3 4 7 10\n1\n7 4"], "outputs": ["Test case : 1\nYES\nNO\n3.000000\nTest case : 2\nNO\n3.328201"]}
coding
444
Solve the programming task below in a Python markdown code block. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Eac...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n6\n", "3\n1\n2\n4\n", "3\n1\n2\n4\n", "4\n1\n1\n1\n2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "3\n"]}
coding
268
Solve the programming task below in a Python markdown code block. Given three distinct integers $a$, $b$, and $c$, find the medium number between all of them. The medium number is the number that is neither the minimum nor the maximum of the given three numbers. For example, the median of $5,2,6$ is $5$, since the mi...
{"inputs": ["1\n1 3 2\n", "1\n1 2 3\n", "1\n1 3 4\n", "1\n2 3 4\n", "1\n1 2 4\n", "1\n17 2 3\n", "2\n1 2 3\n2 3 1\n", "3\n1 2 3\n1 2 3\n1 2 3\n"], "outputs": ["2\n", "2\n", "3\n", "3\n", "2\n", "3\n", "2\n2\n", "2\n2\n2\n"]}
coding
279
Solve the programming task below in a Python markdown code block. Alice and Bob play ping-pong with simplified rules. During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternatel...
{"inputs": ["1\n85 4\n", "1\n85 50\n", "1\n85 91\n", "1\n85 37\n", "1\n99 531\n", "1\n99 750\n", "1\n99 141\n", "1\n99 107\n"], "outputs": ["84 4\n", "84 50\n", "84 91\n", "84 37\n", "98 531\n", "98 750\n", "98 141\n", "98 107\n"]}
coding
715
Solve the programming task below in a Python markdown code block. Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahu...
{"inputs": ["1\n1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 3\n", "2\n2 1\n", "4\n1 1 1 3\n", "4\n1 2 1 4\n", "4\n1 1 1 2\n"], "outputs": ["YES", "NO", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
318
Solve the programming task below in a Python markdown code block. In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: - If a noun's singular form does not end with s, append s to the end of...
{"inputs": ["a\n", "s\n", "aox", "bsu", "xoa", "bsv", "xo`", "csv"], "outputs": ["as\n", "ses\n", "aoxs\n", "bsus\n", "xoas\n", "bsvs\n", "xo`s\n", "csvs\n"]}
coding
202
Solve the programming task below in a Python markdown code block. Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them. A poor student is dreaming that he is sitting the mathematica...
{"inputs": ["2 2\n1 1\n", "1 1\n1 1\n", "2 4\n6 6\n", "3 3\n1 1\n", "4 4\n1 1\n", "2 2\n1 2\n", "0 1\n1 1\n", "2 4\n6 8\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
coding
502
Solve the programming task below in a Python markdown code block. #### Task: Your job here is to write a function (`keepOrder` in JS/CoffeeScript, `keep_order` in Ruby/Crystal/Python, `keeporder` in Julia), which takes a sorted array `ary` and a value `val`, and returns the lowest index where you could insert `val` to...
{"functional": "_inputs = [[[1, 2, 3, 4, 7], 5], [[1, 2, 3, 4, 7], 0], [[1, 1, 2, 2, 2], 2], [[1, 2, 3, 4], 5], [[1, 2, 3, 4], -1], [[1, 2, 3, 4], 2], [[1, 2, 3, 4], 0], [[1, 2, 3, 4], 1], [[1, 2, 3, 4], 3], [[], 1], [[], 0], [[1, 1, 1, 1], 2], [[1, 1, 1, 1], 1], [[1, 1, 1, 1], 0], [[1, 3, 5, 6], 0], [[1, 3, 5, 6], 2],...
coding
481
Solve the programming task below in a Python markdown code block. Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word. To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position. Write a ...
{"functional": "_inputs = [['dog', 'car'], ['dog', 'god'], ['dog', 'cog'], ['dog', 'cod'], ['dog', 'bog'], ['dog', 'dog'], ['abcde', 'abcde'], ['same', 'same'], ['z', 'z']]\n_outputs = [[0], [1], [2], [1], [2], [3], [5], [4], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b,...
coding
431
Solve the programming task below in a Python markdown code block. Given an array of numbers, calculate the largest sum of all possible blocks of consecutive elements within the array. The numbers will be a mix of positive and negative values. If all numbers of the sequence are nonnegative, the answer will be the sum of...
{"functional": "_inputs = [[[-1, -2, -3]], [[]], [[1, 2, 3, 4]], [[31, -41, 59, 26, -53, 58, 97, -93, -23, 84]]]\n_outputs = [[0], [0], [10], [187]]\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 isin...
coding
281
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Today a plane was hijacked by a maniac. All the passengers of the flight are taken as hostage. Chef is also one of them. He invited one of the passengers to play a game with h...
{"inputs": ["2\n3 3 3\n1\n3 3 3\n2", "2\n6 3 3\n1\n3 3 3\n2", "2\n0 0 3\n2\n3 3 3\n2", "2\n6 0 3\n2\n3 3 3\n2", "2\n1 0 3\n1\n3 3 0\n2", "2\n0 0 3\n2\n3 3 4\n0", "2\n6 0 3\n3\n3 3 3\n2", "2\n0 0 3\n2\n3 4 0\n2"], "outputs": ["1\n4", "1\n4\n", "2\n4\n", "3\n4\n", "1\n3\n", "2\n-2\n", "5\n4\n", "2\n3\n"]}
coding
523
Solve the programming task below in a Python markdown code block. Vova is playing a computer game. There are in total $n$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $k$. During each turn Vova can choose what to...
{"inputs": ["1\n1000000000 499999999 3 2\n", "1\n1000000000 999999999 2 1\n", "1\n1000000000 499999999 3 2\n", "1\n1000000000 999999999 2 1\n", "1\n1001000000 499999999 3 2\n", "1\n1000010000 999999999 2 1\n", "1\n1001000000 316833107 3 2\n", "1\n1000000000 499999999 3 1\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "10...
coding
689
Solve the programming task below in a Python markdown code block. Kabir Singh is playing a game on the non-negative side of x-axis. It takes him $1 second$ to reach from Pth position to (P−1)th position or (P+1)th position. Kabir never goes to the negative side and also doesn't stop at any moment of time. The movemen...
{"inputs": ["4\n0 1\n1 1\n1 3\n4 6"], "outputs": ["0\n1\n5\n46"]}
coding
619
Solve the programming task below in a Python markdown code block. You are given two integers $l$ and $r$, $l\le r$. Find the largest possible value of $a mod b$ over all pairs $(a, b)$ of integers for which $r\ge a \ge b \ge l$. As a reminder, $a mod b$ is a remainder we get when dividing $a$ by $b$. For example, $26 ...
{"inputs": ["4\n1 1\n9312924 1000001000\n6 51\n1 481905067\n", "4\n1 1\n7655209 1000001000\n6 85\n1 481905067\n", "4\n1 1\n9312924 1000001000\n6 70\n1 481905067\n", "4\n1 1\n7655209 1000001000\n6 56\n1 481905067\n", "4\n1 1\n2508889 1010100000\n9 26\n1 999999999\n", "4\n1 1\n2508889 1010100000\n9 42\n1 999999999\n", "4...
coding
393
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], [...
coding
312
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that: The first ten characters consis...
{"functional": "def check(candidate):\n assert candidate(details = [\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"]) == 2\n assert candidate(details = [\"1313579440F2036\",\"2921522980M5644\"]) == 0\n\n\ncheck(Solution().countSeniors)"}
coding
152
Solve the programming task below in a Python markdown code block. Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left. There were $n$ classes of that subject during the s...
{"inputs": ["2\n7\n", "2\n0\n", "2\n0\n", "2\n7\n", "2\n5\n", "2\n4\n", "2\n1\n", "2\n2\n"], "outputs": ["0 7 \n", "0 0 \n", "0 0\n", "0 7\n", "0 5\n", "0 4\n", "0 1\n", "0 2\n"]}
coding
582
Solve the programming task below in a Python markdown code block. A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1 corridors so that you can get from any room to any other one b...
{"inputs": ["4\n1 2\n1 3\n2 4\n1\n2 3\n", "5\n1 2\n1 3\n2 5\n2 4\n1\n5 4\n", "4\n1 2\n2 3\n2 4\n2\n1 2\n1 2\n", "4\n1 3\n2 3\n2 4\n2\n1 2\n1 2\n", "4\n1 3\n2 3\n2 4\n2\n1 1\n1 2\n", "4\n1 4\n2 3\n2 4\n2\n1 1\n1 3\n", "5\n1 2\n1 3\n2 5\n2 4\n1\n5 3\n", "4\n1 4\n4 3\n2 4\n2\n1 1\n1 3\n"], "outputs": ["1\n", "3\n", "0\n0\...
coding
482
Solve the programming task below in a Python markdown code block. The students of Codechef Middle School are visiting an amusement park. The children want to go on a ride, however, there is a minimum height requirement of $X$ cm. Determine if the children are eligible to go on the ride. Print "Yes" if they are eligibl...
{"inputs": ["2\n120 100\n90 100"], "outputs": ["Yes\nNo"]}
coding
290
Solve the programming task below in a Python markdown code block. You are given a sequence a_1, a_2, ..., a_{n} of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment a_{i} lies within segment a_{j}. Segment [l_1, r_1] lies within segment [l_2, r_2] iff l_...
{"inputs": ["2\n3 7\n3 9\n", "2\n1 4\n1 5\n", "2\n1 1\n1 1\n", "2\n1 2\n1 3\n", "2\n1 1\n1 2\n", "2\n2 3\n2 4\n", "2\n1 3\n3 3\n", "2\n1 3\n1 5\n"], "outputs": ["1 2\n", "1 2\n", "2 1\n", "1 2\n", "1 2\n", "1 2\n", "2 1\n", "1 2\n"]}
coding
402
Solve the programming task below in a Python markdown code block. You are given an array of $n$ integers $a_1$, $a_2$, ..., $a_n$, and a set $b$ of $k$ distinct integers from $1$ to $n$. In one operation, you may choose two integers $i$ and $x$ ($1 \le i \le n$, $x$ can be any integer) and assign $a_i := x$. This oper...
{"inputs": ["1 0\n1337\n", "1 0\n1337\n", "1 0\n2501\n", "1 1\n35\n1\n", "1 1\n120\n1\n", "1 1\n1337\n1\n", "1 1\n1337\n1\n", "5 0\n4 3 1 2 3\n"], "outputs": ["0\n", "0\n", "0", "0", "0", "0\n", "0\n", "2\n"]}
coding
491
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return nu...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3]), val = 2), tree_node([2,1,3]))\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3]), val = 5), tree_node([]))\n\n\ncheck(Solution().searchBST)"}
coding
157
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. The last time in Byteland, Chef defeated the magician in his challenge and won a gold coin. The magician does not want to give up his coin so easily...
{"inputs": ["4\n3 1\n3 2\n4 1\n1 5"], "outputs": ["0.500000\n1.000000\n0.500000\n1.000000"]}
coding
735
Solve the programming task below in a Python markdown code block. # Task For the given set `S` its powerset is the set of all possible subsets of `S`. Given an array of integers nums, your task is to return the powerset of its elements. Implement an algorithm that does it in a depth-first search fashion. That is, for...
{"functional": "_inputs = [[[1, 2]], [[1, 2, 3]], [[1]], [[125, 15, 155, 15, 158]], [[1, 2, 3, 4]]]\n_outputs = [[[[], [2], [1], [1, 2]]], [[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]], [[[], [1]]], [[[], [158], [15], [15, 158], [155], [155, 158], [155, 15], [155, 15, 158], [15], [15, 158], [15, 15], [15, 15...
coding
348
Solve the programming task below in a Python markdown code block. You are given a non-degenerate triangle (a non-degenerate triangle is a triangle with positive area). The vertices of the triangle have coordinates $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$. You want to draw a straight line to cut the triangle into tw...
{"inputs": ["4\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n", "20\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n\n4 7\n6 8\n3 5\n\n4 5\n...
coding
437
Solve the programming task below in a Python markdown code block. Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along ...
{"inputs": ["4\nflovr-with-eggs 010\nchadken-him -26\nflotrswithout-efg- 7\nriwpep--tdpsghif 0001\n3\nf\nilour.wfth\n.huix-ruokf\na\nld\nkicj", "4\nflovr-with-eggs 000\nchbdken-him -26\nflotrswithouu-efg- 7\nriwpep--tdpsghif 0001\n3\nf\nitour.wflh\n.huix-rupkf\na\nkd\nkibj", "4\nflovr-with-eggs 010\nchbdken-him -26\nfl...
coding
397
Solve the programming task below in a Python markdown code block. From tomorrow, the long-awaited summer vacation will begin. So I decided to invite my friends to go out to the sea. However, many of my friends are shy. They would hate it if they knew that too many people would come with them. Besides, many of my frie...
{"inputs": ["4\n2 5\n4 7\n2 4\n5 6", "4\n2 1\n4 7\n2 4\n5 6", "4\n2 2\n4 7\n2 4\n3 6", "4\n2 6\n4 7\n2 4\n5 6", "4\n2 0\n4 7\n2 4\n3 6", "4\n4 0\n4 7\n2 4\n3 6", "4\n2 5\n4 7\n2 4\n6 6", "4\n2 4\n4 7\n2 4\n3 6"], "outputs": ["3\n", "1\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]}
coding
519
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings str1 and str2 of the same length, determine whether you can transform str1 into str2 by doing zero or more conversions. In one conversion you can convert all occurrences of one character in str1 to a...
{"functional": "def check(candidate):\n assert candidate(str1 = \"aabcc\", str2 = \"ccdee\") == True\n assert candidate(str1 = \"leetcode\", str2 = \"codeleet\") == False\n\n\ncheck(Solution().canConvert)"}
coding
119
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a contai...
{"functional": "def check(candidate):\n assert candidate([1,8,6,2,5,4,8,3,7]) == 49 \n assert candidate(height = [1,1]) == 1\n\n\ncheck(Solution().maxArea)"}
coding
131
Solve the programming task below in a Python markdown code block. This time your assignment is really simple. Calculate GCD(1, 1) * GCD(1, 2) * ... * GCD(1, M) * GCD(2, 1) * GCD(2, 2) * ... * GCD(2, M) * ... * GCD(N, 1) * GCD(N, 2) * ... * GCD(N, M). where GCD is defined as the Greatest Common Divisor. Input Format...
{"inputs": ["4 4\n"], "outputs": ["96\n"]}
coding
284
Solve the programming task below in a Python markdown code block. A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$. You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the other di...
{"inputs": ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n", "4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n"], "outputs": ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n", "11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n"]}
coding
623
Solve the programming task below in a Python markdown code block. Initially, Chef had an array A of length N. Chef performs the following operation on A at most once: Select L and R such that 1 ≤ L ≤ R ≤ N and set A_{i} := A_{i} + 1 for all L ≤ i ≤ R. Determine the maximum number of *inversions* Chef can decrease from...
{"inputs": ["3\n5\n4 2 3 1 5\n6\n1 2 3 4 5 6\n4\n2 1 1 1\n"], "outputs": ["2\n0\n3\n"]}
coding
704
Solve the programming task below in a Python markdown code block. We have N+M balls, each of which has an integer written on it. It is known that: - The numbers written on N of the balls are even. - The numbers written on M of the balls are odd. Find the number of ways to choose two of the N+M balls (disregarding ...
{"inputs": ["1 2", "4 0", "0 5", "1 3", "0 0", "2 2", "4 6", "2 3"], "outputs": ["1\n", "6\n", "10\n", "3\n", "0\n", "2\n", "21\n", "4\n"]}
coding
274
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, return the length of the longest substring of s that contains at most k distinct characters.   Please complete the following python code precisely: ```python class Solution: def ...
{"functional": "def check(candidate):\n assert candidate(s = \"eceba\", k = 2) == 3\n assert candidate(s = \"aa\", k = 1) == 2\n\n\ncheck(Solution().lengthOfLongestSubstringKDistinct)"}
coding
82
Solve the programming task below in a Python markdown code block. Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number b_{i}. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. Sh...
{"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n5 6\n", "2\n3 2\n", "2\n1 1\n", "2\n3 2\n", "2\n5 6\n", "2\n0 1\n"], "outputs": ["1 1", "0 1", "1 1", "1 1", "0 1\n", "1 1\n", "1 1\n", "1 1\n"]}
coding
363
Solve the programming task below in a Python markdown code block. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of s...
{"inputs": ["1\n4\n5\n", "1\n5\n4\n", "1\n5\n5\n", "1\n5\n4\n", "1\n4\n5\n", "1\n5\n5\n", "1\n5\n2\n", "1\n4\n6\n"], "outputs": ["4\n", "4\n", "5\n", "4 ", "4 ", "5 ", "2\n", "4\n"]}
coding
578
Solve the programming task below in a Python markdown code block. An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operat...
{"inputs": ["3\n3\n2 3 1\n3\n2 1 3\n4\n1 2 3 4\n"], "outputs": ["5\n6\n10\n"]}
coding
449
Solve the programming task below in a Python markdown code block. Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him. Before the very beginning of the game several cards are lain ...
{"inputs": ["11\n", "??\n", "00\n", "10?\n", "01?\n", "1?1\n", "0101\n", "000?\n"], "outputs": ["11\n", "00\n01\n10\n11\n", "00\n", "00\n01\n", "00\n01\n", "01\n11\n", "01\n", "00\n"]}
coding
735
Solve the programming task below in a Python markdown code block. What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example: ``` 'abba' & 'baab' == true 'abba' & 'bbaa' == true 'abba' & 'abbba' == false 'abba' & 'abca' == false ``` Write a function that will ...
{"functional": "_inputs = [['abba', ['aabb', 'abcd', 'bbaa', 'dada']], ['racer', ['crazer', 'carer', 'racar', 'caers', 'racer']], ['a', ['a', 'b', 'c', 'd']], ['ab', ['cc', 'ac', 'bc', 'cd', 'ab', 'ba', 'racar', 'caers', 'racer']], ['abba', ['a', 'b', 'c', 'd', 'aabb', 'bbaa', 'abab', 'baba', 'baab', 'abcd', 'abbba', '...
coding
257
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of size n. You are asked to solve n queries for each integer i in the range 0 <= i < n. To solve the ith query: Find the minimum value in each possible subarray of size i + 1 of th...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,2,4]) == [4,2,1,0]\n assert candidate(nums = [10,20,50,10]) == [50,20,10,10]\n\n\ncheck(Solution().findMaximums)"}
coding
163
Solve the programming task below in a Python markdown code block. Given an integer $x$, find two non-negative integers $a$ and $b$ such that $(a \wedge b) + (a \vee b) = x$, where $\wedge$ is the bitwise AND operation and $\vee$ is the bitwise OR operation. -----Input----- - The first line of the input contains a sing...
{"inputs": ["2\n1\n8"], "outputs": ["0 1\n5 3"]}
coding
289
Solve the programming task below in a Python markdown code block. Petya has n positive integers a_1, a_2, ..., a_{n}. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one lette...
{"inputs": ["1\nh\n", "1\na\n", "1\na\n", "1\nh\n", "1\nb\n", "1\ni\n", "1\nc\n", "2\na\na\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]}
coding
556
Solve the programming task below in a Python markdown code block. Neo has a complex matrix script. The matrix script is a $N$ X $\mbox{M}$ grid of strings. It consists of alphanumeric characters, spaces and symbols (!,@,#,$,%,&). To decode the script, Neo needs to read each column and select only the alphanumeric cha...
{"inputs": ["7 3\nTsi\nh%x\ni #\nsM \n$a \n#t%\nir!\n"], "outputs": ["This is Matrix# %!\n"]}
coding
341
Solve the programming task below in a Python markdown code block. Chefina has two sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_N$. She views two sequences with length $N$ as identical if, after they are sorted in non-decreasing order, the $i$-th element of one sequence is equal to the $i$-th element of th...
{"inputs": ["3\n1\n1\n2\n2\n1 2\n2 1\n2\n1 1\n2 2"], "outputs": ["-1\n0\n1"]}
coding
594
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] Chef has a sequence $A_{1}, A_{2}, \ldots, A_{N}$. In one operation, Chef can choose one index $i$ ($1 ≤ i ≤ N$) and change $A_{i}$ to $A_{i}^{p}$, where $p = \max(0, {\lceil \frac{A_{i}}{2} \rceil} - 1)$. Help Chef...
{"inputs": ["4\n4\n7 3 5 1\n5\n4 2 7 8 10\n2\n9 9\n3\n1 1 1"], "outputs": ["0\n1\n0\n-1"]}
coding
534
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score: Select an element m from nums. Remove the selected eleme...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5], k = 3) == 18\n assert candidate(nums = [5,5,5], k = 2) == 11\n\n\ncheck(Solution().maximizeSum)"}
coding
139
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Vietnamese as well. It is well-known that ∑sqrt(a_{i}), a_{i} ∈ N is a root of some integer-coefficient polynomial. For example: sqrt(2) is a root of polynomial: x^{2} − 2. Now, your task is to find not ...
{"inputs": ["2\n1\n2\n2\n2 3"], "outputs": ["2\n1000000005 0 1\n4\n1 0 999999997 0 1"]}
coding
440
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: res = 0 for init = 0 to inf cur = init ok = true for i = 1 to |s| ...
{"inputs": ["3\n--+-\n---\n++--+-\n", "3\n-+--\n---\n++--+-\n", "3\n--+-\n---\n+--++-\n", "3\n-+--\n---\n+--++-\n", "3\n--+-\n---\n-+-++-\n", "3\n---+\n---\n++--+-\n", "3\n-+--\n---\n---+++\n", "3\n--+-\n---\n-+--++\n"], "outputs": ["7\n9\n6\n", "9\n9\n6\n", "7\n9\n9\n", "9\n9\n9\n", "7\n9\n7\n", "10\n9\n6\n", "9\n9\n1...
coding
316
Solve the programming task below in a Python markdown code block. Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how ma...
{"inputs": ["a\na\n", "a\nb\n", "a\na\n", "a\nb\n", "c\nc\n", "a\nc\n", "b\nc\n", "c\nb\n"], "outputs": ["1\n", "0\n", "1", "0", "1\n", "0\n", "0\n", "0\n"]}
coding
407
Solve the programming task below in a Python markdown code block. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is worki...
{"inputs": ["1 1\n5 8\n", "1 1\n1 1\n", "1 1\n5 8\n", "1 1\n1 1\n", "1 1\n0 1\n", "1 1\n9 8\n", "1 0\n10 20\n", "1 0\n12 12\n"], "outputs": ["8", "1", "8", "1", "0\n", "8\n", "10", "12"]}
coding
673
Solve the programming task below in a Python markdown code block. Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor. Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He ...
{"inputs": ["3 2\n0 0\n1 0\n2 0", "1 4\n0 0\n2 1\n2 0", "3 8\n0 0\n0 0\n2 0", "3 4\n0 0\n1 0\n2 0", "3 4\n0 0\n1 1\n2 0", "3 4\n0 0\n2 1\n2 0", "1 4\n0 0\n2 1\n2 1", "3 4\n0 0\n0 0\n2 0"], "outputs": ["2\n", "0\n", "8\n", "2\n", "2\n", "2\n", "0\n", "4\n"]}
coding
583
Solve the programming task below in a Python markdown code block. Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his ...
{"inputs": ["0 6 1 5", "1 0 0 0", "2 0 0 0", "4 0 0 0", "1 6 -1 4", "1 11 1 6", "-1 0 0 4", "-1 0 0 1"], "outputs": ["4\n", "0\n", "0\n", "0\n", "3\n", "5\n", "0\n", "0\n"]}
coding
294
Please solve the programming task below using a self-contained code snippet in a markdown code block. Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected. You are given a 0-indexed string s, and you type ea...
{"functional": "def check(candidate):\n assert candidate(s = \"string\") == \"rtsng\"\n assert candidate(s = \"poiinter\") == \"ponter\"\n\n\ncheck(Solution().finalString)"}
coding
119
Solve the programming task below in a Python markdown code block. You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). Input The first input line contains the string....
{"inputs": ["a\n", "b\n", "`\n", "yy\n", "fg\n", "xy\n", "gf\n", "yx\n"], "outputs": ["0", "0\n", "0\n", "1", "0", "0\n", "0\n", "0\n"]}
coding
145
Solve the programming task below in a Python markdown code block. Polycarp loves geometric progressions — he collects them. However, as such progressions occur very rarely, he also loves the sequences of numbers where it is enough to delete a single element to get a geometric progression. In this task we shall define ...
{"inputs": ["1\n2\n", "1\n0\n", "1\n1\n", "1\n3\n", "1\n4\n", "1\n-1\n", "1\n-2\n", "1\n-4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
370
Solve the programming task below in a Python markdown code block. Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to pla...
{"inputs": ["1 3\n", "5 3\n", "2 1\n", "8 5\n", "5 2\n", "3 5\n", "1 2\n", "3 3\n"], "outputs": ["2B", "1A1B1A", "1A", "1A1B1A1B", "2A1B", "1B1A1B\n", "1B\n", "Impossible\n"]}
coding
664
Solve the programming task below in a Python markdown code block. # Task Given the birthdates of two people, find the date when the younger one is exactly half the age of the other. # Notes * The dates are given in the format YYYY-MM-DD and are not sorted in any particular order * Round **down** to the nearest day *...
{"functional": "_inputs = [['1990-12-06', '2000-02-29'], ['2012-03-31', '1990-06-09'], ['1984-08-14', '1990-04-17'], ['2000-06-30', '1978-03-17'], ['1969-12-20', '2000-10-07']]\n_outputs = [['2009-05-24'], ['2034-01-21'], ['1995-12-19'], ['2022-10-14'], ['2031-07-26']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n i...
coding
111
Solve the programming task below in a Python markdown code block. Find the sum of the odd numbers within an array, after cubing the initial integers. The function should return `undefined`/`None`/`nil`/`NULL` if any of the values aren't numbers. ~~~if:java,csharp Note: There are ONLY integers in the JAVA and C# versi...
{"functional": "_inputs = [[[1, 2, 3, 4]], [[-3, -2, 2, 3]], [['a', 12, 9, 'z', 42]], [[True, False, 2, 4, 1]]]\n_outputs = [[28], [0], [None], [None]]\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 i...
coding
127
Solve the programming task below in a Python markdown code block. Cirno_9baka has a tree with $n$ nodes. He is willing to share it with you, which means you can operate on it. Initially, there are two chess pieces on the node $1$ of the tree. In one step, you can choose any piece, and move it to the neighboring node. ...
{"inputs": ["2 2\n2 1\n1 2\n1 1\n", "2 2\n1 2\n1 2\n1 1\n", "2 2\n2 1\n1 1\n1 1\n", "2 2\n2 1\n1 1\n2 1 2\n", "2 2\n1 2\n1 2\n2 1 2\n", "4 2\n1 2\n1 3\n2 4\n1 3\n1 4\n", "4 2\n1 2\n2 3\n3 4\n4 1 2 3 4\n1 1\n", "10 2\n5 6\n4 7\n7 1\n8 2\n6 9\n4 8\n10 5\n9 2\n3 5\n5 5 1 3 2 7\n3 7 8 4\n"], "outputs": ["2", "2", "0", "2",...
coding
677
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order. The subtree sum of a node is defined as the sum of all the node ...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,2,-3])) == [2,-3,4]\n assert candidate(root = tree_node([5,2,-5])) == [2]\n\n\ncheck(Solution().findFrequentTreeSum)"}
coding
167
Solve the programming task below in a Python markdown code block. There are n stones arranged on an axis. Initially the i-th stone is located at the coordinate s_i. There may be more than one stone in a single place. You can perform zero or more operations of the following type: * take two stones with indices i an...
{"inputs": ["1\n1\n1\n", "1\n0\n1\n", "1\n1\n2\n", "1\n1\n3\n", "1\n1\n5\n", "2\n1 5\n3 4\n", "2\n1 9\n3 4\n", "2\n2 9\n3 4\n"], "outputs": ["YES\n0\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
671
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money. You must buy exactly two chocol...
{"functional": "def check(candidate):\n assert candidate(prices = [1,2,2], money = 3) == 0\n assert candidate(prices = [3,2,3], money = 3) == 3\n\n\ncheck(Solution().buyChoco)"}
coding
168
Solve the programming task below in a Python markdown code block. You are given two positive integers N and K. You have to perform the following operation exactly K times: - For the current value of N, choose any positive integer D such that D is a [divisor] of N and multiply D with N. Formally, N := (N * D) such tha...
{"inputs": ["3\n1 5\n2 2\n10 1"], "outputs": ["1\n30\n180"]}
coding
701
Solve the programming task below in a Python markdown code block. Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test c...
{"inputs": ["2\n6 9\n5 0\n", "2\n9 9\n53 9\n", "2\n4 9\n51 5\n", "2\n6 9\n10 0\n", "2\n4 6\n47 7\n", "2\n9 9\n27 9\n", "2\n9 9\n17 4\n", "2\n9 8\n53 9\n"], "outputs": ["-1\n5\n", "-1\n8\n", "-1\n24\n", "-1\n19\n", "-1\n17\n", "-1\n-1\n", "-1\n-1\n", "-1\n8\n"]}
coding
278
Solve the programming task below in a Python markdown code block. This is a hard version of the problem. In this version, there are two colors of the cards. Alice has $n$ cards, each card is either black or white. The cards are stacked in a deck in such a way that the card colors alternate, starting from a white card....
{"inputs": ["5\n10\n6\n17\n8\n1000000\n"], "outputs": ["3 2 2 3\n1 0 2 3\n6 4 3 4\n2 1 2 3\n250278 249924 249722 250076\n"]}
coding
458
Solve the programming task below in a Python markdown code block. You are given an array consisting of $n$ integers $a_1$, $a_2$, ..., $a_n$. Initially $a_x = 1$, all other elements are equal to $0$. You have to perform $m$ operations. During the $i$-th operation, you choose two indices $c$ and $d$ such that $l_i \le ...
{"inputs": ["1\n16 771 1\n2 146\n", "1\n152 771 0\n3 282\n", "1\n65 1380 0\n3 282\n", "1\n13 1380 0\n3 282\n", "1\n152 771 1\n2 146\n", "1\n152 771 0\n13 15\n", "1\n239 771 0\n3 282\n", "1\n65 2224 0\n3 282\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
556
Solve the programming task below in a Python markdown code block. You're in ancient Greece and giving Philoctetes a hand in preparing a training exercise for Hercules! You've filled a pit with two different ferocious mythical creatures for Hercules to battle! The formidable **"Orthus"** is a 2 headed dog with 1 tail. ...
{"functional": "_inputs = [[123, 39], [371, 88], [24, 12], [113, 37], [635, 181], [25, 555], [12, 25], [54, 956], [5455, 54956], [0, 0], [-1, -1], [-45, 5], [99, 0], [0, 99], [5, -55]]\n_outputs = [[[24, 15]], [[23, 65]], [[12, 0]], [[24, 13]], [[90, 91]], ['No solutions'], ['No solutions'], ['No solutions'], ['No solu...
coding
258
Solve the programming task below in a Python markdown code block. You want to build a temple for snakes. The temple will be built on a mountain range, which can be thought of as n blocks, where height of i-th block is given by hi. The temple will be made on a consecutive section of the blocks and its height should star...
{"inputs": ["3\n3\n1 2 1\n4\n1 1 2 1\n5\n1 2 6 2 1"], "outputs": ["0\n1\n3"]}
coding
506
Please solve the programming task below using a self-contained code snippet in a markdown code block. For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that ...
{"functional": "def check(candidate):\n assert candidate(str1 = \"ABCABC\", str2 = \"ABC\") == \"ABC\"\n assert candidate(str1 = \"ABABAB\", str2 = \"ABAB\") == \"AB\"\n assert candidate(str1 = \"LEET\", str2 = \"CODE\") == \"\"\n\n\ncheck(Solution().gcdOfStrings)"}
coding
124
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 $N$ dishes, numbered $1$ through $N$. For each valid $i$, dish $i$ is described by a string $D_{i}$ containing only lowercase vowels, i.e. c...
{"inputs": ["1\n3\naaooaoaooa\nuiieieiieieuuu\naeioooeeiiaiei"], "outputs": ["2"]}
coding
636
Solve the programming task below in a Python markdown code block. Ela likes Chess a lot. During breaks, she usually challenges her co-worker in DTL to some chess games. She's not an expert at classic chess, but she's very interested in Chess variants, where she has to adapt to new rules and test her tactical mindset to...
{"inputs": ["1\n4\n4 1 4 2 3 1\n1 3\n", "1\n100000\n1 1 2 1 1 2\n26298 33691\n", "6\n8\n7 2 8 2 7 1\n5 1\n8\n2 2 1 2 2 1\n5 5\n8\n2 2 1 2 2 1\n6 6\n8\n1 1 1 2 2 1\n5 5\n8\n2 2 1 2 2 1\n8 8\n8\n8 8 8 7 7 8\n4 8\n", "3\n100000\n100000 100000 99999 100000 100000 99999\n69 100000\n100000\n2 100000 1 99999 1 100000\n100000 ...
coding
715
Solve the programming task below in a Python markdown code block. You are given an array A of length N. The *interesting value* of a subarray is defined as the product of the maximum and minimum elements of the subarray. Find the minimum and maximum *interesting value* over all subarrays for the given array. Note: ...
{"inputs": ["2\n2\n2 2\n3\n5 0 9\n"], "outputs": ["4 4\n0 81"]}
coding
620
Please solve the programming task below using a self-contained code snippet in a markdown code block. The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: "../" : Move to the parent folder of the current folder. (If you are already in the mai...
{"functional": "def check(candidate):\n assert candidate(logs = [\"d1/\",\"d2/\",\"../\",\"d21/\",\"./\"]) == 2\n assert candidate(logs = [\"d1/\",\"d2/\",\"./\",\"d3/\",\"../\",\"d31/\"]) == 3\n assert candidate(logs = [\"d1/\",\"../\",\"../\",\"../\"]) == 0\n\n\ncheck(Solution().minOperations)"}
coding
191