task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that...
{"inputs": ["z\n", "abc\n", "bbcd\n", "abcd\n", "wxxyxxx\n", "xxxyxxx\n", "hfihihhfh\n", "hhihhhffh\n"], "outputs": ["YES\nz\n", "YES\nabc\n", "YES\ncbdb", "NO\n", "YES\nwxxxxxy", "YES\nxxxxxxy\n", "NO\n", "YES\nfhhhfhihh"]}
341
101
coding
Solve the programming task below in a Python markdown code block. Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3. Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, кото...
{"inputs": ["3 1\n", "2 1\n", "2 3\n", "1 2\n", "1 3\n", "3 2\n"], "outputs": ["2\n", "3\n", "1\n", "3\n", "2\n", "1\n"]}
246
66
coding
Solve the programming task below in a Python markdown code block. Consider a zero-indexed matrix with $m$ rows and $n$ columns, where each row is filled gradually. Given the first row of the matrix, you can generate the elements in the subsequent rows using the following formula: $a_{i,j}=a_{i-1,j}\oplus a_{i-1,j+1}\t...
{"inputs": ["4 2\n6 7 1 3\n"], "outputs": ["1 6 2 5\n"]}
514
30
coding
Solve the programming task below in a Python markdown code block. Let's denote a function $f(x)$ in such a way: we add $1$ to $x$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, $f(599) = 6$: $599 + 1 = 600 \rightarrow 60 \rightarrow 6$; $f(7) = 8$: $7 + 1 ...
{"inputs": ["1\n", "9\n", "3\n", "5\n", "5\n", "1\n", "9\n", "3\n"], "outputs": ["9\n", "9\n", "9\n", "9\n", "9\n", "9\n", "9\n", "9\n"]}
479
70
coding
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...
621
804
coding
Solve the programming task below in a Python markdown code block. Chinese Fedor is a research scientist, who has recently found a road map of Ancient Berland. Ancient Berland consisted of N cities that were connected by M bidirectional roads. The road builders weren't knowledgable. Hence, the start city and the end...
{"inputs": ["3 3\n1 2 3\n2 3 1\n1 3 2"], "outputs": ["36"]}
593
33
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. You can use each character in text at most once. Return the maximum number of instances that can...
{"functional": "def check(candidate):\n assert candidate(text = \"nlaebolko\") == 1\n assert candidate(text = \"loonbalxballpoon\") == 2\n assert candidate(text = \"leetcode\") == 0\n\n\ncheck(Solution().maxNumberOfBalloons)"}
100
66
coding
Solve the programming task below in a Python markdown code block. ## Description The task is described in the title: find the sum of all numbers with the same digits(permutations) **including** duplicates. However, due to the fact that this is a performance edition kata, `num` can go up to `10**10000`. That's a number...
{"functional": "_inputs = [[123], [1185]]\n_outputs = [[1332], [99990]]\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 ...
376
174
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting only of uppercase English letters. You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s. ...
{"functional": "def check(candidate):\n assert candidate(s = \"ABFCACDB\") == 2\n assert candidate(s = \"ACBBD\") == 5\n\n\ncheck(Solution().minLength)"}
132
48
coding
Solve the programming task below in a Python markdown code block. This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \le a_i \le 1$. You can hack this problem only if you solve and lock both problems. Christmas is coming, and our protagonist, Bob, is preparing a spectacular present f...
{"inputs": ["1\n1\n", "1\n1\n", "3\n1 0 1\n", "3\n0 0 1\n", "3\n0 0 1\n", "3\n0 1 0\n", "3\n1 1 1\n", "3\n0 1 1\n"], "outputs": ["-1\n", "-1", "2\n", "-1\n", "-1", "-1\n", "2\n", "1\n"]}
514
109
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w, where w is divisible by 32 (that is, no byte will be split across rows). The heig...
{"functional": "def check(candidate):\n assert candidate(length = 1, w = 32, x1 = 30, x2 = 31, y = 0) == [3]\n assert candidate(length = 3, w = 96, x1 = 0, x2 = 95, y = 0) == [-1, -1, -1]\n\n\ncheck(Solution().drawLine)"}
216
100
coding
Solve the programming task below in a Python markdown code block. ## The Problem James is a DJ at a local radio station. As it's getting to the top of the hour, he needs to find a song to play that will be short enough to fit in before the news block. He's got a database of songs that he'd like you to help him filter ...
{"functional": "_inputs = [[215], [270], [13], [300]]\n_outputs = [['For Reasons Unknown'], ['YYZ'], [False], ['Surfing With The Alien']]\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, (...
477
188
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. Find a permutation P = [P_{1}, P_{2}, \ldots, P_{N}] of the integers \{1, 2, \ldots, N\} such that sum of averages of all consecutive triplets is minimized, i.e. \sum_{i=1}^{N-2} \frac{P_{i} + P_{i+1} + P_{i+2}}{3} is mini...
{"inputs": ["2\n4\n3\n"], "outputs": ["3 2 1 4\n3 2 1"]}
465
29
coding
Solve the programming task below in a Python markdown code block. A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A ...
{"inputs": ["0 8 7 1", "1 7 6 8", "5 4 5 2", "0 8 3 1", "1 1 6 8", "2 4 5 2", "0 1 6 8", "2 3 5 2"], "outputs": ["Balanced\n", "Right\n", "Left\n", "Left\n", "Right\n", "Right\n", "Right\n", "Right\n"]}
271
111
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer threshold. Find any subarray of nums of length k such that every element in the subarray is greater than threshold / k. Return the size of any such subarray. If there...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,4,3,1], threshold = 6) == 3\n assert candidate(nums = [6,5,6,5,8], threshold = 7) == 1\n\n\ncheck(Solution().validSubarraySize)"}
126
71
coding
Solve the programming task below in a Python markdown code block. Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the beauty of the tower as follows: * The beauty of...
{"inputs": ["2 5 6 1", "2 9 7 0", "4 1 3 5", "4 1 1 5", "4 1 1 7", "1 2 2 2", "6 1 1 7", "4 2 2 5"], "outputs": ["0\n", "1\n", "24\n", "56\n", "8\n", "2\n", "792\n", "0\n"]}
414
114
coding
Solve the programming task below in a Python markdown code block. This is a spin off of my first [kata](http://www.codewars.com/kata/56bc28ad5bdaeb48760009b0). You are given a list of character sequences as a comma separated string. Write a function which returns another string containing all the character sequences ex...
{"functional": "_inputs = [[''], ['1'], ['1, 3'], ['1,2,3'], ['1,2,3,4']]\n_outputs = [[None], [None], [None], ['2'], ['2 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...
143
191
coding
Solve the programming task below in a Python markdown code block. Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as ...
{"inputs": ["0\n", "3\n", "8\n", "9\n", "1\n", "3\n", "5\n", "9\n"], "outputs": ["0", "1", "1", "1", "1", "1", "1", "1\n"]}
402
63
coding
Solve the programming task below in a Python markdown code block. Make a function **"add"** that will be able to sum elements of **list** continuously and return a new list of sums. For example: ``` add [1,2,3,4,5] == [1, 3, 6, 10, 15], because it's calculated like this : [1, 1 + 2, 1 + 2 + 3, 1 + 2 + 3 + 4, 1 + 2 ...
{"functional": "_inputs = [[[5, 10, 15, 20, 25, 30, 35, 40]], [[6, 12, 18, 24, 30, 36, 42]], [[7, 14, 21, 28, 35, 42, 49, 56]], [[8, 16, 24, 32, 40, 48, 56, 64]], [[9, 18, 27, 36, 45, 54]]]\n_outputs = [[[5, 15, 30, 50, 75, 105, 140, 180]], [[6, 18, 36, 60, 90, 126, 168]], [[7, 21, 42, 70, 105, 147, 196, 252]], [[8, 24...
169
448
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a tree with $N$ nodes numbered from $1$ to $N$. A set $S$ of nodes is called valid if there exist two vertices $u$ and $v$ (possibly, $u=v$) suc...
{"inputs": ["2\n4\n1 2\n3 1\n2 4\n4\n1 2\n2 3\n2 4"], "outputs": ["15\n13"]}
596
44
coding
Solve the programming task below in a Python markdown code block. Coders is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into se...
{"inputs": ["19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19"], "outputs": ["4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916"]}
367
169
coding
Solve the programming task below in a Python markdown code block. Snuke found N strange creatures. Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively. Every creature can absorb another creature whose size is at most twice the size of itself. Whe...
{"inputs": ["3\n3 1 3", "3\n1 1 3", "3\n5 1 3", "3\n1 1 2", "3\n5 2 3", "3\n1 1 1", "3\n3 1 4", "5\n1 1 1 1 2"], "outputs": ["2\n", "3\n", "2\n", "3\n", "3\n", "3\n", "2", "5\n"]}
312
113
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Eidi gifts are a tradition in which children receive money from elder relatives during the Eid celebration. Chef has three children (numbered $1, 2,...
{"inputs": ["5\n5 7 10 10 20 50\n5 5 5 20 10 20\n10 1 17 5 10 15\n3 6 3 8 10 9\n8 5 5 50 10 10"], "outputs": ["FAIR\nNOT FAIR\nNOT FAIR\nNOT FAIR\nFAIR"]}
576
103
coding
Solve the programming task below in a Python markdown code block. Complete the solution so that the function will break up camel casing, using a space between words. ### Example ``` solution("camelCasing") == "camel Casing" ``` Also feel free to reuse/extend the following starter code: ```python def solution(s): `...
{"functional": "_inputs = [['helloWorld'], ['camelCase'], ['breakCamelCase']]\n_outputs = [['hello World'], ['camel Case'], ['break Camel Case']]\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 isinsta...
73
174
coding
Solve the programming task below in a Python markdown code block. A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example `12` is the LCM of `(1, 12), (2, 12), (3,4)` etc. For a given positive integer N, the number of different integer pairs with LCM is equal t...
{"functional": "_inputs = [[1], [12], [24], [25], [101101291], [12345676], [1251562], [625], [9801], [30858025]]\n_outputs = [[1], [8], [11], [3], [5], [68], [41], [5], [23], [63]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_to...
144
251
coding
Solve the programming task below in a Python markdown code block. Write a function that outputs the transpose of a matrix - a new matrix where the columns and rows of the original are swapped. For example, the transpose of: | 1 2 3 | | 4 5 6 | is | 1 4 | | 2 5 | | 3 6 | The input to your func...
{"functional": "_inputs = [[[[1]]], [[[1, 2, 3]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]]]]\n_outputs = [[[[1]]], [[[1], [2], [3]]], [[[1, 4, 7], [2, 5, 8], [3, 6, 9]]], [[[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-...
147
326
coding
Solve the programming task below in a Python markdown code block. You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ in...
{"inputs": ["1\n3\n4\n2\n7"], "outputs": ["0 1\n1 2\n3 4"]}
552
30
coding
Solve the programming task below in a Python markdown code block. You are given positive integers N and M. How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7. Here, two sequences a' and a'' are considered different when there e...
{"inputs": ["3 4", "3 6", "5 4", "3 1", "6 4", "4 6", "5 6", "3 2"], "outputs": ["6\n", "9\n", "15\n", "1\n", "21\n", "16\n", "25\n", "3\n"]}
246
82
coding
Solve the programming task below in a Python markdown code block. For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are $W_1, W_2, W_3$. Ada's strength is $S$. Whenever she hits a stack of bricks, consider the large...
{"inputs": ["3\n3 1 2 2\n2 1 1 1\n3 2 2 1"], "outputs": ["2\n2\n2"]}
541
40
coding
Solve the programming task below in a Python markdown code block. You are given an array A of N integers, initially all zero. There are Q types of operations that you are allowed to perform. Each operation is described by two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ N) and is as follows: Set A_{j} = A_{j} \oplus...
{"inputs": ["2 2\n1 2\n1 1"], "outputs": ["4"]}
387
22
coding
Solve the programming task below in a Python markdown code block. Failed Sort - Bug Fixing #4 Oh no, Timmy's Sort doesn't seem to be working? Your task is to fix the sortArray function to sort all numbers in ascending order Also feel free to reuse/extend the following starter code: ```python def sort_array(value): ```
{"functional": "_inputs = [['12345'], ['54321'], ['34251'], ['11111'], ['10101']]\n_outputs = [['12345'], ['12345'], ['12345'], ['11111'], ['00111']]\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 isi...
74
218
coding
Solve the programming task below in a Python markdown code block. Indian National Olympiad in Informatics 2012 You are given a table with 2 rows and N columns. Each cell has an integer in it. The score of such a table is defined as follows: for each column, consider the sum of the two numbers in the column; the maximum...
{"inputs": ["and output corresponding to the example above.\nSample input\n4\n7 1 6 2\nSample output\n9 10 10 11\nNote: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous ...
620
89
coding
Solve the programming task below in a Python markdown code block. An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. #...
{"functional": "_inputs = [['foefet', 'toffee'], ['Buckethead', 'DeathCubeK'], ['Twoo', 'WooT'], ['dumble', 'bumble'], ['ound', 'round'], ['apple', 'pale']]\n_outputs = [[True], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n...
127
215
coding
Solve the programming task below in a Python markdown code block. The kingdom of Zion has cities connected by bidirectional roads. There is a unique path between any pair of cities. Morpheus has found out that the machines are planning to destroy the whole kingdom. If two machines can join forces, they will attack. ...
{"inputs": ["5 3\n2 1 8\n1 0 5\n2 4 5\n1 3 4\n2\n4\n0\n"], "outputs": ["10\n"]}
631
47
coding
Solve the programming task below in a Python markdown code block. Implement a function, so it will produce a sentence out of the given parts. Array of parts could contain: - words; - commas in the middle; - multiple periods at the end. Sentence making rules: - there must always be a space between words; - there must ...
{"functional": "_inputs = [[['hello', 'world']], [['Quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']], [['hello', ',', 'my', 'dear']], [['one', ',', 'two', ',', 'three']], [['One', ',', 'two', 'two', ',', 'three', 'three', 'three', ',', '4', '4', '4', '4']], [['hello', 'world', '.']], [['Bye', '.']], [['...
123
397
coding
Solve the programming task below in a Python markdown code block. Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has...
{"inputs": ["2\n2 3\n1 4\n", "2\n2 0\n1 6\n", "2\n2 1\n1 6\n", "2\n2 1\n0 6\n", "2\n5 6\n1 10\n", "2\n5 9\n1 10\n", "2\n3 9\n1 10\n", "2\n3 9\n1 12\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]}
516
136
coding
Solve the programming task below in a Python markdown code block. You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume. You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one t...
{"inputs": ["1\n1\n100\n", "1\n1\n100\n", "1\n100000000\n1\n", "1\n100000000\n1\n", "5\n5 4 3 7 3\n7 7 14 57 94\n", "5\n5 4 3 7 3\n7 7 14 57 94\n", "5\n5 4 3 7 3\n7 7 14 57 61\n", "5\n5 4 3 7 3\n7 1 14 57 61\n"], "outputs": ["10\n", "10\n", "100000000000\n", "100000000000\n", "89\n", "89\n", "112\n", "118\n"]}
613
228
coding
Solve the programming task below in a Python markdown code block. You are given an array A containing N integers. A [subsequence] of this array is called *good* if all the elements of this subsequence are distinct. Find the number of *good* non-empty subsequences of A. This number can be large, so report it modulo 10^...
{"inputs": ["2\n2\n1 1\n2\n1 2\n"], "outputs": ["2\n3\n"]}
434
28
coding
Solve the programming task below in a Python markdown code block. You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two adjacent elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the mi...
{"inputs": ["2\n1 0", "2\n1 1", "2\n0 2", "2\n2 2", "2\n0 1", "2\n2 0", "2\n0 0", "2\n0 3"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
237
94
coding
Solve the programming task below in a Python markdown code block. JJ has an array A initially of length N. He can perform the following operation on A: 1) Pick any index i (1 ≤ i ≤ |A|) such that A_{i} > 1 \\ 2) Select any two integers X and Y such that X + Y = A_{i} and X, Y ≥ 1 \\ 3) Replace A_{i} with X and Y Note...
{"inputs": ["3\n4\n3 7 6 4\n5\n1 4 5 4 1\n5\n1 2 3 4 5\n"], "outputs": ["2\n0\n4\n"]}
664
52
coding
Solve the programming task below in a Python markdown code block. There are $n$ monsters standing in a row numbered from $1$ to $n$. The $i$-th monster has $h_i$ health points (hp). You have your attack power equal to $a$ hp and your opponent has his attack power equal to $b$ hp. You and your opponent are fighting the...
{"inputs": ["2 1 3 1\n6 13\n", "2 1 3 0\n50 50\n", "2 1 3 0\n50 64\n", "2 1 3 0\n10 64\n", "2 1 3 1\n10 64\n", "2 1 3 1\n10 13\n", "2 2 5 7\n14 50\n", "2 2 9 7\n14 50\n"], "outputs": ["2\n", "0\n", "0\n", "0\n", "1\n", "2\n", "2\n", "2\n"]}
570
165
coding
Solve the programming task below in a Python markdown code block. AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual number...
{"inputs": ["3\n3 3\n1 1\n3 2", "3\n4 3\n1 1\n3 1", "3\n4 3\n1 2\n3 1", "3\n2 3\n1 1\n1 2", "3\n4 3\n1 1\n1 2", "3\n2 1\n1 1\n3 2", "3\n3 3\n1 2\n3 2", "3\n4 3\n1 2\n2 1"], "outputs": ["10\n", "16\n", "32\n", "9\n", "12\n", "5\n", "15\n", "24\n"]}
381
164
coding
Solve the programming task below in a Python markdown code block. Many years ago Berland was a small country where only $n$ people lived. Each person had some savings: the $i$-th one had $a_i$ burles. The government considered a person as wealthy if he had at least $x$ burles. To increase the number of wealthy people ...
{"inputs": ["1\n1 3\n2\n", "1\n1 2\n2\n", "1\n1 2\n9\n", "1\n1 6\n2\n", "1\n1 1\n9\n", "1\n1 1\n2\n", "1\n1 4\n2\n", "1\n1 3\n9\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n"]}
718
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2. Given an integer n, return the number of square triples such that 1 <= a, b, c <= n.   Please complete the following python code pre...
{"functional": "def check(candidate):\n assert candidate(n = 5) == 2\n assert candidate(n = 10) == 4\n\n\ncheck(Solution().countTriples)"}
102
45
coding
Solve the programming task below in a Python markdown code block. ### Task The __dot product__ is usually encountered in linear algebra or scientific computing. It's also called __scalar product__ or __inner product__ sometimes: > In mathematics, the __dot product__, or __scalar product__ (or sometimes __inner product...
{"functional": "_inputs = [[[], []], [[1, 2, 3, 4, 5], [0, 1, 1, 1, 0]], [[1, 2, 3, 4, 5], [0, 0, 1, 1, -4]], [[1, 3, 5], [4, -2, 1]]]\n_outputs = [[0], [6], [-17], [-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...
481
243
coding
Solve the programming task below in a Python markdown code block. The Spelling Bee bees are back... # How many bees are in the beehive? * bees can be facing UP, DOWN, LEFT, RIGHT, and now also _diagonally_ up/down/left/right * bees can share parts of other bees ## Examples Ex1 ``` bee.bee .e..e.. .b..eeb ```...
{"functional": "_inputs = [[None]]\n_outputs = [[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, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_e...
145
157
coding
Solve the programming task below in a Python markdown code block. In computer science and discrete mathematics, an [inversion](https://en.wikipedia.org/wiki/Inversion_%28discrete_mathematics%29) is a pair of places in a sequence where the elements in these places are out of their natural order. So, if we use ascending ...
{"functional": "_inputs = [[[1, 2, 3]], [[-3, -2, -1]], [[-20, 0, 20]], [[-13, 4, 8]], [[1, 3, 2]], [[-2, -3, -1]], [[-20, 20, 0]], [[-13, 9, 8]], [[3, 6, 2]], [[3, 6, 2, 7, 3]], [[26, 32, -21, 45, 21]], [[14, 12, 17, 124, 1, -12, 21, -24]], [[]], [[25, 12, 7, 4, 2, -7, -12, -22]], [[324, 123, 36, 4, -1, -72, -123]], [...
277
566
coding
Solve the programming task below in a Python markdown code block. You are Dastan, the great Prince of Persia! After searching long for the mysterious 'Sands of Time', you have finally arrived at the gates of the city that hosts the ancient temple of the gods. However, the gate is locked and it can only be opened with a...
{"inputs": ["3\n5 3\nH T T H T\n7 4\nH H T T T H H\n6 1\nT H T H T T"], "outputs": ["1\n2\n2"]}
487
49
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. There is a party going on in a club situated in some city. N gangsters will attend that party. The i-th gangster comes to the party at the beginning of S_{i} time and will leave the party...
{"inputs": ["3\n3 2\n1 3\n3 5\n4 6\n4 3\n1 8\n2 9\n3 10\n4 11\n4 3\n1 5\n4 9\n8 13\n12 17"], "outputs": ["1\n2\n0"]}
709
77
coding
Solve the programming task below in a Python markdown code block. Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangemen...
{"inputs": ["2 8 6", "2 2 2", "2 2 1", "2 0 6", "1 8 6", "2 0 2", "1 8 1", "2 4 2"], "outputs": ["NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
177
94
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody win...
{"inputs": ["8 50 50 0", "1 000 0 0", "2 100 0 0", "6 50 50 0", "5 50 50 0", "3 50 50 0", "4 100 0 0", "2 50 50 0"], "outputs": ["127441420\n", "0\n", "2\n", "386718762\n", "351562510\n", "125000005\n", "4\n", "500000006\n"]}
359
166
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef Watson uses a social network called ChefBook, which has a new feed consisting of posts by his friends. Each post can be characterized by f - the identifier of the friend...
{"inputs": ["2 4\n1 2\n1 1 WhoDoesntLoveChefBook\n2 2 WinterIsComing\n3 10 TheseViolentDelightsHaveViolentEnds\n4 3 ComeAtTheKingBestNotMiss"], "outputs": ["WinterIsComing\nWhoDoesntLoveChefBook\nTheseViolentDelightsHaveViolentEnds\nComeAtTheKingBestNotMiss"]}
619
89
coding
Solve the programming task below in a Python markdown code block. Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive. For permutation p = p_0, p_1, ..., p_{n}, Polo has defined its beauty — number $(0 \oplus p_{0}) +(1 \oplus p_{1}) + \cdots +(n \oplus p_{n...
{"inputs": ["4\n", "7\n", "1\n", "2\n", "3\n", "8\n", "2\n", "7\n"], "outputs": ["20\n0 2 1 4 3\n", "56\n7 6 5 4 3 2 1 0\n", "2\n1 0\n", "6\n0 2 1\n", "12\n3 2 1 0\n", "72\n0 6 5 4 3 2 1 8 7\n", "6\n0 2 1 ", "56\n7 6 5 4 3 2 1 0 "]}
265
158
coding
Solve the programming task below in a Python markdown code block. You probably know that the "mode" of a set of data is the data point that appears most frequently. Looking at the characters that make up the string `"sarsaparilla"` we can see that the letter `"a"` appears four times, more than any other letter, so the ...
{"functional": "_inputs = [['tomato'], [[1, 3, 3, 7]], [['redder']]]\n_outputs = [[['o', 't']], [[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 le...
393
181
coding
Solve the programming task below in a Python markdown code block. Given a name, turn that name into a perfect square matrix (nested array with the amount of arrays equivalent to the length of each array). You will need to add periods (`.`) to the end of the name if necessary, to turn it into a matrix. If the name h...
{"functional": "_inputs = [[''], ['G'], ['Beyonce'], ['Franklin'], ['Bill'], ['Frank']]\n_outputs = [['name must be at least one letter'], [[['G']]], [[['B', 'e', 'y'], ['o', 'n', 'c'], ['e', '.', '.']]], [[['F', 'r', 'a'], ['n', 'k', 'l'], ['i', 'n', '.']]], [[['B', 'i'], ['l', 'l']]], [[['F', 'r', 'a'], ['n', 'k', '....
162
274
coding
Solve the programming task below in a Python markdown code block. Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n0\n", "1 2\n0 1\n", "1 2\n1 0\n", "1 2\n1 1\n", "2 1\n1\n0\n", "2 1\n0\n1\n"], "outputs": ["0\n", "0", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]}
525
111
coding
Solve the programming task below in a Python markdown code block. Given a string, remove characters until the string is made up of any two alternating characters. When you choose a character to remove, all instances of that character must be removed. Determine the longest string possible that contains just two altern...
{"inputs": ["10\nbeabeefeab\n"], "outputs": ["5\n"]}
517
20
coding
Solve the programming task below in a Python markdown code block. Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his res...
{"inputs": ["2\n-1 1\n", "2\n-1 -1\n", "5\n-1 -1 4 1 -1\n", "5\n-1 -1 4 2 -1\n", "5\n-1 -1 5 3 -1\n", "5\n-1 -1 5 1 -1\n", "5\n-1 -1 1 3 -1\n", "5\n-1 -1 1 5 -1\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "4\n", "3\n", "4\n"]}
452
146
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length ...
{"inputs": ["3\n2\n1 2\n3\n1 2 1\n4\n2 6 5 2"], "outputs": ["2\n2 1\n2\n2 1 1\n4\n6 2 2 5"]}
571
58
coding
Solve the programming task below in a Python markdown code block. A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that w...
{"inputs": ["abc\nxyy\n", "abc\nyyx\n", "abc\nyzx\n", "acb\nyzx\n", "adb\nyzx\n", "abc\nxyz\n", "bbcd\ndabc\n", "bdcb\ndabc\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1", "-1\n", "-1\n"]}
337
95
coding
Solve the programming task below in a Python markdown code block. You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. -----Constraints----- - All values in input are integers. - 0 \leq L...
{"inputs": ["3 5", "1 5", "2 5", "6 8", "1 8", "0 8", "0 9", "0 7"], "outputs": ["12\n", "2\n", "6\n", "42\n", "2\n", "0\n", "0\n", "0\n"]}
218
80
coding
Solve the programming task below in a Python markdown code block. There are N persons called Person 1 through Person N. You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times. If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is ...
{"inputs": ["5 2\n1 4\n3 4\n3 1", "5 3\n1 2\n3 4\n3 1", "5 3\n1 2\n3 5\n3 1", "5 2\n1 2\n3 4\n3 1", "5 3\n2 2\n3 4\n5 1", "5 2\n1 4\n3 4\n5 1", "5 2\n1 4\n3 4\n4 1", "5 3\n1 2\n3 4\n5 1"], "outputs": ["3\n", "4\n", "4\n", "2\n", "2\n", "3\n", "3\n", "3"]}
291
173
coding
Solve the programming task below in a Python markdown code block. Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully — instead of carrying to the next column, she carries to the column two columns to the left. For example, the regular way to evaluate the sum $2039 + 2976$ woul...
{"inputs": ["1\n1\n", "1\n2\n", "1\n204\n", "1\n174\n", "1\n7323\n", "1\n3974\n", "1\n6652\n", "1\n4402\n"], "outputs": ["0\n", "1\n", "23\n", "118\n", "2480\n", "3608\n", "4156\n", "1761\n"]}
617
117
coding
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"]}
286
175
coding
Solve the programming task below in a Python markdown code block. Little Lucy loves to arrange her flowers in patterns similar to those of a binary search tree. Her father, a computer scientist himself, takes note of this and finds out that she has N flowers. Every day she takes some of these N flowers and arranges the...
{"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["1\n4\n14\n50 \n"]}
359
32
coding
Solve the programming task below in a Python markdown code block. Your task is to create a function that does four basic mathematical operations. The function should take three arguments - operation(string/char), value1(number), value2(number). The function should return result of numbers after applying the chosen o...
{"functional": "_inputs = [['+', 4, 7], ['-', 15, 18], ['*', 5, 5], ['/', 49, 7]]\n_outputs = [[11], [-3], [25], [7]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
166
198
coding
Solve the programming task below in a Python markdown code block. Write a program which reads two integers x and y, and prints them in ascending order. Constraints * 0 ≤ x, y ≤ 10000 * the number of datasets ≤ 3000 Input The input consists of multiple datasets. Each dataset consists of two integers x and y separate...
{"inputs": ["3 1\n2 2\n5 3\n0 0", "3 1\n2 2\n9 3\n0 0", "3 1\n0 2\n9 3\n0 0", "3 0\n0 2\n9 3\n0 0", "3 2\n2 2\n5 6\n0 0", "3 1\n2 3\n9 3\n0 0", "3 0\n0 2\n9 5\n0 0", "3 2\n2 3\n5 6\n0 0"], "outputs": ["1 3\n2 2\n3 5\n", "1 3\n2 2\n3 9\n", "1 3\n0 2\n3 9\n", "0 3\n0 2\n3 9\n", "2 3\n2 2\n5 6\n", "1 3\n2 3\n3 9\n", "0 3\...
169
254
coding
Solve the programming task below in a Python markdown code block. Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals ...
{"inputs": ["3\n4 8 2\n", "3\n3 5 6\n", "3\n6 8 2\n", "3\n1 1 1\n", "3\n4 8 2\n", "3\n3 5 6\n", "1\n100000\n", "1\n100000\n"], "outputs": ["2", "5", "5\n", "0\n", "2\n", "5\n", "0", "0\n"]}
394
117
coding
Solve the programming task below in a Python markdown code block. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 2\n", "1\n1 3\n", "1\n0 1\n", "1\n2 1\n", "1\n2 2\n", "1\n2 0\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
559
100
coding
Solve the programming task below in a Python markdown code block. Gopal is climbing the stairs. He can jump 1 or 2 or 3 steps at a time. He wants to climb N steps. In how many ways can he reach the Nth step? As the answer can be too large Output it modulo 10^9+7. Input: First line of the input contains an integer T de...
{"inputs": ["100\n184\n87\n178\n116\n194\n136\n187\n93\n50\n22\n163\n28\n91\n60\n164\n127\n141\n27\n173\n137\n12\n169\n168\n30\n183\n131\n63\n124\n68\n136\n130\n3\n23\n59\n70\n168\n194\n57\n12\n43\n30\n174\n22\n120\n185\n138\n199\n125\n116\n171\n14\n127\n92\n181\n157\n74\n63\n171\n197\n82\n106\n126\n85\n128\n137\n106\n...
222
1,290
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list, and an integer k. Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed).   Pleas...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), k = 2), list_node([1,4,3,2,5]))\n assert is_same_list(candidate(head = list_node([7,9,6,6,7,8,3,0,9,5]), k = 5), list_node([7,9,6,6,8,7,3,0,9,5]))\n assert is_same_list(candidate(head = list_node([1]), k = 1), ...
146
208
coding
Solve the programming task below in a Python markdown code block. You are given an array of $n$ integers: $a_1, a_2, \ldots, a_n$. Your task is to find some non-zero integer $d$ ($-10^3 \leq d \leq 10^3$) such that, after each number in the array is divided by $d$, the number of positive numbers that are presented in t...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n-1\n", "1\n-1\n", "1\n-2\n", "1\n777\n", "2\n1 0\n"], "outputs": ["0", "0", "1\n", "-1", "-1", "-1\n", "1", "1"]}
566
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money. You must buy exactly two chocol...
{"functional": "def check(candidate):\n assert candidate(prices = [1,2,2], money = 3) == 0\n assert candidate(prices = [3,2,3], money = 3) == 3\n\n\ncheck(Solution().buyChoco)"}
168
64
coding
Solve the programming task below in a Python markdown code block. # Story Due to lack of maintenance the minute-hand has fallen off Town Hall clock face. And because the local council has lost most of our tax money to a Nigerian email scam there are no funds to fix the clock properly. Instead, they are asking for v...
{"functional": "_inputs = [[0], [360], [90], [180], [270], [30], [40], [45], [50], [60]]\n_outputs = [['12:00'], ['12:00'], ['03:00'], ['06:00'], ['09:00'], ['01:00'], ['01:20'], ['01:30'], ['01:40'], ['02:00']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r...
248
263
coding
Solve the programming task below in a Python markdown code block. Given a triangle of consecutive odd numbers: ``` 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... ``` find the triangle's row knowing its index (the rows are 1-indexed), e.g.: ``` odd_row(1) ...
{"functional": "_inputs = [[1], [2], [13], [19], [41], [93]]\n_outputs = [[[1]], [[3, 5]], [[157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181]], [[343, 345, 347, 349, 351, 353, 355, 357, 359, 361, 363, 365, 367, 369, 371, 373, 375, 377, 379]], [[1641, 1643, 1645, 1647, 1649, 1651, 1653, 1655, 1657, 1659,...
221
1,144
coding
Solve the programming task below in a Python markdown code block. You will be given m strings. For each of those strings, you need to count the total number of appearances of that string as substrings in all possible strings of length n containing only lower case English letters. A string may appear in a string multi...
{"inputs": ["3\n2 1\naa\n2 1\nd\n12 3\ncdmn\nqweewef\nqs\n\n"], "outputs": ["Case 1:\n1\nCase 2:\n52\nCase 3:\n443568031\n71288256\n41317270"]}
472
88
coding
Solve the programming task below in a Python markdown code block. There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total? --...
{"inputs": ["2", "0", "9", "4", "5", "8", "3", "1"], "outputs": ["3\n", "0\n", "45\n", "10\n", "15\n", "36\n", "6", "1"]}
140
64
coding
Solve the programming task below in a Python markdown code block. Chef rented a car for a day. Usually, the cost of the car is Rs 10 per km. However, since Chef has booked the car for the whole day, he needs to pay for at least 300 kms even if the car runs less than 300 kms. If the car ran X kms, determine the cost ...
{"inputs": ["5\n800\n3\n299\n301\n300\n"], "outputs": ["8000\n3000\n3000\n3010\n3000\n"]}
497
55
coding
Solve the programming task below in a Python markdown code block. Valentine's Day is approaching and thus Chef wants to buy some chocolates for someone special. Chef has a total of X rupees and one chocolate costs Y rupees. What is the maximum number of chocolates Chef can buy? ------ Input Format ------ - First l...
{"inputs": ["4\n5 10\n16 5\n35 7\n100 1\n"], "outputs": ["0\n3\n5\n100\n"]}
388
43
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Andy and Bob are the only two delivery men of Pizza-chef store. Today, the store received N orders. It's known that the amount of tips may be different when handled by different delivery man. ...
{"inputs": ["5 3 3\n1 2 3 4 5\n5 4 3 2 1", "5 3 3\n1 2 3 4 5\n5 4 3 0 1", "5 3 3\n1 0 3 5 5\n5 4 3 0 1", "5 3 3\n1 2 3 4 5\n2 4 2 0 2", "5 3 3\n1 2 5 4 5\n2 4 2 1 3", "5 3 3\n1 2 5 4 9\n2 4 2 1 2", "5 3 3\n1 2 4 4 9\n2 4 2 1 2", "5 3 3\n1 0 3 4 5\n5 2 3 0 1"], "outputs": ["21", "21\n", "22\n", "18\n", "20\n", "24\n", "...
447
261
coding
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"]}
373
39
coding
Solve the programming task below in a Python markdown code block. You are given a positive integer X. Your task is to tell whether there exist two positive integers a and b (a > 0, b > 0) such that 2\cdot a + 2\cdot b + a\cdot b = X If there exist positive integers a and b satisfying the above condition print YES, ot...
{"inputs": ["4\n2\n5\n6\n12\n"], "outputs": ["NO\nYES\nNO\nYES\n"]}
402
29
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations, or false otherwise. The allowed operation on some point (x, y) is to c...
{"functional": "def check(candidate):\n assert candidate(sx = 1, sy = 1, tx = 3, ty = 5) == True\n assert candidate(sx = 1, sy = 1, tx = 2, ty = 2) == False\n assert candidate(sx = 1, sy = 1, tx = 1, ty = 1) == True\n\n\ncheck(Solution().reachingPoints)"}
134
101
coding
Solve the programming task below in a Python markdown code block. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each ti...
{"inputs": ["1 3 2\n1\n", "1 7 10\n1\n", "1 10 2\n1\n", "1 9 10\n1\n", "2 4 1\n1 1\n", "1 10 10\n1\n", "2 4 1\n1 0\n", "1 18 10\n1\n"], "outputs": ["2\n", "3\n", "2\n", "1\n", "2\n", "0\n", "2\n", "10\n"]}
412
130
coding
Solve the programming task below in a Python markdown code block. The Little Elephant loves numbers. He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations...
{"inputs": ["2\n", "3\n", "9\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
133
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of integers, return the length of the longest arithmetic subsequence in nums. Note that: A subsequence is an array that can be derived from another array by deleting some or no elements without ch...
{"functional": "def check(candidate):\n assert candidate(nums = [3,6,9,12]) == 4\n assert candidate(nums = [9,4,7,2,10]) == 3\n assert candidate(nums = [20,1,15,3,10,5,8]) == 4\n\n\ncheck(Solution().longestArithSeqLength)"}
135
90
coding
Solve the programming task below in a Python markdown code block. After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you. You will need a rental car in order for you to get around in your vacation. The...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]\n_outputs = [[40], [80], [100], [140], [180], [220], [230], [270], [310], [350]]\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 ...
171
230
coding
Solve the programming task below in a Python markdown code block. Check if given chord is minor or major. _____________________________________________________________ Rules: 1. Basic minor/major chord have three elements. 2. Chord is minor when interval between first and second element equals 3 and between second a...
{"functional": "_inputs = [['C E G'], ['Db F Ab'], ['D F# A'], ['Eb G Bb'], ['E G# B'], ['F A C'], ['F# A# C#'], ['Gb Bb Db'], ['G B D'], ['Ab C Eb'], ['A C# E'], ['Bb D F'], ['B D# F#'], ['C Eb G'], ['C# E G#'], ['D F A'], ['D# F# A#'], ['Eb Gb Bb'], ['E G B'], ['F Ab C'], ['F# A C#'], ['G Bb D'], ['G# B D#'], ['A C E...
320
521
coding
Solve the programming task below in a Python markdown code block. After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are give...
{"inputs": ["3 0\n", "6 0\n", "4 0\n", "8 0\n", "3 0\n", "16 0\n", "13 0\n", "11 0\n"], "outputs": ["3 1\n", "3 20\n", "3 4\n", "3 56\n", "3 1", "3 560\n", "3 286\n", "3 165\n"]}
539
112
coding
Solve the programming task below in a Python markdown code block. We consider permutations of the numbers $1,..., N$ for some $N$. By permutation we mean a rearrangment of the number $1,...,N$. For example 24517638245176382 \quad 4 \quad 5 \quad 1 \quad 7 \quad 6 \quad 3 \quad 8 is a permutation of $1,2,...,8$. Of cour...
{"inputs": ["8\n2 4 5 1 7 6 3 8", "8\n1 2 3 4 5 6 7 8"], "outputs": ["4\n1 2 4 1\n3 5 7 3\n6 6\n8 8", "8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"]}
747
106
coding
Solve the programming task below in a Python markdown code block. Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved pro...
{"inputs": ["3\n3 5 4\n", "3\n6 5 4\n", "3\n6 5 8\n", "3\n6 5 6\n", "3\n4 5 6\n", "3\n4 0 6\n", "3\n4 0 7\n", "3\n7 0 7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
561
118
coding
Solve the programming task below in a Python markdown code block. You are given an array $A$ of $N$ positive and pairwise distinct integers. You can permute the elements in any way you want. The cost of an ordering $(A_1, A_2, \ldots, A_N)$ is defined as $ (((A_1 \bmod A_2) \bmod A_3)......) \bmod A_N$ where $X \bmod...
{"inputs": ["1\n2\n7 12"], "outputs": ["7"]}
413
19
coding
Solve the programming task below in a Python markdown code block. Ashish has an array a of consisting of 2n positive integers. He wants to compress a into an array b of size n-1. To do this, he first discards exactly 2 (any two) elements from a. He then performs the following operation until there are no elements left ...
{"inputs": ["3\n3\n1 2 3 4 5 6\n2\n5 7 9 6\n5\n1 3 3 4 5 90 100 101 2 3\n", "3\n3\n1 2 3 5 9 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 000 101 2 3\n", "3\n3\n1 2 3 5 9 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 000 100 2 3\n", "3\n3\n1 2 3 4 5 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 100 101 2 3\n", "3\n3\n1 2 3 4 5 6\n2\n5 7 9 6\n5\n1 3 3 2 5 90 000 ...
663
688
coding
Solve the programming task below in a Python markdown code block. Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, lets add some flavor of ingenui...
{"functional": "_inputs = [[[1, 2, 3]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5]]]\n_outputs = [[9], [19], [33]]\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)...
306
195
coding
Solve the programming task below in a Python markdown code block. The problem is quite simple. You're given a number N and a positive integer K. Tell if N can be represented as a sum of K prime numbers (not necessarily distinct). Input Format The first line contains a single integer T, denoting the number of test c...
{"inputs": ["2\n10 2\n1 6\n"], "outputs": ["Yes\nNo\n"]}
226
25
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such ...
{"functional": "def check(candidate):\n assert candidate(n = 8) == 6\n assert candidate(n = 1) == 1\n assert candidate(n = 4) == -1\n\n\ncheck(Solution().pivotInteger)"}
119
55
coding
Solve the programming task below in a Python markdown code block. In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of ...
{"inputs": ["9", "30", "22", "41", "91", "36", "36\n", "91\n"], "outputs": ["2\n", "3\n", "4\n", "5\n", "3", "8", "8\n", "3\n"]}
347
69
coding
Solve the programming task below in a Python markdown code block. problem You are in charge of quality control at a machine manufacturing plant. This machine requires a power supply, a motor, and a cable as parts. The manufacturing plant has a power supply, b motors, and c cables, numbered from 1 to a, a + 1 to a + b,...
{"inputs": ["2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 2 1\n0 0 0", "2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 2 0\n0 0 0", "3 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 5 1\n0 0 0", "2 2 2\n4\n3 4 5 0\n2 3 6 0\n1 4 4 1\n2 3 2 0\n0 0 0", "2 2 2\n4\n2 4 5 0\n1 3 6 0\n1 4 5 0\n2 3 2 1\n0 0 0", "3 2 2\n4\n2 4 5 0\n2 4 6 0\n1 4 ...
692
504
coding
Solve the programming task below in a Python markdown code block. You are given a string of lower case letters. Your task is to figure out the index of the character on whose removal it will make the string a palindrome. There will always be a valid solution. In case the string is already a palindrome, then -1 is also...
{"inputs": ["3\naaab\nbaa\naaa"], "outputs": ["3\n0\n-1"]}
313
25
coding
Solve the programming task below in a Python markdown code block. Will you make it? You were camping with your friends far away from home, but when it's time to go back, you realize that your fuel is running out and the nearest pump is ```50``` miles away! You know that on average, your car runs on about ```25``` mile...
{"functional": "_inputs = [[50, 25, 2], [60, 30, 3], [70, 25, 1], [100, 25, 3]]\n_outputs = [[True], [True], [False], [False]]\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...
175
207