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. Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column. Constraints * 1 ≤ r, c ≤ 100 *...
{"inputs": ["4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 1\n2 3 4 4 6", "4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 1\n2 3 4 8 6", "4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 1\n2 6 4 8 6", "4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 2\n2 6 4 8 6", "4 5\n2 1 3 4 8\n2 2 2 4 5\n3 3 0 1 2\n2 6 4 8 6", "4 5\n1 1 3 1 5\n2 2 2 4 5\n3 3 0 1 1\n2 3 4 4 6", "4...
coding
321
Solve the programming task below in a Python markdown code block. Chef built a binary string S that has exactly N hills and M valleys. A hill is any index 1 < i < |S| such that both its neighbors are strictly smaller than it, i.e, S_{i-1} < S_{i} and S_{i+1} < S_{i}. A valley is any index 1 < i < |S| such that both i...
{"inputs": ["3\n3 2\n2 3\n3 3"], "outputs": ["7\n0101010\n7\n1010101\n8\n01010101"]}
coding
695
Solve the programming task below in a Python markdown code block. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selectio...
{"inputs": ["3 8\n9 6 9", "3 8\n6 6 6", "3 8\n9 9 9", "3 8\n6 6 9", "3 8\n15 6 9", "3 8\n15 3 9", "3 8\n15 2 9", "1 11\n2 0 7"], "outputs": ["1\n", "0\n", "0\n", "0", "0\n", "0\n", "0\n", "0\n"]}
coding
334
Solve the programming task below in a Python markdown code block. You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair o...
{"inputs": ["3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "5\n"], "outputs": ["6\n", "18\n", "38\n", "68\n", "110\n", "166\n", "238\n", "38\n"]}
coding
383
Solve the programming task below in a Python markdown code block. Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the ...
{"inputs": ["5\n27 21 D 745654582374 hwftj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg", "5\n26 21 D 745654582374 hwftj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg", "5\n26 21 D 745654582374 h...
coding
731
Solve the programming task below in a Python markdown code block. Would you want to fight against bears riding horses? Me neither. Limak is a grizzly bear. He is a general of the dreadful army of Bearland. The most important part of an army is the cavalry of course. The cavalry of Bearland consists of N warriors and ...
{"inputs": ["2\n6\n12 9 7 1 20 10\n3 6 4 7 5 5\n4\n5 17 10 1\n200 400 800 600"], "outputs": ["YES\nNO"]}
coding
635
Solve the programming task below in a Python markdown code block. Vinay loves stories on serial killers. He is hypnotized to the stories of The Zodiac Killer. Zodiac was a serial killer in USA in late 1960s and early 1970s. He never revealed his original identity but named himself as Zodiac on the letters he posted to ...
{"inputs": ["10\n21\n182 223 158 146 223 165 144 155 150 158 156 223 172 143 154 158 148 150 145 152 209\n82\n182 223 158 146 223 139 151 154 223 144 145 154 223 136 151 144 223 148 150 147 147 154 155 223 139 151 144 140 154 223 139 154 154 145 158 152 154 141 140 223 150 145 223 139 151 154 223 179 158 148 154 140 15...
coding
408
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, h...
{"inputs": ["5 46\n38 4 11 1 49\n100\n13 55 29 31 977\n", "5 46\n38 4 11 1 49\n100\n135 55 29 31 977\n", "5 49\n38 23 11 1 49\n50\n135 55 24 31 977\n", "5 49\n38 4 11 1 49\n100\n135 55 24 31 977\n", "5 49\n38 4 11 1 49\n100\n135 55 29 31 977\n", "5 1\n1 1 1 2 9\n1000000000\n10 20 30 7 50\n", "5 49\n38 8 11 17 49\n50\n1...
coding
592
Solve the programming task below in a Python markdown code block. Somu went to the gym today. He decided to do X sets of squats. Each set consists of 15 squats. Determine the total number of squats that he did today. ------ Input Format ------ - The first line contains a single integer T — the number of test cases. ...
{"inputs": ["3\n1\n4\n99\n"], "outputs": ["15\n60\n1485\n"]}
coding
274
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that: 0 <= i < j <= n - 1 and nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff. ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [3,2,5], nums2 = [2,2,1], diff = 1) == 3\n assert candidate(nums1 = [3,-1], nums2 = [-2,2], diff = -1) == 0\n\n\ncheck(Solution().numberOfPairs)"}
coding
142
Solve the programming task below in a Python markdown code block. The name of our college is "Government College of Engineering and Textile Technology Berhampore". There is another college named "Government College of Engineering and Textile Technology Serampore". As the names are quite similar, those who are unaware o...
{"inputs": ["3\nGovernment clg Berhampore\nSeRaMporE textile college\nGirls college Kolkata"], "outputs": ["GCETTB\nGCETTS\nOthers"]}
coding
268
Solve the programming task below in a Python markdown code block. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who ...
{"inputs": ["6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n4 5\n5 6\n2 6\n0\n0", "6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n5 6\n2 6\n0\n0", "6\n5\n1 2\n1 3\n3 5\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n6 6\n2 6\n0\n0", "6\n5\n1 2\n1 3\n3 5\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n1 6\n2 6\n0\n0", "6\n5\n1 2\n1 3\n2 4\n2 3\n3...
coding
364
Solve the programming task below in a Python markdown code block. Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commen...
{"inputs": ["9 7 3 8\n", "2 7 3 7\n", "7 2 3 7\n", "1 2 1 1\n", "9 2 1 1\n", "1 2 5 1\n", "7 2 1 2\n", "5 2 2 2\n"], "outputs": ["15\n", "14\n", "3\n", "1\n", "1\n", "1\n", "1\n", "2\n"]}
coding
515
Solve the programming task below in a Python markdown code block. A: IP Address (Internet Protocol Address) problem Since one number string is given, find the number of valid delimiters for IPv4 IP addresses. However, the effective delimiters for IPv4 IP addresses are as follows. * The sequence of numbers is divided...
{"inputs": ["17", "15", "14", "25", "16", "59", "13", "30"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
282
Solve the programming task below in a Python markdown code block. Create a program that will return whether an input value is a str, int, float, or bool. Return the name of the value. ### Examples - Input = 23 --> Output = int - Input = 2.3 --> Output = float - Input = "Hello" --> Output = str - Input = True --> Outpu...
{"functional": "_inputs = [[10], [9.7], ['Hello World!'], [[1, 2, 3, 4]], [1023], [True], ['True'], [{'name': 'John', 'age': 32}], [None], [3.141], [False], ['8.6'], ['*&^'], [4.5]]\n_outputs = [['int'], ['float'], ['str'], ['list'], ['int'], ['bool'], ['str'], ['dict'], ['NoneType'], ['float'], ['bool'], ['str'], ['st...
coding
107
Solve the programming task below in a Python markdown code block. Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second char...
{"inputs": ["1\nt j\n", "2\nip cd", "2\nip dc", "2\npi cd", "2\npi ce", "2\noi ce", "2\nni ce", "2\nni ec"], "outputs": ["tj\n", "icpd\n", "idpc\n", "pcid\n", "pcie\n", "ocie\n", "ncie\n", "neic\n"]}
coding
179
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also giv...
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]) == 9\n assert candidate(nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]) == 0\n\n\ncheck(Solution().minimumScore)"}
coding
328
Solve the programming task below in a Python markdown code block. Someone gave Alyona an array containing n positive integers a_1, a_2, ..., a_{n}. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat...
{"inputs": ["1\n1\n", "1\n2\n", "1\n2\n", "1\n1\n", "1\n3\n", "2\n2 1\n", "2\n1 1\n", "2\n1 3\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "3\n", "2\n", "3\n"]}
coding
444
Solve the programming task below in a Python markdown code block. Let's call an array consisting of n integer numbers a_1, a_2, ..., a_{n}, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pa...
{"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "5 2\n1 2\n2 3\n", "2 2\n1 1\n2 1\n", "2 2\n1 1\n2 1\n", "5 2\n1 2\n2 1\n", "5 2\n1 2\n2 3\n", "1 2\n1 1\n2 100\n"], "outputs": ["1\n", "1\n", "5\n", "2\n", "2\n", "3\n", "5\n", "100\n"]}
coding
628
Solve the programming task below in a Python markdown code block. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, ...
{"inputs": ["3 1 5", "2 2 2", "1 3 3", "3 1 3", "6 1 3", "7 1 3", "7 1 2", "7 1 4"], "outputs": ["0\n", "1\n", "3\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
196
Solve the programming task below in a Python markdown code block. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a m...
{"inputs": ["4 1 2\n", "4 1 0\n", "4 3 0\n", "4 2 0\n", "7 4 0\n", "2 1 0\n", "2 0 0\n", "5 2 2\n"], "outputs": ["1 2 4 5 ", "1 1 2 1 ", "-1\n", "1 1 2 3 ", "1 1 2 3 4 5 1 ", "-1\n", "1 1 ", "1 2 4 5 6 "]}
coding
501
Solve the programming task below in a Python markdown code block. Chef has decided to go to a gold mine along with N of his friends (thus, total N+1 people including Chef go to the gold mine). The gold mine contains a total of X kg of gold. Every person has the capacity of carrying up \textbf{atmost} Y kg of gold. Wi...
{"inputs": ["3\n2 10 3\n2 10 4\n1 5 10\n"], "outputs": ["NO\nYES\nYES\n"]}
coding
373
Solve the programming task below in a Python markdown code block. Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation. For that Polycarpus came to school a...
{"inputs": ["1\n0\n", "1\n-1\n", "1\n-1\n", "2\n0 0\n0 0\n", "2\n0 1\n1 0\n", "2\n0 1\n1 1\n", "2\n1 1\n1 0\n", "2\n-1 0\n0 0\n"], "outputs": ["0\n", "0 ", "0 ", "0 0 ", "1 1 ", "1 1 ", "1 1 ", "0 0 "]}
coding
708
Solve the programming task below in a Python markdown code block. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other w...
{"inputs": ["1\n5 2\n3 14\n", "1\n5 1\n3 14\n", "1\n5 12\n5 0\n", "1\n5 1\n5 14\n", "1\n5 12\n5 1\n", "1\n5 9\n41 14\n", "1\n8 9\n41 14\n", "1\n5 3\n41 14\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
388
Solve the programming task below in a Python markdown code block. Your friend Ivan asked you to help him rearrange his desktop. The desktop can be represented as a rectangle matrix of size $n \times m$ consisting of characters '.' (empty cell of the desktop) and '*' (an icon). The desktop is called good if all its ico...
{"inputs": ["1 1 1\n*\n1 1\n", "2 5 5\n*...*\n*****\n1 3\n2 2\n1 3\n1 5\n2 3\n", "4 4 8\n..**\n.*..\n*...\n...*\n1 3\n2 3\n3 1\n2 3\n3 4\n4 3\n2 3\n2 2\n"], "outputs": ["0\n", "2\n3\n3\n3\n2\n", "3\n4\n4\n3\n4\n5\n5\n5\n"]}
coding
605
Solve the programming task below in a Python markdown code block. Chef is given three numbers A, B, and C. He wants to find whether he can select exactly two numbers out of these such that the product of the selected numbers is negative. ------ Input Format ------ - The first line of input will contain a single int...
{"inputs": ["5\n1 5 7\n-5 0 4\n6 -1 0\n-3 -5 -2\n0 0 -4\n"], "outputs": ["NO\nYES\nYES\nNO\nNO\n"]}
coding
380
Solve the programming task below in a Python markdown code block. Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences. Let's assume that strings s and t have the same length n, then ...
{"inputs": ["1\nC\n", "1\nT\n", "1\nT\n", "1\nA\n", "1\nG\n", "1\nC\n", "2\nAG\n", "2\nAG\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "4\n", "4\n"]}
coding
736
Solve the programming task below in a Python markdown code block. Consider a matrix where each cell contains either a $0$ or a $1$. Any cell containing a $1$ is called a filled cell. Two cells are said to be connected if they are adjacent to each other horizontally, vertically, or diagonally. In the following grid, a...
{"inputs": ["4\n4\n1 1 0 0\n0 1 1 0\n0 0 1 0\n1 0 0 0\n"], "outputs": ["5\n"]}
coding
540
Solve the programming task below in a Python markdown code block. The Binomial Form of a polynomial has many uses, just as the standard form does. For comparison, if p(x) is in Binomial Form and q(x) is in standard form, we might write p(x) := a0 \* xC0 + a1 \* xC1 + a2 \* xC2 + ... + aN \* xCN q(x) := b0 + b1 \* x ...
{"functional": "_inputs = [[[1, 2, 7], 3], [[1, 2, 7, 0, 5], 2], [[1, 1, 1, 1, 7, 0, 5], 2], [[1, 2, 7, 0, 5], 0.6], [[1, 2, 7, 0, 5], 0]]\n_outputs = [[16], [12], [12], [4.24], [5.0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, re...
coding
529
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters. Return the number of strings in words that are a prefix of s. A prefix of a string is a substring tha...
{"functional": "def check(candidate):\n assert candidate(words = [\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"], s = \"abc\") == 3\n assert candidate(words = [\"a\",\"a\"], s = \"aa\") == 2\n\n\ncheck(Solution().countPrefixes)"}
coding
121
Solve the programming task below in a Python markdown code block. After the hundred years of war started by the Fire Nation, its time for the Water Tribes to bring it to an end. Avatar asked Sokka to go to the Southern WarZone from The Northern WarZone and gave him some money in a bag for his journey. Sokka has the Wor...
{"inputs": ["2\n5\n2"], "outputs": ["200000002\n0"]}
coding
679
Solve the programming task below in a Python markdown code block. Nature photographing may be fun for tourists, but it is one of the most complicated things for photographers. To capture all the facets of a bird, you might need more than one cameras. You recently encountered such a situation. There are $n$ photographer...
{"inputs": ["2\n2\n0 1\n0 1\n2\n0 1\n100 1\n"], "outputs": ["0.785398163397\n0.000100999899"]}
coding
523
Solve the programming task below in a Python markdown code block. Polycarp has a string $s[1 \dots n]$ of length $n$ consisting of decimal digits. Polycarp performs the following operation with the string $s$ no more than once (i.e. he can perform operation $0$ or $1$ time): Polycarp selects two numbers $i$ and $j$ ($...
{"inputs": ["1\n4\n2021\n", "1\n4\n2029\n", "1\n4\n2030\n", "1\n4\n2040\n", "1\n4\n2050\n", "1\n4\n2090\n", "1\n4\n2080\n", "1\n4\n2070\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
730
Solve the programming task below in a Python markdown code block. You are given an array A, consisting of N integers and an array B, consisting of M integers. The subsequence of A is the array that can be obtained by picking the elements at the arbitrary sorted set of positions from A. Your task is to count the number ...
{"inputs": ["4 2\n7 7 7 7\n3 4\n\n", "5 3\n1 5 2 4 7\n7 9 6\n\n"], "outputs": ["6", "4"]}
coding
698
Solve the programming task below in a Python markdown code block. You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y...
{"inputs": ["`a\n", "a`\n", "aa\n", "aa`\n", "a`a\n", "aaa\n", "aabba\n", "bbaab\n"], "outputs": ["1\n", "1\n", "1\n", "4\n", "3\n", "5\n", "18\n", "18\n"]}
coding
338
Solve the programming task below in a Python markdown code block. Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction $\frac{a}{b}$ is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its n...
{"inputs": ["3\n", "4\n", "5\n", "6\n", "8\n", "9\n", "9\n", "5\n"], "outputs": ["1 2\n", "1 3\n", "2 3\n", "1 5\n", "3 5\n", "4 5\n", "4 5\n", "2 3\n"]}
coding
310
Solve the programming task below in a Python markdown code block. String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string s. You can perform two different operations on this string: swa...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n10\n", "2\n11\n", "2\n11\n", "2\n10\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "10\n", "1\n", "1\n", "10\n"]}
coding
373
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. In a *red-blue tree*, each vertex is either red or blue and adjacent vertices always have different colours. You are given a tree with $N$ vertices...
{"inputs": ["1 \n7 \n1 2 \n1 3 \n2 4 \n2 5 \n3 6 \n3 7 \n0010010"], "outputs": ["3"]}
coding
573
Solve the programming task below in a Python markdown code block. The final match of the Berland Football Cup has been held recently. The referee has shown $n$ yellow cards throughout the match. At the beginning of the match there were $a_1$ players in the first team and $a_2$ players in the second team. The rules of ...
{"inputs": ["2\n3\n5\n1\n8\n", "8\n4\n1\n2\n9\n", "1\n7\n2\n3\n5\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n2\n", "1\n1\n7\n1\n2\n", "1\n1\n1\n3\n4\n", "8\n4\n1\n2\n9\n"], "outputs": ["0 4\n", "5 8\n", "0 2\n", "1 1\n", "2 2\n", "0 1\n", "2 2\n", "5 8\n"]}
coding
661
Solve the programming task below in a Python markdown code block. Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows: - Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, ...
{"inputs": ["3\n3", "3\n4", "3\n2", "3\n8", "3\n6", "1\n1\n", "6\n1\n", "3\n74"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "1\n", "6\n", "3\n"]}
coding
576
Solve the programming task below in a Python markdown code block. This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of upperca...
{"inputs": ["FC", "DF", "EF", "FD", "FE", "GE", "GD", "ED"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
211
Solve the programming task below in a Python markdown code block. After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer the next obvious question: how does one compute the least common multiple (lcm) of Fibonacci numbers? Unfortunately, Dere...
{"inputs": ["5\n1\n3\n3\n6\n9\n"], "outputs": ["136\n"]}
coding
349
Solve the programming task below in a Python markdown code block. Recently, Norge found a string $s = s_1 s_2 \ldots s_n$ consisting of $n$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $s$. Yes, all $\frac{n (n + 1)}{2}$ of them! A substring of $s...
{"inputs": ["7 1\naaaaaaa\nb\n", "7 1\naaaaaba\nb\n", "7 1\naaaaaba\na\n", "7 1\naaaaaba\nc\n", "7 1\naaaaaaa\nb\n", "7 2\nabacaba\na b\n", "7 2\nabacaba\na c\n", "7 2\nabacaba\na d\n"], "outputs": ["0\n", "1\n", "16\n", "0\n", "0\n", "12\n", "8\n", "4\n"]}
coding
604
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. Chef wants you to handle $Q$ queries. There are two types of queries: 1 L R X: for each $i$ ($L ≤ i ≤ R$), add $(...
{"inputs": ["5 4\n1 10 3 6 5\n1 1 3 5\n2 3\n1 4 5 7\n2 5"], "outputs": ["52\n69"]}
coding
527
Solve the programming task below in a Python markdown code block. In computing, there are two primary byte order formats: big-endian and little-endian. Big-endian is used primarily for networking (e.g., IP addresses are transmitted in big-endian) whereas little-endian is used mainly by computers with microprocessors. ...
{"functional": "_inputs = [[153, 8], [255, 8], [256, 8], [1534, 32], [364334, 32], [2, 64], [164345, 64], [23, 128], [256245645346, 128], [6423, 256], [988847589347589798345, 256], [98, 512], [9827498275894278943758934789347, 512], [111, 1024], [859983475894789589772983457982345896389458937589738945435, 1024], [9834587...
coding
326
Please solve the programming task below using a self-contained code snippet in a markdown code block. Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resou...
{"functional": "def check(candidate):\n assert candidate(k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]) == 4\n assert candidate(k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]) == 6\n\n\ncheck(Solution().findMaximizedCapital)"}
coding
244
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell...
{"functional": "def check(candidate):\n assert candidate([7,1,5,3,6,4]) == 5\n assert candidate(prices = [7,6,4,3,1]) == 0\n\n\ncheck(Solution().maxProfit)"}
coding
120
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.   Please complete the following python code preci...
{"functional": "def check(candidate):\n assert candidate(heights = [2,1,5,6,2,3]) == 10\n assert candidate( heights = [2,4]) == 4\n\n\ncheck(Solution().largestRectangleArea)"}
coding
82
Solve the programming task below in a Python markdown code block. Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones are not. ...
{"inputs": ["4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone"], "outputs": ["3\n2\n1\n0"]}
coding
310
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matrix, respectively. Initially on day 0, the enti...
{"functional": "def check(candidate):\n assert candidate(row = 2, col = 2, cells = [[1,1],[2,1],[1,2],[2,2]]) == 2\n assert candidate(row = 2, col = 2, cells = [[1,1],[1,2],[2,1],[2,2]]) == 1\n assert candidate(row = 3, col = 3, cells = [[1,2],[2,1],[3,3],[2,2],[1,1],[1,3],[2,3],[3,2],[3,1]]) == 3\n\n\ncheck(S...
coding
270
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 arr and an integer k. The array arr is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the...
{"functional": "def check(candidate):\n assert candidate(arr = [1,4,1,3], k = 2) == 1\n assert candidate(arr = [2,5,5,7], k = 3) == 5\n\n\ncheck(Solution().makeSubKSumEqual)"}
coding
168
Solve the programming task below in a Python markdown code block. Sardar Singh has many men fighting for him, and he would like to calculate the power of each of them to better plan for his fight against Ramadhir. The power of a string S of lowercase English alphabets is defined to be \sum_{i = 1}^{|S|} i\cdot ord(S...
{"inputs": ["1\nfaizal"], "outputs": ["273"]}
coding
450
Solve the programming task below in a Python markdown code block. Given two non-negative decimal integers $a$ and $b$, calculate their AND (logical conjunction), OR (logical disjunction) and XOR (exclusive disjunction) and print them in binary representation of 32 bits. Constraints * $0 \leq a, b \leq 2^{32} - 1$ In...
{"inputs": ["1 1", "2 1", "2 0", "1 0", "0 0", "1 3", "2 3", "4 0"], "outputs": ["00000000000000000000000000000001\n00000000000000000000000000000001\n00000000000000000000000000000000\n", "00000000000000000000000000000000\n00000000000000000000000000000011\n00000000000000000000000000000011\n", "00000000000000000000000000...
coding
223
Solve the programming task below in a Python markdown code block. Introduction to Disjunctions In logic and mathematics, a disjunction is an operation on 2 or more propositions. A disjunction is true if and only if 1 or more of its operands is true. In programming, we typically denote a disjunction using "||", but in...
{"functional": "_inputs = [[[False, True, True], False], [[False, True, False], False], [[False, True, True, True], True], [[True, True, True], False], [[True, True, True, True], False]]\n_outputs = [[True], [True], [True], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin...
coding
403
Solve the programming task below in a Python markdown code block. Chef was driving on a highway at a speed of X km/hour. To avoid accidents, there are fine imposed on overspeeding as follows: No fine if the speed of the car ≤ 70 km/hour. Rs 500 fine if the speed of the car is strictly greater than 70 and ≤ 100. Rs 200...
{"inputs": ["7\n40\n110\n70\n100\n69\n101\n85\n"], "outputs": ["0\n2000\n0\n500\n0\n2000\n500\n"]}
coding
481
Solve the programming task below in a Python markdown code block. You are given a prime number $p$, $n$ integers $a_1, a_2, \ldots, a_n$, and an integer $k$. Find the number of pairs of indexes $(i, j)$ ($1 \le i < j \le n$) for which $(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$. -----Input----- The first line co...
{"inputs": ["2 2 1\n1 0\n", "2 2 0\n1 0\n", "2 2 1\n1 0\n", "2 2 0\n1 0\n", "2 2 0\n2 0\n", "2 4 0\n2 0\n", "2 4 0\n0 0\n", "2 5 0\n0 0\n"], "outputs": ["1", "0", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
coding
409
Please solve the programming task below using a self-contained code snippet in a markdown code block. The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each house has one and only one parent house. After a tour, the smart thief reali...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,2,3,None,3,None,1])) == 7\n assert candidate(root = tree_node([3,4,5,1,3,None,1])) == 9\n\n\ncheck(Solution().rob)"}
coding
202
Solve the programming task below in a Python markdown code block. Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in th...
{"inputs": ["0 2\n4 3\n3 4", "2 2\n6 4\n4 4", "2 2\n6 4\n5 4", "0 2\n8 3\n3 4", "2 2\n6 1\n5 4", "0 2\n8 3\n3 0", "2 2\n6 2\n5 4", "0 2\n7 3\n3 0"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
coding
464
Solve the programming task below in a Python markdown code block. Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there were also ...
{"inputs": ["3 7 0\n", "2 0 1\n", "1 1 0\n", "0 0 1\n", "1 0 1\n", "5 7 1\n", "1 1 1\n", "0 0 0\n"], "outputs": ["-", "+", "0", "?", "?", "-", "?", "0"]}
coding
501
Solve the programming task below in a Python markdown code block. ## Task: Your task is to write a function which returns the sum of following series upto nth term(parameter). Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +... ## Rules: * You need to round the answer to 2 decimal places and return it as String. ...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [15], [39], [58], [0]]\n_outputs = [['1.00'], ['1.25'], ['1.39'], ['1.49'], ['1.57'], ['1.63'], ['1.68'], ['1.73'], ['1.77'], ['1.94'], ['2.26'], ['2.40'], ['0.00']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst...
coding
236
Solve the programming task below in a Python markdown code block. You are the "computer expert" of a local Athletic Association (C.A.A.). Many teams of runners come to compete. Each time you get a string of all race results of every team who has run. For example here is a string showing the individual results of a tea...
{"functional": "_inputs = [['01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17'], ['02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|41'], ['02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|32|34, 2|17|17'], ['0|15|59, 0|16|16, 0|17|20, 0|22|34, 0|19|34, 0|15|0'], ['11|15|59, 10|16|16, 12|17|20, 9|22|34, 13|19|34, 11|15...
coding
621
Solve the programming task below in a Python markdown code block. You have a string $s$ consisting of digits from $0$ to $9$ inclusive. You can perform the following operation any (possibly zero) number of times: You can choose a position $i$ and delete a digit $d$ on the $i$-th position. Then insert the digit $\min{(...
{"inputs": ["4\n04829\n9\n01\n314752277691991\n"], "outputs": ["02599\n9\n01\n111334567888999\n"]}
coding
478
Solve the programming task below in a Python markdown code block. Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function do...
{"inputs": ["1\n1\n", "1\n0\n", "2\n2 1\n", "2\n1 1\n", "2\n2 4\n", "2\n1 3\n", "2\n4 1\n", "2\n1 0\n"], "outputs": ["1\n1 1\n", "0\n", "2\n1 1\n1 2\n", "1\n1 2\n", "4\n2 2\n2 2\n1 2\n1 2\n", "3\n2 2\n2 2\n1 2\n", "4\n1 1\n1 1\n1 1\n1 2\n", "1\n1 1\n"]}
coding
565
Solve the programming task below in a Python markdown code block. When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the b...
{"inputs": ["1 3\n5\n", "1 3\n5\n", "1 10\n4\n", "1 10\n4\n", "2 10\n6 4\n", "2 10\n6 4\n", "2 10\n6 6\n", "2 11\n6 6\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n"]}
coding
381
Solve the programming task below in a Python markdown code block. There are two exits in a bus with 100 seats: First exit is located beside seat number 1. Second exit is located beside seat number 100. Seats are arranged in a straight line from 1 to 100 with equal spacing between any 2 adjacent seats. A passenger pre...
{"inputs": ["6\n1\n50\n100\n30\n51\n73\n"], "outputs": ["LEFT\nLEFT\nRIGHT\nLEFT\nRIGHT\nRIGHT\n"]}
coding
458
Solve the programming task below in a Python markdown code block. Interns Mehta and Sharma are waiting for their "build" to complete. Mehta comes up with an interesting game with an array P of integers of size N. She defines the rules of the game as: Pick a number i from the set {1,2,...N-2}. Remove P[i] from the array...
{"inputs": ["8\n477 744 474 777 447 747 777 474"], "outputs": ["2937051"]}
coding
261
Solve the programming task below in a Python markdown code block. An uppercase or lowercase English letter \alpha will be given as input. If \alpha is uppercase, print A; if it is lowercase, print a. -----Constraints----- - \alpha is an uppercase (A - Z) or lowercase (a - z) English letter. -----Input----- Input is ...
{"inputs": ["b", "C", "`", "D", "c", "E", "d", "F"], "outputs": ["a\n", "A\n", "a\n", "A\n", "a\n", "A\n", "a\n", "A\n"]}
coding
126
Solve the programming task below in a Python markdown code block. You will be given a fruit which a farmer has harvested, your job is to see if you should buy or sell. You will be given 3 pairs of fruit. Your task is to trade your harvested fruit back into your harvested fruit via the intermediate pair, you should ret...
{"functional": "_inputs = [[[['apple', 'orange'], ['orange', 'pear'], ['apple', 'pear']], 'apple'], [[['orange', 'apple'], ['orange', 'pear'], ['pear', 'apple']], 'apple'], [[['apple', 'orange'], ['pear', 'orange'], ['apple', 'pear']], 'apple'], [[['orange', 'apple'], ['pear', 'orange'], ['pear', 'apple']], 'apple'], [...
coding
286
Solve the programming task below in a Python markdown code block. Leonardo loves primes and created ${q}$ queries where each query takes the form of an integer, $n$. For each $n$, count the maximum number of distinct prime factors of any number in the inclusive range $[1,n]$. Note: Recall that a prime number is only d...
{"inputs": ["6\n1\n2\n3\n500\n5000\n10000000000\n"], "outputs": ["0\n1\n1\n4\n5\n10\n"]}
coding
443
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef is a software developer, so he has to switch between different languages sometimes. Each programming language has some features, which are represented by integer...
{"inputs": ["3\n1 2 2 1 3 4\n3 4 2 1 4 3\n1 2 1 3 2 4"], "outputs": ["1\n2\n0"]}
coding
494
Solve the programming task below in a Python markdown code block. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted ...
{"inputs": ["t\n", "N\n", "s\n", "O\n", "r\n", "P\n", "q\n", "Q\n"], "outputs": ["t", "N", "s\n", "O\n", "r\n", "P\n", "q\n", "Q\n"]}
coding
255
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array. Return all lonely numbers in nums. You may return the answer in ...
{"functional": "def check(candidate):\n assert candidate(nums = [10,6,5,8]) == [10,8]\n assert candidate(nums = [1,3,5,3]) == [1,5]\n\n\ncheck(Solution().findLonely)"}
coding
108
Solve the programming task below in a Python markdown code block. Monocarp has arranged $n$ colored marbles in a row. The color of the $i$-th marble is $a_i$. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one ...
{"inputs": ["2\n2 1\n", "2\n2 1\n", "2\n2 2\n", "2\n2 4\n", "2\n13 13\n", "2\n13 13\n", "6\n1 2 3 1 1 2\n", "6\n3 1 2 3 3 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "4\n", "4\n"]}
coding
598
Solve the programming task below in a Python markdown code block. You have been appointed as the designer for your school's computer network. In total, there are N computers in the class, and M computer-to-computer connections need to be made. Also, there are three mandatory conditions the design should fulfill. The fi...
{"inputs": ["2\n10 1\n5 5"], "outputs": ["-1 -1\n1 2\n2 3\n3 4\n4 5\n5 1"]}
coding
528
Solve the programming task below in a Python markdown code block. This time around, Baby Ehab will play with permutations. He has $n$ cubes arranged in a row, with numbers from $1$ to $n$ written on them. He'll make exactly $j$ operations. In each operation, he'll pick up $2$ cubes and switch their positions. He's won...
{"inputs": ["2 3\n", "3 2\n", "4 2\n", "2 200\n", "3 200\n"], "outputs": ["1 1 1 \n", "3 3 \n", "6 12 \n", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
coding
383
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j.   Please complete the following python code precisely: ```python class Solution: def ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1,1,3]) == 4\n assert candidate(nums = [1,1,1,1]) == 6\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().numIdenticalPairs)"}
coding
87
Solve the programming task below in a Python markdown code block. Write a program that will take a string of digits and give you all the possible consecutive slices of length `n` in that string. Raise an error if `n` is larger than the length of the string. ## Examples For example, the string `"01234"` has the foll...
{"functional": "_inputs = [['01234', 1], ['01234', 2], ['01234', 3], ['01234', 4], ['01234', 5]]\n_outputs = [[[[0], [1], [2], [3], [4]]], [[[0, 1], [1, 2], [2, 3], [3, 4]]], [[[0, 1, 2], [1, 2, 3], [2, 3, 4]]], [[[0, 1, 2, 3], [1, 2, 3, 4]]], [[[0, 1, 2, 3, 4]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isi...
coding
169
Solve the programming task below in a Python markdown code block. The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of ...
{"inputs": ["1 1\n!\n", "1 1\n!\n", "2 2\nR1\n", "2 1\nR1\n", "2 1\nOA\n", "2 2\nGW\n", "2 1\nOA\n", "2 2\nGW\n"], "outputs": ["PRINT !\n", "PRINT !\n", "PRINT 1\nLEFT\nPRINT R\n", "PRINT R\nRIGHT\nPRINT 1\n", "PRINT O\nRIGHT\nPRINT A\n", "PRINT W\nLEFT\nPRINT G\n", "PRINT O\nRIGHT\nPRINT A\n", "PRINT W\nLEFT\nPRINT G\...
coding
691
Solve the programming task below in a Python markdown code block. Write a program that reads two numbers $X$ and $K$. The program first finds the factors of $X$ and then gives the sum of $K$th power of every factor. The program also finds the factor of $k$ and outputs the sum of $X$ times of every factor. -----Input:...
{"inputs": ["1\n8 6"], "outputs": ["266304 88"]}
coding
318
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and an integer threshold. Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,5,4], threshold = 5) == 3\n assert candidate(nums = [1,2], threshold = 2) == 1\n assert candidate(nums = [2,3,4,5], threshold = 4) == 3\n\n\ncheck(Solution().longestAlternatingSubarray)"}
coding
197
Solve the programming task below in a Python markdown code block. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite qua...
{"inputs": ["21 3 64", "21 0 64", "4 767 636", "7 770 636", "5 936 910", "15 90 456", "8 18 2018", "28 90 542"], "outputs": ["3\n", "0\n", "4\n", "7\n", "5\n", "15\n", "24\n", "28\n"]}
coding
308
Solve the programming task below in a Python markdown code block. You are given a set S of strings consisting of `0` and `1`, and an integer K. Find the longest string that is a subsequence of K or more different strings in S. If there are multiple strings that satisfy this condition, find the lexicographically smalle...
{"inputs": ["2 5\n0\n11\n1111", "3 0\n1\n3\n1111\n01000110", "3 2\n1\n2\n1011\n01001110", "3 2\n1\n2\n1011\n01000110", "3 2\n1\n2\n1111\n01000110", "3 2\n1\n3\n1111\n01000110", "3 0\n1\n3\n1111\n00000110", "3 2\n1\n2\n1111\n01001110"], "outputs": ["", "000\n", "00\n", "00\n", "00\n", "00\n", "000\n", "00\n"]}
coding
531
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 went to Australia and saw the destruction caused by bushfires, which made him sad, so he decided to help the animals by feeding them fruits. Fir...
{"inputs": ["1\n6 4\n1 2 3 3 2 2\n7 3 9 1 1 1"], "outputs": ["5"]}
coding
628
Solve the programming task below in a Python markdown code block. -----Problem Statement----- We have an integer sequence $A$, whose length is $N$. Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the contents...
{"inputs": ["6\n1 3 -4 2 2 -2"], "outputs": ["3"]}
coding
269
Solve the programming task below in a Python markdown code block. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original...
{"inputs": ["BWBBW", "WWBBB", "WBBWB", "WBBXB", "BXBBW", "BXBWB", "BXWBB", "WXBBB"], "outputs": ["3\n", "1\n", "3\n", "3\n", "3\n", "4\n", "3\n", "2\n"]}
coding
427
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j]. Return the maximum difference. If no s...
{"functional": "def check(candidate):\n assert candidate(nums = [7,1,5,4]) == 4\n assert candidate(nums = [9,4,3,2]) == -1\n assert candidate(nums = [1,5,2,10]) == 9\n\n\ncheck(Solution().maximumDifference)"}
coding
119
Solve the programming task below in a Python markdown code block. One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area sh...
{"inputs": ["6 5\n", "1 1\n", "2 1\n", "2 2\n", "5 5\n", "9 10\n", "8 10\n", "15 13\n"], "outputs": ["5 4\n", "1 1\n", "1 1", "2 2", "5 4", "8 10", "8 10\n", "10 8"]}
coding
249
Solve the programming task below in a Python markdown code block. There is a sequence of words in CamelCase as a string of letters, $\boldsymbol{\mathrm{~S~}}$, having the following properties: It is a concatenation of one or more words consisting of English letters. All letters in the first word are lowercase. For e...
{"inputs": ["saveChangesInTheEditor\n"], "outputs": ["5\n"]}
coding
297
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Captain Dehatti from Bawanian village is making strategy to win the Fake Cricket World Cup organised in his village. He want his team to score runs only in 4's and 6's because he belie...
{"inputs": ["6\n10 2 9\n6 2 9\n6 1 9\n4 1 9\n5 1 9\n10 3 9"], "outputs": ["2\n4\n1\n1\n0\n12"]}
coding
552
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 players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of ...
{"functional": "def check(candidate):\n assert candidate(players = [4,7,9], trainers = [8,2,5,8]) == 2\n assert candidate(players = [1,1,1], trainers = [10]) == 1\n\n\ncheck(Solution().matchPlayersAndTrainers)"}
coding
178
Solve the programming task below in a Python markdown code block. We have a string S consisting of lowercase English letters. If the length of S is at most K, print S without change. If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result. -----Constraints...
{"inputs": ["1\nz\n", "2\nz\n", "1\nfa\n", "7\necitslosdnaokin", "7\nnikoandrolstice", "7\noikoandrolstice", "7\noikoancrolstice", "7\noikobncsoletics"], "outputs": ["z\n", "z\n", "f...\n", "ecitslo...\n", "nikoand...\n", "oikoand...\n", "oikoanc...\n", "oikobnc...\n"]}
coding
212
Solve the programming task below in a Python markdown code block. A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1$, and th...
{"inputs": ["2 1\n0 1\n", "2 1\n1 0\n", "2 1\n1 1\n", "2 1\n0 0\n", "2 1\n1 0\n", "2 1\n0 1\n", "2 1\n1 1\n", "2 1\n0 0\n"], "outputs": ["0", "1", "1", "1", "1\n", "0\n", "1\n", "1\n"]}
coding
645
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smalle...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([2,2,5,None,None,5,7])) == 5\n assert candidate(root = tree_node([2,2,2])) == -1\n\n\ncheck(Solution().findSecondMinimumValue)"}
coding
222
Solve the programming task below in a Python markdown code block. Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure...
{"inputs": ["3 1\n1 1\n2 6\n5 3\n0 0 5 5", "3 1\n0 2\n2 4\n0 6\n0 0 0 5", "3 1\n0 2\n2 4\n0 6\n0 0 1 5", "3 1\n0 1\n2 4\n0 6\n0 0 1 5", "3 1\n0 1\n2 4\n0 6\n0 0 0 5", "3 1\n0 1\n2 8\n0 6\n0 0 0 5", "3 1\n1 1\n2 6\n5 3\n0 0 1 5", "3 1\n1 1\n2 4\n5 3\n0 0 5 5"], "outputs": ["2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"...
coding
655
Solve the programming task below in a Python markdown code block. Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels o...
{"inputs": ["2 2 0\n", "0 0 1\n", "0 1 0\n", "1 4 3\n", "3 2 0\n", "1 4 4\n", "1 0 0\n", "5 0 5\n"], "outputs": [" 2\n", " 0\n", " 0\n...
coding
422
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots, a_n$. You can perform operations on the array. In each operation you can choose an integer $i$ ($1 \le i < n$), and swap elements $a_i$ and $a_{i+1}$ of the array, if $a_i + a_{i+1}$ is odd. Determine whether it ...
{"inputs": ["4\n4\n1 6 31 14\n2\n4 2\n5\n2 9 6 7 10\n3\n6 6 6\n"], "outputs": ["Yes\nNo\nNo\nYes\n"]}
coding
525
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way: nums[0] = 0 nums[1] = 1 nums[2 * i] = nums[i] when 2 <= 2 * i <= n nums[2 * i + 1] = nums[i] + nums[i + 1]...
{"functional": "def check(candidate):\n assert candidate(n = 7) == 3\n assert candidate(n = 2) == 1\n assert candidate(n = 3) == 2\n\n\ncheck(Solution().getMaximumGenerated)"}
coding
158
Solve the programming task below in a Python markdown code block. Given a string of lowercase letters in the range ascii[a-z], determine the index of a character that can be removed to make the string a palindrome. There may be more than one solution, but any will do. If the word is already a palindrome or there is n...
{"inputs": ["3 \naaab \nbaa \naaa \n"], "outputs": ["3\n0\n-1\n"]}
coding
427
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has an undirected graph on N vertices. There are edges between all but M pairs of vertices. A permutation p on the vertices of the graph is represented as p[1], p[2],...
{"inputs": ["2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2", "2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2"], "outputs": ["2\n0", "2\n0"]}
coding
400
Solve the programming task below in a Python markdown code block. Chef has N laddus of K sweetness each. Chef wants to eat all laddus, but Chef is restricted with the given condition that he must not eat two adjacent laddus. Chef starts calculating the maximum sweetness that he will get from the laddus. Find the maximu...
{"inputs": ["2\n1 2\n4 3"], "outputs": ["2\n6"]}
coding
301