task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is so good at programming that he won almost all competitions. With all the prizes, Chef bought a new house. The house looks like a grid of size N (1-indexed) which cons...
{"inputs": ["3\n1\n2\n3"], "outputs": ["2\n12\n36"]}
472
24
coding
Solve the programming task below in a Python markdown code block. You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i. How many kinds of items did you get? -----Constraints----- - 1 \leq N \leq 2\times 10^5 - S_i consists of lowercase English letters and has a length b...
{"inputs": ["4\na`aa\na\naaa\naa", "4\na`ab\na\naaa\naa", "4\nb`aa\na\naaa\naa", "4\nc`aa\na\naaa\naa", "4\n`caa\na\naaa\naa", "4\n`caa\na\naab\naa", "4\n`caa\na\nbaa\naa", "4\n`caa\n`\naab\naa"], "outputs": ["4\n", "4\n", "4\n", "4\n", "4\n", "4\n", "4\n", "4\n"]}
159
139
coding
Solve the programming task below in a Python markdown code block. Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence a_1, a_1 +...
{"inputs": ["1 1 1 1\n", "9 8 7 5\n", "2 6 6 8\n", "2 4 8 8\n", "2 4 4 2\n", "1 2 4 8\n", "8 4 2 1\n", "2 3 4 6\n"], "outputs": ["1\n", "42\n", "42\n", "42\n", "42\n", "16\n", "42\n", "42\n"]}
370
125
coding
Solve the programming task below in a Python markdown code block. A group of people played a game. All players had distinct scores, which are positive integers. Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i. Find the maximum possible num...
{"inputs": ["3\n4 5\n2 9\n6 2", "3\n4 5\n2 9\n6 3", "3\n4 7\n2 9\n6 2", "3\n8 3\n2 14\n3 3", "5\n1 10\n3 6\n5 2\n4 4\n2 8", "2\n1 1000100000\n1000000000 1", "2\n1 1000100000\n1000000010 1", "2\n0 1000110010\n1000001010 1"], "outputs": ["8\n", "9\n", "8", "11\n", "7", "1000000001\n", "1000000011\n", "1000001011\n"]}
317
236
coding
Solve the programming task below in a Python markdown code block. Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining car...
{"inputs": ["5\n1 2 0 3 7", "5\n1 2 1 3 7", "5\n1 2 1 3 7\n", "5\n1 2 0 3 11", "5\n1 2 0 3 18", "5\n1 2 0 5 18", "5\n1 2 0 9 18", "5\n4 -2 0 3 1"], "outputs": ["5\n", "3", "3\n", "5\n", "5\n", "5\n", "5\n", "5\n"]}
326
146
coding
Solve the programming task below in a Python markdown code block. Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat ser...
{"inputs": ["+adabacaba0\n", "+adabacab`0\n", "+acabadab\n+caba0aba\n", "+`cabadab\n+caba0aba\n", "+acabadab\n+caca0aba\n", "+acabadab\n+caba0ab`\n", "+cab\n+abac\n-abac\n+baca\n", "+dab\n+abac\n-abac\n+baca\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
503
131
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of length N: A_1, A_2, ..., A_N. For each integer i between 1 and N (inclusive), answer the following question: - Find the maximum value among the N-1 elements other than A_i in the sequence. -----Constraints----- - 2 \leq N \...
{"inputs": ["2\n5\n4", "2\n3\n4", "2\n4\n4", "2\n4\n0", "2\n5\n3", "2\n5\n8", "2\n3\n5", "2\n8\n4"], "outputs": ["4\n5\n", "4\n3\n", "4\n4\n", "0\n4\n", "3\n5\n", "8\n5\n", "5\n3\n", "4\n8\n"]}
310
110
coding
Solve the programming task below in a Python markdown code block. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would ...
{"inputs": ["2\n7 6\n", "2\n1 1\n", "2\n1 1\n", "2\n1 2\n", "2\n3 6\n", "2\n7 6\n", "2\n3 11\n", "2\n96 97\n"], "outputs": ["0\n", "1\n", "1", "1\n", "2\n", "0", "5\n", "1\n"]}
497
103
coding
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"]}
671
116
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend fo...
{"functional": "def check(candidate):\n assert candidate(n = 5, k = 2) == [4,5]\n assert candidate(n = 4, k = 4) == [2,3,4]\n\n\ncheck(Solution().circularGameLosers)"}
331
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string num of length n consisting of digits. Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.   Please complete the fo...
{"functional": "def check(candidate):\n assert candidate(num = \"1210\") == True\n assert candidate(num = \"030\") == False\n\n\ncheck(Solution().digitCount)"}
96
46
coding
Solve the programming task below in a Python markdown code block. Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n01\n", "2\n10\n", "2\n11\n", "2\n00\n"], "outputs": ["1\n", "1\n", "1", "1", "2\n", "2\n", "2\n", "2\n"]}
510
88
coding
Solve the programming task below in a Python markdown code block. Complete the function that determines the score of a hand in the card game [Blackjack](https://en.wikipedia.org/wiki/Blackjack) (aka 21). The function receives an array of strings that represent each card in the hand (`"2"`, `"3",` ..., `"10"`, `"J"`, `...
{"functional": "_inputs = [[['2', '3']], [['4', '5', '6']], [['7', '7', '8']], [['9', '2', '10']], [['4', '7', '8']], [['J', '3']], [['J', 'Q']], [['K', 'J', 'Q']], [['A', '3']], [['A', 'J']], [['A', 'A', 'A', 'J']], [['A', '2', 'A', '9', '9']], [['A', 'A']], [['8', 'A', 'A']], [['5', '4', 'A', 'A']], [['A', '2', 'A', ...
329
374
coding
Solve the programming task below in a Python markdown code block. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room o...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n1 1\n", "2\n1 2\n", "3\n1 1 3\n", "3\n1 1 3\n", "3\n1 1 2\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "4\n", "8\n", "8\n", "12\n"]}
478
105
coding
Solve the programming task below in a Python markdown code block. In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call...
{"inputs": ["2 5\n38 9\n25 15", "2 5\n38 9\n39 15", "2 5\n38 9\n17 15", "2 10\n26 9\n1 15", "2 5\n20 3\n25 10", "1 5\n38 9\n25 15", "2 5\n20 10\n25 15", "2 5\n20 16\n25 15"], "outputs": ["55\n", "56\n", "47\n", "62\n", "29\n", "74\n", "40\n", "52\n"]}
450
176
coding
Solve the programming task below in a Python markdown code block. You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \...
{"inputs": ["1\n1 3\n2 1 1\n", "1\n1 5\n1 2 4 3 3\n", "1\n1 5\n1 3 2 2 4\n", "1\n1 7\n1 2 4 3 3 3 5\n", "1\n2 4\n2 1 1 1\n2 2 2 1\n", "5\n2 3\n1 2 3\n1 1 1\n2 2\n4 1\n2 3\n2 2\n2 1\n1 1\n2 3\n6 2 1\n5 4 3\n2 1\n1\n2\n", "4\n1 10\n1 2 3 2 2 2 2 2 3 3\n1 10\n1 2 3 3 3 3 3 2 3 3\n1 10\n1 2 3 3 3 3 2 2 3 3\n1 5\n1 4 3 2 5\...
590
331
coding
Solve the programming task below in a Python markdown code block. You are given $q$ queries in the following form: Given three integers $l_i$, $r_i$ and $d_i$, find minimum positive integer $x_i$ such that it is divisible by $d_i$ and it does not belong to the segment $[l_i, r_i]$. Can you answer all the queries? Re...
{"inputs": ["1\n1 1 1\n", "1\n2 5 6\n", "1\n5 5 5\n", "1\n6 6 6\n", "1\n1 3 2\n", "1\n6 6 6\n", "1\n1 1 1\n", "1\n1 3 2\n"], "outputs": ["2\n", "6\n", "10\n", "12\n", "4\n", "12\n", "2\n", "4\n"]}
285
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s consisting of only lowercase English letters, and an integer count. A substring of s is said to be an equal count substring if, for each unique letter in the substring, it appears ex...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabcbbcc\", count = 3) == 3\n assert candidate(s = \"abcd\", count = 2) == 0\n assert candidate(s = \"a\", count = 5) == 0\n\n\ncheck(Solution().equalCountSubstrings)"}
131
75
coding
Solve the programming task below in a Python markdown code block. Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d. Johnny's truck has a gas tank that holds exactly n liters,...
{"inputs": ["16 5 2\n8 2\n5 1\n", "153 105 1\n96 83995\n", "10 4 4\n3 5\n5 8\n6 3\n8 4\n", "229 79 2\n27 270968\n76 284309\n", "229 79 2\n27 349050\n76 284309\n", "229 79 2\n27 349050\n16 284309\n", "229 79 2\n53 349050\n16 284309\n", "229 123 2\n6 270968\n76 284309\n"], "outputs": ["-1\n", "4031760\n", "22\n", "-1\n",...
497
264
coding
Solve the programming task below in a Python markdown code block. You are given an integer m as a product of integers a_1, a_2, ... a_{n} $(m = \prod_{i = 1}^{n} a_{i})$. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n product...
{"inputs": ["1\n1\n", "1\n1\n", "1\n15\n", "1\n15\n", "2\n5 7\n", "2\n1 2\n", "2\n1 6\n", "2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "4\n", "2\n", "4\n", "2\n"]}
430
96
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Russian here The Head Chef is studying the motivation and satisfaction level of his chefs . The motivation and satisfaction of a Chef can be represented as an integer . The Head Chef wants to know the N th smallest sum of o...
{"inputs": ["1\n3 1\n1 2 3\n4 5 6\n4", "1\n3 1\n1 4 3\n4 5 6\n4", "1\n6 1\n1 4 3\n4 5 6\n1", "1\n6 1\n0 4 3\n4 5 6\n1", "1\n3 1\n1 2 1\n4 5 6\n4", "1\n6 1\n0 8 6\n2 5 6\n1", "1\n8 1\n1 1 3\n4 6 2\n0", "1\n1 1\n2 8 2\n4 2 4\n0"], "outputs": ["7", "7\n", "5\n", "4\n", "6\n", "2\n", "9\n", "12\n"]}
640
206
coding
Solve the programming task below in a Python markdown code block. Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings $a$ and $b$. It is known that $|b| \leq |a|$, that is, the length of $b$ is at most the length of $a$. The Cossack considers every substring...
{"inputs": ["0\n1\n", "0\n1\n", "01100010\n00110\n", "01100010\n10110\n", "01100010\n10100\n", "01100010\n11100\n", "01100010\n11110\n", "01100010\n11111\n"], "outputs": ["0\n", "0", "3\n", "1\n", "3\n", "1\n", "3\n", "1\n"]}
592
151
coding
Solve the programming task below in a Python markdown code block. A famous student of AESC MSU, as you know, comes from Kostomuksha. Kostomuksha has a popular game called Doka. The essence of Doka is as follows: You are given an array A and an integer X. You want to calculate how many subarrays of this array have a g...
{"inputs": ["3\n3 3\n3 3 3\n4 4\n1 2 3 4\n4 54\n36 81 54 54"], "outputs": ["6\n1\n6"]}
666
55
coding
Solve the programming task below in a Python markdown code block. # One is the loneliest number ## Task The range of vision of a digit is its own value. `1` can see one digit to the left and one digit to the right,` 2` can see two digits, and so on. Thus, the loneliness of a digit `N` is the sum of the digits which ...
{"functional": "_inputs = [[34315], [123456], [8854778], [65432165432], [0], [1], [11111]]\n_outputs = [[True], [True], [False], [False], [False], [True], [True]]\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...
312
220
coding
Solve the programming task below in a Python markdown code block. You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented ...
{"inputs": ["A\n", "G\n", "T\n", "C\n", "C\n", "G\n", "A\n", "T\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
434
70
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. As we all know, Binomial Coefficient C(n, r) is defined by the following formula. Also define S(n) as follows. Note that n will be provided to you as an input parameter. Since S(n) can be ...
{"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["2\n4\n2\n4\n8"]}
258
30
coding
Solve the programming task below in a Python markdown code block. Truncate the given string (first argument) if it is longer than the given maximum length (second argument). Return the truncated string with a `"..."` ending. Note that inserting the three dots to the end will add to the string length. However, if the ...
{"functional": "_inputs = [['pippi', 3], ['Peter Piper picked a peck of pickled peppers', 14], ['A-tisket a-tasket A green and yellow basket', 43], ['A-tisket a-tasket A green and yellow basket', 45], ['A-', 1], ['Chingel loves his Angel so much!!!', 27], ['I like ice-cream.Do you?', 19], ['Seems like you have passed t...
193
332
coding
Solve the programming task below in a Python markdown code block. One important contest will take place on the most famous programming platform (Topforces) very soon! The authors have a pool of $n$ problems and should choose at most three of them into this contest. The prettiness of the $i$-th problem is $a_i$. The au...
{"inputs": ["1\n5\n2 6 10 30 30\n", "1\n5\n2 6 11 30 30\n", "1\n5\n6 7 15 30 30\n", "1\n5\n2 6 10 41 30\n", "1\n5\n30 30 27 7 6\n", "1\n5\n2 9 10 41 30\n", "1\n5\n30 55 27 7 6\n", "1\n5\n30 30 15 10 6\n"], "outputs": ["30\n", "41\n", "37\n", "71\n", "64\n", "80\n", "112\n", "31\n"]}
556
200
coding
Solve the programming task below in a Python markdown code block. Check if given chord is minor or major. _____________________________________________________________ Rules: 1. Basic minor/major chord have three elements. 2. Chord is minor when interval between first and second element equals 3 and between second a...
{"functional": "_inputs = [['C E G'], ['Db F Ab'], ['D F# A'], ['Eb G Bb'], ['E G# B'], ['F A C'], ['F# A# C#'], ['Gb Bb Db'], ['G B D'], ['Ab C Eb'], ['A C# E'], ['Bb D F'], ['B D# F#'], ['C Eb G'], ['C# E G#'], ['D F A'], ['D# F# A#'], ['Eb Gb Bb'], ['E G B'], ['F Ab C'], ['F# A C#'], ['G Bb D'], ['G# B D#'], ['A C E...
320
521
coding
Solve the programming task below in a Python markdown code block. Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}. Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c. -----Constraints----- - 1 \leq K \leq 200 - K is an integer. -----Input----- Input is given from Standard...
{"inputs": ["4", "8", "3", "5", "7", "0", "1", "9"], "outputs": ["76\n", "624\n", "30\n", "141\n", "400\n", "0\n", "1\n", "885\n"]}
267
72
coding
Solve the programming task below in a Python markdown code block. Every year the professor selects the top two students from his class and takes them on a fun filled field trip, this year Ali and Zafar were selected. The professor took them to a place where there was a never-ending queue of solid metal cubes. The profe...
{"inputs": ["4\n3 3 8 8", "4\n2 8 7 3"], "outputs": ["3", "4"]}
489
34
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti]. You have to divide the intervals into one or more groups such that each interval is in...
{"functional": "def check(candidate):\n assert candidate(intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]) == 3\n assert candidate(intervals = [[1,3],[5,6],[8,10],[11,13]]) == 1\n\n\ncheck(Solution().minGroups)"}
162
82
coding
Solve the programming task below in a Python markdown code block. There are some candies that need to be distributed to some children as fairly as possible (i.e. the variance of result needs to be as small as possible), but I don't know how to distribute them, so I need your help. Your assignment is to write a function...
{"functional": "_inputs = [[-5, 0], [10, 0], [15, 0], [-5, -5], [10, -5], [15, -5]]\n_outputs = [[[]], [[]], [[]], [[]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list,...
636
202
coding
Solve the programming task below in a Python markdown code block. Mr. Chanek gives you a sequence a indexed from 1 to n. Define f(a) as the number of indices where a_i = i. You can pick an element from the current sequence and remove it, then concatenate the remaining elements together. For example, if you remove the...
{"inputs": ["1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n5\n", "1\n7\n", "1\n3\n", "1\n83\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
368
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes that course prevCoursej...
{"functional": "def check(candidate):\n assert candidate(n = 3, relations = [[1,3],[2,3]], time = [3,2,5]) == 8\n assert candidate(n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]) == 12\n\n\ncheck(Solution().minimumTime)"}
245
100
coding
Solve the programming task below in a Python markdown code block. There is a new attraction in Singapore Zoo: The Infinite Zoo. The Infinite Zoo can be represented by a graph with an infinite number of vertices labeled $1,2,3,\ldots$. There is a directed edge from vertex $u$ to vertex $u+v$ if and only if $u\&v=v$, wh...
{"inputs": ["5\n1 4\n3 6\n1 6\n6 2\n5 5\n", "5\n1 4\n3 7\n1 6\n6 2\n5 5\n", "5\n1 5\n3 6\n1 6\n6 2\n5 5\n", "5\n1 5\n3 6\n1 6\n6 2\n4 5\n", "5\n1 2\n3 7\n2 6\n3 2\n6 5\n", "5\n1 3\n3 7\n2 6\n3 2\n6 5\n", "5\n1 3\n3 7\n2 3\n1 2\n6 5\n", "5\n1 4\n3 6\n1 6\n6 3\n5 5\n"], "outputs": ["YES\nYES\nNO\nNO\nYES\n", "YES\nNO\nNO...
375
294
coding
Solve the programming task below in a Python markdown code block. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seco...
{"inputs": ["2 1\n2 3\n", "2 4\n3 7\n", "2 3\n2 4\n", "2 3\n1 6\n", "2 3\n5 8\n", "2 3\n6 9\n", "2 3\n1 8\n", "2 3\n2 5\n"], "outputs": ["1\n", "1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n"]}
555
118
coding
Solve the programming task below in a Python markdown code block. # Task Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he's not a very good reader yet, so whenever he enc...
{"functional": "_inputs = [[4, \"The Fox asked the stork, 'How is the soup?'\"], [1, '...'], [3, 'This play was good for us.'], [3, 'Suddenly he stopped, and glanced up at the houses'], [6, 'Zebras evolved among the Old World horses within the last four million years.'], [5, 'Although zebra species may have overlapping...
316
303
coding
Solve the programming task below in a Python markdown code block. You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j <...
{"inputs": ["1\n1\n", "1\n1\n", "3\n3 2 1\n", "3\n3 2 1\n", "5\n5 1 2 3 4\n", "5\n4 3 5 1 2\n", "5\n2 3 4 1 5\n", "5\n1 2 3 4 5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "5\n", "1\n", "1\n", "1\n"]}
246
126
coding
Solve the programming task below in a Python markdown code block. Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maxi...
{"inputs": ["2\n1 1\n", "2\n1 2\n", "2\n1 2\n", "2\n1 1\n", "2\n1 3\n", "2\n2 1\n", "2\n0 0\n", "2\n1 0\n"], "outputs": ["0", "1", "1\n", "0\n", "2\n", "1\n", "0\n", "1\n"]}
381
100
coding
Solve the programming task below in a Python markdown code block. Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would like to greet him slightly different. She added a special case to her function, but she made a mistake. Can you help her? Also feel free to re...
{"functional": "_inputs = [['James'], ['Jane'], ['Jim'], ['Johnny']]\n_outputs = [['Hello, James!'], ['Hello, Jane!'], ['Hello, Jim!'], ['Hello, my love!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ...
85
185
coding
Solve the programming task below in a Python markdown code block. Chef feels that being the Head Chef is a very difficult job. More than cooking, managing the kitchen and distributing the work between various cooks proves to be a tiring task. There are many dishes to be prepared. And he has a team of talented cooks to ...
{"inputs": ["1\n3 2\n0 3\n1 3"], "outputs": ["3"]}
432
24
coding
Solve the programming task below in a Python markdown code block. Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, ...
{"inputs": ["1\n", ",\n", "0\n", ",,\n", "1,\n", ",1\n", "2,\n", ",2\n"], "outputs": ["1\n", ",\n", "0\n", ", ,\n", "1,\n", ", 1\n", "2,\n", ", 2\n"]}
498
77
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighbo...
{"inputs": ["2\n---+-+-+++\n-------", "2\n+++-+-+---\n-------", "2\n-+--+++--+\n-------", "2\n-+-+-+-+-+\n-------", "2\n--++---+++\n-----+-", "2\n---+-+-+++\n-----+-", "2\n+-+-+-+--+\n-------", "2\n---+++-+-+\n-------"], "outputs": ["2\n3", "2\n3\n", "4\n3\n", "0\n3\n", "4\n2\n", "2\n2\n", "2\n3\n", "2\n3\n"]}
401
139
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given an integer sequence $A$ with length $N$. Find the number of (unordered) pairs of elements such that the average of these two elements is also present in the se...
{"inputs": ["3\n2\n2 2\n3\n2 1 3\n6\n4 2 5 1 3 5"], "outputs": ["1\n1\n7"]}
486
44
coding
Solve the programming task below in a Python markdown code block. For a permutation P of integers from 1 to N, let's define its value as (1 \oplus P_{1}) + (2 \oplus P_{2}) + \ldots + (N \oplus P_{N}). Given N, find the maximum possible value of the permutation of integers from 1 to N. As a reminder, \oplus denotes ...
{"inputs": ["5\n1\n2\n3\n4\n29012022"], "outputs": ["0\n6\n6\n20\n841697449540506"]}
510
52
coding
Solve the programming task below in a Python markdown code block. There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between t...
{"inputs": ["2 0\n", "3 0\n", "4 0\n", "2 0\n", "4 0\n", "3 0\n", "7 0\n", "5 0\n"], "outputs": ["1\n", "2\n", "3\n", "1\n", "3\n", "2\n", "6\n", "4\n"]}
556
86
coding
Solve the programming task below in a Python markdown code block. Given N and M Dexter wants to know how many pairs a,b(1 ≤ a < b ≤N) are there such that (a+b) is divisible by M. For example when N=4 and M=3, there are 2 possible pairs the sum of which is divisible by M and they are (1,2) and (2,4). ------ Input ----...
{"inputs": ["3\n2 3\n4 3\n1 6"], "outputs": ["1\n2\n0"]}
205
28
coding
Solve the programming task below in a Python markdown code block. Gigi is a clever monkey, living in the zoo, his teacher (animal keeper) recently taught him some knowledge of "0". In Gigi's eyes, "0" is a character contains some circle(maybe one, maybe two). So, a is a "0",b is a "0",6 is also a "0",and 8 have two "...
{"functional": "_inputs = [[''], ['0'], ['0oO0oO'], ['1234567890'], ['abcdefghijklmnopqrstuvwxyz'], ['()'], ['E'], ['aA'], ['BRA'], ['%%']]\n_outputs = [[0], [1], [6], [5], [8], [1], [0], [1], [3], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return mat...
224
223
coding
Solve the programming task below in a Python markdown code block. Chef made $N$ pieces of cakes, numbered them $1$ through $N$ and arranged them in a row in this order. There are $K$ possible types of flavours (numbered $1$ through $K$); for each valid $i$, the $i$-th piece of cake has a flavour $A_i$. Chef wants to se...
{"inputs": ["2\n6 2\n1 1 1 2 2 1\n5 3\n1 1 2 2 1"], "outputs": ["3\n5"]}
423
44
coding
Solve the programming task below in a Python markdown code block. Given is a sequence of integers A_1, A_2, ..., A_N. If its elements are pairwise distinct, print YES; otherwise, print NO. -----Constraints----- - 2 ≤ N ≤ 200000 - 1 ≤ A_i ≤ 10^9 - All values in input are integers. -----Input----- Input is given fro...
{"inputs": ["5\n2 9 1 4 5", "5\n2 9 1 3 5", "5\n2 9 0 3 5", "5\n2 4 0 3 5", "5\n2 4 1 3 5", "5\n2 4 1 3 2", "5\n1 4 1 3 2", "5\n1 4 1 1 2"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
156
142
coding
Solve the programming task below in a Python markdown code block. A study has shown that playing a musical instrument helps in increasing one's IQ by 7 points. Chef knows he can't beat Einstein in physics, but he wants to try to beat him in an IQ competition. You know that Einstein had an IQ of 170, and Chef currently...
{"inputs": ["165", "120"], "outputs": ["Yes", "No"]}
407
22
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n soldiers standing in a line. Each soldier is assigned a unique rating value. You have to form a team of 3 soldiers amongst them under the following rules: Choose 3 soldiers with index (i, j, k) with ratin...
{"functional": "def check(candidate):\n assert candidate(rating = [2,5,3,4,1]) == 3\n assert candidate(rating = [2,1,3]) == 0\n assert candidate(rating = [1,2,3,4]) == 4\n\n\ncheck(Solution().numTeams)"}
173
76
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game. The board is a 3 x 3 array that consists of char...
{"functional": "def check(candidate):\n assert candidate(board = [\"O \",\" \",\" \"]) == False\n assert candidate(board = [\"XOX\",\" X \",\" \"]) == False\n assert candidate(board = [\"XOX\",\"O O\",\"XOX\"]) == True\n\n\ncheck(Solution().validTicTacToe)"}
233
84
coding
Solve the programming task below in a Python markdown code block. Oh no! You have stumbled upon a mysterious signal consisting of beeps of various lengths, and it is of utmost importance that you find out the secret message hidden in the beeps. There are long and short beeps, the longer ones roughly three times as lo...
{"functional": "_inputs = [['.... . .-.. .-.. --- .-- --- .-. .-.. -..'], ['.---- ... - .- -. -.. ..--- -. -..'], ['.. .- -- .- - . ... -'], ['.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----.'], ...
520
304
coding
Solve the programming task below in a Python markdown code block. We have the numbers with different colours with the sequence: ['red', 'yellow', 'blue']. That sequence colours the numbers in the following way: 1 2 3 4 5 6 7 8 9 10 11 12 13 ..... We have got the following recursive function:...
{"functional": "_inputs = [[3, 3, 'blue'], [100, 4, 'red'], [250, 6, 'yellow'], [1000, 7, 'red']]\n_outputs = [[[6, 15, 21]], [[136, 190, 253, 325]], [[]], [[1081, 1225, 1378, 1540, 1711, 1891, 2080]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math...
537
268
coding
Solve the programming task below in a Python markdown code block. All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position x_{i} — a coordinate on the Ox axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A pers...
{"inputs": ["2\n0 0\n", "2\n0 1\n", "2\n0 2\n", "2\n0 3\n", "2\n-1 1\n", "2\n-2 1\n", "2\n-4 1\n", "2\n-6 1\n"], "outputs": ["0 0\n0 0\n", "1 1\n1 1\n", "2 2\n2 2\n", "3 3\n3 3\n", "2 2\n2 2\n", "3 3\n3 3\n", "5 5\n5 5\n", "7 7\n7 7\n"]}
414
154
coding
Solve the programming task below in a Python markdown code block. Move every letter in the provided string forward 10 letters through the alphabet. If it goes past 'z', start again at 'a'. Input will be a string with length > 0. Also feel free to reuse/extend the following starter code: ```python def move_ten(st): ``...
{"functional": "_inputs = [['testcase'], ['codewars'], ['exampletesthere'], ['returnofthespacecamel'], ['bringonthebootcamp'], ['weneedanofficedog']]\n_outputs = [['docdmkco'], ['mynogkbc'], ['ohkwzvodocdrobo'], ['bodebxypdroczkmomkwov'], ['lbsxqyxdrolyydmkwz'], ['goxoonkxyppsmonyq']]\nimport math\ndef _deep_eq(a, b, t...
74
242
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n grid representing a field of cherries, each cell is one of three possible integers. 0 means the cell is empty, so you can pass through, 1 means the cell contains a cherry that you can pick up a...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,-1],[1,0,-1],[1,1,1]]) == 5\n assert candidate(grid = [[1,1,-1],[1,-1,1],[-1,1,1]]) == 0\n\n\ncheck(Solution().cherryPickup)"}
266
77
coding
Solve the programming task below in a Python markdown code block. SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same gr...
{"inputs": ["1\n0\n", "1\n0\n", "1\n-1\n", "1\n-2\n", "2\n5 5\n", "2\n2 0\n", "2\n0 2\n", "2\n0 1\n"], "outputs": ["1\n", "1 ", "1\n", "1\n", "3 0\n", "3 0\n", "3 0\n", "3 0\n"]}
358
103
coding
Solve the programming task below in a Python markdown code block. Let's call a number a binary decimal if it's a positive integer and all digits in its decimal notation are either $0$ or $1$. For example, $1\,010\,111$ is a binary decimal, while $10\,201$ and $787\,788$ are not. Given a number $n$, you are asked to re...
{"inputs": ["1\n1\n", "3\n121\n5\n1000000000\n"], "outputs": ["1\n", "2\n5\n1\n"]}
365
45
coding
Solve the programming task below in a Python markdown code block. Salmon received an array $A$ of size $N$ and an array $B$ of size $M$ for Christmas. He would like to move all the elements in $B$ to $A$ using a special method described below. While $B$ is not empty, Salmon does the following operations in order: * R...
{"inputs": ["5 3\n10 5 2 5 4\n3 1 2"], "outputs": ["5"]}
574
31
coding
Solve the programming task below in a Python markdown code block. The development of algae in a pond is as follows. Let the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds: - x_{i+1} = rx_i - D You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{20...
{"inputs": ["8 3 0", "8 0 0", "2 0 1", "1 1 1", "2 0 2", "4 0 2", "1 0 2", "2 1 0"], "outputs": ["-3\n-27\n-219\n-1755\n-14043\n-112347\n-898779\n-7190235\n-57521883\n-460175067\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n", "0\n-1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n", "4\n8\n16\n32\n...
340
377
coding
Solve the programming task below in a Python markdown code block. You are given N integer sequences A1, A2, ..., AN. Each of these sequences contains N elements. You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly grea...
{"inputs": ["1\n3\n1 2 3\n4 5 6\n7 8 9"], "outputs": ["18"]}
417
33
coding
Solve the programming task below in a Python markdown code block. Write a function called `sumIntervals`/`sum_intervals()` that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only be counted once. ### Intervals Intervals are represented by a pair of intege...
{"functional": "_inputs = [[[[1, 5]]]]\n_outputs = [[4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_de...
384
160
coding
Solve the programming task below in a Python markdown code block. Write a function that takes as its parameters *one or more numbers which are the diameters of circles.* The function should return the *total area of all the circles*, rounded to the nearest integer in a string that says "We have this much circle: xyz"...
{"functional": "_inputs = [[48, 7, 8, 9, 10], [1], [1, 1, 1, 2, 3, 4, 5], [894, 5778, 4839, 476], [4.5456, 746.5, 98.34, 344.543], [1, 1, 1], [13.58, 14.9, 56.99, 107.321], [56894.04839, 843975.4839, 4.08437403489], [5, 6, 7, 8, 9, 10, 105083, 48839, 4853, 28, 483]]\n_outputs = [['We have this much circle: 2040'], ['We...
173
502
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river. A frog, initially on the first stone, wants to travel to the last stone and then retu...
{"functional": "def check(candidate):\n assert candidate(stones = [0,2,5,6,7]) == 5\n assert candidate(stones = [0,3,9]) == 9\n\n\ncheck(Solution().maxJump)"}
204
57
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith ele...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,1,1,0]) == [1,4,2,0,0,0]\n assert candidate(nums = [0,1]) == [1,0]\n\n\ncheck(Solution().applyOperations)"}
221
69
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person. The population of some year x is the number of people alive during that year. The ith ...
{"functional": "def check(candidate):\n assert candidate(logs = [[1993,1999],[2000,2010]]) == 1993\n assert candidate(logs = [[1950,1961],[1960,1971],[1970,1981]]) == 1960\n\n\ncheck(Solution().maximumPopulation)"}
149
97
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N. You are allowed to perform the following types of operations on string S: Delete any one character from S, and concatenate the remaining parts of the string. For example, if we delete the third character of S ...
{"inputs": ["4\n2\n01\n3\n101\n3\n111\n4\n0000\n"], "outputs": ["1\n2\n1\n0\n"]}
576
44
coding
Solve the programming task below in a Python markdown code block. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that ...
{"inputs": ["2 1\n12\n", "2 1\n31\n", "2 1\n33\n", "2 1\n99\n", "3 1\n123\n", "3 1\n898\n", "3 2\n798\n", "3 2\n192\n"], "outputs": ["2\n22\n", "2\n33\n", "2\n33\n", "2\n99\n", "3\n222\n", "3\n999\n", "3\n808\n", "3\n202\n"]}
299
142
coding
Solve the programming task below in a Python markdown code block. Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the squ...
{"inputs": ["3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 3 4", "3 4 4\n1101\n0110\n1101\n1 1 3 4\n2 1 3 1\n2 2 3 4\n1 2 2 4", "3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n2 2 3 4", "3 4 4\n1101\n0110\n1101\n2 1 3 4\n2 1 3 1\n2 2 3 4\n1 2 2 4", "3 4 4\n1101\n1110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n2 2...
676
519
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers. All gar...
{"functional": "def check(candidate):\n assert candidate(n = 3, paths = [[1,2],[2,3],[3,1]]) == [1,2,3]\n assert candidate(n = 4, paths = [[1,2],[3,4]]) == [1,2,1,2]\n assert candidate(n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]) == [1,2,3,4]\n\n\ncheck(Solution().gardenNoAdj)"}
209
129
coding
Solve the programming task below in a Python markdown code block. Given a set of N natural numbers 1,2,3........N and Q query.For each query you have to calculate the total number of subset in which Ith. number of set come at Kth postion.Elements of every subset should be in sorted order. The answer could be very l...
{"inputs": ["1\n3 3\n1 2\n2 1\n3 2"], "outputs": ["0\n2\n2"]}
461
32
coding
Solve the programming task below in a Python markdown code block. There are N positive integers arranged in a circle. Now, the i-th number is A_i. Takahashi wants the i-th number to be B_i. For this objective, he will repeatedly perform the following operation: * Choose an integer i such that 1 \leq i \leq N. * Let a...
{"inputs": ["3\n1 1 1\n13 1 7", "3\n2 1 1\n13 5 7", "3\n2 1 1\n13 1 7", "3\n2 1 1\n13 2 7", "3\n2 1 1\n13 2 0", "3\n1 1 1\n13 2 0", "3\n1 1 1\n13 3 0", "3\n1 1 1\n13 4 0"], "outputs": ["4\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
366
166
coding
Solve the programming task below in a Python markdown code block. Little Dima has two sequences of points with integer coordinates: sequence (a_1, 1), (a_2, 2), ..., (a_{n}, n) and sequence (b_1, 1), (b_2, 2), ..., (b_{n}, n). Now Dima wants to count the number of distinct sequences of points of length 2·n that can be...
{"inputs": ["1\n1\n2\n7\n", "1\n1\n2\n7\n", "2\n1 2\n1 2\n4\n", "2\n1 2\n2 2\n4\n", "2\n1 2\n2 2\n4\n", "2\n1 2\n1 2\n4\n", "2\n1 2\n2 3\n11\n", "2\n1 2\n2 6\n11\n"], "outputs": ["1\n", "1\n", "1\n", "3\n", "3\n", "1\n", "2\n", "2\n"]}
541
144
coding
Solve the programming task below in a Python markdown code block. Ivan unexpectedly saw a present from one of his previous birthdays. It is array of $n$ numbers from $1$ to $200$. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, mor...
{"inputs": ["2\n2 9\n", "2\n1 9\n", "2\n1 2\n", "2\n1 3\n", "2\n2 21\n", "2\n1 21\n", "2\n3 30\n", "2\n1 30\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
422
106
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level. Return the minimum rounds requ...
{"functional": "def check(candidate):\n assert candidate(tasks = [2,2,3,3,2,4,4,4,4,4]) == 4\n assert candidate(tasks = [2,3,3]) == -1\n\n\ncheck(Solution().minimumRounds)"}
118
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed binary string s which represents the types of buildings along a street where: s[i] = '0' denotes that the ith building is an office and s[i] = '1' denotes that the ith building is a restaura...
{"functional": "def check(candidate):\n assert candidate(s = \"001101\") == 6\n assert candidate(s = \"11100\") == 0\n\n\ncheck(Solution().numberOfWays)"}
209
53
coding
Solve the programming task below in a Python markdown code block. Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited n...
{"inputs": ["1 1\n", "1 9\n", "1 2\n", "4 2\n", "9 3\n", "8 2\n", "1 3\n", "1 4\n"], "outputs": ["1\n", "9\n", "2\n", "3\n", "7\n", "4\n", "3\n", "4\n"]}
487
86
coding
Solve the programming task below in a Python markdown code block. You came to a local shop and want to buy some chocolate bars. There are $n$ bars in the shop, $i$-th of them costs $a_i$ coins (and you want to buy all of them). You have $m$ different coupons that allow you to buy chocolate bars. $i$-th coupon allows y...
{"inputs": ["2\n5 7\n1\n2\n", "2\n5 7\n1\n2\n", "2\n123456 656\n1\n2\n", "2\n123456 1214\n1\n2\n", "2\n1000000000 1\n1\n2\n", "2\n1000000000 1\n1\n2\n", "2\n123456 13640\n1\n2\n", "2\n170815 20668\n1\n2\n"], "outputs": ["7\n", "7\n", "123456\n", "123456\n", "1000000000\n", "1000000000\n", "123456\n", "170815\n"]}
601
223
coding
Solve the programming task below in a Python markdown code block. There is a circular pond with a perimeter of K meters, and N houses around them. The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond. When traveling between these houses, you can on...
{"inputs": ["7 3\n0 5 17", "7 3\n0 4 17", "7 3\n0 4 28", "7 3\n0 8 28", "7 3\n1 8 31", "9 3\n0 5 17", "7 3\n0 8 17", "7 3\n0 2 28"], "outputs": ["-5\n", "-6\n", "-17\n", "-13\n", "-16\n", "-3\n", "-2\n", "-19\n"]}
276
139
coding
Solve the programming task below in a Python markdown code block. # Task Given a number `n`, return a string representing it as a sum of distinct powers of three, or return `"Impossible"` if that's not possible to achieve. # Input/Output `[input]` integer `n` A positive integer n. `1 ≤ n ≤ 10^16`. `[output]` a...
{"functional": "_inputs = [[4], [2], [28], [84], [1418194818], [87754], [531441], [8312964441463288], [5559060566575209], [243]]\n_outputs = [['3^1+3^0'], ['Impossible'], ['3^3+3^0'], ['3^4+3^1'], ['Impossible'], ['3^10+3^9+3^8+3^7+3^5+3^3+3^1+3^0'], ['3^12'], ['Impossible'], ['3^33+3^9+3^1'], ['3^5']]\nimport math\nde...
328
327
coding
Solve the programming task below in a Python markdown code block. Vanja and Miksi have already finished everything for this year at their university, so they decided to spend their free time playing a game with a binary sequence $A_1, A_2, \dots, A_N$ (i.e. a sequence containing only integers $0$ and $1$). At the begin...
{"inputs": ["2\n2 1\n1 0\n3 5\n0 1 0"], "outputs": ["1\n2"]}
566
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will: Take their own seat if it is still available, a...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 1.00000\n\n\ncheck(Solution().nthPersonGetsNthSeat)"}
120
41
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given three integers x, y, and z. You have x strings equal to "AA", y strings equal to "BB", and z strings equal to "AB". You want to choose some (possibly all or none) of these strings and concatenate them in...
{"functional": "def check(candidate):\n assert candidate(x = 2, y = 5, z = 1) == 12\n assert candidate(x = 3, y = 2, z = 2) == 14\n\n\ncheck(Solution().longestString)"}
159
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules: The chosen integers have to be in the range [1, n]. Each integer can be chosen ...
{"functional": "def check(candidate):\n assert candidate(banned = [1,6,5], n = 5, maxSum = 6) == 2\n assert candidate(banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1) == 0\n assert candidate(banned = [11], n = 7, maxSum = 50) == 7\n\n\ncheck(Solution().maxCount)"}
144
109
coding
Solve the programming task below in a Python markdown code block. Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each p...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n0 0\n", "2\n1 2 1 2\n", "2\n2 1 1 2\n", "2\n2 1 1 2\n", "2\n1 2 1 2\n", "2\n1 1 2 2\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "2\n", "2\n", "1\n", "0\n"]}
484
122
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D array of strings equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] means that Ai / Bi = values[i]. Determine if there exists a contradiction in the equations...
{"functional": "def check(candidate):\n assert candidate(equations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"a\",\"c\"]], values = [3,0.5,1.5]) == False\n assert candidate(equations = [[\"le\",\"et\"],[\"le\",\"code\"],[\"code\",\"et\"]], values = [2,5,0.5]) == True\n\n\ncheck(Solution().checkContradictions)"}
171
103
coding
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 unique strings words. A palindrome pair is a pair of integers (i, j) such that: 0 <= i, j < words.length, i != j, and words[i] + words[j] (the concatenation of the two strings) is a...
{"functional": "def check(candidate):\n assert candidate(words = [\"abcd\",\"dcba\",\"lls\",\"s\",\"sssll\"]) == [[0,1],[1,0],[3,2],[2,4]] \n assert candidate(words = [\"bat\",\"tab\",\"cat\"]) == [[0,1],[1,0]] \n assert candidate(words = [\"a\",\"\"]) == [[0,1],[1,0]]\n\n\ncheck(Solution().palindromePairs)"}
145
110
coding
Solve the programming task below in a Python markdown code block. Nickname Generator Write a function, `nicknameGenerator` that takes a string name as an argument and returns the first 3 or 4 letters as a nickname. If the 3rd letter is a consonant, return the first 3 letters. If the 3rd letter is a vowel, return the...
{"functional": "_inputs = [['Jimmy'], ['Samantha'], ['Sam'], ['Kayne'], ['Melissa'], ['James'], ['Gregory'], ['Jeannie'], ['Kimberly'], ['Timothy'], ['Dani'], ['Saamy'], ['Saemy'], ['Saimy'], ['Saomy'], ['Saumy'], ['Boyna'], ['Kiyna'], ['Sayma'], ['Ni'], ['Jam'], ['Suv']]\n_outputs = [['Jim'], ['Sam'], ['Error: Name to...
176
323
coding
Solve the programming task below in a Python markdown code block. Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: ...
{"inputs": ["?0?", "?/?", "??0", "??/", "?.?", "??1", "?-?", "?,?"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
277
66
coding
Solve the programming task below in a Python markdown code block. Your task is to calculate the number of arrays such that: each array contains $n$ elements; each element is an integer from $1$ to $m$; for each array, there is exactly one pair of equal elements; for each array $a$, there exists an index $i$ such th...
{"inputs": ["3 4\n", "3 5\n", "2 2\n", "3 3\n", "2 3\n", "3 3\n", "2 2\n", "2 3\n"], "outputs": ["6\n", "10\n", "0\n", "3\n", "0\n", "3\n", "0\n", "0\n"]}
371
87
coding
Solve the programming task below in a Python markdown code block. Given a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node stores a positive integer Vi. Define Pi as follows: Pi=Vi if the i-th node is a leaf, otherwise Pi=max(Vi*PL, Vi*PR), where L...
{"inputs": ["2\n1 2 3\n3\n3 1 5 2 6 4 7\n0"], "outputs": ["3\n105"]}
306
40
coding
Solve the programming task below in a Python markdown code block. # Right in the Center _This is inspired by one of Nick Parlante's exercises on the [CodingBat](https://codingbat.com/java) online code practice tool._ Given a sequence of characters, does `"abc"` appear in the CENTER of the sequence? The sequence of c...
{"functional": "_inputs = [['abc'], ['abcabcabc'], ['AAabcBBB'], ['AAAabcBB'], ['AAAAabcBB'], ['AAabcabcBB'], ['abcabcabcabc'], ['AabcBBB'], [''], ['ABC'], ['abcZ'], ['Yabc']]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [False], [False], [False], [True], [True]]\nimport math\ndef _deep_eq(a,...
222
240
coding
Solve the programming task below in a Python markdown code block. The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kin...
{"inputs": ["1 1 0 2\n9\n7\n", "1 1 0 0\n1\n1\n", "1 1 0 0\n1\n2\n", "1 1 2 1\n7\n8\n", "1 1 1 0\n1\n1\n", "1 1 0 0\n9\n7\n", "1 1 0 0\n1\n4\n", "1 1 2 1\n7\n6\n"], "outputs": ["0\n", "1\n1 1\n", "0\n", "1\n1 1\n", "1\n1 1\n", "0\n", "0\n", "1\n1 1\n"]}
657
166
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtrans...
{"inputs": ["5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 3 0\n3 5\n4 2\n2 5\n", "5 3\n2 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 5 0\n3 5\n4 2\n2 5\n", "5 3\n2 2 1 3 2\n3 5\n4 3\n2 5\n", "5 3\n4 2 1 0 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 2 5 0\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 2\n3 5\n4 3\n2 5\n"], "outputs": ["20\n", "18\n",...
655
270
coding
Solve the programming task below in a Python markdown code block. The look and say sequence is a sequence in which each number is the result of a "look and say" operation on the previous element. Considering for example the classical version startin with `"1"`: `["1", "11", "21, "1211", "111221", ...]`. You can see th...
{"functional": "_inputs = [['1', 1], ['1', 3], ['1', 5], ['22', 10], ['14', 2]]\n_outputs = [['1'], ['21'], ['111221'], ['22'], ['1114']]\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, (...
318
210
coding
Solve the programming task below in a Python markdown code block. You are given a matrix with $n$ rows (numbered from $1$ to $n$) and $m$ columns (numbered from $1$ to $m$). A number $a_{i, j}$ is written in the cell belonging to the $i$-th row and the $j$-th column, each number is either $0$ or $1$. A chip is initial...
{"inputs": ["1\n6 4\n0 1 1 0\n0 1 1 0\n0 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 1 1\n", "1\n6 4\n0 1 1 0\n0 1 1 0\n0 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 1 1\n", "1\n6 4\n0 1 1 1\n0 1 1 0\n0 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 1 1\n", "1\n6 4\n0 1 1 0\n0 1 1 0\n1 1 1 0\n0 1 1 0\n1 1 1 1\n1 1 0 1\n", "1\n6 4\n0 1 1 0\n1 1 1 0\n1 1 1 0\n0 1 1 0\...
711
486
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game with a rooted tree. The tree has $N$ vertices and the first node, $1$, is always the root. Here are the basic rules: They move in alternating turns, and both players always move optimally. During each move, a player remo...
{"inputs": ["1\n5\n1 2\n3 1\n3 4\n4 5\n"], "outputs": ["Alice\n"]}
519
32