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. "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher ...
{"inputs": ["1\n1\n", "1\n6\n", "1\n0\n", "1\n3\n", "1\n3\n", "1\n1\n", "1\n6\n", "1\n0\n"], "outputs": ["0", "0", "0", "0", "0\n", "0\n", "0\n", "0\n"]}
coding
413
Solve the programming task below in a Python markdown code block. There are n points on a straight line, and the i-th point among them is located at x_{i}. All these coordinates are distinct. Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring...
{"inputs": ["3\n1 4 7\n", "3\n1 4 6\n", "3\n1 2 6\n", "3\n1 3 6\n", "3\n1 4 7\n", "3\n1 3 6\n", "3\n1 4 6\n", "3\n1 2 6\n"], "outputs": ["0\n", "3\n", "3\n", "3\n", "0\n", "3\n", "3\n", "3\n"]}
coding
301
Solve the programming task below in a Python markdown code block. Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meet...
{"inputs": ["1\n?\n", "1\nq\n", "1\np\n", "1\nr\n", "1\ns\n", "1\nt\n", "1\nu\n", "1\no\n"], "outputs": ["a", "q", "p\n", "r\n", "s\n", "t\n", "u\n", "o\n"]}
coding
487
Solve the programming task below in a Python markdown code block. When you want to get the square of a binomial of two variables x and y, you will have: `$(x+y)^2 = x^2 + 2xy + y ^2$` And the cube: `$(x+y)^3 = x^3 + 3x^2y + 3xy^2 +y^3$` It is known from many centuries ago that for an exponent n, the result of a bin...
{"functional": "_inputs = [[0], [1], [2], [3], [6], [10]]\n_outputs = [[[1, 1]], [[1, 2, 3]], [[1, 2, 4, 7]], [[1, 2, 4, 8, 15]], [[1, 2, 4, 8, 16, 32, 64, 127]], [[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2047]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
441
Solve the programming task below in a Python markdown code block. Alex, Bob, and, Chef are standing on the coordinate plane. Chef is standing at the origin (coordinates (0, 0)) while the location of Alex and Bob are (X_{1}, Y_{1}) and (X_{2}, Y_{2}) respectively. Amongst Alex and Bob, find out who is at a farther dist...
{"inputs": ["3\n-1 0 3 4\n3 4 -4 -3\n8 -6 0 5\n"], "outputs": ["BOB\nEQUAL\nALEX"]}
coding
458
Solve the programming task below in a Python markdown code block. There are N points on X-Y plane with integer coordinates (xi, yi). You are given a set of polygons with all of its edges parallel to the axes (in other words, all angles of the polygons are 90 degree angles and all lines are in the cardinal directions. T...
{"inputs": ["6 1\n1 1\n3 3\n3 5\n5 2\n6 3\n7 4\n10\n1 3\n1 6\n4 6\n4 3\n6 3\n6 1\n4 1\n4 2\n3 2\n3 3\n", "16 2\n0 0\n0 1\n0 2\n0 3\n1 0\n1 1\n1 2\n1 3\n2 0\n2 1\n2 2\n2 3\n3 0\n3 1\n3 2\n3 3\n8\n0 0\n0 1\n1 1\n1 2\n0 2\n0 3\n3 3\n3 0\n4\n0 0\n0 1\n1 1\n1 0\n"], "outputs": ["4\n", "16\n4\n"]}
coding
600
Solve the programming task below in a Python markdown code block. You are given a grid with $n$ rows and $m$ columns. Rows and columns are numbered from $1$ to $n$, and from $1$ to $m$. The intersection of the $a$-th row and $b$-th column is denoted by $(a, b)$. Initially, you are standing in the top left corner $(1, ...
{"inputs": ["6\n1 1\n2 1\n1 3\n4 2\n4 6\n10 5\n"], "outputs": ["0\n1\n-1\n6\n10\n17\n"]}
coding
561
Solve the programming task below in a Python markdown code block. One day, Tanya was studying graph theory. She is very inquisitive, so the following problem soon came to her mind. Find the number of undirected unweighted connected simple graphs with $N$ vertices (numbered $1$ through $N$) and $M$ edges, such that for ...
{"inputs": ["3\n4 3\n1 2 1\n4 6\n1 2 1\n3 2\n2 2"], "outputs": ["2\n0\n0"]}
coding
596
Solve the programming task below in a Python markdown code block. A penguin Rocher has $n$ sticks. He has exactly one stick with length $i$ for all $1 \le i \le n$. He can connect some sticks. If he connects two sticks that have lengths $a$ and $b$, he gets one stick with length $a + b$. Two sticks, that were used in ...
{"inputs": ["4\n1\n2\n3\n4\n", "4\n1\n2\n3\n8\n", "4\n1\n2\n1\n4\n", "4\n2\n2\n3\n5\n", "4\n1\n2\n4\n4\n", "4\n1\n3\n1\n4\n", "4\n1\n2\n5\n4\n", "4\n1\n3\n3\n5\n"], "outputs": ["1\n1\n2\n2\n", "1\n1\n2\n4\n", "1\n1\n1\n2\n", "1\n1\n2\n3\n", "1\n1\n2\n2\n", "1\n2\n1\n2\n", "1\n1\n3\n2\n", "1\n2\n2\n3\n"]}
coding
399
Solve the programming task below in a Python markdown code block. Problem Statement 2 players, Cyborg and Geno are playing a game on a matrix. In each turn, the player choses a number from the matrix which is not selected yet and adds the number to his sum. In the end, the player with the largest sum wins the game. As...
{"inputs": ["3\n1 1\n3\n2 3\n4 4 4\n4 4 4\n2 3\n4 3 4\n4 4 4"], "outputs": ["Cyborg\nDraw\nCyborg"]}
coding
439
Solve the programming task below in a Python markdown code block. Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered bot...
{"inputs": ["1 2 1\n1\n2 1\n", "1 2 1\n1\n2 1\n", "1 2 1\n2\n2 1\n", "1 2 31\n1\n1 2\n", "1 2 23\n1\n1 2\n", "1 2 31\n1\n1 2\n", "2 2 2\n2 1\n1 2\n", "2 2 2\n2 1\n1 2\n"], "outputs": ["1\n", "1\n", "2\n", "62\n", "46\n", "\n62\n", "2\n", "2\n"]}
coding
660
Solve the programming task below in a Python markdown code block. The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t_1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x...
{"inputs": ["4 2 4\n3 4\n1 1\n", "5 4 0\n1 2\n3 1\n", "2 0 2\n1 1\n1 1\n", "5 4 2\n1 2\n3 1\n", "4 2 4\n3 4\n2 1\n", "6 4 2\n1 2\n3 1\n", "3 1 3\n1 2\n1 1\n", "2 2 0\n7 3\n1 1\n"], "outputs": ["8\n", "7\n", "2\n", "4\n", "6\n", "4\n", "2\n", "6\n"]}
coding
699
Solve the programming task below in a Python markdown code block. You are given two numbers A and B along with an integer X. In one operation you can do one of the following: Set A = A + X and B = B - X Set A = A - X and B = B + X Determine if you can make A and B equal after applying the operation any number of times...
{"inputs": ["4\n5 7 1\n3 4 2\n4 4 6\n2 5 3\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
385
Solve the programming task below in a Python markdown code block. Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share referenc...
{"inputs": ["340\n5277\n9302\n7274\n3\n5968\n1327\n255\n27\n5665\n8104\n138\n4051\n4168\n507\n7773\n2688\n3497\n4074\n1403\n3599\n2007\n7621\n3124\n1195\n7245\n1979\n3365\n6607\n4816\n9336\n3620\n1557\n3404\n5451\n3739\n2504\n1845\n5533\n8298\n2893\n7814\n2505\n9785\n4709\n7880\n6262\n5135\n2088\n9309\n7259\n9993\n325\...
coding
208
Solve the programming task below in a Python markdown code block. There is a game called "Unique Bid Auction". You can read more about it here: https://en.wikipedia.org/wiki/Unique_bid_auction (though you don't have to do it to solve this problem). Let's simplify this game a bit. Formally, there are $n$ participants...
{"inputs": ["2\n2\n1 1\n1\n1\n", "2\n2\n1 1\n1\n1\n", "2\n2\n1 2\n1\n1\n", "2\n6\n1 1 1 3 3 3\n4\n1 1 1 3\n", "2\n6\n1 1 1 3 3 3\n4\n1 1 1 3\n", "2\n6\n1 1 1 3 6 3\n4\n1 1 1 3\n", "2\n6\n1 1 1 3 6 3\n4\n1 1 1 1\n", "2\n6\n1 1 2 3 6 3\n4\n1 1 1 1\n"], "outputs": ["-1\n1\n", "-1\n1\n", "1\n1\n", "-1\n4\n", "-1\n4\n", "5\...
coding
503
Solve the programming task below in a Python markdown code block. The Aizu Wakamatsu city office decided to lay a hot water pipeline covering the whole area of the city to heat houses. The pipeline starts from some hot springs and connects every district in the city. The pipeline can fork at a hot spring or a district,...
{"inputs": ["3 5\n0 8 25 56 0\n9 13 16 0 17\n20 9 16 10 22\n17 27 18 16\n2 4 0\n2 5\n21\n0 0", "3 5\n22 4 30 19 71\n5 12 11 0 8\n5 8 1 11 19\n17 21 19 16\n9 12 0\n19 3\n6\n0 0", "3 5\n0 8 30 19 44\n6 12 9 0 8\n30 8 16 4 22\n17 21 18 16\n7 12 0\n19 2\n21\n0 0", "3 5\n12 8 2 19 44\n5 12 16 0 8\n30 8 0 10 22\n17 21 18 16\...
coding
591
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef and his friend John have not see each other for years. They are both are looking forward to meeting again in the city they both grew up in. The city has N public square...
{"inputs": ["2\n6 2\n1 3 1\n2 3 2\n3 4 3\n4 5 4\n4 6 5\n1 5\n6 6\n1 3 1\n2 3 2\n3 4 3\n4 5 4\n4 6 5\n1 2 3 4 5 6"], "outputs": ["4 1\n29 6"]}
coding
671
Solve the programming task below in a Python markdown code block. Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with n vertices and a root in the vertex 1. There is an ant in each leaf of the tree. In one second some ants can simu...
{"inputs": ["2\n2 1\n", "10\n1 3\n4 3\n10 4\n5 6\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n10 4\n5 5\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n10 4\n7 5\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n10 6\n7 5\n6 2\n5 2\n7 5\n7 8\n7 9\n", "10\n1 3\n4 3\n9 4\n10 6\n6 2\n5 2\n7 6\n8 8\n7 9\n", "10\n1 3\n4 2\n10 4\n8 6\n...
coding
301
Solve the programming task below in a Python markdown code block. You are given four integers $a$, $b$, $x$ and $y$. Initially, $a \ge x$ and $b \ge y$. You can do the following operation no more than $n$ times: Choose either $a$ or $b$ and decrease it by one. However, as a result of this operation, value of $a$ can...
{"inputs": ["1\n10 10 8 5 3\n", "1\n10 10 8 5 3\n", "1\n10 10 8 1 3\n", "1\n10 10 0 1 3\n", "1\n10 10 10 5 3\n", "1\n10 10 10 5 4\n", "1\n10 20 10 5 3\n", "1\n10 10 10 5 0\n"], "outputs": ["70\n", "70\n", "70\n", "70\n", "70\n", "60\n", "170\n", "100\n"]}
coding
661
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle. Two rectangles i and j (i < j) are consider...
{"functional": "def check(candidate):\n assert candidate(rectangles = [[4,8],[3,6],[10,20],[15,30]]) == 6\n assert candidate(rectangles = [[4,5],[7,8]]) == 0\n\n\ncheck(Solution().interchangeableRectangles)"}
coding
153
Solve the programming task below in a Python markdown code block. Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p_1, p_2, ..., p_{n}], where p_{i} denotes the n...
{"inputs": ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n5 4 3 2 1\n1 5 3\n1 5 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n5 4 3 2 1\n1 5 4\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n3 4 4\n2 5 3\n", "5 5\n5 4 6 2 1\n1 5 4\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n8 4 3 2 1\n1 5 3\n1 3 1\n2 ...
coding
686
Solve the programming task below in a Python markdown code block. Imagine you start on the 5th floor of a building, then travel down to the 2nd floor, then back up to the 8th floor. You have travelled a total of 3 + 6 = 9 floors of distance. Given an array representing a series of floors you must reach by elevator, re...
{"functional": "_inputs = [[[5, 2, 8]], [[1, 2, 3]], [[7, 1, 7, 1]]]\n_outputs = [[9], [2], [18]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len...
coding
235
Please solve the programming task below using a self-contained code snippet in a markdown code block. The Tribonacci sequence Tn is defined as follows:  T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn.   Please complete the following python code precisely: ```python clas...
{"functional": "def check(candidate):\n assert candidate(n = 4) == 4\n assert candidate(n = 25) == 1389537\n\n\ncheck(Solution().tribonacci)"}
coding
111
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting only of lowercase English letters. In one move, you can select any two adjacent characters of s and swap them. Return the minimum number of moves needed to make s a palindrome. Note...
{"functional": "def check(candidate):\n assert candidate(s = \"aabb\") == 2\n assert candidate(s = \"letelt\") == 2\n\n\ncheck(Solution().minMovesToMakePalindrome)"}
coding
111
Solve the programming task below in a Python markdown code block. Create a program that calculates and outputs the surface distance by inputting the north latitude and east longitude of two cities on the earth. However, the earth is a sphere with a radius of 6,378.1 km, and the surface distance between two points is th...
{"inputs": ["35.68 139.77 51.15 359.82\n1.37 103.92 41.78 272.25\n51.15 359.82 -34.58 301.52\n-1 -1 -1 -1", "35.68 139.77 51.15 360.3067312023825\n1.37 103.92 41.78 272.25\n51.15 359.82 -34.58 301.52\n-1 -1 -1 -1", "35.68 139.77 51.15 359.82\n1.37 103.92 41.78 272.25\n51.15 359.82 -34.03920544232073 301.52\n-1 -1 -1 -1...
coding
513
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr). Return the maximum absolute sum of any (possibly empty) subarr...
{"functional": "def check(candidate):\n assert candidate(nums = [1,-3,2,3,-4]) == 5\n assert candidate(nums = [2,-5,1,-4,3,-2]) == 8\n\n\ncheck(Solution().maxAbsoluteSum)"}
coding
158
Solve the programming task below in a Python markdown code block. *"You have a reason to leave this place, but I don't."* In the fourth game, Sang-Woo and Ali are competing against each other. Sang-Woo is the more intelligent one between them, and he plans to win the game by cheating. Ali is your childhood friend and ...
{"inputs": ["3\n5\nab?c?\naeg?k\n6\nabcde?\nehio??\n4\nabcd\nabcd"], "outputs": ["4\n6\n0"]}
coding
722
Solve the programming task below in a Python markdown code block. Given two arrays A and B each of length N. Find the value \sum_{i=1}^N\sum_{j=1}^N \max(A_{i}\oplus B_{j},A_{i}\& B_{j}). Here \oplus and \& denote the [bitwise XOR operation] and [bitwise AND operation] respectively. ------ Input Format ------ ...
{"inputs": ["3\n2\n3 4\n1 2\n1\n0\n0\n3\n2 4 3\n1 2 1"], "outputs": ["15\n0\n30"]}
coding
729
Solve the programming task below in a Python markdown code block. One day, $n$ people ($n$ is an even number) met on a plaza and made two round dances, each round dance consists of exactly $\frac{n}{2}$ people. Your task is to find the number of ways $n$ people can make two round dances if each round dance consists of ...
{"inputs": ["2\n", "4\n", "8\n", "6\n", "6\n", "2\n", "4\n", "8\n"], "outputs": ["1\n", "3\n", "1260\n", "40\n", "40\n", "1\n", "3\n", "1260\n"]}
coding
461
Solve the programming task below in a Python markdown code block. Polycarp found the string $s$ and the permutation $p$. Their lengths turned out to be the same and equal to $n$. A permutation of $n$ elements — is an array of length $n$, in which every integer from $1$ to $n$ occurs exactly once. For example, $[1, 2, ...
{"inputs": ["1\n12\nzsmlzcqpszjy\n2 3 4 5 6 7 8 9 10 11 12 1\n", "3\n5\nababa\n3 4 5 2 1\n5\nababa\n2 1 4 5 3\n10\ncodeforces\n8 6 1 7 5 2 9 3 10 4\n", "1\n26\nofnbnccxwsnaxyjwnmefjhkwmi\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1\n", "1\n78\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqq...
coding
653
Solve the programming task below in a Python markdown code block. A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beauti...
{"inputs": ["7\n", "3\n", "5\n", "4\n", "2\n", "1\n", "74\n", "88\n"], "outputs": ["-1\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
361
Solve the programming task below in a Python markdown code block. Alice and Bob were having an argument about which of them is taller than the other. Charlie got irritated by the argument, and decided to settle the matter once and for all. Charlie measured the heights of Alice and Bob, and got to know that Alice's hei...
{"inputs": ["2\n150 160\n160 150"], "outputs": ["B\nA"]}
coding
352
Solve the programming task below in a Python markdown code block. Alice has a standard deck of 52 cards. She wants to play a card game with K-1 of her friends. This particular game requires each person to have an equal number of cards, so Alice needs to discard a certain number of cards from her deck so that she can eq...
{"inputs": ["4\n3\n50\n2\n14\n"], "outputs": ["1\n2\n0\n10\n"]}
coding
413
Solve the programming task below in a Python markdown code block. It is the World Cup Finals. Chef only finds a match interesting if the skill difference of the competing teams is *less than or equal to* D. Given that the skills of the teams competing in the final are X and Y respectively, determine whether Chef will ...
{"inputs": ["3\n5 3 4\n5 3 1\n5 5 0\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
335
Solve the programming task below in a Python markdown code block. In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And d...
{"inputs": ["2\n2 3\n", "2\n2 3\n", "3\n2 3 5\n", "3\n2 3 5\n", "3\n2 3 4\n", "4\n2 4 4 2\n", "4\n2 2 3 5\n", "1\n1000000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "0\n", "0\n"]}
coding
515
Solve the programming task below in a Python markdown code block. Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar...
{"inputs": ["1 7\n", "1 1\n", "2 7\n", "2 1\n", "8 6\n", "1 1\n", "1 2\n", "1 3\n"], "outputs": ["6\n", "5\n", "5\n", "4\n", "6\n", "5\n", "5\n", "5\n"]}
coding
504
Solve the programming task below in a Python markdown code block. This is a beginner friendly kata especially for UFC/MMA fans. It's a fight between the two legends: Conor McGregor vs George Saint Pierre in Madison Square Garden. Only one fighter will remain standing, and after the fight in an interview with Joe Roga...
{"functional": "_inputs = [['George Saint Pierre'], ['Conor McGregor'], ['george saint pierre'], ['conor mcgregor']]\n_outputs = [['I am not impressed by your performance.'], [\"I'd like to take this chance to apologize.. To absolutely NOBODY!\"], ['I am not impressed by your performance.'], [\"I'd like to take this ch...
coding
162
Solve the programming task below in a Python markdown code block. In elementary arithmetic a "carry" is a digit that is transferred from one column of digits to another column of more significant digits during a calculation algorithm. This Kata is about determining the number of carries performed during the addition o...
{"functional": "_inputs = [['123 456\\n555 555\\n123 594'], ['321 679\\n098 805\\n123 867'], ['123 457\\n631 372\\n999 111'], ['123 457\\n123 456\\n654 312\\n999 000\\n123 457'], ['1 9\\n123456789 111111101\\n01 09\\n11 09\\n123 457'], ['99 99']]\n_outputs = [['No carry operation\\n3 carry operations\\n1 carry operatio...
coding
225
Solve the programming task below in a Python markdown code block. Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements. He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, t...
{"inputs": ["6\n2\n5\n9\n6\n1\n54", "6\n2\n5\n9\n6\n2\n54", "6\n2\n5\n9\n6\n2\n76", "6\n2\n5\n9\n6\n2\n85", "6\n2\n1\n9\n6\n2\n85", "6\n2\n1\n9\n6\n2\n54", "6\n2\n1\n6\n6\n2\n54", "6\n4\n1\n6\n6\n2\n54"], "outputs": ["6", "6", "6", "6", "6", "6", "6", "5"]}
coding
364
Solve the programming task below in a Python markdown code block. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the fo...
{"inputs": ["0 0\n", "0 0\n", "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n", "2 3\naaaaa\nacacaca\naabaa\nccbcacc\ncaaac\n", "1 3\naaaaa\nacacaca\naabaa\nccbcacc\ncaaac\n", "1 3\nabaaa\nacacaca\naabaa\nccbcacc\ncaaac\n", "2 3\naaaaa\nacacaca\naabaa\ndcacacc\ncaaac\n", "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n"], "...
coding
338
Solve the programming task below in a Python markdown code block. Instead of writing,$a \times (b+c) = a \times b + a \times c$, Joe by mistakenly swapped the $\times$ and + signs on the left hand side. The equation became, $a+(b \times c)= a \times b + a \times c$ ? Joe somehow knew the value of a, but forgot the val...
{"inputs": ["2"], "outputs": ["4\n"]}
coding
232
Please solve the programming task below using a self-contained code snippet in a markdown code block. At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you and order one at a time (in the order specified by bills). Each customer will only buy one lemonade and pay with either a ...
{"functional": "def check(candidate):\n assert candidate(bills = [5,5,5,10,20]) == True\n assert candidate(bills = [5,5,10,10,20]) == False\n\n\ncheck(Solution().lemonadeChange)"}
coding
181
Solve the programming task below in a Python markdown code block. Jim is doing his discrete maths homework which requires him to repeatedly calculate ^{n}C_{r}(n choose r) for different values of n. Knowing that this is time consuming, he goes to his sister June for help. June, being a computer science student knows h...
{"inputs": ["3\n2\n4\n5\n"], "outputs": ["1 2 1\n1 4 6 4 1\n1 5 10 10 5 1\n"]}
coding
378
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share...
{"functional": "def check(candidate):\n assert candidate(mat = [[0,0],[0,1]]) == 3\n assert candidate(mat = [[0]]) == 0\n assert candidate(mat = [[1,0,0],[1,0,0]]) == -1\n\n\ncheck(Solution().minFlips)"}
coding
163
Solve the programming task below in a Python markdown code block. You are appointed director of a famous concert hall, to save it from bankruptcy. The hall is very popular, and receives many requests to use its two fine rooms, but unfortunately the previous director was not very efficient, and it has been losing money ...
{"inputs": ["4\n1 2 10\n2 3 10\n3 3 2\n1 3 13\n6\n1 20 1000\n3 25 10000\n5 30 5000\n22 300 5500\n7 295 9000\n7 7 6000\n8\n32 251 2261\n123 281 1339\n188 235 5641\n174 217 7273\n22 255 7851\n60 198 9190\n119 274 878\n122 173 8640\n0", "4\n1 2 10\n2 3 10\n3 3 10\n1 3 10\n6\n1 20 1000\n3 25 00000\n5 15 5000\n22 165 5500\n...
coding
643
Solve the programming task below in a Python markdown code block. Two players (numbered $\mbox{1}$ and $2$) are playing a game of Tower Breakers! The rules of the game are as follows: Player $\mbox{1}$ always moves first, and both players always move optimally. Initially there are $N$ towers of various heights. The pl...
{"inputs": ["2\n2 \n1 2\n3 \n1 2 3\n"], "outputs": ["1\n2\n"]}
coding
507
Solve the programming task below in a Python markdown code block. Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use them. Let’...
{"inputs": ["2 10 3\n100 3\n99 1\n", "2 100 2\n100 2\n100 2\n", "2 1000 1\n100 1\n100 1\n", "2 1000 1\n100 1\n100 2\n", "2 1001 0\n101 1\n100 2\n", "2 1000 1\n101 1\n100 2\n", "2 1001 1\n101 1\n100 2\n", "2 100 10\n100 11\n90 9\n"], "outputs": ["NO\n", "YES\n51 2\n0 1\n1 2\n", "YES\n1001 2\n0 1\n1 2\n", "YES\n501 2\n0 ...
coding
628
Solve the programming task below in a Python markdown code block. A spy needs your help to encrypt a 5 letter message. To encrypt the message the following steps are need to be done: 1)Each letter of the message will be converted to it's equivalent number (i.e A=0, B=1,..Z=25) 2)98, 57, 31, 45, 46 are the 5 numbers i...
{"inputs": ["2\nHELLO\nHELL"], "outputs": ["BJQEI\nBJQE"]}
coding
568
Solve the programming task below in a Python markdown code block. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers f...
{"inputs": ["3 2 2 2\n* * +\n", "1 2 3 4\n* + *\n", "2 2 2 2\n* * +\n", "1 1 1 1\n+ + *\n", "1 2 3 4\n* + +\n", "15 1 3 1\n* * +\n", "8 1 7 14\n+ + +\n", "7 0 8 15\n+ + *\n"], "outputs": ["10\n", "10\n", "8\n", "3\n", "9\n", "18\n", "30\n", "0\n"]}
coding
329
Solve the programming task below in a Python markdown code block. # How much is the fish! (- Scooter ) The ocean is full of colorful fishes. We as programmers want to know the hexadecimal value of these fishes. ## Task Take all hexadecimal valid characters (a,b,c,d,e,f) of the given name and XOR them. Return the resul...
{"functional": "_inputs = [['pufferfish'], ['puffers'], ['balloonfish'], ['blowfish'], ['bubblefish'], ['globefish'], ['swellfish'], ['toadfish'], ['toadies'], ['honey toads'], ['sugar toads'], ['sea squab'], [''], ['Aeneus corydoras'], ['African glass catfish'], ['African lungfish'], ['Aholehole'], ['Airbreathing catf...
coding
145
Solve the programming task below in a Python markdown code block. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ ...
{"inputs": ["2 2\n40 90\n", "2 2\n61441 92480\n", "2 5\n49248 87211\n", "2 2\n44358 92480\n", "2 5\n77821 87211\n", "2 2\n44358 24160\n", "6 4\n1 3 9 8 24 1\n", "6 4\n1 3 1 8 24 1\n"], "outputs": ["1", "0", "0", "0\n", "0\n", "0\n", "1\n", "3\n"]}
coding
286
Solve the programming task below in a Python markdown code block. Chef is playing Ludo. According to the rules of Ludo, a player can enter a new token into the play only when he rolls a 6 on the die. In the current turn, Chef rolled the number X on the die. Determine if Chef can enter a new token into the play in the ...
{"inputs": ["3\n1\n6\n3\n"], "outputs": ["NO\nYES\nNO\n"]}
coding
288
Solve the programming task below in a Python markdown code block. For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfies the condition: $1 \leq l \leq r \leq N$ and $a_l + a_{l+1} + ... + a...
{"inputs": ["6 5\n1 2 3 2 6 6\n6 9 5 21 15", "6 5\n1 2 4 2 6 6\n6 9 5 21 15", "6 5\n1 2 4 2 6 7\n6 9 5 21 15", "6 5\n1 4 0 2 7 6\n6 1 3 21 15", "6 5\n0 2 4 2 6 6\n6 9 5 21 15", "6 5\n1 2 3 4 7 6\n6 9 12 21 15", "6 5\n1 2 3 2 7 6\n6 9 12 21 15", "6 5\n1 2 3 5 5 6\n6 9 12 21 15"], "outputs": ["10\n13\n7\n21\n18\n", "9\n1...
coding
296
Solve the programming task below in a Python markdown code block. On a certain train, Chef-the ticket collector, collects a fine of Rs. X if a passenger is travelling without a ticket. It is known that a passenger carries either a single ticket or no ticket. P passengers are travelling and they have a total of Q tick...
{"inputs": ["4\n4 1 1\n2 10 7\n8 5 4\n9 7 0"], "outputs": ["0\n6\n8\n63"]}
coding
461
Solve the programming task below in a Python markdown code block. Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi wi...
{"inputs": ["2 3\n2 1 3\n2 1 3\n2 1 3", "1 3\n2 1 3\n2 1 3\n2 1 3", "1 3\n2 1 3\n2 1 4\n2 1 3", "3 3\n2 1 3\n2 1 3\n2 1 3", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 6 5\n2 5 4 3 1", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 6 7\n2 5 4 3 1", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 0 1 4 5\n2 5 ...
coding
426
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 recently visited ShareChat Cafe and was highly impressed by the food. Being a food enthusiast, he decided to enquire about the ingredients of ea...
{"inputs": ["2\n3\nabcaa\nbcbd\nbgc\n3\nquick\nbrown\nfox"], "outputs": ["2\n0"]}
coding
515
Solve the programming task below in a Python markdown code block. E869120's and square1001's 16-th birthday is coming soon. Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces. E869120 and square1001 were just about to eat A and B of those pieces, respectively, when they found a ...
{"inputs": ["0 8", "5 1", "0 9", "8 1", "8 0", "5 5", "5 2", "3 1"], "outputs": ["Yay!\n", "Yay!\n", ":(\n", "Yay!\n", "Yay!\n", "Yay!\n", "Yay!\n", "Yay!\n"]}
coding
245
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Lately, Chef has been inspired by the "pawri" meme. Therefore, he decided to take a string $S$ and change each of its substrings that spells "party" to "pawr...
{"inputs": ["3\npart\npartypartiparty\nyemaihuyemericarhaiauryahapartyhorahihai"], "outputs": ["part\npawripartipawri\nyemaihuyemericarhaiauryahapawrihorahihai"]}
coding
335
Solve the programming task below in a Python markdown code block. -----Input----- The input contains a single integer a (10 ≤ a ≤ 999). -----Output----- Output 0 or 1. -----Examples----- Input 13 Output 1 Input 927 Output 1 Input 48 Output 0
{"inputs": ["13\n", "48\n", "10\n", "33\n", "25\n", "10\n", "33\n", "25\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]}
coding
74
Solve the programming task below in a Python markdown code block. Toby has found a game to entertain himself.The game is like this: You are in a coordinate system initially at (0,0) and you are given a sequence of steps which lead to your destination.The steps are given in the form of directions: ’U’ ,’D’ , ’L’ and ‘R...
{"inputs": ["3\n7\nULUDLLU\n4\nRUUR\n4\nLRLR"], "outputs": ["2\n0\n4"]}
coding
518
Solve the programming task below in a Python markdown code block. N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the sc...
{"inputs": ["6 1 2 2\n2 1 1 5 0 2", "6 1 5 2\n2 1 1 3 1 2", "6 1 2 2\n2 1 1 5 0 0", "6 1 2 4\n2 1 1 5 0 0", "6 1 5 1\n3 1 1 3 0 2", "6 1 2 1\n1 1 1 5 0 2", "6 1 5 2\n2 0 1 3 1 2", "6 1 2 4\n2 1 1 2 0 0"], "outputs": ["5\n", "3\n", "4\n", "6\n", "2\n", "1\n", "3\n", "6\n"]}
coding
349
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For t...
{"functional": "def check(candidate):\n assert candidate(n = 3) == 1 \n assert candidate(n = 0) == 0\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().bulbSwitch)"}
coding
134
Solve the programming task below in a Python markdown code block. There is a field divided into $n$ rows and $m$ columns. Some cells are empty (denoted as E), other cells contain robots (denoted as R). You can send a command to all robots at the same time. The command can be of one of the four types: move up; move r...
{"inputs": ["6\n1 3\nERR\n2 2\nER\nRE\n2 2\nER\nER\n1 1\nR\n4 3\nEEE\nEEE\nERR\nEER\n3 3\nEEE\nEER\nREE\n"], "outputs": ["YES\nNO\nYES\nYES\nYES\nNO\n"]}
coding
559
Solve the programming task below in a Python markdown code block. Harsh was recently gifted a book consisting of N pages. Each page contains exactly M words printed on it. As he was bored, he decided to count the number of words in the book. Help Harsh find the total number of words in the book. ------ Input Format ...
{"inputs": ["4\n1 1\n4 2\n2 4\n95 42\n"], "outputs": ["1\n8\n8\n3990\n"]}
coding
394
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. An integer x is said to be a Perfect Power if there exists positive integers a and b (i.e a, and b should be ≥ 1) such that x = a^{b+1}. Given an integer n, ...
{"inputs": ["7\n7\n10\n26\n242\n129\n394857629456789876\n353872815358409997"], "outputs": ["8\n9\n25\n243\n128\n394857628993920400\n353872815358410000"]}
coding
763
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly...
{"functional": "def check(candidate):\n assert candidate(nums = [1, 7, 3, 6, 5, 6]) == 3\n assert candidate(nums = [1, 2, 3]) == -1\n assert candidate(nums = [2, 1, -1]) == 0\n\n\ncheck(Solution().pivotIndex)"}
coding
155
Solve the programming task below in a Python markdown code block. Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants. -----Input----- The only line contains four integers $...
{"inputs": ["2 3 5 8\n", "1 1 2 1\n", "1 1 2 1\n", "2 3 5 8\n", "4 6 7 13\n", "4 1 5 15\n", "4 1 5 15\n", "4 2 5 15\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "4\n"]}
coding
248
Solve the programming task below in a Python markdown code block. Write a method named `getExponent(n,p)` that returns the largest integer exponent `x` such that p^(x) evenly divides `n`. if `p<=1` the method should return `null`/`None` (throw an `ArgumentOutOfRange` exception in C#). Also feel free to reuse/extend the...
{"functional": "_inputs = [[27, 3]]\n_outputs = [[3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_...
coding
97
Solve the programming task below in a Python markdown code block. Vova had a pretty weird sleeping schedule. There are $h$ hours in a day. Vova will sleep exactly $n$ times. The $i$-th time he will sleep exactly after $a_i$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of thi...
{"inputs": ["1 10 0 9\n5\n", "1 10 0 9\n5\n", "2 24 21 22\n23 1\n", "2 24 14 16\n17 2\n", "4 3 0 0\n1 1 1 1\n", "2 24 22 23\n22 2\n", "4 3 0 0\n1 1 1 1\n", "2 24 22 23\n22 2\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "4\n", "2\n", "4\n", "2\n"]}
coding
690
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] and [Mandarin Chinese]. A great deal of energy is lost as metabolic heat when the organisms from one trophic level are consumed by the next level. Suppose in Chefland the energy reduces by a factor of K, i.e, if in...
{"inputs": ["3\n5 3\n6 7\n10 2\n"], "outputs": ["2\n1\n4"]}
coding
614
Solve the programming task below in a Python markdown code block. *Inspired by the [Fold an Array](https://www.codewars.com/kata/fold-an-array) kata. This one is sort of similar but a little different.* --- ## Task You will receive an array as parameter that contains 1 or more integers and a number `n`. Here is a li...
{"functional": "_inputs = [[[1, 2, 3, 4, 5], 2], [[1, 2, 3, 4, 5], 3], [[15], 3], [[1, 2, 3, 4], 1], [[1, 2, 3, 4, 5, 6], 20], [[32, 45, 43, 23, 54, 23, 54, 34], 2], [[32, 45, 43, 23, 54, 23, 54, 34], 0], [[3, 234, 25, 345, 45, 34, 234, 235, 345], 3], [[3, 234, 25, 345, 45, 34, 234, 235, 345, 34, 534, 45, 645, 645, 645...
coding
456
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. In a season, each player has three statistics: runs, wickets, and catches. Given the season stats of two players A and B, denoted by R, W, and C respectively,...
{"inputs": ["3\n0 1 2\n2 3 4\n10 10 10\n8 8 8\n10 0 10\n0 10 0"], "outputs": ["B\nA\nA"]}
coding
535
Solve the programming task below in a Python markdown code block. Given a triplet of integers (X , Y , Z), such that X ≤ Y and Y ≥ Z, we define f(X , Y , Z) to be (X + Y) * (Y + Z). If either X > Y or Y < Z, or both, then f(X , Y , Z) is defined to be 0. You are provided three arrays A , B and C of any length (their...
{"inputs": ["1 \n3 1 3\n1 2 3\n5\n4 5 6\n\n"], "outputs": ["399"]}
coding
757
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. This problem's statement is really a short one. You are given an integer S. Consider an infinite sequence S, 2S, 3S, ... . Find the first number in this sequence that can be represented as Q^{...
{"inputs": ["2\n2\n2 2\n2\n2 3"], "outputs": ["8\n216"]}
coding
524
Solve the programming task below in a Python markdown code block. Your program will receive an array of complex numbers represented as strings. Your task is to write the `complexSum` function which have to return the sum as a string. Complex numbers can be written in the form of `a+bi`, such as `2-3i` where `2` is th...
{"functional": "_inputs = [[['2+3i', '3-i']], [['2-3i', '3+i']], [['3', '-3+i']], [[]], [['3+4i']], [['123+456i']], [['0']], [['-i']], [['1', '1']], [['-5', '5']], [['1', '10', '100', '1000']], [['5+4i', '11+3i']], [['-2-4i', '-8+6i']], [['-1-i', '7+10i']], [['3+4i', '3-4i']], [['10+i', '10-i', '9']], [['2+3i', '0', '0...
coding
272
Solve the programming task below in a Python markdown code block. You'll be given a list of two strings, and each will contain exactly one colon (`":"`) in the middle (but not at beginning or end). The length of the strings, before and after the colon, are random. Your job is to return a list of two strings (in the sa...
{"functional": "_inputs = [[['abc:123', 'cde:456']], [['a:12345', '777:xyz']]]\n_outputs = [[['abc:456', 'cde:123']], [['a:xyz', '777:12345']]]\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 isinstanc...
coding
184
Solve the programming task below in a Python markdown code block. Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to find numbe...
{"inputs": ["1\n4\n1010"], "outputs": ["4"]}
coding
467
Solve the programming task below in a Python markdown code block. For the upcoming semester, the admins of your university decided to keep a total of X seats for the MATH-1 course. A student interest survey was conducted by the admins and it was found that Y students were interested in taking up the MATH-1 course. Fin...
{"inputs": ["4\n1 1\n12 34\n50 49\n49 50\n"], "outputs": ["0\n22\n0\n1"]}
coding
486
Solve the programming task below in a Python markdown code block. Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'! To compose a story, Stephen wrote out $n$ words consisting of the first $5$ lowercase letters of the Latin alphabet. He wants to select t...
{"inputs": ["6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nab\nab\nc\nbc\n5\ncbdca\nd\na\nd\ne\n3\nb\nc\nca\n", "6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nba\nab\nc\nbc\n5\ncbdca\nd\na\nd\ne\n3\nb\nc\nca\n", "6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nab\naa\nc\nbc\n5\ncbdc...
coding
743
Solve the programming task below in a Python markdown code block. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). O...
{"inputs": ["(\n", ")\n", "(\n", ")\n", "((\n", "))\n", "()\n", ")(\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]}
coding
665
Solve the programming task below in a Python markdown code block. You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4). Return: * `0` if the elements can form such a sequence, and no ...
{"functional": "_inputs = [['1 2 3 5'], ['1 5'], [''], ['1 2 3 4 5'], ['2 3 4 5'], ['2 6 4 5 3'], ['_______'], ['2 1 4 3 a'], ['1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 ...
coding
336
Solve the programming task below in a Python markdown code block. Problem statement There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows. 1. $ X_0 = 0 $ 2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $ Either. ...
{"inputs": ["4\n0 1\n4 2\n2 4\n3 4", "4\n0 1\n4 2\n2 1\n3 4", "4\n1 2\n4 2\n2 4\n3 4", "4\n1 2\n4 2\n2 4\n3 7", "4\n0 1\n4 3\n2 1\n2 4", "4\n2 2\n4 2\n2 4\n3 7", "4\n2 2\n4 2\n2 7\n3 7", "4\n2 0\n4 2\n2 7\n3 7"], "outputs": ["-16\n", "-4\n", "-12\n", "-21\n", "-5\n", "-35\n", "-56\n", "-49\n"]}
coding
390
Solve the programming task below in a Python markdown code block. Chef has two binary strings A and B, each of length N. He can perform the following operation on A any number of times: Choose L and R (1 ≤ L ≤ R ≤ N), such that, in the [substring] A[L,R], the number of 1s is not equal to the number of 0s and reverse ...
{"inputs": ["3\n2\n11\n00\n5\n10110\n11001\n2\n10\n01"], "outputs": ["NO\nYES\nNO"]}
coding
616
Solve the programming task below in a Python markdown code block. Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and ...
{"inputs": ["0 1", "0 0", "1 0", "2 0", "9 1", "9 0", "2 1", "4 0"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
301
Solve the programming task below in a Python markdown code block. In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingd...
{"inputs": ["7.6\n", "7.5\n", "8.3\n", "9.8\n", "0.9\n", "4.4\n", "2.6\n", "5.0\n"], "outputs": ["8", "8", "8", "GOTO Vasilisa.", "1", "4", "3", "5"]}
coding
652
Solve the programming task below in a Python markdown code block. Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}. Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i...
{"inputs": ["3\n1 2\n3 4\n5 6\n", "3\n1 1\n2 2\n3 3\n", "3\n1 2\n1 2\n3 3\n", "3\n1 1\n1 1\n1 1\n", "5\n1 2\n6 6\n4 4\n3 3\n3 3", "5\n1 2\n2 2\n3 4\n5 5\n6 6", "5\n1 2\n6 6\n4 1\n3 3\n3 2", "5\n1 2\n2 2\n3 4\n9 5\n6 6"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n"]}
coding
277
Solve the programming task below in a Python markdown code block. Tatyana is a big sports fan and she likes volleyball a lot! She writes down the final scores of the game after it has ended in her notebook. If you are not familiar with the rules of volleyball, here's a brief: 2 teams play in total During the course ...
{"inputs": ["3\n25\n", "24\n17\n"], "outputs": ["2925\n", "0\n"]}
coding
392
Solve the programming task below in a Python markdown code block. A person is getting ready to leave and needs a pair of matching socks. If there are $n$ colors of socks in the drawer, how many socks need to be removed to be certain of having a matching pair? Example $n=2$ There are $2$ colors of socks in the dr...
{"inputs": ["2\n1\n2\n"], "outputs": ["2\n3\n"]}
coding
308
Solve the programming task below in a Python markdown code block. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed. Numbers in this system are written as a seq...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["4\n", "10\n", "20\n", "35\n", "56\n", "83\n", "116\n", "155\n"]}
coding
424
Solve the programming task below in a Python markdown code block. You are given two arrays $a$ and $b$, both consisting of $n$ integers. In one move, you can choose two indices $i$ and $j$ ($1 \le i, j \le n$; $i \neq j$) and swap $a_i$ with $a_j$ and $b_i$ with $b_j$. You have to perform the swap in both arrays. You...
{"inputs": ["3\n2\n1 2\n1 2\n2\n2 1\n1 2\n4\n2 3 1 2\n2 3 2 3\n"], "outputs": ["0\n-1\n3\n3 1\n3 2\n4 3\n"]}
coding
488
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner: lower[i] = arr[i] - ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,10,6,4,8,12]) == [3,7,11]\n assert candidate(nums = [1,1,3,3]) == [2,2]\n assert candidate(nums = [5,435]) == [220]\n\n\ncheck(Solution().recoverArray)"}
coding
238
Please solve the programming task below using a self-contained code snippet in a markdown code block. The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1 F(n) = F(n -...
{"functional": "def check(candidate):\n assert candidate(n = 2) == 1\n assert candidate(n = 3) == 2\n assert candidate(n = 4) == 3\n\n\ncheck(Solution().fib)"}
coding
135
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.   Please complete the following python code precis...
{"functional": "def check(candidate):\n assert candidate(mat = [[0,1],[1,0]], target = [[1,0],[0,1]]) == True\n assert candidate(mat = [[0,1],[1,1]], target = [[1,0],[0,1]]) == False\n assert candidate(mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]) == True\n\n\ncheck(Solution().findRotati...
coding
92
Solve the programming task below in a Python markdown code block. Chef has a string S of length N, consisting of +, -, and 0, where + denotes a source of positive charge, - denotes a source of negative charge, and 0 denotes a neutral object. Each second, the charge sources emit their respective charge to their immedia...
{"inputs": ["4\n2\n00\n3\n-+0\n6\n00+-00\n8\n0-0+000-\n"], "outputs": ["2\n0\n0\n2\n"]}
coding
734
Solve the programming task below in a Python markdown code block. Chef has two strings A and B consisting of lowercase alphabets, each of length N. Help Chef in finding the number of indices i (1 ≤ i ≤ N) such that A[i \dots N] < B[i \dots N]. S[i \dots N] denotes the suffix of string S starting at index i, i.e. S_{iS...
{"inputs": ["2\n2\nab\nbb\n3\naaa\naab"], "outputs": ["1\n3\n"]}
coding
570
Solve the programming task below in a Python markdown code block. Chef has opened up a new restaurant. Like every other restaurant, critics critique this place. The Chef wants to gather as much positive publicity as he can. Also, he is very aware of the fact that people generally do not tend to go through all the revie...
{"inputs": ["10\n1 1\n1 7\n2\n1 9\n1 21\n1 8\n1 5\n2\n1 9\n2"], "outputs": ["No reviews yet\n9\n9"]}
coding
759
Solve the programming task below in a Python markdown code block. You've purchased a ready-meal from the supermarket. The packaging says that you should microwave it for 4 minutes and 20 seconds, based on a 600W microwave. Oh no, your microwave is 800W! How long should you cook this for?! ___ # Input You'll be giv...
{"functional": "_inputs = [['600W', 4, 20, '800W'], ['800W', 3, 0, '1200W'], ['100W', 8, 45, '50W'], ['7500W', 0, 5, '600W'], ['450W', 3, 25, '950W'], ['21W', 64, 88, '25W'], ['83W', 61, 80, '26W'], ['38W', 95, 22, '12W']]\n_outputs = [['3 minutes 15 seconds'], ['2 minutes 0 seconds'], ['17 minutes 30 seconds'], ['1 mi...
coding
277
Solve the programming task below in a Python markdown code block. Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he ca...
{"inputs": ["5 49\n22 23 7 17 49\n50\n102 55 77 3 977\n", "5 49\n22 23 11 17 49\n50\n102 55 77 3 977\n", "5 1\n1 1 1 2 9\n1000000000\n10 20 30 40 50\n", "5 49\n22 23 11 17 49\n50\n102 55 77 34 977\n", "5 1\n1 1 1 2 9\n1000000000\n10 20 30 76 50\n", "5 1\n1 1 2 2 9\n1000000000\n10 20 30 40 50\n", "5 1\n1 1 1 2 9\n100000...
coding
544
Solve the programming task below in a Python markdown code block. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left...
{"inputs": ["1\nB 1\nW 1\n", "1\nB 1\nW 1\n", "1\nW 1\nB 1\n", "2\nW 2\nB 1\nW 1\nB 2\n", "3\nB 1\nW 1\nB 3\nW 2\nW 3\nB 2", "3\nB 1\nW 1\nB 2\nW 2\nW 3\nB 3", "3\nB 1\nW 1\nB 3\nW 3\nW 2\nB 2", "3\nB 1\nW 2\nB 2\nW 1\nW 3\nB 3"], "outputs": ["0\n", "0\n", "0\n", "2\n", "3", "0", "4", "2"]}
coding
457
Solve the programming task below in a Python markdown code block. Contest T-shirts Segtree has $ M $ contest T-shirts. He decided to spend $ N $ days on the contest T-shirt alone, and told $ i = 1, 2, 3, \ dots, N $ "$ A_i $ T-shirt on the $ i $ day." I made a plan for $ N $ to wear. However, if you keep the current...
{"inputs": ["2 0\n2 2 1", "2 0\n2 0 1", "2 0\n2 0 0", "2 0\n1 0 0", "4 0\n1 0 0", "0 0\n2 2 1", "2 1\n2 0 1", "3 0\n2 0 0"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
350