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. Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: * 'U': go up, (x, y) → (...
{"inputs": ["0 1\nD\n", "1 0\nD\n", "0 0\nD\n", "1 1\nLD\n", "0 -1\nU\n", "-1 0\nR\n", "-1 1\nR\n", "2 4\nRU\n"], "outputs": ["No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
466
102
coding
Solve the programming task below in a Python markdown code block. A number can be called v-number if the sum of the lower half of the array is equal to the sum of the upper half of the array. EXAMPLE: if num = 1221 sum of lower half = 3 sum of upper half = 3 then it can be called as v-number INPUT: First line con...
{"inputs": ["4\n1230\n1245789652314562114563414556521414\n11111111111111111111111111111111111111111111111111\n4785632124584233245478996321", "5\n457896663332211445588744552112255478993321254646356\n55668877442266554411221122445566224477886655\n784132368474166365474565214556475132484741\n22558899774421233665514485214565...
146
394
coding
Solve the programming task below in a Python markdown code block. Utkarsh is currently sitting for placements. He has applied to three companies named A, B, and C. You know Utkarsh's order of preference among these 3 companies, given to you as characters first, second, and third respectively (where first is the compan...
{"inputs": ["2\nA B C\nA B\nB C A\nA C"], "outputs": ["A\nC"]}
499
28
coding
Solve the programming task below in a Python markdown code block. Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2 + \ldots...
{"inputs": ["2\n1 1\n", "2\n1 2\n", "2\n0 1\n", "2\n0 1\n", "2\n2 1\n", "2\n1 0\n", "2\n2 2\n", "2\n2 3\n"], "outputs": ["1\n", "3\n", "0\n", "0\n", "3\n", "0\n", "8\n", "499122194\n"]}
570
110
coding
Solve the programming task below in a Python markdown code block. You are given three integers $a$, $b$, and $c$. Determine if one of them is the sum of the other two. -----Input----- The first line contains a single integer $t$ ($1 \leq t \leq 9261$) — the number of test cases. The description of each test case co...
{"inputs": ["1\n14 5 14\n", "1\n19 18 16\n", "7\n1 4 3\n2 5 8\n9 11 20\n0 0 0\n20 20 20\n4 12 3\n15 7 8\n", "12\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "19\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10...
307
791
coding
Solve the programming task below in a Python markdown code block. Ashton appeared for a job interview and is asked the following question. Arrange all the distinct substrings of a given string in lexicographical order and concatenate them. Print the $k^{th}$ character of the concatenated string. It is assured that giv...
{"inputs": ["1\ndbac\n3\n"], "outputs": ["c\n"]}
566
19
coding
Solve the programming task below in a Python markdown code block. It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x. For example, the prairie partitions of 12,...
{"inputs": ["1\n1\n", "1\n2\n", "1\n4\n", "1\n7\n", "1\n6\n", "1\n14\n", "1\n16\n", "1\n23\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
500
89
coding
Solve the programming task below in a Python markdown code block. Regular Tic-Tac-Toe is boring. That's why in this Kata you will be playing Tic-Tac-Toe in **3D** using a 4 x 4 x 4 matrix! # Kata Task Play the game. Work out who wins. Return a string * `O wins after moves` * `X wins after moves` * `No winner`...
{"functional": "_inputs = [[[]]]\n_outputs = [['No winner']]\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...
210
159
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.   Please complete the f...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,3],[2,6],[8,10],[15,18]]) == [[1,6],[8,10],[15,18]]\n assert candidate(intervals = [[1,4],[4,5]]) == [[1,5]]\n\n\ncheck(Solution().merge)"}
93
86
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given four integers a, b, c and d. Determine if there's a rectangle such that the lengths of its sides are a, b, c and d (in any order). ------ Input ------ The fi...
{"inputs": ["3\n1 1 2 2\n3 2 2 3\n1 2 2 2"], "outputs": ["YES\nYES\nNO"]}
240
40
coding
Solve the programming task below in a Python markdown code block. The number 81 has a special property, a certain power of the sum of its digits is equal to 81 (nine squared). Eighty one (81), is the first number in having this property (not considering numbers of one digit). The next one, is 512. Let's see both cases...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7]]\n_outputs = [[81], [512], [2401], [4913], [5832], [17576], [19683]]\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, tu...
226
212
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$. Find any pair of integers $(x,y)$ ($1\leq x,y\leq n$) such that $x^y\cdot y+y^x\cdot x = n$. -----Input----- The first line contains a single integer $t$ ($1\leq t\leq 10^4$) — the number of test cases. Each test case c...
{"inputs": ["5\n3\n7\n42\n31250\n20732790\n"], "outputs": ["-1\n-1\n1 21\n1 15625\n1 10366395\n"]}
317
64
coding
Solve the programming task below in a Python markdown code block. Chef received an array A of N integers as a valentine's day present. He wants to maximize the length of the longest strictly increasing subsequence by choosing a subarray and adding a fixed integer X to all its elements. More formally, Chef wants to max...
{"inputs": ["3\n3\n1 2 1\n5\n1 5 8 6 9\n4\n1 2 2 1\n"], "outputs": ["3\n5\n3\n"]}
598
48
coding
Solve the programming task below in a Python markdown code block. Ho ho! So you think you know integers, do you? Well then, young wizard, tell us what the Nth digit of the [Champernowne constant](https://en.wikipedia.org/wiki/Champernowne_constant) is! The constant proceeds like this: `0.12345678910111213141516...` I...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [20], [35], [36], [37], [100], [101], [102], [103], [104], [105], [190], [2890], [38890], [488890], [5888890], [3678608], [3678609], [3678610], [3678611], [3678612], [3678613], [3678614], [3897249], [3897189], [3897309], [3897369]...
338
729
coding
Solve the programming task below in a Python markdown code block. # Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. The letters called airstrike to help them in war -...
{"functional": "_inputs = [['z'], ['z*dq*mw*pb*s'], ['zdqmwpbs'], ['zz*zzs'], ['sz**z**zs'], ['z*z*z*zs'], ['*wwwwww*z*']]\n_outputs = [['Right side wins!'], [\"Let's fight again!\"], [\"Let's fight again!\"], ['Right side wins!'], ['Left side wins!'], ['Left side wins!'], ['Left side wins!']]\nimport math\ndef _deep_e...
336
244
coding
Solve the programming task below in a Python markdown code block. Problem statement Of the string set $ S $ that meets the following conditions, configure $ 1 $ with the largest number of elements. * The length of the string contained in $ S $ is $ 1 $ or more and $ N $ or less. * The lengths of the strings contained...
{"inputs": ["2"], "outputs": ["2\n0\n11"]}
418
17
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. A sequence of integers is beautiful if each element of this sequence is divisible by 4. You are given a sequence a_{1}, a_{2}, ..., a_{n}. In one step, you may choose any tw...
{"inputs": ["1\n7\n1 2 3 1 2 3 8"], "outputs": ["3"]}
309
28
coding
Solve the programming task below in a Python markdown code block. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type a_{i}. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of ...
{"inputs": ["3\n1 1 1\n", "3\n1 1 1\n", "3\n2 1 1\n", "3\n3 1 1\n", "3\n3 1 2\n", "3\n1 1 2\n", "3\n1 1 3\n", "3\n1 1 4\n"], "outputs": ["1\n1 3\n", "1\n1 3\n", "1\n1 3\n", "1\n1 3\n", "-1\n", "1\n1 3\n", "1\n1 3\n", "1\n1 3\n"]}
437
146
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n binary matrix grid. In one operation, you can choose any i and j that meet the following conditions: 0 <= i < m 0 <= j < n grid[i][j] == 1 and change the values of all cells in row i ...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1],[1,1,1],[0,1,0]]) == 2\n assert candidate(grid = [[0,1,0],[1,0,1],[0,1,0]]) == 2\n assert candidate(grid = [[0,0],[0,0]]) == 0\n\n\ncheck(Solution().removeOnes)"}
135
94
coding
Solve the programming task below in a Python markdown code block. Clock shows 'h' hours, 'm' minutes and 's' seconds after midnight. Your task is to make 'Past' function which returns time converted to milliseconds. ## Example: ```python past(0, 1, 1) == 61000 ``` Input constraints: `0 <= h <= 23`, `0 <= m <= 59`, ...
{"functional": "_inputs = [[0, 1, 1], [1, 1, 1], [0, 0, 0], [1, 0, 1], [1, 0, 0]]\n_outputs = [[61000], [3661000], [0], [3601000], [3600000]]\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(...
128
230
coding
Solve the programming task below in a Python markdown code block. You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here htt...
{"inputs": ["10:10\n0\n", "10:01\n0\n", "04:05\n0\n", "02:59\n1\n", "09:11\n0\n", "19:00\n0\n", "23:59\n1\n", "11:59\n1\n"], "outputs": ["10:10\n", "10:01\n", "04:05\n", "03:00\n", "09:11\n", "19:00\n", "00:00\n", "12:00\n"]}
281
150
coding
Solve the programming task below in a Python markdown code block. Monocarp wants to draw four line segments on a sheet of paper. He wants the $i$-th segment to have its length equal to $a_i$ ($1 \le i \le 4$). These segments can intersect with each other, and each segment should be either horizontal or vertical. Monoc...
{"inputs": ["4\n1 1 3 4\n2 8 5 5\n2 1 4 1\n101 21 0 111\n", "4\n1 1 3 4\n1 8 5 5\n2 1 4 1\n101 4 54 011\n", "4\n1 1 3 4\n2 8 5 5\n4 1 4 1\n101 21 0 011\n", "4\n1 1 3 4\n2 7 5 5\n2 1 4 1\n111 29 4 101\n", "4\n0 1 3 4\n2 5 1 5\n3 1 4 1\n101 8 20 101\n", "4\n1 1 3 4\n2 7 5 5\n2 0 4 1\n111 29 4 101\n", "4\n1 1 3 4\n2 8 4 5...
543
429
coding
Solve the programming task below in a Python markdown code block. Consider creating the following number pattern. 4 8 2 3 1 0 8 3 7 6 2 0 5 4 1 8 1 0 3 2 5 9 5 9 9 1 3 7 4 4 4 8 0 4 1 8 8 2 8 4 9 6 0 0 2 5 6 0 2 1 6 2 7 8 Five This pattern follows the rules below. A B C In the sequence of numbers, C is the ones...
{"inputs": ["4823108376\n2273064329\n0123456789", "4823108376\n2314825047\n0123456789", "4823108376\n1842094049\n0123456789", "4823108376\n2704372300\n0123456789", "4823108376\n2811474872\n0123456789", "4823108376\n1472363412\n0123456789", "4823108376\n5495669921\n0123456789", "4823108376\n2337446006\n0123456789"], "ou...
356
342
coding
Solve the programming task below in a Python markdown code block. Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size $l\times b$ into smaller identical pieces such that each piece is a square having maximum possible side length with no left over piece of bread. Inp...
{"inputs": ["2\n2 2\n6 9\n"], "outputs": ["1\n6\n"]}
319
24
coding
Solve the programming task below in a Python markdown code block. Implement a function which behaves like the 'uniq -c' command in UNIX. It takes as input a sequence and returns a sequence in which all duplicate elements following each other have been reduced to one instance together with the number of times a duplic...
{"functional": "_inputs = [[['a', 'a', 'b', 'b', 'c', 'a', 'b', 'c']], [['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']], [[None, 'a', 'a']], [['foo']], [['']], [[]]]\n_outputs = [[[['a', 2], ['b', 2], ['c', 1], ['a', 1], ['b', 1], ['c', 1]]], [[['a', 3], ['b', 3], ['c', 3]]], [[[None, 1], ['a', 2]]], [[['foo', 1]]], [[[...
145
305
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well known programmer. He owns a brand new Android phone of screen size of dimension n × m (n denotes the height of the phone and m denotes the width). Chef wants t...
{"inputs": ["2\n4 6 12\n3 3 10"], "outputs": ["3\n0"]}
498
28
coding
Solve the programming task below in a Python markdown code block. You are playing a game on a $n \times m$ grid, in which the computer has selected some cell $(x, y)$ of the grid, and you have to determine which one. To do so, you will choose some $k$ and some $k$ cells $(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k)$, ...
{"inputs": ["2\n2 3\n3 1\n", "2\n999 21\n21 999\n"], "outputs": ["2\n1\n", "2\n2\n"]}
578
48
coding
Solve the programming task below in a Python markdown code block. Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption. The encrypted password is a string S consists of ASCII printable ch...
{"inputs": ["4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#xd098d", "4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd098x", "4\n2\n5 3\n3 1\n5\n-1\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# /\n0xd21#xd098d", "4\n2\n5 3\n3 1\n5\n-1\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd0...
555
695
coding
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"]}
540
48
coding
Solve the programming task below in a Python markdown code block. Unicode Transformation Format – 8-bit As the name suggests UTF-8 was designed to encode data in a stream of bytes. It works by splitting the bits up in multiples of eight. This is achieved by inserting headers to mark in how many bytes the bits were spl...
{"functional": "_inputs = [['\\x80'], ['\u07ff'], ['\u0800'], ['\\uffff']]\n_outputs = [['1100001010000000'], ['1101111110111111'], ['111000001010000010000000'], ['111011111011111110111111']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a...
632
264
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them. A string s is a subsequence of string t if deleting som...
{"functional": "def check(candidate):\n assert candidate(str1 = \"abac\", str2 = \"cab\") == \"cabac\"\n assert candidate(str1 = \"aaaaaaaa\", str2 = \"aaaaaaaa\") == \"aaaaaaaa\"\n\n\ncheck(Solution().shortestCommonSupersequence)"}
121
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right. When two ants moving ...
{"functional": "def check(candidate):\n assert candidate(n = 4, left = [4,3], right = [0,1]) == 4\n assert candidate(n = 7, left = [], right = [0,1,2,3,4,5,6,7]) == 7\n assert candidate(n = 7, left = [0,1,2,3,4,5,6,7], right = []) == 7\n\n\ncheck(Solution().getLastMoment)"}
199
113
coding
Solve the programming task below in a Python markdown code block. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game i...
{"inputs": ["4\n1 0 0 2\n", "4\n1 0 0 0\n", "4\n1 0 1 2\n", "5\n4 1 4 7 6\n", "5\n2 1 4 7 6\n", "5\n2 2 4 7 6\n", "5\n2 2 6 7 6\n", "5\n2 2 9 7 6\n"], "outputs": ["1\n1\n2\n", "1\n1\n2\n", "1\n1\n3\n", "4\n5\n9\n17\n", "2\n3\n7\n15\n", "2\n4\n8\n17\n", "2\n4\n10\n19\n", "2\n4\n13\n22\n"]}
583
193
coding
Solve the programming task below in a Python markdown code block. Given are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \leq x \leq y \leq R) such that the remainder when y is divided by x is equal to y \mbox{ XOR } x.What is \mbox{ XOR }? The XOR of integers A and B, A \mbox{ XO...
{"inputs": ["3 3", "3 0", "2 5", "3 4", "4 5", "2 3", "2 3\n", "1 1\n"], "outputs": ["1\n", "0\n", "6\n", "2\n", "3\n", "3", "3\n", "1\n"]}
341
79
coding
Solve the programming task below in a Python markdown code block. Chef is making a dish that consists of exactly two ingredients. He has four ingredients A, B, C and D with tastiness a, b, c, and d respectively. He can use either A or B as the first ingredient and either C or D as the second ingredient. The tastiness...
{"inputs": ["2\n3 5 6 2\n16 15 5 4\n"], "outputs": ["11\n21"]}
331
35
coding
Solve the programming task below in a Python markdown code block. Hossam woke up bored, so he decided to create an interesting array with his friend Hazem. Now, they have an array $a$ of $n$ positive integers, Hossam will choose a number $a_i$ and Hazem will choose a number $a_j$. Count the number of interesting pair...
{"inputs": ["2\n3\n1 1 1\n2\n1 2\n", "2\n5\n6 2 3 8 1\n6\n7 2 8 3 2 10\n", "2\n5\n1 1 1 1 1\n6\n7 2 8 3 2 10\n"], "outputs": ["6\n2\n", "2\n4\n", "20\n4\n"]}
530
105
coding
Solve the programming task below in a Python markdown code block. Lucy had recently learned the game, called Natural Numbers. The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smalle...
{"inputs": ["2\n5\nKouta 1\nYuka 1\nMayu 3\nyucL 2\nNana 5\n2\nLucy 2\nNana 2", "2\n5\nKouta 1\nYuka 0\nMayu 3\nyucL 2\nNana 5\n2\nLucy 2\nNana 2", "2\n5\nKouta 2\nakuY 0\nMayu 3\nyucL 2\nNana 5\n2\nLucy 2\nNana 2", "2\n5\nKouta 1\nYuka 1\nMayu 3\nLucy 2\nNana 5\n2\nLucy 2\nOana 2", "2\n5\nKouta 0\nYuka 1\nMayu 3\nLucy...
540
434
coding
Solve the programming task below in a Python markdown code block. Takahashi Lake has a perimeter of L. On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between 0 and L (including 0 but not L), which is the distance from t...
{"inputs": ["5 3\n1\n7\n8", "3 3\n1\n2\n3", "10 3\n1\n7\n8", "0 3\n2\n7\n32", "4 3\n1\n7\n10", "3 3\n2\n6\n63", "3 3\n2\n6\n50", "3 3\n1\n1\n22"], "outputs": ["11\n", "4\n", "16\n", "32\n", "10\n", "63\n", "50\n", "22\n"]}
470
139
coding
Solve the programming task below in a Python markdown code block. Polycarp wants to buy exactly $n$ shovels. The shop sells packages with shovels. The store has $k$ types of packages: the package of the $i$-th type consists of exactly $i$ shovels ($1 \le i \le k$). The store has an infinite number of packages of each t...
{"inputs": ["1\n8 2\n", "1\n8 2\n", "1\n91 5\n", "1\n49 3\n", "1\n91 5\n", "1\n49 3\n", "1\n14 2\n", "1\n49 6\n"], "outputs": ["4\n", "4\n", "91\n", "49\n", "91\n", "49\n", "7\n", "49\n"]}
521
113
coding
Solve the programming task below in a Python markdown code block. # Task John loves encryption. He can encrypt any string by the following algorithm: ``` take the first and the last letters of the word; replace the letters between them with their number; replace this number with the sum of it digits until a...
{"functional": "_inputs = [['abc', 'abc'], ['abc', 'abd'], ['fKhjuytrdfcdc', 'flJc'], ['OKhjuytrdfcdc', 'OijK']]\n_outputs = [[True], [False], [True], [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...
296
202
coding
Solve the programming task below in a Python markdown code block. Your task is to make two functions, ```max``` and ```min``` (`maximum` and `minimum` in PHP and Python) that take a(n) array/vector of integers ```list``` as input and outputs, respectively, the largest and lowest number in that array/vector. #Examples ...
{"functional": "_inputs = [[[-52, 56, 30, 29, -54, 0, -110]], [[42, 54, 65, 87, 0]], [[1, 2, 3, 4, 5, 10]], [[-1, -2, -3, -4, -5, -10]], [[9]]]\n_outputs = [[-110], [0], [1], [-10], [9]]\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, ...
219
257
coding
Solve the programming task below in a Python markdown code block. Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "2 2\n1\n2\n", "2 2\n1\n4\n", "1 2\n1\n4\n", "2 2\n1\n2\n", "1 1\n1000\n", "1 1\n1000\n"], "outputs": ["1\n", "1\n", "2\n2\n", "2\n2\n", "1\n1\n", "2\n2\n", "1\n", "1\n"]}
315
124
coding
Solve the programming task below in a Python markdown code block. You are given a set of n pens, each of them can be red, blue, green, orange, and violet in color. Count a minimum number of pens that should be taken out from the set so that any two neighboring pens have different colors. Pens are considered to be neigh...
{"inputs": ["2\n5\nRBBRG\n5\nRBGOV"], "outputs": ["1\n0"]}
315
26
coding
Solve the programming task below in a Python markdown code block. All of the animals are having a feast! Each animal is bringing one dish. There is just one rule: the dish must start and end with the same letters as the animal's name. For example, the great blue heron is bringing garlic naan and the chickadee is bringi...
{"functional": "_inputs = [['great blue heron', 'garlic naan'], ['chickadee', 'chocolate cake'], ['brown bear', 'bear claw'], ['marmot', 'mulberry tart'], ['porcupine', 'pie'], ['cat', 'yogurt'], ['electric eel', 'lasagna'], ['slow loris', 'salsas'], ['ox', 'orange lox'], ['blue-footed booby', 'blueberry'], ['fruit-fly...
196
284
coding
Solve the programming task below in a Python markdown code block. I've got a crazy mental illness. I dislike numbers a lot. But it's a little complicated: The number I'm afraid of depends on which day of the week it is... This is a concrete description of my mental illness: Monday --> 12 Tuesday --> numbers gr...
{"functional": "_inputs = [['Monday', 13], ['Monday', 12], ['Tuesday', 0], ['Tuesday', 100], ['Tuesday', 95], ['Wednesday', 35], ['Wednesday', 34], ['Thursday', 2], ['Thursday', 0], ['Friday', 5], ['Friday', 4], ['Saturday', 55], ['Saturday', 56], ['Sunday', 55], ['Sunday', 666], ['Sunday', -666]]\n_outputs = [[False],...
182
308
coding
Solve the programming task below in a Python markdown code block. The Duck song For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes. Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them...
{"inputs": ["1 6 2\n4 3 3\n", "5 1 1\n4 3 2\n", "1 2 3\n3 2 1\n", "1 8 4\n3 1 9\n", "6 1 2\n4 9 6\n", "3 2 1\n1 2 3\n", "1 7 9\n4 5 7\n", "4 6 4\n4 5 6\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
547
150
coding
Solve the programming task below in a Python markdown code block. E869120's and square1001's 16-th birthday is coming soon. Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces. E869120 and square1001 were just about to eat A and B of those pieces, respectively, when they found a ...
{"inputs": ["0 8", "5 1", "0 9", "8 1", "8 0", "5 5", "5 2", "3 1"], "outputs": ["Yay!\n", "Yay!\n", ":(\n", "Yay!\n", "Yay!\n", "Yay!\n", "Yay!\n", "Yay!\n"]}
245
93
coding
Solve the programming task below in a Python markdown code block. Given two integers A and B, find the count of integers X \in [L, R] such that at least one of the following is true: X and A are [coprime] X and B are [coprime] ------ Input Format ------ - The first and only line of input contains four integers A,B,L...
{"inputs": ["6 15 1 10\n", "235714494 193478285 2 100000000000\n"], "outputs": ["6\n", "65435081000\n"]}
268
73
coding
Solve the programming task below in a Python markdown code block. Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a_1, a_2, ..., a_{n} of length n, that the following condition fulfills: a_2 - a_1 = a_3 - a_2 = a_4 - a_3 = ... ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n10\n", "1\n11\n", "1\n-1\n", "1\n17\n", "1\n10\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
467
92
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays nums1 and nums2 of length n, count the pairs of indices (i, j) such that i < j and nums1[i] + nums1[j] > nums2[i] + nums2[j]. Return the number of pairs satisfying the condition.   Please comp...
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,1,2,1], nums2 = [1,2,1,2]) == 1\n assert candidate(nums1 = [1,10,6,2], nums2 = [1,4,1,5]) == 5\n\n\ncheck(Solution().countPairs)"}
112
82
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays. The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] w...
{"functional": "def check(candidate):\n assert candidate(arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2) == 2\n assert candidate(arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3) == 2\n assert candidate(arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6) == 1\n\n\ncheck(Solution().findTheDistanceValue)"}
123
140
coding
Solve the programming task below in a Python markdown code block. There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the ...
{"inputs": ["6 2 1", "5 3 1", "5 3 2", "3 2 0", "7 2 1", "2 2 1", "7 3 2", "5 4 2"], "outputs": ["12\n", "144\n", "216\n", "2\n", "14\n", "4\n", "1488\n", "972\n"]}
283
105
coding
Solve the programming task below in a Python markdown code block. Check if given numbers are prime numbers. If number N is prime ```return "Probable Prime"``` else ``` return "Composite"```. HINT: Upper bount is really big so you should use an efficient algorithm. Input   1 < N ≤ 10^(100) Example   prime_or_composi...
{"functional": "_inputs = [[2], [3], [5], [9], [12]]\n_outputs = [['Probable Prime'], ['Probable Prime'], ['Probable Prime'], ['Composite'], ['Composite']]\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 ...
134
188
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix. Both robots initially start at (0...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,5,4],[1,5,1]]) == 4\n assert candidate(grid = [[3,3,1],[8,5,2]]) == 4\n assert candidate(grid = [[1,3,1,15],[1,3,3,1]]) == 7\n\n\ncheck(Solution().gridGame)"}
311
90
coding
Solve the programming task below in a Python markdown code block. Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the ...
{"inputs": ["1 3\n1 2\n", "1 3\n0 2\n", "1 0\n1 9\n", "1 6\n0 2\n", "1 0\n1 7\n", "1 10\n1 9\n", "1 1\n0 10\n", "1 22\n22 33\n"], "outputs": ["1\n", "1\n", "1\n", "4\n", "1\n", "1\n", "0\n", "0\n"]}
310
123
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Onc...
{"functional": "def check(candidate):\n assert candidate(n = 4, time = 5) == 2\n assert candidate(n = 3, time = 2) == 3\n\n\ncheck(Solution().passThePillow)"}
181
55
coding
Solve the programming task below in a Python markdown code block. Accepts a string from the user and print the reverse string as the output without using any built-in function. -----Input:----- Each testcase contains of a single line of input, a string. -----Output:----- For each testcase, output in a single line ans...
{"inputs": ["1\nTracy"], "outputs": ["ycarT"]}
89
17
coding
Solve the programming task below in a Python markdown code block. Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the num...
{"inputs": ["6\n", "4\n", "3\n", "5\n", "31\n", "28\n", "98\n", "88\n"], "outputs": ["9/4\n", "3/2\n", "2/1\n", "7/3\n", "222/29\n", "85/13\n", "317/16\n", "1529/86\n"]}
252
102
coding
Solve the programming task below in a Python markdown code block. You are given two numbers A and B along with an integer X. In one operation you can do one of the following: Set A = A + X and B = B - X Set A = A - X and B = B + X Determine if you can make A and B equal after applying the operation any number of times...
{"inputs": ["4\n5 7 1\n3 4 2\n4 4 6\n2 5 3\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
385
44
coding
Solve the programming task below in a Python markdown code block. Each number should be formatted that it is rounded to two decimal places. You don't need to check whether the input is a valid number because only valid numbers are used in the tests. ``` Example: 5.5589 is rounded 5.56 3.3424 is rounded 3.34 ``` ...
{"functional": "_inputs = [[4.659725356], [173735326.37837327], [4.653725356]]\n_outputs = [[4.66], [173735326.38], [4.65]]\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)):...
107
222
coding
Solve the programming task below in a Python markdown code block. Range Minimum Query is a well-known problem: given an array of distinct integers with size $n=2^k$ and $m$ queries, find the minimum element on subsegment $[L_i,R_i]$. One of the most efficient and famous solutions to this problem is a segment tree. A s...
{"inputs": ["2\n1 1 1\n", "4\n3 1 3 1 2 4 1\n"], "outputs": ["NO \n", "YES\n1 1 3 1 2 3 4 \n"]}
709
58
coding
Solve the programming task below in a Python markdown code block. # Task Consider a `bishop`, a `knight` and a `rook` on an `n × m` chessboard. They are said to form a `triangle` if each piece attacks exactly one other piece and is attacked by exactly one piece. Calculate the number of ways to choose positions of ...
{"functional": "_inputs = [[2, 3], [1, 30], [3, 3], [2, 2], [5, 2], [40, 40]]\n_outputs = [[8], [0], [48], [0], [40], [92400]]\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...
325
212
coding
Solve the programming task below in a Python markdown code block. Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants...
{"inputs": ["bbbabb\nbb\n1 6 3 4 2 5\n", "bababc\nbb\n1 6 3 4 2 5\n", "bbbabc\nbb\n1 6 3 4 2 5\n", "cbabbb\nbb\n1 6 3 4 2 5\n", "bbabbb\nbb\n1 6 3 4 2 5\n", "bbbabb\nba\n1 6 3 4 2 5\n", "abbabb\nba\n1 6 3 4 2 5\n", "bbabba\nba\n1 6 3 4 2 5\n"], "outputs": ["4", "2\n", "4\n", "4\n", "4\n", "3\n", "3\n", "2\n"]}
614
192
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, return the punishment number of n. The punishment number of n is defined as the sum of the squares of all integers i such that: 1 <= i <= n The decimal representation of i * i can be parti...
{"functional": "def check(candidate):\n assert candidate(n = 10) == 182\n assert candidate(n = 37) == 1478\n\n\ncheck(Solution().punishmentNumber)"}
116
51
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. All of the tickets belong to a ...
{"functional": "def check(candidate):\n assert candidate(tickets = [[\"MUC\",\"LHR\"],[\"JFK\",\"MUC\"],[\"SFO\",\"SJC\"],[\"LHR\",\"SFO\"]]) == [\"JFK\",\"MUC\",\"LHR\",\"SFO\",\"SJC\"]\n assert candidate(tickets = [[\"JFK\",\"SFO\"],[\"JFK\",\"ATL\"],[\"SFO\",\"ATL\"],[\"ATL\",\"JFK\"],[\"ATL\",\"SFO\"]]) == [\...
196
149
coding
Solve the programming task below in a Python markdown code block. Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Kolya is hungry, so he ...
{"inputs": ["2\n2\n2\n1\n", "9\n2\n4\n1\n", "9\n2\n2\n1\n", "4\n2\n4\n2\n", "5\n3\n6\n4\n", "9\n2\n2\n1\n", "2\n2\n2\n1\n", "9\n2\n4\n1\n"], "outputs": ["1\n", "4\n", "8\n", "2\n", "1\n", "8\n", " 1\n", " ...
465
122
coding
Solve the programming task below in a Python markdown code block. There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not. Person i gives A_i testimonies. The j-th testimony by Person i is represented by...
{"inputs": ["1\n0\n", "2\n1\n2 0\n1\n1 1", "2\n1\n2 0\n0\n1 0", "2\n1\n2 0\n0\n2 0", "2\n1\n2 0\n0\n0 0", "2\n1\n2 0\n0\n0 1", "2\n1\n2 1\n1\n1 1", "2\n1\n2 1\n1\n1 0"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]}
449
149
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sentence text (A sentence is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words ...
{"functional": "def check(candidate):\n assert candidate(text = \"Leetcode is cool\") == \"Is cool leetcode\"\n assert candidate(text = \"Keep calm and code on\") == \"On and keep calm code\"\n assert candidate(text = \"To be or not to be\") == \"To be or to be not\"\n\n\ncheck(Solution().arrangeWords)"}
140
83
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game with a number line and some segments. Takahashi is standing on the number line and he is initially at coordinate 0. Aoki has N segments. The i-th segment is [L_i,R_i], that is, a segment consisting of points with coord...
{"inputs": ["3\n2 2\n3 4\n5 6", "3\n1 2\n3 4\n5 6", "3\n2 2\n3 4\n10 6", "3\n3 2\n3 4\n20 6", "3\n3 4\n3 4\n20 6", "3\n3 4\n3 4\n28 6", "3\n3 2\n3 4\n14 6", "3\n1 4\n3 4\n48 6"], "outputs": ["12\n", "12", "22\n", "42\n", "40\n", "56\n", "30\n", "96\n"]}
418
171
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security s...
{"functional": "def check(candidate):\n assert candidate([1,2,3,1]) == 4\n assert candidate([2,7,9,3,1]) == 12\n\n\ncheck(Solution().rob)"}
139
53
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n x n integer matrix grid where grid[r][c] represents the height of ...
{"functional": "def check(candidate):\n assert candidate(grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]) == 35\n assert candidate(grid = [[0,0,0],[0,0,0],[0,0,0]]) == 0\n\n\ncheck(Solution().maxIncreaseKeepingSkyline)"}
240
93
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1. Note that an integer is sai...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3], nums2 = [2,4]) == 2\n assert candidate(nums1 = [1,2,3,6], nums2 = [2,3,4,5]) == 2\n\n\ncheck(Solution().getCommon)"}
125
75
coding
Solve the programming task below in a Python markdown code block. Chef and Paja are bored, so they are playing an infinite game of ping pong. The rules of the game are as follows: - The players play an infinite number of games. At the end of each game, the player who won it scores a point. - In each game, one of the pl...
{"inputs": ["3\n1 3 3\n5 7 2\n38657 76322 564"], "outputs": ["Paja\nChef\nPaja"]}
465
46
coding
Solve the programming task below in a Python markdown code block. Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once. The i-th dish (1 \leq i \leq N) he ate was Dish A_i. When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points. Ad...
{"inputs": ["2\n2 1\n1 1\n1\n", "2\n1 0\n4 2\n56", "2\n1 0\n1 2\n56", "2\n1 0\n21 50\n2", "2\n1 0\n22 77\n2", "2\n1 0\n37 77\n2", "2\n1 0\n50 50\n50", "2\n1 0\n50 74\n56"], "outputs": ["2\n", "6\n", "3\n", "71\n", "99\n", "114\n", "100\n", "124\n"]}
392
165
coding
Solve the programming task below in a Python markdown code block. In his publication Liber Abaci Leonardo Bonacci, aka Fibonacci, posed a problem involving a population of idealized rabbits. These rabbits bred at a fixed rate, matured over the course of one month, had unlimited resources, and were immortal. Beginning ...
{"functional": "_inputs = [[0, 4], [1, 4], [4, 0], [6, 3], [8, 12], [7, 4], [9, 8], [10, 2], [11, 33], [100, 3], [40, 6], [4, 100]]\n_outputs = [[0], [1], [1], [40], [8425], [181], [10233], [341], [58212793], [465790837923166086127602033842234887], [2431532871909060205], [201]]\nimport math\ndef _deep_eq(a, b, tol=1e-5...
233
342
coding
Solve the programming task below in a Python markdown code block. A matrix of size $n \times m$ is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers $(a_1, a_2, \dots , a_k)$ is a palindrome, if for any integer $i$ ($1 \le i \le k$) the equality $a_i = a_{k - i + 1}$ holds. Sas...
{"inputs": ["2\n4 2\n4 2\n2 4\n4 2\n2 4\n3 4\n1 2 3 4\n5 6 7 8\n9 10 11 18\n", "2\n4 2\n4 2\n2 4\n4 2\n2 4\n3 4\n1 2 3 4\n5 6 5 8\n9 10 11 18\n", "2\n4 2\n6 2\n0 4\n4 2\n2 4\n2 4\n1 2 3 7\n12 6 7 14\n0 9 11 6\n", "2\n4 2\n6 2\n0 4\n8 2\n2 4\n2 4\n1 2 3 7\n12 6 7 14\n0 9 11 6\n", "2\n4 2\n6 2\n0 4\n8 2\n2 4\n2 4\n1 0 3 ...
450
507
coding
Solve the programming task below in a Python markdown code block. Implement a function which takes a string, and returns its hash value. Algorithm steps: * `a` := sum of the ascii values of the input characters * `b` := sum of every difference between the consecutive characters of the input (second char minus first c...
{"functional": "_inputs = [['int main(int argc, char *argv[]) { return 0; }'], [\" Yo - What's Good?! \"], [' df af asd '], ['global hash'], ['section .text'], ['hash:'], [' xor eax, eax'], [' ret'], ['; -----> end of hash <-----'], ['int hash(const char *str);'], [''], [' '], [' '], [' '], [' ']]\n_outputs...
226
318
coding
Solve the programming task below in a Python markdown code block. To address the situation of Water Scarcity in Chefland, Chef has started an awareness campaign to motivate people to use greywater for toilets, washing cars, gardening, and many other chores which don't require the use of freshwater. These activities pre...
{"inputs": ["3\n3 1 1 3\n1 1 1 2\n2 1 1 1"], "outputs": ["YES\nYES\nNO"]}
586
40
coding
Solve the programming task below in a Python markdown code block. Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed t...
{"inputs": ["4\n", "6\n", "8\n", "2\n", "3\n", "7\n", "5\n", "1\n"], "outputs": ["3\n", "5\n", "4\n", "1\n", "2\n", "4\n", "3\n", "0\n"]}
201
70
coding
Solve the programming task below in a Python markdown code block. You are a real estate broker in ancient Knossos. You have $m$ unsold houses, and each house $j$ has an area, $x_j$, and a minimum price, $y_j$. You also have $n$ clients, and each client $\boldsymbol{i}$ wants a house with an area greater than $a_i$ and ...
{"inputs": ["3 3\n5 110\n9 500\n20 400\n10 100\n2 200\n30 300\n"], "outputs": ["2\n"]}
745
55
coding
Solve the programming task below in a Python markdown code block. There are 2 stores in Chefland and both sell the same product. The first store sells the product for 100 rupees whereas the second store sells it for 200 rupees. It is the holiday season and both stores have announced a special discount. The first store...
{"inputs": ["4\n5 20\n10 60\n7 7\n10 55\n"], "outputs": ["FIRST\nSECOND\nFIRST\nBOTH\n"]}
635
42
coding
Solve the programming task below in a Python markdown code block. Chef feels that being the Head Chef is a very difficult job. More than cooking, managing the kitchen and distributing the work between various cooks proves to be a tiring task. There are many dishes to be prepared. And he has a team of talented cooks to ...
{"inputs": ["1\n3 2\n0 3\n1 3"], "outputs": ["3"]}
432
24
coding
Solve the programming task below in a Python markdown code block. There are n heroes fighting in the arena. Initially, the i-th hero has a_i health points. The fight in the arena takes place in several rounds. At the beginning of each round, each alive hero deals 1 damage to all other heroes. Hits of all heroes occur ...
{"inputs": ["7 4\n", "6 4\n", "4 5\n", "3 1\n", "5 8\n", "4 4\n", "6 8\n", "4 8\n"], "outputs": ["16384", "4096", "301", "1", "12048", "148", "119644", "1144"]}
362
101
coding
Solve the programming task below in a Python markdown code block. Chef has two binary strings A and B, both having length N. He can perform the following operation on A any number of times (possibly zero): Select any index i (1 ≤ i ≤ N - 1) and simultaneously set A_{i} := A_{i} \oplus A_{i + 1} and A_{i + 1} := A_{i} \...
{"inputs": ["3\n2\n00\n10\n3\n010\n000\n4\n0011\n0100\n"], "outputs": ["NO\nYES\nYES\n"]}
559
48
coding
Solve the programming task below in a Python markdown code block. Priya loves bitwise AND, but she hates programming. Help her solve this problem. Given an array $A$ of size $N$, let $B_{ij}$ denote the [bitwise AND] of $A[i]$ and $A[j]$. You have to find the number of pairs $(i, j)$, such that $i < j$ and $B_{ij} = ...
{"inputs": ["2\n5\n1 1 1 1 1\n1\n10"], "outputs": ["10\n0"]}
369
32
coding
Solve the programming task below in a Python markdown code block. Given is a string S of length N. Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( ...
{"inputs": ["2\nwy", "2\nvy", "2\nyx", "2\nxz", "2\nzx", "2\nx{", "2\nzy", "2\nyz"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
333
79
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pa...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3])) == 6\n assert candidate(root = tree_node([-10,9,20,None,None,15,7])) == 42\n\n\ncheck(Solution().maxPathSum)"}
189
66
coding
Solve the programming task below in a Python markdown code block. In an infinite array with two rows, the numbers in the top row are denoted `. . . , A[−2], A[−1], A[0], A[1], A[2], . . .` and the numbers in the bottom row are denoted `. . . , B[−2], B[−1], B[0], B[1], B[2], . . .` For each integer `k`, the entry `...
{"functional": "_inputs = [[[1, 2, 3, 4], 2], [[38, 200, -18, 45], 1], [[1, 0, 0, 1], 5], [[0, 2, 0, 3], -2], [[-20, 1, -3, 14], -5], [[1, 2, 3, 5], 100], [[0, 4, 6, 13], 100]]\n_outputs = [[3], [200], [20], [-126], [-44402], [60560100487003612846322657690093088848428068520476594299], [335254562473098582210532865941148...
362
407
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. You are given an undirected graph with N nodes (numbered 1 through N). For each valid i, the i-th node has a weight W_{i}. Also, for each pair of nodes i and j, there...
{"inputs": ["2\n2\n1 2\n2\n2 1\n"], "outputs": ["2\n1"]}
484
27
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character w...
{"functional": "def check(candidate):\n assert candidate(s = \"egg\", t = \"add\") == True\n assert candidate(s = \"foo\", t = \"bar\") == False\n assert candidate(s = \"paper\", t = \"title\") == True\n\n\ncheck(Solution().isIsomorphic)"}
122
68
coding
Solve the programming task below in a Python markdown code block. Check Tutorial tab to know how to to solve. The included code stub will read an integer, $n$, from STDIN. Without using any string methods, try to print the following: $123\cdots n$ Note that "$\bullet\bullet\bullet\bullet$" represents the cons...
{"inputs": ["3\n"], "outputs": ["123\n"]}
168
16
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer num consisting only of digits 6 and 9. Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).   Please complete the following python code p...
{"functional": "def check(candidate):\n assert candidate(num = 9669) == 9969\n assert candidate(num = 9996) == 9999\n assert candidate(num = 9999) == 9999\n\n\ncheck(Solution().maximum69Number)"}
93
75
coding
Solve the programming task below in a Python markdown code block. Chef has made a list for his monthly expenses. The list has N expenses with index 1 to N. The money spent on each expense depends upon the monthly income of Chef. Chef spends 50\% of his total income on the expense with index 1. The money spent on the i...
{"inputs": ["4\n1 2\n1 3\n2 3\n3 4\n"], "outputs": ["2\n4\n2\n2"]}
676
35
coding
Solve the programming task below in a Python markdown code block. Nina has an $n\times n$ chessboard and $\boldsymbol{\mbox{k}}$ jumping rooks. Every cell of the chessboard is either blocked or free, and Nina can only put a single rook in any free cell. Two jumping rooks beat each other if they are either in the same...
{"inputs": ["3 4\n...\n...\n...\n", "5 10\n..#..\n..#..\n#####\n..#..\n..#..\n"], "outputs": ["2\n", "4\n"]}
608
52
coding
Solve the programming task below in a Python markdown code block. Your favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of $n$ tracks numbered from $1$ to $n$. The playlist is automatic and cyclic: whenever track $i$ finishes playing, track $i+1$ star...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "3\n4 3 6\n", "3\n2 5 3\n", "3\n2 5 3\n", "3\n3 5 3\n", "3\n3 9 5\n", "3\n4 1 2\n"], "outputs": ["-1 -1\n", "-1 -1 ", "-1 -1 -1\n", "3 2 4\n", "3 2 4 \n", "-1 -1 -1\n", "3 2 4\n", "1 3 2\n"]}
744
143
coding
Solve the programming task below in a Python markdown code block. -----Problem description.----- This problem deals with the I/O methods used in codechef. You are supposed to print the integer in its reverse form , or in simple words, print the reverse of the given integer . For instance , reverse of 120 is 21 (not ...
{"inputs": ["3\n1234\n4567\n1"], "outputs": ["4321\n7654\n1"]}
279
34
coding
Solve the programming task below in a Python markdown code block. Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat g...
{"inputs": ["2\n", "3\n", "4\n", "5\n", "6\n", "6\n", "4\n", "5\n"], "outputs": ["1 ", "1 1 ", "1 1 2 ", "1 1 1 2 ", "1 1 1 2 3 ", "1 1 1 2 3", "1 1 2", "1 1 1 2"]}
405
100
coding
Solve the programming task below in a Python markdown code block. Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid al...
{"inputs": ["1 2\n", "1 1\n", "2 2\n", "3 4\n", "1 1\n", "3 4\n", "2 2\n", "4 4\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "4\n"]}
366
86
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Jem couldn't even finish half of the homework exercises in "Advanced topics in algorithm" class. The teacher is really upset and gives him one final problem to solve - if he ...
{"inputs": ["3\n2\n3 4\n4\n1 5 3 4\n6\n2 4 6 7 8 10"], "outputs": ["3\n-1\n7"]}
535
48
coding
Solve the programming task below in a Python markdown code block. Alice thinks of a non-decreasing sequence of non-negative integers and wants Bob to guess it by providing him the set of all its K-sums with repetitions. What is this? Let the sequence be {A[1], A[2], ..., A[N]} and K be some positive integer that both...
{"inputs": ["3\n1 3\n3\n2 2\n12 34 56\n3 2\n2 3 4 4 5 6\n"], "outputs": ["1\n6 28\n1 2 3\n"]}
747
60