task_type
stringclasses 1
value | problem
stringlengths 261
3.34k
| answer
stringlengths 35
6.15k
| problem_tokens
int64 62
774
| answer_tokens
int64 12
2.04k
|
|---|---|---|---|---|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:
subtexti is a non-empty string.
The concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).
subtexti == subtextk - i + 1 for all valid values of i (i.e., 1 <= i <= k).
Return the largest possible value of k.
Please complete the following python code precisely:
```python
class Solution:
def longestDecomposition(self, text: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(text = \"ghiabcdefhelloadamhelloabcdefghi\") == 7\n assert candidate(text = \"merchant\") == 1\n assert candidate(text = \"antaprezatepzapreanta\") == 11\n\n\ncheck(Solution().longestDecomposition)"}
| 159
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
Take an integer `n (n >= 0)` and a digit `d (0 <= d <= 9)` as an integer. Square all numbers `k (0 <= k <= n)` between 0 and n. Count the numbers of
digits `d` used in the writing of all the `k**2`. Call `nb_dig` (or nbDig or ...) the function taking `n` and `d` as parameters and returning this count.
#Examples:
```
n = 10, d = 1, the k*k are 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
We are using the digit 1 in 1, 16, 81, 100. The total count is then 4.
nb_dig(25, 1):
the numbers of interest are
1, 4, 9, 10, 11, 12, 13, 14, 19, 21 which squared are 1, 16, 81, 100, 121, 144, 169, 196, 361, 441
so there are 11 digits `1` for the squares of numbers between 0 and 25.
```
Note that `121` has twice the digit `1`.
Also feel free to reuse/extend the following starter code:
```python
def nb_dig(n, d):
```
|
{"functional": "_inputs = [[5750, 0], [11011, 2], [12224, 8], [11549, 1], [14550, 7], [8304, 7], [10576, 9], [12526, 1], [7856, 4], [14956, 1]]\n_outputs = [[4700], [9481], [7733], [11905], [8014], [3927], [7860], [13558], [7132], [17267]]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(nb_dig(*i), o[0])"}
| 365
| 309
|
coding
|
Solve the programming task below in a Python markdown code block.
## Task
Given a positive integer as input, return the output as a string in the following format:
Each element, corresponding to a digit of the number, multiplied by a power of 10 in such a way that with the sum of these elements you can obtain the original number.
## Examples
Input | Output
--- | ---
0 | ""
56 | "5\*10+6"
60 | "6\*10"
999 | "9\*100+9\*10+9"
10004 | "1\*10000+4"
Note: `input >= 0`
Also feel free to reuse/extend the following starter code:
```python
def simplify(n):
```
|
{"functional": "_inputs = [[8964631], [56], [999], [11], [991], [47], [234], [196587], [660], [600], [9090], [10104], [80008], [90000], [0]]\n_outputs = [['8*1000000+9*100000+6*10000+4*1000+6*100+3*10+1'], ['5*10+6'], ['9*100+9*10+9'], ['1*10+1'], ['9*100+9*10+1'], ['4*10+7'], ['2*100+3*10+4'], ['1*100000+9*10000+6*1000+5*100+8*10+7'], ['6*100+6*10'], ['6*100'], ['9*1000+9*10'], ['1*10000+1*100+4'], ['8*10000+8'], ['9*10000'], ['']]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(simplify(*i), o[0])"}
| 178
| 455
|
coding
|
Solve the programming task below in a Python markdown code block.
Galileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tessellation with the generators arranged in a grid. He has stored the number of stars in a Voronoi cell at a position in a matrix that corresponds to the position of the generator in the grid.
This dataset does not directly help Galileo, because he needs to be able to query the number of stars in a rectangular portion of the sky. Galileo tried to write a program that does this on his own, but it turned out to be too slow. Can you help him?
-----Input Format-----
The first line contains two integers n and m that denote the height and width of the matrix respectively. This is followed by n lines each containing m integers each.
The line following this would contain a single integer t, the number of queries to be run. Each query line consists of 4 integers px, py, qx, qy. The first two integers denote the row and column numbers of the upper left corner of the rectangular region, and the second pair of numbers correspond to the lower right corner.
-----Output Format-----
For each query output a single line containing the number of stars in that rectangular region.
-----Example-----
Input:
3 3
10 10 10
10 10 10
10 10 10
4
1 1 1 1
1 1 3 3
2 1 3 3
3 1 3 3
Output:
10
90
60
30
|
{"inputs": ["3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3"], "outputs": ["10\n90\n60\n30"]}
| 370
| 85
|
coding
|
Solve the programming task below in a Python markdown code block.
We want to find the numbers higher or equal than 1000 that the sum of every four consecutives digits cannot be higher than a certain given value.
If the number is ``` num = d1d2d3d4d5d6 ```, and the maximum sum of 4 contiguous digits is ```maxSum```, then:
```python
d1 + d2 + d3 + d4 <= maxSum
d2 + d3 + d4 + d5 <= maxSum
d3 + d4 + d5 + d6 <= maxSum
```
For that purpose, we need to create a function, ```max_sumDig()```, that receives ```nMax```, as the max value of the interval to study (the range (1000, nMax) ), and a certain value, ```maxSum```, the maximum sum that every four consecutive digits should be less or equal to. The function should output the following list with the data detailed bellow:
```[(1), (2), (3)]```
(1) - the amount of numbers that satisfy the constraint presented above
(2) - the closest number to the mean of the results, if there are more than one, the smallest number should be chosen.
(3) - the total sum of all the found numbers
Let's see a case with all the details:
```
max_sumDig(2000, 3) -------> [11, 1110, 12555]
(1) -There are 11 found numbers: 1000, 1001, 1002, 1010, 1011, 1020, 1100, 1101, 1110, 1200 and 2000
(2) - The mean of all the found numbers is:
(1000 + 1001 + 1002 + 1010 + 1011 + 1020 + 1100 + 1101 + 1110 + 1200 + 2000) /11 = 1141.36363,
so 1110 is the number that is closest to that mean value.
(3) - 12555 is the sum of all the found numbers
1000 + 1001 + 1002 + 1010 + 1011 + 1020 + 1100 + 1101 + 1110 + 1200 + 2000 = 12555
Finally, let's see another cases
```
max_sumDig(2000, 4) -----> [21, 1120, 23665]
max_sumDig(2000, 7) -----> [85, 1200, 99986]
max_sumDig(3000, 7) -----> [141, 1600, 220756]
```
Happy coding!!
Also feel free to reuse/extend the following starter code:
```python
def max_sumDig(nMax, maxSum):
```
|
{"functional": "_inputs = [[2000, 3], [2000, 4], [2000, 7], [3000, 7], [4000, 4], [5000, 2], [5000, 3], [5000, 4], [5000, 5], [5000, 6], [5000, 7], [5000, 8], [5000, 9]]\n_outputs = [[[11, 1110, 12555]], [[21, 1120, 23665]], [[85, 1200, 99986]], [[141, 1600, 220756]], [[35, 2000, 58331]], [[5, 1100, 6111]], [[15, 1200, 21666]], [[35, 2000, 58331]], [[70, 2000, 132216]], [[122, 2010, 244875]], [[196, 2110, 413306]], [[296, 2200, 649951]], [[426, 2250, 967696]]]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(max_sumDig(*i), o[0])"}
| 754
| 496
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment l_{i} and ends at moment r_{i}.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.
Polycarp wants to check out all n shows. Are two TVs enough to do so?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 2·10^5) — the number of shows.
Each of the next n lines contains two integers l_{i} and r_{i} (0 ≤ l_{i} < r_{i} ≤ 10^9) — starting and ending time of i-th show.
-----Output-----
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
-----Examples-----
Input
3
1 2
2 3
4 5
Output
YES
Input
4
1 2
2 3
2 3
1 2
Output
NO
|
{"inputs": ["2\n0 1\n0 1\n", "2\n0 4\n0 4\n", "2\n0 2\n0 6\n", "2\n2 5\n0 5\n", "2\n0 2\n0 6\n", "2\n0 1\n0 1\n", "2\n0 4\n0 4\n", "2\n2 5\n0 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES"]}
| 298
| 133
|
coding
|
Solve the programming task below in a Python markdown code block.
Peter loves any kinds of cheating. A week before ICPC, he broke into Doctor's PC and sneaked a look at all the problems that would be given in ICPC. He solved the problems, printed programs out, and brought into ICPC. Since electronic preparation is strictly prohibited, he had to type these programs again during the contest.
Although he believes that he can solve every problems thanks to carefully debugged programs, he still has to find an optimal strategy to make certain of his victory.
Teams are ranked by following rules.
1. Team that solved more problems is ranked higher.
2. In case of tie (solved same number of problems), team that received less Penalty is ranked higher.
Here, Penalty is calculated by these rules.
1. When the team solves a problem, time that the team spent to solve it (i.e. (time of submission) - (time of beginning of the contest)) are added to penalty.
2. For each submittion that doesn't solve a problem, 20 minutes of Penalty are added. However, if the problem wasn't solved eventually, Penalty for it is not added.
You must find that order of solving will affect result of contest. For example, there are three problem named A, B, and C, which takes 10 minutes, 20 minutes, and 30 minutes to solve, respectively. If you solve A, B, and C in this order, Penalty will be 10 + 30 + 60 = 100 minutes. However, If you do in reverse order, 30 + 50 + 60 = 140 minutes of Penalty will be given.
Peter can easily estimate time to need to solve each problem (actually it depends only on length of his program.) You, Peter's teammate, are asked to calculate minimal possible Penalty when he solve all the problems.
Input
Input file consists of multiple datasets. The first line of a dataset is non-negative integer N (0 ≤ N ≤ 100) which stands for number of problem. Next N Integers P[1], P[2], ..., P[N] (0 ≤ P[i] ≤ 10800) represents time to solve problems.
Input ends with EOF. The number of datasets is less than or equal to 100.
Output
Output minimal possible Penalty, one line for one dataset.
Example
Input
3
10 20 30
7
56 26 62 43 25 80 7
Output
100
873
|
{"inputs": ["3\n19 22 1\n7\n93 26 38 43 66 4 3", "3\n19 22 1\n7\n93 26 38 43 36 4 3", "3\n19 22 0\n7\n93 26 38 3 66 80 1", "3\n19 22 0\n7\n93 26 38 43 36 4 3", "3\n19 22 1\n7\n93 26 38 3 66 80 1", "3\n19 20 2\n7\n56 26 2 43 31 12 7", "3\n19 22 0\n7\n93 26 38 43 36 4 2", "3\n19 44 1\n7\n93 26 38 3 66 80 1"], "outputs": ["63\n681\n", "63\n612\n", "60\n758\n", "60\n612\n", "63\n758\n", "64\n455\n", "60\n605\n", "85\n758\n"]}
| 553
| 334
|
coding
|
Solve the programming task below in a Python markdown code block.
The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers, especially those with trailing zeros. For example, the number $9200$ has two trailing zeros. Aki thinks the more trailing zero digits a number has, the prettier it is.
However, Aki believes, that the number of trailing zeros of a number is not static, but depends on the base (radix) it is represented in. Thus, he considers a few scenarios with some numbers and bases. And now, since the numbers he used become quite bizarre, he asks you to help him to calculate the beauty of these numbers.
Given two integers $n$ and $b$ (in decimal notation), your task is to calculate the number of trailing zero digits in the $b$-ary (in the base/radix of $b$) representation of $n\,!$ (factorial of $n$).
-----Input-----
The only line of the input contains two integers $n$ and $b$ ($1 \le n \le 10^{18}$, $2 \le b \le 10^{12}$).
-----Output-----
Print an only integer — the number of trailing zero digits in the $b$-ary representation of $n!$
-----Examples-----
Input
6 9
Output
1
Input
38 11
Output
3
Input
5 2
Output
3
Input
5 10
Output
1
-----Note-----
In the first example, $6!_{(10)} = 720_{(10)} = 880_{(9)}$.
In the third and fourth example, $5!_{(10)} = 120_{(10)} = 1111000_{(2)}$.
The representation of the number $x$ in the $b$-ary base is $d_1, d_2, \ldots, d_k$ if $x = d_1 b^{k - 1} + d_2 b^{k - 2} + \ldots + d_k b^0$, where $d_i$ are integers and $0 \le d_i \le b - 1$. For example, the number $720$ from the first example is represented as $880_{(9)}$ since $720 = 8 \cdot 9^2 + 8 \cdot 9 + 0 \cdot 1$.
You can read more about bases here.
|
{"inputs": ["6 9\n", "5 2\n", "1 2\n", "2 2\n", "2 2\n", "1 2\n", "9 9\n", "9 2\n"], "outputs": ["1\n", "3\n", "0\n", "1\n", "1\n", "0\n", "2\n", "7\n"]}
| 593
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane.
Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (x, y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (x, y).
-----Input-----
The first line contains two space-separated integers x and y (|x|, |y| ≤ 100).
-----Output-----
Print a single integer, showing how many times Valera has to turn.
-----Examples-----
Input
0 0
Output
0
Input
1 0
Output
0
Input
0 1
Output
2
Input
-1 -1
Output
3
|
{"inputs": ["0 0\n", "1 0\n", "0 1\n", "0 6\n", "1 1\n", "0 6\n", "1 1\n", "2 1\n"], "outputs": ["0\n", "0\n", "2\n", "22\n", "1\n", "22\n", "1\n", "5\n"]}
| 318
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has $N$ points (numbered $1$ through $N$) in a 2D Cartesian coordinate system. For each valid $i$, the $i$-th point is $(x_i, y_i)$. He also has a fixed integer $c$ and he may perform operations of the following type: choose a point $(x_i, y_i)$ and move it to $(x_i + c, y_i + c)$ or $(x_i - c, y_i - c)$.
Now, Chef wants to set up one or more checkpoints (points in the same coordinate system) and perform zero or more operations in such a way that after they are performed, each of his (moved) $N$ points is located at one of the checkpoints.
Chef's primary objective is to minimise the number of checkpoints. Among all options with this minimum number of checkpoints, he wants to choose one which minimises the number of operations he needs to perform.
Can you help Chef find the minimum number of required checkpoints and the minimum number of operations he needs to perform to move all $N$ points to these checkpoints?
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains two space-separated integers $N$ and $c$.
- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $x_i$ and $y_i$.
-----Output-----
For each test case, print a single line containing two integers ― the minimum number of checkpoints and the minimum number of moves.
-----Constraints-----
- $1 \le T \le 5$
- $1 \le N \le 5 \cdot 10^5$
- $|x_i|, |y_i| \le 10^9$ for each valid $i$
- $0 < c \le 10^9$
- the sum of $N$ over all test cases does not exceed $5 \cdot 10^5$
-----Example Input-----
1
3 1
1 1
1 0
3 2
-----Example Output-----
2 2
-----Explanation-----
Example case 1: One optimal solution is to set up checkpoints at coordinates $(1, 1)$ and $(1, 0)$. Since the points $(1, 1)$ and $(1, 0)$ are already located at checkpoints, Chef can just move the point $(3, 2)$ to the checkpoint $(1, 0)$ in two moves: $(3, 2) \rightarrow (2, 1) \rightarrow (1, 0)$.
|
{"inputs": ["1\n3 1\n1 1\n1 0\n3 2"], "outputs": ["2 2"]}
| 589
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each player has an army. Army of the i-th player can be described by non-negative integer x_{i}. Consider binary representation of x_{i}: if the j-th bit of number x_{i} equal to one, then the army of the i-th player has soldiers of the j-th type.
Fedor is the (m + 1)-th player of the game. He assume that two players can become friends if their armies differ in at most k types of soldiers (in other words, binary representations of the corresponding numbers differ in at most k bits). Help Fedor and count how many players can become his friends.
-----Input-----
The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000).
The i-th of the next (m + 1) lines contains a single integer x_{i} (1 ≤ x_{i} ≤ 2^{n} - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.
-----Output-----
Print a single integer — the number of Fedor's potential friends.
-----Examples-----
Input
7 3 1
8
5
111
17
Output
0
Input
3 3 3
1
2
3
4
Output
3
|
{"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "1 1 2\n1\n1\n", "4 2 2\n5\n6\n7\n", "2 2 1\n2\n1\n1\n", "2 2 1\n2\n1\n1\n", "4 2 2\n5\n6\n7\n", "4 2 3\n5\n6\n7\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "2\n"]}
| 390
| 144
|
coding
|
Solve the programming task below in a Python markdown code block.
Let's denote the $f(x)$ function for a string $x$ as the number of distinct characters that the string contains. For example $f({abc}) = 3$, $f({bbbbb}) = 1$, and $f({babacaba}) = 3$.
Given a string $s$, split it into two non-empty strings $a$ and $b$ such that $f(a) + f(b)$ is the maximum possible. In other words, find the maximum possible value of $f(a) + f(b)$ such that $a + b = s$ (the concatenation of string $a$ and string $b$ is equal to string $s$).
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer $n$ ($2 \leq n \leq 2\cdot10^5$) — the length of the string $s$.
The second line contains the string $s$, consisting of lowercase English letters.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output a single integer — the maximum possible value of $f(a) + f(b)$ such that $a + b = s$.
-----Examples-----
Input
5
2
aa
7
abcabcd
5
aaaaa
10
paiumoment
4
aazz
Output
2
7
2
10
3
-----Note-----
For the first test case, there is only one valid way to split ${aa}$ into two non-empty strings ${a}$ and ${a}$, and $f({a}) + f({a}) = 1 + 1 = 2$.
For the second test case, by splitting ${abcabcd}$ into ${abc}$ and ${abcd}$ we can get the answer of $f({abc}) + f({abcd}) = 3 + 4 = 7$ which is maximum possible.
For the third test case, it doesn't matter how we split the string, the answer will always be $2$.
|
{"inputs": ["5\n2\naa\n7\nabcabcd\n5\naaaaa\n10\npaiumoment\n4\naazz\n"], "outputs": ["2\n7\n2\n10\n3\n"]}
| 505
| 49
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Consider a string of lowercase Latin letters and space characters (" ").
First, rearrange the letters in each word `alphabetically`.
And then rearrange the words in ascending order of the sum of their characters' `ASCII` values.
If two or more words have the same `ASCII` value, rearrange them by their length in ascending order; If their length still equals to each other, rearrange them `alphabetically`.
Finally, return the result.
# Example
For `s = "batman is bruce wayne"`, the result should be `"is bceru aenwy aamntb"`.
```
After rearranging the letters the string turns into
"aamntb is bceru aenwy".
The ASCII values of each word are: [627, 220, 529, 548].
After sorting the words the following string is obtained:
"is bceru aenwy aamntb" (with ASCII values of [220, 529, 548, 627]).```
For `s = "peter parker is spiderman"`, the result should be `"is eeprt aekprr adeimnprs"`
`(ASCII values: [220, 554, 645, 963])`
# Input/Output
- `[input]` string `s`
A string of lowercase words. Each word is separated by exactly one space character.
- `[output]` a string
Also feel free to reuse/extend the following starter code:
```python
def revamp(s):
```
|
{"functional": "_inputs = [['batman is bruce wayne'], ['peter parker is spiderman'], ['codewars is great'], ['airplanes in the night sky']]\n_outputs = [['is bceru aenwy aabmnt'], ['is eeprt aekprr adeimnprs'], ['is aegrt acdeorsw'], ['in eht ksy ghint aaeilnprs']]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(revamp(*i), o[0])"}
| 363
| 231
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Given an array A of N non-negative integers, you can choose any non-negative integer X and replace every element A_{i} with (A_{i}\oplus X) Here, \oplus denotes the [bitwise XOR operation].
Using the above operation exactly once, your goal is to minimize the bitwise OR of the new array. In other words, find X such that (A_{1}\oplus X)\lor \cdots \lor (A_{N} \oplus X) is minimized, where \lor denotes the [bitwise OR operation].
Find the value of X and the minimum possible bitwise OR of the new array.
------ Input Format ------
- The first line contains a single integer T - the number of test cases. Then T test cases follow.
- The first line of each test case contains a single integer N - the length of the array.
- The next line contains N integers A_{1},\ldots, A_{N}.
------ Output Format ------
For each test case, print two integers: X and the minimum possible bitwise OR of the new array.
If there are multiple values of X that achieve the minimum bitwise OR, print any of them.
------ Constraints ------
$1 ≤ T ≤ 5000$
$ 1 ≤ N ≤ 100 $
$ 0 ≤ A_{i} ≤ 10^{9} $
----- Sample Input 1 ------
1
2
4 6
----- Sample Output 1 ------
6 2
----- explanation 1 ------
Here, if we take $X=6$, then our expression would become $(4\oplus 6) \lor (6\oplus 6) = 2\lor 0 = 2$, which is the minimum possible.
|
{"inputs": ["1\n2\n4 6"], "outputs": ["6 2"]}
| 409
| 20
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array of integers $a_1,a_2,\ldots,a_n$. Find the maximum possible value of $a_ia_ja_ka_la_t$ among all five indices $(i, j, k, l, t)$ ($i<j<k<l<t$).
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1\le t\le 2 \cdot 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($5\le n\le 10^5$) — the size of the array.
The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($-3\times 10^3\le a_i\le 3\times 10^3$) — given array.
It's guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, print one integer — the answer to the problem.
-----Example-----
Input
4
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
Output
-120
12
0
945
-----Note-----
In the first test case, choosing $a_1,a_2,a_3,a_4,a_5$ is a best choice: $(-1)\cdot (-2) \cdot (-3)\cdot (-4)\cdot (-5)=-120$.
In the second test case, choosing $a_1,a_2,a_3,a_5,a_6$ is a best choice: $(-1)\cdot (-2) \cdot (-3)\cdot 2\cdot (-1)=12$.
In the third test case, choosing $a_1,a_2,a_3,a_4,a_5$ is a best choice: $(-1)\cdot 0\cdot 0\cdot 0\cdot (-1)=0$.
In the fourth test case, choosing $a_1,a_2,a_3,a_4,a_6$ is a best choice: $(-9)\cdot (-7) \cdot (-5)\cdot (-3)\cdot 1=945$.
|
{"inputs": ["1\n5\n-3000 -777 -3000 810 831\n", "1\n5\n-3000 -777 -3123 810 831\n", "1\n5\n-3000 -777 -1726 810 831\n", "1\n5\n-3000 -777 -3123 810 176\n", "1\n5\n-3000 -777 -3000 810 3000\n", "1\n5\n-3000 -777 -3000 2024 3000\n", "1\n5\n-3000 -1535 -3000 3000 349\n", "1\n5\n-3000 -216 -3000 2024 3000\n"], "outputs": ["-4707058230000000\n", "-4900047617430000\n", "-2708127501660000\n", "-1037795885280000\n", "-16992990000000000\n", "-42461496000000000\n", "-14464305000000000\n", "-11803968000000000\n"]}
| 563
| 402
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
Note
解説
Constraints
* $1 \leq n, m, l \leq 100$
* $0 \leq a_{ij}, b_{ij} \leq 10000$
Input
In the first line, three integers $n$, $m$ and $l$ are given separated by space characters
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$ matrix $B$ are given.
Output
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space character between adjacent elements.
Example
Input
3 2 3
1 2
0 3
4 5
1 2 1
0 3 2
Output
1 8 5
0 9 6
4 23 14
|
{"inputs": ["3 2 3\n1 2\n0 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n1 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n2 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n2 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 2\n3 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 3\n4 9\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 2\n4 9\n1 2 2\n1 3 2"], "outputs": ["3 8 5\n3 9 6\n9 23 14\n", "3 8 5\n4 11 7\n9 23 14\n", "3 8 5\n5 13 8\n9 23 14\n", "3 8 6\n5 13 10\n9 23 18\n", "3 8 6\n6 15 12\n9 23 18\n", "2 5 4\n6 15 12\n9 23 18\n", "2 5 4\n6 15 12\n13 35 26\n", "2 5 4\n5 12 10\n13 35 26\n"]}
| 324
| 444
|
coding
|
Solve the programming task below in a Python markdown code block.
Archith was a making noise in digital logic class.Sir was very frustrated by the behaviour of Archith. Sir asked archith to meet him in staff room. As archith reached staff room sir gave a smile and asked to complete this assignment in one day if not he will be suspended. Archith has low attendence so he has to complete the assignment in one day.Assignment consists of checking a parity of numbers and there were huge no of numbers .So he asked your help to sove this problem for him.
INPUT :
first line consists of T test cases.
Next T lines consists of decimal numbers N.
OUTPUT :
It should print the given number as "even" if the number has even number of 1's in binary form and "odd" if the number has odd number of 1's in binary form.
0<T<100
0<N<10^9
SAMPLE INPUT
2
12
14
SAMPLE OUTPUT
even
odd
|
{"inputs": ["20\n212245523\n546843625\n456431356\n546463364\n584651321\n352145896\n53\n2\n32\n32\n32692\n32646\n41354\n4351\n312\n524\n54365\n58421\n54213\n23452"], "outputs": ["odd\nodd\nodd\nodd\nodd\neven\neven\nodd\nodd\nodd\nodd\neven\neven\nodd\neven\nodd\nodd\neven\nodd\nodd"]}
| 213
| 183
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array a consisting of n integers.
Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r.
Your task is to choose three positive (greater than 0) integers x, y and z such that:
* x + y + z = n;
* max(1, x) = min(x + 1, x + y) = max(x + y + 1, n).
In other words, you have to split the array a into three consecutive non-empty parts that cover the whole array and the maximum in the first part equals the minimum in the second part and equals the maximum in the third part (or determine it is impossible to find such a partition).
Among all such triples (partitions), you can choose any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the length of a.
The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.
It is guaranteed that the sum of n does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).
Output
For each test case, print the answer: NO in the only line if there is no such partition of a that satisfies the conditions from the problem statement. Otherwise, print YES in the first line and three integers x, y and z (x + y + z = n) in the second line.
If there are several answers, you can print any.
Example
Input
6
11
1 2 3 3 3 4 4 3 4 2 1
8
2 9 1 7 3 9 4 1
9
2 1 4 2 4 3 3 1 2
7
4 2 1 1 4 1 4
5
1 1 1 1 1
7
4 3 4 3 3 3 4
Output
YES
6 1 4
NO
YES
2 5 2
YES
4 1 2
YES
1 1 3
YES
2 1 4
|
{"inputs": ["3\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n", "3\n3\n2 1 1\n3\n1 1 1\n3\n1 1 1\n", "3\n3\n2 1 1\n3\n1 2 1\n3\n1 1 1\n", "3\n3\n1 1 1\n3\n1 1 2\n3\n1 1 1\n", "3\n3\n2 1 2\n3\n2 1 1\n3\n1 2 1\n", "3\n3\n1 1 1\n3\n1 1 2\n3\n2 1 1\n", "3\n3\n2 1 1\n3\n2 2 2\n3\n1 2 1\n", "3\n3\n1 1 1\n3\n1 1 1\n3\n1 1 2\n"], "outputs": ["YES\n1 1 1\nYES\n1 1 1\nYES\n1 1 1\n", "NO\nYES\n1 1 1\nYES\n1 1 1\n", "NO\nNO\nYES\n1 1 1\n", "YES\n1 1 1\nNO\nYES\n1 1 1\n", "NO\nNO\nNO\n", "YES\n1 1 1\nNO\nNO\n", "NO\nYES\n1 1 1\nNO\n", "YES\n1 1 1\nYES\n1 1 1\nNO\n"]}
| 602
| 366
|
coding
|
Solve the programming task below in a Python markdown code block.
Salmon has some hidden numbers that he wants you to find!
Given an integer $N$, find and output any two integers A and B such that:
* $1 ≤ A, B ≤ 10^{9}$, and
* $A*B = N$.
------ Input: ------
The first line of input consists of a single integer $T$ ($1 ≤ T ≤ 10^{5}$) -- the number of testcases.
The next $T$ lines will consist of one integer, $N$ ($1 ≤ N ≤ 10^{9}$).
------ Output: ------
For each of the $T$ testcases, output two space-separated integers $A$ and $B$.
------ Subtasks ------
* Subtask 1 [100 points]: No additional constraints.
----- Sample Input 1 ------
5
1
3
5
8
10
----- Sample Output 1 ------
1 1
1 3
1 5
1 8
2 5
|
{"inputs": ["5\n1\n3\n5\n8\n10"], "outputs": ["1 1\n1 3\n1 5\n1 8\n2 5\n"]}
| 228
| 42
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a rectangular grid with $n$ rows and $m$ columns. The cell located on the $i$-th row from the top and the $j$-th column from the left has a value $a_{ij}$ written in it.
You can perform the following operation any number of times (possibly zero):
Choose any two adjacent cells and multiply the values in them by $-1$. Two cells are called adjacent if they share a side.
Note that you can use a cell more than once in different operations.
You are interested in $X$, the sum of all the numbers in the grid.
What is the maximum $X$ you can achieve with these operations?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
The first line of each test case contains two integers $n$,$m$ ($2 \le n$, $m \le 10$).
The following $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{ij}$ ($-100\leq a_{ij}\le 100$).
-----Output-----
For each testcase, print one integer $X$, the maximum possible sum of all the values in the grid after applying the operation as many times as you want.
-----Examples-----
Input
2
2 2
-1 1
1 1
3 4
0 -1 -2 -3
-1 -2 -3 -4
-2 -3 -4 -5
Output
2
30
-----Note-----
In the first test case, there will always be at least one $-1$, so the answer is $2$.
In the second test case, we can use the operation six times to elements adjacent horizontally and get all numbers to be non-negative. So the answer is: $2\times 1 + 3\times2 + 3\times 3 + 2\times 4 + 1\times 5 = 30$.
|
{"inputs": ["1\n3 3\n-3 -2 -1\n0 -2 0\n-3 -2 -1\n", "1\n3 3\n0 -1 -2\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-1 0 -1\n", "1\n3 3\n-3 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-1 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-4 -4 -1\n-3 -4 -2\n-3 -2 0\n", "1\n3 3\n-6 -4 -1\n-3 -4 -2\n-3 -2 0\n"], "outputs": ["14\n", "22\n", "24\n", "22\n", "16\n", "14\n", "23\n", "25\n"]}
| 468
| 272
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a permutation $p$ of $n$ integers $1$, $2$, ..., $n$ (a permutation is an array where each element from $1$ to $n$ occurs exactly once).
Let's call some subsegment $p[l, r]$ of this permutation special if $p_l + p_r = \max \limits_{i = l}^{r} p_i$. Please calculate the number of special subsegments.
-----Input-----
The first line contains one integer $n$ ($3 \le n \le 2 \cdot 10^5$).
The second line contains $n$ integers $p_1$, $p_2$, ..., $p_n$ ($1 \le p_i \le n$). All these integers are pairwise distinct.
-----Output-----
Print the number of special subsegments of the given permutation.
-----Examples-----
Input
5
3 4 1 5 2
Output
2
Input
3
1 3 2
Output
1
-----Note-----
Special subsegments in the first example are $[1, 5]$ and $[1, 3]$.
The only special subsegment in the second example is $[1, 3]$.
|
{"inputs": ["3\n1 3 2\n", "3\n2 3 1\n", "3\n3 2 1\n", "3\n2 1 3\n", "3\n1 2 3\n", "3\n3 1 2\n", "3\n1 3 2\n", "5\n3 4 1 5 2\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1", "2\n"]}
| 271
| 121
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Only $x$ hours are left for the March Long Challenge and Chef is only left with the last problem unsolved. However, he is sure that he cannot solve the problem in the remaining time. From experience, he figures out that he needs exactly $H$ hours to solve the problem.
Now Chef finally decides to use his special power which he has gained through years of intense yoga. He can travel back in time when he concentrates. Specifically, his power allows him to travel to $N$ different time zones, which are $T_{1}, T_{2}, \ldots, T_{N}$ hours respectively behind his current time.
Find out whether Chef can use one of the available time zones to solve the problem and submit it before the contest ends.
------ Input ------
The first line of the input contains three space-separated integers $N$, $H$ and $x$.
The second line contains $N$ space-separated integers $T_{1}, T_{2}, \ldots, T_{N}$.
------ Output ------
Print a single line containing the string "YES" if Chef can solve the problem on time or "NO" if he cannot.
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 ≤ N ≤ 100$
$1 ≤ x < H ≤ 100$
$1 ≤ T_{i} ≤ 100$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2 5 3
1 2
----- Sample Output 1 ------
YES
----- explanation 1 ------
Chef already has $3$ hours left. He can go to the $2$-nd time zone, which is $2$ hours back in time. Then he has a total of $3 + 2 = 5$ hours, which is sufficient to solve the problem.
----- Sample Input 2 ------
2 6 3
1 2
----- Sample Output 2 ------
NO
----- explanation 2 ------
If Chef goes to the $1$-st time zone, he will have $3 + 1 = 4$ hours, which is insufficient to solve the problem.
If he goes to the $2$-nd time zone, he will have $3 + 2 = 5$ hours, which is also insufficient to solve the problem.
Since none of the time travel options can be used to gain sufficient time to solve the problem, Chef is incapable of solving it.
|
{"inputs": ["2 5 3\n1 2", "2 6 3\n1 2"], "outputs": ["YES", "NO"]}
| 602
| 34
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n binary matrix mat, return the number of special positions in mat.
A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).
Please complete the following python code precisely:
```python
class Solution:
def numSpecial(self, mat: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(mat = [[1,0,0],[0,0,1],[1,0,0]]) == 1\n assert candidate(mat = [[1,0,0],[0,1,0],[0,0,1]]) == 3\n\n\ncheck(Solution().numSpecial)"}
| 109
| 75
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has opened up a new restaurant. Like every other restaurant, critics critique this place. The Chef wants to gather as much positive publicity as he can. Also, he is very aware of the fact that people generally do not tend to go through all the reviews. So he picks out the positive reviews and posts it on the website of the restaurant. A review is represented by an integer which is the overall rating of the restaurant as calculated by that particular review.
A review is considered to be positive if it is among the top one-third of the total reviews when they are sorted by their rating. For example, suppose the ratings given by 8 different reviews are as follows:
2 8 3 1 6 4 5 7
Then the top one-third reviews will be 8 and 7. Note that we considered one-third to be 8/3=2 top reviews according to integer division. (see Notes)
So here is what the Chef wants from you: Given the reviews(ratings) by different critics, the Chef needs you to tell him what is the minimum rating that his website will be displaying. For example in the above case, the minimum rating that will be displayed is 7. Also, different critics keep reviewing the restaurant continuosly. So the new reviews keep coming in. The Chef wants your website ratings to be up-to-date. So you should keep updating the ratings there. At any point of time, the Chef might want to know the minimum rating being displayed. You'll have to answer that query. An interesting thing to note here is that a review might be in the website for some time and get knocked out later because of new better reviews and vice-versa.
Notes: To be precise, the number of reviews displayed website will be floor(n / 3), where n denotes the current number of all reviews.
------ Input ------
First line of the input file consists of a single integer N, the number of operations to follow. The next N lines contain one operation each on a single line. An operation can be of 2 types:
1 x : Add a review with rating 'x' to the exisiting list of reviews (x is an integer)
2 : Report the current minimum rating on the website
------ Output ------
For every test case, output a single integer each for every operation of type 2 mentioned above. If no review qualifies as a positive review, print "No reviews yet".
------ Constraints ------
1 ≤ N ≤ 250000
1 ≤ x ≤ 1000000000
----- Sample Input 1 ------
10
1 1
1 7
2
1 9
1 21
1 8
1 5
2
1 9
2
----- Sample Output 1 ------
No reviews yet
9
9
----- explanation 1 ------
Before the first query of the Chef, i.e. the first operation of type 2 in the input, the only ratings were 1 & 7. Thus, there will be total of 2/3 = 0 positive ratings. For the next two, the ratings list now looks like: 1 5 7 8 9 21. Hence, top one-third will have 6/3 = 2 ratings as positive. And lowest displayed rating will be 9. Similarly for the last operation of type 2. Note that there are two ratings of the same value 9 now and only one of them can be in the top reviews. In such a case, you can choose any one of them.
|
{"inputs": ["10\n1 1\n1 7\n2\n1 9\n1 21\n1 8\n1 5\n2\n1 9\n2"], "outputs": ["No reviews yet\n9\n9"]}
| 759
| 54
|
coding
|
Solve the programming task below in a Python markdown code block.
-----Problem Statement-----
We have an integer sequence $A$, whose length is $N$.
Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
-----Input-----
Input is given in the following format:
$N$
$A_1$ $A_2$ . . . $A_N$
-----Output-----
Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$.
-----Constraints-----
- $1 \leq N \leq 2\times10^5$
- $-10^9 \leq A_i \leq 10^9$
- All values in input are integers.
-----Sample Input-----
6
1 3 -4 2 2 -2
-----Sample Output-----
3
-----EXPLANATION-----
There are three contiguous subsequences whose sums are $0$: $(1, 3, -4)$, $(-4, 2, 2)$ and $(2, -2)$
|
{"inputs": ["6\n1 3 -4 2 2 -2"], "outputs": ["3"]}
| 269
| 24
|
coding
|
Solve the programming task below in a Python markdown code block.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^6) — the n mentioned in the statement.
-----Output-----
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
-----Examples-----
Input
9
Output
504
Input
7
Output
210
-----Note-----
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.
|
{"inputs": ["9\n", "7\n", "1\n", "5\n", "6\n", "2\n", "8\n", "3\n"], "outputs": ["504\n", "210\n", "1\n", "60\n", "60\n", "2\n", "280\n", "6\n"]}
| 274
| 78
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])
Please complete the following python code precisely:
```python
class Solution:
def canThreePartsEqualSum(self, arr: List[int]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(arr = [0,2,1,-6,6,-7,9,1,2,0,1]) == True\n assert candidate(arr = [0,2,1,-6,6,7,9,-1,2,0,1]) == False\n assert candidate(arr = [3,3,6,5,-2,2,5,1,-9,4]) == True\n\n\ncheck(Solution().canThreePartsEqualSum)"}
| 155
| 113
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer array nums.
Partition nums into two arrays, nums1 and nums2, such that:
Each element of the array nums belongs to either the array nums1 or the array nums2.
Both arrays are non-empty.
The value of the partition is minimized.
The value of the partition is |max(nums1) - min(nums2)|.
Here, max(nums1) denotes the maximum element of the array nums1, and min(nums2) denotes the minimum element of the array nums2.
Return the integer denoting the value of such partition.
Please complete the following python code precisely:
```python
class Solution:
def findValueOfPartition(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,4]) == 1\n assert candidate(nums = [100,1,10]) == 9\n\n\ncheck(Solution().findValueOfPartition)"}
| 167
| 58
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
Constraints
* $2 \leq n \leq 100,000$
* $0 \leq m \leq 100,000$
* $1 \leq q \leq 10,000$
Input
In the first line, two integer $n$ and $m$ are given. $n$ is the number of users in the SNS and $m$ is the number of relations in the SNS. The users in the SNS are identified by IDs $0, 1, ..., n-1$.
In the following $m$ lines, the relations are given. Each relation is given by two integers $s$ and $t$ that represents $s$ and $t$ are friends (and reachable each other).
In the next line, the number of queries $q$ is given. In the following $q$ lines, $q$ queries are given respectively. Each query consists of two integers $s$ and $t$ separated by a space character.
Output
For each query, print "yes" if $t$ is reachable from $s$ through the social network, "no" otherwise.
Example
Input
10 9
0 1
0 2
3 4
5 7
5 6
6 7
6 8
7 8
8 9
3
0 1
5 9
1 3
Output
yes
yes
no
|
{"inputs": ["10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n0 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n0 8\n7 8\n8 5\n3\n0 1\n5 9\n1 3", "16 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n5 4\n5 7\n5 6\n6 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "16 9\n0 1\n0 2\n3 8\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n6 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n2 3", "16 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 4"], "outputs": ["yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nno\nyes\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n"]}
| 358
| 518
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2t pieces he ended up with t tickets, each of which was lucky.
When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest.
Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123.
What maximum number of tickets could Vasya get after that?
Input
The first line contains integer n (1 ≤ n ≤ 104) — the number of pieces. The second line contains n space-separated numbers ai (1 ≤ ai ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide.
Output
Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together.
Examples
Input
3
123 123 99
Output
1
Input
6
1 1 1 23 10 3
Output
1
|
{"inputs": ["1\n1731005\n", "1\n2340786\n", "1\n4533183\n", "1\n3050700\n", "1\n1474114\n", "1\n1456697\n", "1\n19938466\n", "1\n26757320\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 458
| 136
|
coding
|
Solve the programming task below in a Python markdown code block.
A particular month has 30 days, numbered from 1 to 30.
Day 1 is a Monday, and the usual 7-day week is followed (so day 2 is Tuesday, day 3 is Wednesday, and so on).
Every Saturday and Sunday is a holiday. There are N festival days, which are also holidays. Note that it is possible for a festival day to occur on a Saturday or Sunday.
You are given the dates of the festivals. Determine the total number of holidays in this month.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N denoting the number of festival days.
- The second line of each test case contains N distinct space-separated integers A_{1}, A_{2}, \ldots A_{N}, denoting the festival days. Note that the A_{i} are not necessarily given in sorted order.
------ Output Format ------
For each test case, output a new line containing the total number of holidays.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 30$
$1 ≤ A_{i} ≤ 30$
- All the $A_{i}$ are distinct
----- Sample Input 1 ------
3
2
5 7
3
23 1 6
1
13
----- Sample Output 1 ------
9
10
8
----- explanation 1 ------
Test Case $1$: Days $6, 13, 20$ and $27$ are Saturdays, and days $7, 14, 21, 28$ are Sundays. The festivals fall on day $5$ and day $7$, but day $7$ is already a Sunday. This gives us $9$ holidays in total — days $5, 6, 7, 13, 14, 20, 21, 27, 28$.
Test Case $2$: Days $6, 13, 20$ and $27$ are Saturdays, and days $7, 14, 21, 28$ are Sundays. The festivals fall on day $1$, day $6$, and day $23$. This gives us $10$ holidays in total — days $1, 6, 7, 13, 14, 20, 21, 23, 27, 28$.
Test Case $3$: Days $6, 13, 20$ and $27$ are Saturdays, and days $7, 14, 21, 28$ are Sundays. The only festival is on day $13$, which is already a holiday. This gives us $8$ holidays in total — days $6, 7, 13, 14, 20, 21, 27, 28$.
|
{"inputs": ["3\n2\n5 7\n3\n23 1 6\n1\n13\n"], "outputs": ["9\n10\n8\n"]}
| 668
| 39
|
coding
|
Solve the programming task below in a Python markdown code block.
Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.
Two pictures are considered to be different if the coordinates of corresponding rectangles are different.
-----Input-----
The first line of input contains four space-separated integers r, c, n, k (1 ≤ r, c, n ≤ 10, 1 ≤ k ≤ n) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.
The next n lines each contain two integers x_{i} and y_{i} (1 ≤ x_{i} ≤ r, 1 ≤ y_{i} ≤ c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.
-----Output-----
Print a single integer — the number of photographs Paul can take which include at least k violas.
-----Examples-----
Input
2 2 1 1
1 2
Output
4
Input
3 2 3 3
1 1
3 1
2 2
Output
1
Input
3 2 3 2
1 1
3 1
2 2
Output
4
-----Note-----
We will use '*' to denote violinists and '#' to denote violists.
In the first sample, the orchestra looks as follows
*#
**
Paul can take a photograph of just the viola, the 1 × 2 column containing the viola, the 2 × 1 row containing the viola, or the entire string section, for 4 pictures total.
In the second sample, the orchestra looks as follows
#*
*#
#*
Paul must take a photograph of the entire section.
In the third sample, the orchestra looks the same as in the second sample.
|
{"inputs": ["2 2 1 1\n1 2\n", "1 1 1 1\n1 1\n", "1 1 1 1\n1 1\n", "2 2 1 1\n1 2\n", "5 9 2 2\n4 6\n1 5\n", "2 6 2 2\n1 2\n1 5\n", "2 6 2 2\n1 2\n1 5\n", "5 9 2 2\n4 6\n1 5\n"], "outputs": ["4\n", "1\n", "1\n", "4\n", "40\n", "8\n", "8\n", "40\n"]}
| 464
| 168
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.
A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1).
Please complete the following python code precisely:
```python
class Solution:
def minFallingPathSum(self, matrix: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(matrix = [[2,1,3],[6,5,4],[7,8,9]]) == 13\n assert candidate(matrix = [[-19,57],[-40,-5]]) == -59\n\n\ncheck(Solution().minFallingPathSum)"}
| 148
| 74
|
coding
|
Solve the programming task below in a Python markdown code block.
Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strings of length at most 7, consisting of digits and characters "?".
3. At each iteration, the algorithm looks for a command with the minimum index i, such that si occurs in a as a substring. If this command is not found the algorithm terminates.
4. Let's denote the number of the found command as k. In string a the first occurrence of the string sk is replaced by string wk. If the found command at that had form sk >> wk, then the algorithm continues its execution and proceeds to the next iteration. Otherwise, the algorithm terminates.
5. The value of string a after algorithm termination is considered to be the output of the algorithm.
Yaroslav has a set of n positive integers, he needs to come up with his favorite algorithm that will increase each of the given numbers by one. More formally, if we consider each number as a string representing the decimal representation of the number, then being run on each of these strings separately, the algorithm should receive the output string that is a recording of the corresponding number increased by one.
Help Yaroslav.
Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the set. The next n lines contains one positive integer each. All the given numbers are less than 1025.
Output
Print the algorithm which can individually increase each number of the set. In the i-th line print the command number i without spaces.
Your algorithm will be launched for each of these numbers. The answer will be considered correct if:
* Each line will a correct algorithm command (see the description in the problem statement).
* The number of commands should not exceed 50.
* The algorithm will increase each of the given numbers by one.
* To get a respond, the algorithm will perform no more than 200 iterations for each number.
Examples
Input
2
10
79
Output
10<>11
79<>80
|
{"inputs": ["2\n8\n52\n", "2\n10\n79\n", "2\n10\n71\n", "2\n18\n79\n", "2\n15\n71\n", "2\n27\n79\n", "2\n15\n52\n", "2\n10\n79\n"], "outputs": ["0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?\n", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?\n", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?\n", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?\n", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?\n", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?\n", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?"]}
| 521
| 1,074
|
coding
|
Solve the programming task below in a Python markdown code block.
A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS"
MATHE
ATHEM
THEMA
HEMAT
EMATI
MATIC
ATICS
There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the matrix from the top-left position and at each iteration, you either move RIGHT or DOWN, and ultimately reach the bottom-right of the matrix. It is assured that any such tracing generates the same word. How many such tracings can be possible for a given
word of length m+n-1 written as a matrix of size m * n?
Input Format
The first line of input contains an integer T. T test cases follow.
Each test case contains 2 space separated integers m & n (in a new line) indicating that the matrix has m rows and each row has n characters.
Constraints
1 <= T <= 10^{3}
1 ≤ m,n ≤ 10^{6}
Output Format
Print the number of ways (S) the word can be traced as explained in the problem statement.
If the number is larger than 10^{9}+7,
print S mod (10^9 + 7) for each testcase (in a new line).
Sample Input
1
2 3
Sample Output
3
Explanation
Let's consider a word AWAY written as the matrix
AWA
WAY
Here, the word AWAY can be traced in 3 different ways, traversing either RIGHT or DOWN.
AWA
Y
AW
AY
A
WAY
Hence the answer is 3.
Timelimit
Time limit for this challenge is given here
|
{"inputs": ["1\n2 3\n"], "outputs": ["3\n"]}
| 379
| 18
|
coding
|
Solve the programming task below in a Python markdown code block.
You have a string $s$ consisting of digits from $0$ to $9$ inclusive. You can perform the following operation any (possibly zero) number of times:
You can choose a position $i$ and delete a digit $d$ on the $i$-th position. Then insert the digit $\min{(d + 1, 9)}$ on any position (at the beginning, at the end or in between any two adjacent digits).
What is the lexicographically smallest string you can get by performing these operations?
A string $a$ is lexicographically smaller than a string $b$ of the same length if and only if the following holds:
in the first position where $a$ and $b$ differ, the string $a$ has a smaller digit than the corresponding digit in $b$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then the test cases follow.
Each test case consists of a single line that contains one string $s$ ($1 \le |s| \le 2 \cdot 10^5$) — the string consisting of digits. Please note that $s$ is just a string consisting of digits, so leading zeros are allowed.
It is guaranteed that the sum of lengths of $s$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
Print a single string — the minimum string that is possible to obtain.
-----Examples-----
Input
4
04829
9
01
314752277691991
Output
02599
9
01
111334567888999
-----Note-----
In the first test case:
Delete $8$ and insert $9$ at the end of the notation. The resulting notation is $04299$.
Delete $4$ and insert $5$ in the $3$-rd position of the notation. The resulting notation is $02599$.
Nothing needs to be done in the second and third test cases.
|
{"inputs": ["4\n04829\n9\n01\n314752277691991\n"], "outputs": ["02599\n9\n01\n111334567888999\n"]}
| 478
| 66
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findTarget(self, root: Optional[TreeNode], k: int) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,3,6,2,4,None,7]), k = 9) == True\n assert candidate(root = tree_node([5,3,6,2,4,None,7]), k = 28) == False\n\n\ncheck(Solution().findTarget)"}
| 140
| 78
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Please complete the following python code precisely:
```python
class Solution:
def generateParenthesis(self, n: int) -> List[str]:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 3) == [\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]\n assert candidate(n = 1) == [\"()\"]\n\n\ncheck(Solution().generateParenthesis)"}
| 67
| 65
|
coding
|
Solve the programming task below in a Python markdown code block.
For an integer n not less than 0, let us define f(n) as follows:
- f(n) = 1 (if n < 2)
- f(n) = n f(n-2) (if n \geq 2)
Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
-----Constraints-----
- 0 \leq N \leq 10^{18}
-----Input-----
Input is given from Standard Input in the following format:
N
-----Output-----
Print the number of trailing zeros in the decimal notation of f(N).
-----Sample Input-----
12
-----Sample Output-----
1
f(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080, which has one trailing zero.
|
{"inputs": ["7", "5", "5\n", "0\n", "1\n", "2\n", "10", "24"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "1\n", "2\n"]}
| 191
| 67
|
coding
|
Solve the programming task below in a Python markdown code block.
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the n-th position of the sequence.
-----Input-----
The only line contains integer n (1 ≤ n ≤ 10^14) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Output-----
Print the element in the n-th position of the sequence (the elements are numerated from one).
-----Examples-----
Input
3
Output
2
Input
5
Output
2
Input
10
Output
4
Input
55
Output
10
Input
56
Output
1
|
{"inputs": ["3\n", "5\n", "1\n", "2\n", "4\n", "6\n", "8\n", "6\n"], "outputs": ["2\n", "2\n", "1\n", "1\n", "1\n", "3\n", "2\n", "3\n"]}
| 307
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
Let $f(x)$ be the sum of digits of a decimal number $x$.
Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases.
Each test case consists of one line containing two integers $n$ and $k$ ($1 \le n \le 150$, $0 \le k \le 9$).
-----Output-----
For each test case, print one integer without leading zeroes. If there is no such $x$ that $f(x) + f(x + 1) + \dots + f(x + k) = n$, print $-1$; otherwise, print the minimum $x$ meeting that constraint.
-----Example-----
Input
7
1 0
1 1
42 7
13 7
99 1
99 0
99 2
Output
1
0
4
-1
599998
99999999999
7997
|
{"inputs": ["2\n6 9\n5 0\n", "2\n9 9\n53 9\n", "2\n4 9\n51 5\n", "2\n6 9\n10 0\n", "2\n4 6\n47 7\n", "2\n9 9\n27 9\n", "2\n9 9\n17 4\n", "2\n9 8\n53 9\n"], "outputs": ["-1\n5\n", "-1\n8\n", "-1\n24\n", "-1\n19\n", "-1\n17\n", "-1\n-1\n", "-1\n-1\n", "-1\n8\n"]}
| 278
| 163
|
coding
|
Solve the programming task below in a Python markdown code block.
A number $a_2$ is said to be the arithmetic mean of two numbers $a_1$ and $a_3$, if the following condition holds: $a_1 + a_3 = 2\cdot a_2$.
We define an arithmetic mean deviation of three numbers $a_1$, $a_2$ and $a_3$ as follows: $d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$.
Arithmetic means a lot to Jeevan. He has three numbers $a_1$, $a_2$ and $a_3$ and he wants to minimize the arithmetic mean deviation $d(a_1, a_2, a_3)$. To do so, he can perform the following operation any number of times (possibly zero):
Choose $i, j$ from $\{1, 2, 3\}$ such that $i \ne j$ and increment $a_i$ by $1$ and decrement $a_j$ by $1$
Help Jeevan find out the minimum value of $d(a_1, a_2, a_3)$ that can be obtained after applying the operation any number of times.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 5000)$ — the number of test cases.
The first and only line of each test case contains three integers $a_1$, $a_2$ and $a_3$ $(1 \le a_1, a_2, a_3 \le 10^{8})$.
-----Output-----
For each test case, output the minimum value of $d(a_1, a_2, a_3)$ that can be obtained after applying the operation any number of times.
-----Examples-----
Input
3
3 4 5
2 2 6
1 6 5
Output
0
1
0
-----Note-----
Note that after applying a few operations, the values of $a_1$, $a_2$ and $a_3$ may become negative.
In the first test case, $4$ is already the Arithmetic Mean of $3$ and $5$.
$d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0$
In the second test case, we can apply the following operation:
$(2, 2, 6)$ $\xrightarrow[\text{increment $a_2$}]{\text{decrement $a_1$}}$ $(1, 3, 6)$
$d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1$
It can be proven that answer can not be improved any further.
In the third test case, we can apply the following operations:
$(1, 6, 5)$ $\xrightarrow[\text{increment $a_3$}]{\text{decrement $a_2$}}$ $(1, 5, 6)$ $\xrightarrow[\text{increment $a_1$}]{\text{decrement $a_2$}}$ $(2, 4, 6)$
$d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0$
|
{"inputs": ["3\n3 4 5\n2 2 6\n1 6 5\n"], "outputs": ["0\n1\n0\n"]}
| 746
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.
Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an n × n distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).
Input
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph.
Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.
Output
If there exists such a tree, output "YES", otherwise output "NO".
Examples
Input
3
0 2 7
2 0 9
7 9 0
Output
YES
Input
3
1 2 7
2 0 9
7 9 0
Output
NO
Input
3
0 2 2
7 0 9
7 9 0
Output
NO
Input
3
0 1 1
1 0 1
1 1 0
Output
NO
Input
2
0 0
0 0
Output
NO
Note
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7.
In the second example, it is impossible because d1, 1 should be 0, but it is 1.
In the third example, it is impossible because d1, 2 should equal d2, 1.
|
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n6\n", "1\n5\n", "1\n7\n", "1\n3\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 458
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs.
The stairs consists of n steps. The steps are numbered from bottom to top, it means that the lowest step has number 1, and the highest step has number n. Above each of them there is a pointer with the direction (up or down) Olga should move from this step. As soon as Olga goes to the next step, the direction of the pointer (above the step she leaves) changes. It means that the direction "up" changes to "down", the direction "down" — to the direction "up".
Olga always moves to the next step in the direction which is shown on the pointer above the step.
If Olga moves beyond the stairs, she will fall and wake up. Moving beyond the stairs is a moving down from the first step or moving up from the last one (it means the n-th) step.
In one second Olga moves one step up or down according to the direction of the pointer which is located above the step on which Olga had been at the beginning of the second.
For each step find the duration of the dream if Olga was at this step at the beginning of the dream.
Olga's fall also takes one second, so if she was on the first step and went down, she would wake up in the next second.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 10^6) — the number of steps on the stairs.
The second line contains a string s with the length n — it denotes the initial direction of pointers on the stairs. The i-th character of string s denotes the direction of the pointer above i-th step, and is either 'U' (it means that this pointer is directed up), or 'D' (it means this pointed is directed down).
The pointers are given in order from bottom to top.
-----Output-----
Print n numbers, the i-th of which is equal either to the duration of Olga's dream or to - 1 if Olga never goes beyond the stairs, if in the beginning of sleep she was on the i-th step.
-----Examples-----
Input
3
UUD
Output
5 6 3
Input
10
UUDUDUUDDU
Output
5 12 23 34 36 27 18 11 6 1
|
{"inputs": ["1\nD\n", "1\nD\n", "1\nU\n", "1\nD\n", "1\nU\n", "2\nDU\n", "2\nDU\n", "2\nUD\n"], "outputs": ["1 ", "1 ", "1 ", "1\n", "1\n", "1 1 ", "1 1\n", "3 3 "]}
| 555
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Lira loves Linear Algebra and she is especially keen about matrix :).
Today, she learnt some properties about matrices, namely, she learnt about what the trace of a matrix is, as her teacher gave her many exercises for her to practice.
As we know she is pretty clever, she rapidly came up with some definitions of her own and devised a somewhat harder version of the problem initially proposed by her teacher.
Namely, she defines a Positive Invertible Integer Matrix as being an invertible 2x2 matrix composed only of positive (i.e. greater than 0) integer elements and whose determinant is greater than 0.
Now, she is interested in counting how many such matrices are there, such that their trace is equal to N .
It's your turn to solve Lira's problem :D
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
Each test case consist of single integer N, the trace of the matrix.
------ Output ------
For each test case, output a single line containing the number of Positive Invertible Integer Matrices such that their trace is equal to N and determinant is positive.
Read here for additional info:
http://en.wikipedia.org/wiki/Trace_(linear_{algebra})
http://en.wikipedia.org/wiki/Determinant
------ Constraints: ------
$1 ≤ T ≤ 50$
$3 ≤ N ≤ 2500$
----- Sample Input 1 ------
1
3
----- Sample Output 1 ------
2
----- explanation 1 ------
The only two matrices that exist with trace equal to 3 and that satisfy all the given conditions are:
|
{"inputs": ["1\n3"], "outputs": ["2"]}
| 374
| 14
|
coding
|
Solve the programming task below in a Python markdown code block.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
|
{"inputs": ["3\n2 5 3", "3\n2 8 3", "3\n2 8 2", "3\n2 0 4", "3\n1 0 6", "3\n1 0 1", "3\n2 4 3", "12\n001 0 107 5 0 196 001 1 2 101 0 110"], "outputs": ["4\n", "7\n", "8\n", "2\n", "5\n", "0\n", "3", "94\n"]}
| 372
| 141
|
coding
|
Solve the programming task below in a Python markdown code block.
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.
-----Constraints-----
- All values in input are integers.
- 3 \leq N \leq 10
- 1 \leq L_i \leq 100
-----Input-----
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
-----Output-----
If an N-sided polygon satisfying the condition can be drawn, print Yes; otherwise, print No.
-----Sample Input-----
4
3 8 5 1
-----Sample Output-----
Yes
Since 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane.
|
{"inputs": ["4\n3 5 5 1", "4\n3 3 4 1", "4\n3 5 6 1", "4\n4 3 4 1", "4\n3 5 0 1", "4\n4 1 4 1", "4\n3 5 0 0", "4\n2 1 4 1"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n"]}
| 235
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file.
Find the time need to read file split to n fragments. The i-th sector contains the f_{i}-th fragment of the file (1 ≤ f_{i} ≤ n). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the n-th fragment is read. The fragments are read in the order from the first to the n-th.
It takes |a - b| time units to move the magnetic head from the sector a to the sector b. Reading a fragment takes no time.
-----Input-----
The first line contains a positive integer n (1 ≤ n ≤ 2·10^5) — the number of fragments.
The second line contains n different integers f_{i} (1 ≤ f_{i} ≤ n) — the number of the fragment written in the i-th sector.
-----Output-----
Print the only integer — the number of time units needed to read the file.
-----Examples-----
Input
3
3 1 2
Output
3
Input
5
1 3 5 4 2
Output
10
-----Note-----
In the second example the head moves in the following way: 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units 4->5 means movement from the sector 4 to the sector 3, i.e. it takes 1 time units
So the answer to the second example is 4 + 3 + 2 + 1 = 10.
|
{"inputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "3\n3 1 2\n", "3\n3 2 1\n", "3\n2 3 1\n", "3\n1 2 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "3\n", "2\n", "3\n", "2\n"]}
| 501
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progression is a sequence a_1, a_1 + d, a_1 + 2d, ..., a_1 + (n - 1)d, where a_1 and d are any numbers.
Geometric progression is a sequence b_1, b_2 = b_1q, ..., b_{n} = b_{n} - 1q, where b_1 ≠ 0, q ≠ 0, q ≠ 1.
Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.
-----Input-----
The first line contains exactly four integer numbers between 1 and 1000, inclusively.
-----Output-----
Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element.
Print 42 if the given sequence is not an arithmetic or geometric progression.
-----Examples-----
Input
836 624 412 200
Output
-12
Input
1 334 667 1000
Output
1333
-----Note-----
This problem contains very weak pretests!
|
{"inputs": ["1 1 1 1\n", "9 8 7 5\n", "2 6 6 8\n", "2 4 8 8\n", "2 4 4 2\n", "1 2 4 8\n", "8 4 2 1\n", "2 3 4 6\n"], "outputs": ["1\n", "42\n", "42\n", "42\n", "42\n", "16\n", "42\n", "42\n"]}
| 370
| 125
|
coding
|
Solve the programming task below in a Python markdown code block.
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided to rearrange them. Help him restore the original number, on condition that it was the maximum possible one.
-----Input-----
The first line contains a single integer $n$ ($1 \leqslant n \leqslant 10^5$) — the length of the string. The second line contains a string consisting of English lowercase letters: 'z', 'e', 'r', 'o' and 'n'.
It is guaranteed that it is possible to rearrange the letters in such a way that they form a sequence of words, each being either "zero" which corresponds to the digit $0$ or "one" which corresponds to the digit $1$.
-----Output-----
Print the maximum possible number in binary notation. Print binary digits separated by a space. The leading zeroes are allowed.
-----Examples-----
Input
4
ezor
Output
0
Input
10
nznooeeoer
Output
1 1 0
-----Note-----
In the first example, the correct initial ordering is "zero".
In the second example, the correct initial ordering is "oneonezero".
|
{"inputs": ["3\nnoe\n", "3\nnoe\n", "3\none\n", "3\neon\n", "3\nneo\n", "3\neno\n", "3\noen\n", "4\nezor\n"], "outputs": ["1 \n", "1\n", "1 ", "1 ", "1 ", "1 ", "1 ", "0 \n"]}
| 312
| 87
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.
A string is homogenous if all the characters of the string are the same.
A substring is a contiguous sequence of characters within a string.
Please complete the following python code precisely:
```python
class Solution:
def countHomogenous(self, s: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"abbcccaa\") == 13\n assert candidate(s = \"xy\") == 2\n assert candidate(s = \"zzzzz\") == 15\n\n\ncheck(Solution().countHomogenous)"}
| 111
| 62
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a string $s$. You need to find two non-empty strings $a$ and $b$ such that the following conditions are satisfied:
Strings $a$ and $b$ are both subsequences of $s$.
For each index $i$, character $s_i$ of string $s$ must belong to exactly one of strings $a$ or $b$.
String $a$ is lexicographically minimum possible; string $b$ may be any possible string.
Given string $s$, print any valid $a$ and $b$.
Reminder:
A string $a$ ($b$) is a subsequence of a string $s$ if $a$ ($b$) can be obtained from $s$ by deletion of several (possibly, zero) elements. For example, "dores", "cf", and "for" are subsequences of "codeforces", while "decor" and "fork" are not.
A string $x$ is lexicographically smaller than a string $y$ if and only if one of the following holds:
$x$ is a prefix of $y$, but $x \ne y$;
in the first position where $x$ and $y$ differ, the string $x$ has a letter that appears earlier in the alphabet than the corresponding letter in $y$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.
The first and only line of each test case contains one string $s$ ($2 \le |s| \le 100$ where $|s|$ means the length of $s$). String $s$ consists of lowercase Latin letters.
-----Output-----
For each test case, print the strings $a$ and $b$ that satisfy the given conditions. If there are multiple answers, print any.
-----Examples-----
Input
3
fc
aaaa
thebrightboiler
Output
c f
a aaa
b therightboiler
-----Note-----
In the first test case, there are only two choices: either $a =$ f and $b = $ c or $a = $ c and $b = $ f. And $a = $c is lexicographically smaller than $a = $ f.
In the second test case, a is the only character in the string.
In the third test case, it can be proven that b is the lexicographically smallest subsequence of $s$. The second string can be of two variants; one of them is given here.
|
{"inputs": ["3\nfc\naaaa\nthebrightboiler\n", "5\nkbxiahaosfyclumgnaczggrnljumplxknibxmeedvnefh\ndkqosshpegwunnzsohmxxumnnhckwyczaowpoxezqlovukcuuqgrsbrtifngthlquuqdjvyltgjbrmwoefypvdyzqwlainjoqx\nwktnblvszfndrjodikurlytsayblhpdnrytxnhfejtjfzeeamtt\ngkffwelozvmyosbmoufjpjzbeohbulotcinspqmyurolxwlwloobkszpnddxhrkbxoytmdsqxaetqzmufc\npdhelid\n"], "outputs": ["c f\na aaa\nb therightboiler\n", "a kbxihaosfyclumgnaczggrnljumplxknibxmeedvnefh\na dkqosshpegwunnzsohmxxumnnhckwyczowpoxezqlovukcuuqgrsbrtifngthlquuqdjvyltgjbrmwoefypvdyzqwlainjoqx\na wktnblvszfndrjodikurlytsyblhpdnrytxnhfejtjfzeeamtt\na gkffwelozvmyosbmoufjpjzbeohbulotcinspqmyurolxwlwloobkszpnddxhrkbxoytmdsqxetqzmufc\nd phelid\n"]}
| 559
| 361
|
coding
|
Solve the programming task below in a Python markdown code block.
There's a new security company in Paris, and they decided to give their employees an algorithm to make first name recognition faster. In the blink of an eye, they can now detect if a string is a first name, no matter if it is a one-word name or an hyphenated name. They're given this documentation with the algorithm:
*In France, you'll often find people with hyphenated first names. They're called "prénoms composés".
There could be two, or even more words linked to form a new name, quite like jQuery function chaining ;).
They're linked using the - symbol, like Marie-Joelle, Jean-Michel, Jean-Mouloud.
Thanks to this algorithm, you can now recognize hyphenated names quicker than Flash !*
(yeah, their employees know how to use jQuery. Don't ask me why)
Your mission if you accept it, recreate the algorithm.
Using the function **showMe**, which takes a **yourID** argument, you will check if the given argument is a name or not, by returning true or false.
*Note that*
- String will either be a one-word first name, or an hyphenated first name , its words being linked by "-".
- Words can only start with an uppercase letter, and then lowercase letters (from a to z)
Now is your time to help the guards !
Also feel free to reuse/extend the following starter code:
```python
def show_me(name):
```
|
{"functional": "_inputs = [['Francis'], ['Jean-Eluard'], ['Le Mec'], ['Bernard-Henry-Levy'], ['Meme Gertrude'], ['A-a-a-a----a-a'], ['Z-------------'], ['Jean-luc'], ['Jean--Luc'], ['JeanLucPicard'], ['-Jean-Luc'], ['Jean-Luc-Picard-']]\n_outputs = [[True], [True], [False], [True], [False], [False], [False], [False], [False], [False], [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)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(show_me(*i), o[0])"}
| 321
| 258
|
coding
|
Solve the programming task below in a Python markdown code block.
Jim runs a big burger restaurant and, to entertain his customers, he always tell them jokes. He is running out of jokes and he needs you to help him find new ones.
An often heard programmer joke goes like this:
"Why do programmers always mix up Christmas and Halloween? Because Dec 25 is Oct 31".
Got it? :-) It is because $25_{10}$ (25 in Decimal) is equal to ${31}_{8}$ (31 in Octal).
If we are talking about dates, then let $m$ be the month and ${d}$ be the date and the corresponding value be $f(m,d)=d_m$ (${d}$ in base $m$). Let's describe some slightly different jokes:
"Why do programmers always mix up event $\boldsymbol{x}$ and event $y$? Because $f(m_x,d_x)=f(m_y,d_y)$".
Here $m_{x}$ means the month of event ${x}$ and $d_x$ the day of event ${x}$. Similar for $m_y$ and $d_y$.
Jim knows that his customers love this kind of jokes. That's why he gives you a calendar with $N$ events in it and asks you to count the number of such jokes he can create using the given events.
Two jokes ($(x_1,x_2)$ and $(y_{1},y_{2})$) differ if they don't contain the same events.
Note:
The given numbers are all represented with digits from 0-9, that's why for months like ${11}$ or $12$, we can't use additional characters to represent 10 or 11.
It might happen, that a special event cannot be used for a joke because the base conversion is invalid. For example $25_2$ is not possible since base $2$ can only contain digits ${0}$ and ${1}$.
Unary base is invalid.
Two events can have the same date.
Input Format
On the first line you will get $N$. The following $N$ lines you will be given the dates $m_i$, $d_i$ of the special events, each separated by a single space.
Output Format
Print the number of jokes Jim can make.
Constraints
$1\leq N\leq10^5$
($m_i$, $d_i$) will be a valid date in the Gregorian Calendar without leap day.
Sample Input #1
2
10 25
8 31
Sample Output #1
1
Sample Input #2
2
2 25
2 25
Sample Output #2
0
Sample Input #3
2
11 10
10 11
Sample Output #3
1
Explanation
There are two special events happening on $(10,25)$ and $(8,31)$. He can make one joke, namely the one described in the description.
In the second test case there are no valid dates we can use for our jokes since 25 is not defined for base 2.
In the third test case $f(11,10)=10_{11}=11_{10}=f(10,11)$.
|
{"inputs": ["2\n2 25\n2 25\n", "2\n10 25\n8 31\n", "2\n11 10\n10 11\n"], "outputs": ["0\n", "1\n", "1\n"]}
| 703
| 63
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of $n$ elements.
Your can perform the following operation no more than $n$ times: Select three indices $x,y,z$ $(1 \leq x < y < z \leq n)$ and replace $a_x$ with $a_y - a_z$. After the operation, $|a_x|$ need to be less than $10^{18}$.
Your goal is to make the resulting array non-decreasing. If there are multiple solutions, you can output any. If it is impossible to achieve, you should report it as well.
-----Input-----
Each test contains multiple test cases. The first line will contain a single integer $t$ $(1 \leq t \leq 10000)$ — the number of test cases. Then $t$ test cases follow.
The first line of each test case contains a single integer $n$ $(3 \leq n \leq 2 \cdot 10^5)$ — the size of the array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots ,a_n$ $(-10^9 \leq a_i \leq 10^9)$, the elements of $a$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print $-1$ in a single line if there is no solution. Otherwise in the first line you should print a single integer $m$ $(0 \leq m \leq n)$ — number of operations you performed.
Then the $i$-th of the following $m$ lines should contain three integers $x,y,z$ $(1 \leq x < y < z \leq n)$— description of the $i$-th operation.
If there are multiple solutions, you can output any. Note that you don't have to minimize the number of operations in this task.
-----Examples-----
Input
3
5
5 -4 2 -1 2
3
4 3 2
3
-3 -2 -1
Output
2
1 2 3
3 4 5
-1
0
-----Note-----
In the first example, the array becomes
$[-6,-4,2,-1,2]$ after the first operation,
$[-6,-4,-3,-1,2]$ after the second operation.
In the second example, it is impossible to make the array sorted after any sequence of operations.
In the third example, the array is already sorted, so we don't need to perform any operations.
|
{"inputs": ["3\n5\n5 -4 2 -1 2\n3\n4 3 2\n3\n-3 -2 -1\n"], "outputs": ["3\n1 4 5\n2 4 5\n3 4 5\n-1\n0\n"]}
| 590
| 66
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return a string array answer (1-indexed) where:
answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
answer[i] == "Fizz" if i is divisible by 3.
answer[i] == "Buzz" if i is divisible by 5.
answer[i] == i (as a string) if none of the above conditions are true.
Please complete the following python code precisely:
```python
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 3) == [\"1\",\"2\",\"Fizz\"]\n assert candidate(n = 5) == [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]\n assert candidate(n = 15) == [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]\n\n\ncheck(Solution().fizzBuzz)"}
| 133
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Given three positive integers N, L and R, find the number of non-decreasing sequences of size at least 1 and at most N, such that each element of the sequence lies between L and R, both inclusive.
Print the answer modulo 10^{6}+3.
------ Input ------
First line of input contains T, the number of the test cases.
Each of next T lines contains three space separated integers N, L and R.
------ Output ------
For each test case print the answer modulo 10^{6}+3 in a single line.
------ Constraints ------
$1 ≤ T ≤ 100$
$L ≤ R$
------ Subtasks ------
$Subtask #1 (20 points): 1 ≤ N, L, R ≤ 100
$$Subtask #2 (30 points): 1 ≤ N, L, R ≤ 10^{4}
$$Subtask #3 (50 points): 1 ≤ N, L, R ≤ 10^{9}
----- Sample Input 1 ------
2
1 4 5
2 4 5
----- Sample Output 1 ------
2
5
----- explanation 1 ------
test #1: [4] and [5] are the two sequences.
test #2: [4], [5], [4, 4], [4, 5] and [5, 5] are the five sequences.
|
{"inputs": ["2\n1 4 5\n2 4 5", "2\n1 4 5\n2 4 5"], "outputs": ["2\n5", "2\n5"]}
| 326
| 46
|
coding
|
Solve the programming task below in a Python markdown code block.
Simple interest on a loan is calculated by simply taking the initial amount (the principal, p) and multiplying it by a rate of interest (r) and the number of time periods (n).
Compound interest is calculated by adding the interest after each time period to the amount owed, then calculating the next interest payment based on the principal PLUS the interest from all previous periods.
Given a principal *p*, interest rate *r*, and a number of periods *n*, return an array [total owed under simple interest, total owed under compound interest].
```
EXAMPLES:
interest(100,0.1,1) = [110,110]
interest(100,0.1,2) = [120,121]
interest(100,0.1,10) = [200,259]
```
Round all answers to the nearest integer. Principal will always be an integer between 0 and 9999; interest rate will be a decimal between 0 and 1; number of time periods will be an integer between 0 and 49.
---
More on [Simple interest, compound interest and continuous interest](https://betterexplained.com/articles/a-visual-guide-to-simple-compound-and-continuous-interest-rates/)
Also feel free to reuse/extend the following starter code:
```python
def interest(p,r,n):
```
|
{"functional": "_inputs = [[100, 0.1, 1], [100, 0.1, 2], [100, 0.1, 10], [100, 0, 10], [0, 0.1, 10], [100, 0.1, 0]]\n_outputs = [[[110, 110]], [[120, 121]], [[200, 259]], [[100, 100]], [[0, 0]], [[100, 100]]]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(interest(*i), o[0])"}
| 309
| 281
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.
After doing so, return the array.
Please complete the following python code precisely:
```python
class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(arr = [17,18,5,4,6,1]) == [18,6,6,6,1,-1]\n assert candidate(arr = [400]) == [-1]\n\n\ncheck(Solution().replaceElements)"}
| 90
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well.
You are given a grid with $N$ rows and $M$ columns, where each cell contains either '0' or '1'.
Find out whether all the cells containing '1'-s form a rectangle, I.e, is there a rectangular contiguous subgrid such that every cell within it is a '1', and all the cells containing '1'-s are within this subgrid.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains a single string with length $M$ describing the $i$-th row of the grid.
------ Output ------
For each test case, print a single line containing the string "YES" if the connected component of '1'-s is a rectangle or "NO" if it is not.
Note: The output is case-insensitive ― each letter may be printed in upper case or lower case.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N, M ≤ 500$
Sum of $N*M$ over all tests is atmost $1.5*10^{6}$
Each string contains only characters '0' and '1'
It is guaranteed that grid contains at least a single '1'
----- Sample Input 1 ------
3
3 3
010
111
010
4 4
0000
0110
1110
1100
3 3
011
011
000
----- Sample Output 1 ------
NO
NO
YES
----- explanation 1 ------
Example case 1: The minimal rectangle which covers all '1'-s also covers $4$ cells which contain '0'-s.
Example case 2: The minimal rectangle which covers all '1'-s also covers $2$ cells which contain '0'-s.
Example case 3: We can form a minimal rectangle with side length $2$ which covers all cells containing '1'-s and none of the cells containing '0'-s.
|
{"inputs": ["3\n3 3\n010\n111\n010\n4 4\n0000\n0110\n1110\n1100\n3 3\n011\n011\n000"], "outputs": ["NO\nNO\nYES"]}
| 534
| 72
|
coding
|
Solve the programming task below in a Python markdown code block.
Variation of this nice kata, the war has expanded and become dirtier and meaner; both even and odd numbers will fight with their pointy `1`s. And negative integers are coming into play as well, with, ça va sans dire, a negative contribution (think of them as spies or saboteurs).
Again, three possible outcomes: `odds win`, `evens win` and `tie`.
Examples:
```python
bits_war([1,5,12]) => "odds win" #1+101 vs 1100, 3 vs 2
bits_war([7,-3,20]) => "evens win" #111-11 vs 10100, 3-2 vs 2
bits_war([7,-3,-2,6]) => "tie" #111-11 vs -1+110, 3-2 vs -1+2
```
Also feel free to reuse/extend the following starter code:
```python
def bits_war(numbers):
```
|
{"functional": "_inputs = [[[1, 5, 12]], [[7, -3, 20]], [[7, -3, -2, 6]], [[-3, -5]], [[]]]\n_outputs = [['odds win'], ['evens win'], ['tie'], ['evens win'], ['tie']]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(bits_war(*i), o[0])"}
| 240
| 210
|
coding
|
Solve the programming task below in a Python markdown code block.
Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 10^9 + 7 (the remainder when divided by 10^9 + 7).
The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1.
-----Input-----
The only line contains two integers n, m (1 ≤ n, m ≤ 10^13) — the parameters of the sum.
-----Output-----
Print integer s — the value of the required sum modulo 10^9 + 7.
-----Examples-----
Input
3 4
Output
4
Input
4 4
Output
1
Input
1 1
Output
0
|
{"inputs": ["3 4\n", "4 4\n", "1 1\n", "3 3\n", "4 1\n", "3 4\n", "4 4\n", "1 1\n"], "outputs": ["4\n", "1\n", "0\n", "1", "0", "4\n", "1\n", "0\n"]}
| 194
| 84
|
coding
|
Solve the programming task below in a Python markdown code block.
Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not.
Valid examples, should return true:
should return false:
Also feel free to reuse/extend the following starter code:
```python
def isDigit(string):
```
|
{"functional": "_inputs = [['s2324'], ['-234.4'], ['3 4'], ['3-4'], ['3 4 '], ['34.65'], ['-0'], ['0.0'], [''], [' ']]\n_outputs = [[False], [True], [False], [False], [False], [True], [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)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(isDigit(*i), o[0])"}
| 75
| 229
|
coding
|
Solve the programming task below in a Python markdown code block.
Problem Statement:
You are one of the organizers of Pragyan.Having worked so hard to ensure
success of the event, you are able to spot the word "pragyan" in any text.
You are given a stream of character strings and you need to output them
till you find the word "pragyan".Stop processing after
NOTE: The word "pragyan" can have 0,1..or all characters in uppercase.
Input format:
Input consists of a single word in each line.
Output Format:
For each word, print the input word till the word "pragyan" is found.Stop
processing after this.
Input Constraints:
Length of each word ≤ 100.
All words contain only alpabets.(No numbers and special characters included).
SAMPLE INPUT
The
quick
brown
fox
praGyan
jumped
over
the
laz
dog
SAMPLE OUTPUT
The
quick
brown
fox
praGyan
|
{"inputs": ["PRAGyAN", "The\nquick\nbrown\nfox\npragyan\njumped\nover\nthe\nlazy\ndog", "The\nquick\nbrown\nfox\njumped\nover\nthe\nlazy\ndog\npragya\npragy\npra\nragyan\noragyan\npragyam\npRaGYAN\nAny\ninput\nbeyond\nthis\nshould\nnot\nbe\nprocessed", "Far\nout\nin\nthe\nuncharted\nbackwaters\nof\nthe\nunfashionable\nend\nof\nthe\nwestern\nspiral\nPRAGYAN\narm\nof\nthe\nGalaxy\nlies\na\nsmall\nunregarded\nyellow\nsun"], "outputs": ["PRAGyAN", "The\nquick\nbrown\nfox\npragyan", "The\nquick\nbrown\nfox\njumped\nover\nthe\nlazy\ndog\npragya\npragy\npra\nragyan\noragyan\npragyam\npRaGYAN", "Far\nout\nin\nthe\nuncharted\nbackwaters\nof\nthe\nunfashionable\nend\nof\nthe\nwestern\nspiral\nPRAGYAN"]}
| 217
| 270
|
coding
|
Solve the programming task below in a Python markdown code block.
Stuart is obsessed to numbers. He like all type of numbers in fact he is having a great collection of numbers in his room. His collection includes N different large numbers. But today he is searching for a number which is having maximum frequency of digit X. Numbers are large so he can’t do the task on his own. Help him to find a number having maximum frequency of digit X.
-----Input-----
First Line contains number of test cases T. First Line of each test case contains N. Next line contains N space separated integers A1,A2,A3,....,AN. Where Ai integer indicates ith number in Stuart's room. Next Line contains digit X.
-----Output-----
Output the number which is having maximum frequency of digit X. If two or more numbers are having same maximum frequency then output the first occurred number among them in A1,A2,A3,....,AN
-----Constraints-----
- 1 ≤ T ≤ 30
- 1 ≤ N ≤ 100
- 1 ≤ Ai ≤ 10200
- 0 ≤ X ≤ 9
-----Example-----
Input:
2
5
345 1323 165 98 456
3
5
335 876 98 1323 349
3
Output:
1323
335
-----Explanation-----
Example case 1. 1323 number is having maximum occurrence of digit 3.
Example case 2. 335 & 1323 are having maximum occurrence of digit 3 so output must be first occurred number in the array i.e. 335.
|
{"inputs": ["2\n5\n345 1323 165 98 456\n3\n5\n335 876 98 1323 349\n3"], "outputs": ["1323\n335"]}
| 369
| 67
|
coding
|
Solve the programming task below in a Python markdown code block.
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.
A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose — to show the developer the imperfection of their protection.
The found algorithm looks the following way. At first the digits of the number are shuffled in the following order <first digit><third digit><fifth digit><fourth digit><second digit>. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455 422 043 125 550 171 232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232.
Vasya is going to write a keygen program implementing this algorithm. Can you do the same?
-----Input-----
The only line of the input contains a positive integer five digit number for which the activation code should be found.
-----Output-----
Output exactly 5 digits without spaces between them — the found activation code of the program.
-----Examples-----
Input
12345
Output
71232
|
{"inputs": ["12345\n", "13542\n", "71232\n", "11111\n", "10000\n", "99999\n", "91537\n", "70809\n"], "outputs": ["71232", "84443", "10151", "36551", "00000", "99999", "27651", "00000"]}
| 358
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
Snuke has a blackboard and a set S consisting of N integers. The i-th element in S is S_i.
He wrote an integer X on the blackboard, then performed the following operation N times:
* Choose one element from S and remove it.
* Let x be the number written on the blackboard now, and y be the integer removed from S. Replace the number on the blackboard with x \bmod {y}.
There are N! possible orders in which the elements are removed from S. For each of them, find the number that would be written on the blackboard after the N operations, and compute the sum of all those N! numbers modulo 10^{9}+7.
Constraints
* All values in input are integers.
* 1 \leq N \leq 200
* 1 \leq S_i, X \leq 10^{5}
* S_i are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N X
S_1 S_2 \ldots S_{N}
Output
Print the answer.
Examples
Input
2 19
3 7
Output
3
Input
5 82
22 11 6 5 13
Output
288
Input
10 100000
50000 50001 50002 50003 50004 50005 50006 50007 50008 50009
Output
279669259
|
{"inputs": ["2 17\n3 7", "2 20\n6 3", "2 19\n3 7", "2 19\n3 11", "2 12\n6 11", "5 193\n5 13 7 5 4", "5 82\n22 11 6 7 13", "5 82\n27 11 6 7 13"], "outputs": ["2\n", "4\n", "3", "3\n", "1\n", "198\n", "516\n", "456\n"]}
| 373
| 151
|
coding
|
Solve the programming task below in a Python markdown code block.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
|
{"inputs": ["1\n1 1\n", "2\n1 110\n2 1 10\n", "2\n1 100\n2 1 10\n", "2\n2 60 2\n3 1 000 4\n", "2\n2 60 2\n3 1 000 5\n", "2\n2 200 1\n3 1 100 2\n", "2\n2 200 2\n3 1 100 2\n", "2\n2 200 2\n3 1 000 2\n"], "outputs": ["1 0\n", "111 10\n", "101 10\n", "61 6\n", "61 7\n", "301 3\n", "301 4\n", "201 4\n"]}
| 544
| 218
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's.
String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones ($n$ is even).
In one operation you can reverse any substring of $s$. A substring of a string is a contiguous subsequence of that string.
What is the minimum number of operations you need to make string $s$ alternating? A string is alternating if $s_i \neq s_{i + 1}$ for all $i$. There are two types of alternating strings in general: 01010101... or 10101010...
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($2 \le n \le 10^5$; $n$ is even) — the length of string $s$.
The second line of each test case contains a binary string $s$ of length $n$ ($s_i \in$ {0, 1}). String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones.
It's guaranteed that the total sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
For each test case, print the minimum number of operations to make $s$ alternating.
-----Example-----
Input
3
2
10
4
0110
8
11101000
Output
0
1
2
-----Note-----
In the first test case, string 10 is already alternating.
In the second test case, we can, for example, reverse the last two elements of $s$ and get: 0110 $\rightarrow$ 0101.
In the third test case, we can, for example, make the following two operations: 11101000 $\rightarrow$ 10101100; 10101100 $\rightarrow$ 10101010.
|
{"inputs": ["3\n2\n10\n4\n0110\n8\n11101000\n", "3\n2\n10\n4\n0110\n8\n11100001\n", "3\n2\n10\n4\n1010\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11101000\n", "3\n2\n10\n4\n0101\n8\n11100001\n", "3\n2\n10\n4\n0101\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11100001\n", "3\n2\n10\n4\n1001\n8\n11101000\n"], "outputs": ["0\n1\n2\n", "0\n1\n3\n", "0\n0\n2\n", "0\n1\n2\n", "0\n0\n3\n", "0\n0\n2\n", "0\n1\n3\n", "0\n1\n2\n"]}
| 507
| 286
|
coding
|
Solve the programming task below in a Python markdown code block.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
|
{"inputs": ["000000\n", "123456\n", "111000\n", "120111\n", "999999\n", "199880\n", "899889\n", "899888\n"], "outputs": ["0\n", "2\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n"]}
| 276
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
-----Constraints-----
- All values in input are integers.
- 2 \leq A \leq 20
- 1 \leq B \leq 20
-----Input-----
Input is given from Standard Input in the following format:
A B
-----Output-----
Print the minimum number of power strips required.
-----Sample Input-----
4 10
-----Sample Output-----
3
3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.
|
{"inputs": ["8 4", "4 9", "2 5", "7 9", "2 9", "4 1", "2 8", "2 7"], "outputs": ["1\n", "3\n", "4\n", "2\n", "8\n", "0\n", "7\n", "6\n"]}
| 177
| 78
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef discovered that his secret recipe has been stolen. He immediately informs the police of the theft.
It is known that the policeman and thief move on the number line. You are given that:
The initial location of the policeman on the number line is X and his speed is 2 units per second.
The initial location of the thief on the number line is Y and his speed is 1 unit per second.
Find the minimum time (in seconds) in which the policeman can catch the thief. Note that, the policeman catches the thief as soon as their locations become equal and the thief will try to evade the policeman for as long as possible.
------ Input Format ------
- The first line of input will contain an integer T — the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains two integers X and Y, as described in the problem statement.
------ Output Format ------
For each test case, output in a single line the minimum time taken by the policeman to catch the thief.
------ Constraints ------
$1 ≤ T ≤ 1000$
$-10^{5} ≤ X, Y ≤ 10^{5}$
----- Sample Input 1 ------
3
1 3
2 1
1 1
----- Sample Output 1 ------
2
1
0
----- explanation 1 ------
Test case $1$: The initial locations of the policeman and thief are $1$ and $3$ respectively. The minimum time taken by the policeman to catch the thief is $2$ seconds, and this happens when both the policeman and the thief move towards the right.
Test case $2$: The initial location of the policeman and thief are $2$ and $1$ respectively. The minimum time taken by the policeman to catch the thief is $1$ second, and this happens when both the policeman and the thief move towards the left.
Test case $3$: The initial locations of the policeman and thief are $1$ and $1$ respectively. Because the police is already present at the location of thief, the time taken by police to catch the thief is $0$ seconds.
|
{"inputs": ["3\n1 3\n2 1\n1 1"], "outputs": ["2\n1\n0"]}
| 462
| 28
|
coding
|
Solve the programming task below in a Python markdown code block.
You are playing the following game with Joisino.
- Initially, you have a blank sheet of paper.
- Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
- Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
-----Constraints-----
- 1≤N≤100000
- 1≤A_i≤1000000000(=10^9)
- All input values are integers.
-----Input-----
Input is given from Standard Input in the following format:
N
A_1
:
A_N
-----Output-----
Print how many numbers will be written on the sheet at the end of the game.
-----Sample Input-----
3
6
2
6
-----Sample Output-----
1
The game proceeds as follows:
- 6 is not written on the sheet, so write 6.
- 2 is not written on the sheet, so write 2.
- 6 is written on the sheet, so erase 6.
Thus, the sheet contains only 2 in the end. The answer is 1.
|
{"inputs": ["3\n6\n2\n7", "3\n6\n2\n8", "3\n3\n2\n8", "3\n0\n2\n8", "3\n0\n2\n7", "3\n0\n3\n7", "3\n0\n6\n7", "3\n0\n5\n7"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]}
| 313
| 110
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.
Given two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a solution, it is guaranteed to be unique.
Please complete the following python code precisely:
```python
class Solution:
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(gas = [1,2,3,4,5], cost = [3,4,5,1,2]) == 3\n assert candidate(gas = [2,3,4], cost = [3,4,3]) == -1\n\n\ncheck(Solution().canCompleteCircuit)"}
| 174
| 81
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line — the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
{"inputs": ["1\n890\n", "1\n454\n", "1\n638\n", "1\n540\n", "1\n119\n", "1\n176\n", "1\n187\n", "1\n353\n"], "outputs": ["809\n", "445\n", "368\n", "405\n", "119\n", "167\n", "178\n", "353\n"]}
| 605
| 118
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share one edge.
Return the minimum number of steps required to convert mat to a zero matrix or -1 if you cannot.
A binary matrix is a matrix with all cells equal to 0 or 1 only.
A zero matrix is a matrix with all cells equal to 0.
Please complete the following python code precisely:
```python
class Solution:
def minFlips(self, mat: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(mat = [[0,0],[0,1]]) == 3\n assert candidate(mat = [[0]]) == 0\n assert candidate(mat = [[1,0,0],[1,0,0]]) == -1\n\n\ncheck(Solution().minFlips)"}
| 163
| 72
|
coding
|
Solve the programming task below in a Python markdown code block.
You will have a list of rationals in the form
```
lst = [ [numer_1, denom_1] , ... , [numer_n, denom_n] ]
```
or
```
lst = [ (numer_1, denom_1) , ... , (numer_n, denom_n) ]
```
where all numbers are positive integers. You have to produce their sum `N / D` in an irreducible form: this means that `N` and `D` have only `1` as a common divisor.
Return the result in the form:
- `[N, D]` in Ruby, Crystal, Python, Clojure, JS, CS, PHP, Julia
- `Just "N D"` in Haskell, PureScript
- `"[N, D]"` in Java, CSharp, TS, Scala, PowerShell, Kotlin
- `"N/D"` in Go, Nim
- `{N, D}` in C++, Elixir
- `{N, D}` in C
- `Some((N, D))` in Rust
- `Some "N D"` in F#, Ocaml
- `c(N, D)` in R
- `(N, D)` in Swift
- `'(N D)` in Racket
If the result is an integer (`D` evenly divides `N`) return:
- an integer in Ruby, Crystal, Elixir, Clojure, Python, JS, CS, PHP, R, Julia
- `Just "n"` (Haskell, PureScript)
- `"n"` Java, CSharp, TS, Scala, PowerShell, Go, Nim, Kotlin
- `{n, 1}` in C++
- `{n, 1}` in C
- `Some((n, 1))` in Rust
- `Some "n"` in F#, Ocaml,
- `(n, 1)` in Swift
- `n` in Racket
If the input list is empty, return
- `nil/None/null/Nothing`
- `{0, 1}` in C++
- `{0, 1}` in C
- `"0"` in Scala, PowerShell, Go, Nim
- `O` in Racket
- `""` in Kotlin
### Example:
```
[ [1, 2], [1, 3], [1, 4] ] --> [13, 12]
1/2 + 1/3 + 1/4 = 13/12
```
### Note
See sample tests for more examples and the form of results.
Also feel free to reuse/extend the following starter code:
```python
def sum_fracts(lst):
```
|
{"functional": "_inputs = [[[[1, 2], [1, 3], [1, 4]]], [[[1, 3], [5, 3]]], [[[12, 3], [15, 3]]], [[[2, 7], [1, 3], [1, 12]]], [[[69, 130], [87, 1310], [3, 4]]], [[[77, 130], [84, 131], [60, 80]]], [[[6, 13], [187, 1310], [31, 41]]], [[[8, 15], [7, 111], [4, 25]]], [[]], [[[81345, 15786], [87546, 11111111], [43216, 255689]]], [[[1, 8], [1, 9]]], [[[2, 8], [1, 9]]]]\n_outputs = [[[13, 12]], [2], [9], [[59, 84]], [[9177, 6812]], [[67559, 34060]], [[949861, 698230]], [[2099, 2775]], [None], [[79677895891146625, 14949283383840498]], [[17, 72]], [[13, 36]]]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(sum_fracts(*i), o[0])"}
| 587
| 528
|
coding
|
Solve the programming task below in a Python markdown code block.
We are interested in obtaining two scores from a given integer:
**First score**: The sum of all the integers obtained from the power set of the digits of the given integer that have the same order
E.g:
```
integer = 1234 ---> (1 + 2 + 3 + 4) + (12 + 13 + 14 + 23 + 24 + 34) +
(123 + 124 + 134 + 234) + 1234 = 10 + 120 + 615 + 1234 = 1979
```
**Second score**: The sum of all the integers obtained from the all the contiguous substrings of the given integer as a string.
E.g.
```
integer = 1234 ---> (1 + 2 + 3 + 4) + (12 + 23 + 34) + (123 + 234) + 1234 = 10 + 69 + 357 + 1234 = 1670
```
The first integer, higher than ```100```, that has both scores with ```3``` common divisors is ```204```. Its first score is ```258``` and the second one ```234```. The common divisors for both scores are ```2, 3, 6```.
In fact the integers ```294``` and ```468``` are the ones in the range ```[100, 500]```, that have both scores with ```7``` common divisors, the maximum amount of common factors in that range.
Your task in this kata is to create a function that may find the integer or integers that have the maximum amount of common divisors for the scores described above.
The example given above will be:
```python
find_int_inrange(100, 500) == [7, 294, 468]
```
As you can see, the function should receive the limits of a range [a, b], and outputs an array with the maximum amount of factors, ```max_am_div``` and the found numbers sorted
```
find_int_inrange(a, b) ----> [max_am_div, k1, k2, ...., kn] # k1 < k2 < ...< kn
```
The function may output only one number.
```python
find_int_inrange(100, 300) == [7, 294]
```
Enjoy it!
Features of the random tests:
```
100 < a < b < 55000
```
Also feel free to reuse/extend the following starter code:
```python
def find_int_inrange(a, b):
```
|
{"functional": "_inputs = [[100, 300], [100, 500], [300, 900]]\n_outputs = [[[7, 294]], [[7, 294, 468]], [[7, 468, 834]]]\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_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(find_int_inrange(*i), o[0])"}
| 634
| 214
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has.
A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.
Please complete the following python code precisely:
```python
class Solution:
def maximumWealth(self, accounts: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(accounts = [[1,2,3],[3,2,1]]) == 6\n assert candidate(accounts = [[1,5],[7,3],[3,5]]) == 10\n assert candidate(accounts = [[2,8,7],[7,1,3],[1,9,5]]) == 17\n\n\ncheck(Solution().maximumWealth)"}
| 136
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef and his friend Miron were getting bored and decided to play a game.
Miron thinks of a sequence of N integers (A1, A2, …., AN) and gives Chef a matrix B, where Bi,j = |Ai - Aj|. He further tells Chef that A1 = 0. The game is for Chef to guess the sequence that Miron thought of.
But Miron is an adversarial player. Every time Chef tries to guess the sequence, he makes a change to the matrix. He makes such a change Q times. Each time, he replaces an entry in some row and the corresponding column with a new one leaving Chef to guess the sequence after each change.
Chef needs a friend to help him against such an adversarial player. Can you be that friend and help Chef find a suitable sequence A for the initial matrix B and also after each change Miron makes?
Note that if several answers exist, then print the lexicographically smallest answer. Further, the numbers in the sequence can be negative.
-----Input-----
The first line contains two space-separated integers N, Q. Each of the N subsequent lines contains N space-separated integers, denoting the matrix B.
Q queries follow. Each query has two lines. The first line of each query contains an integer p, denoting the number of row and column that is changed. The second line of each query contains N space-separated integers F1, F2, F3, ... FN, denoting the new values to the corresponding cells of the matrix (you should make the following assignments Bi,p = Bp,i = Fi for all valid i).
-----Output-----
Print Q + 1 lines which contain N space-separated integers, Miron's initial array and Miron's array after each query.
-----Constraints-----
- 3 ≤ N ≤ 1000
- 1 ≤ Q ≤ 1000
- 0 ≤ Bi,j ≤ 5000
- 1 ≤ p ≤ n
- 0 ≤ Fi ≤ 5000
- it's guaranteed there's always an answer
-----Example-----
Input:
3 2
0 1 2
1 0 1
2 1 0
1
0 4 3
2
4 0 7
Output:
0 -1 -2
0 -4 -3
0 -4 3
-----Explanation-----
Example case 1. Initially, sequence {0, 1, 2} is also suitable, but {0, -1, -2} is lexicografically smaller.
|
{"inputs": ["3 2\n0 1 2\n1 0 1\n2 1 0\n1\n0 4 3\n2\n4 0 7"], "outputs": ["0 -1 -2\n0 -4 -3\n0 -4 3"]}
| 558
| 64
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:
multiply the number on display by 2, or
subtract 1 from the number on display.
Given two integers startValue and target, return the minimum number of operations needed to display target on the calculator.
Please complete the following python code precisely:
```python
class Solution:
def brokenCalc(self, startValue: int, target: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(startValue = 2, target = 3) == 2\n assert candidate(startValue = 5, target = 8) == 2\n assert candidate(startValue = 3, target = 10) == 3\n\n\ncheck(Solution().brokenCalc)"}
| 117
| 74
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chefland has $7$ days in a week. Chef is very conscious about his work done during the week.
There are two ways he can spend his energy during the week. The first way is to do $x$ units of work every day and the second way is to do $y$ ($> x$) units of work for the first $d$ ($< 7$) days and to do $z$ ($< x$) units of work thereafter since he will get tired of working more in the initial few days.
Find the maximum amount of work he can do during the week if he is free to choose either of the two strategies.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains a single line of input, four integers $d$, $x$, $y$, $z$.
------ Output ------
For each testcase, output in a single line the answer to the problem.
------ Constraints ------
$1 ≤ T ≤ 5\cdot 10^{3}$
$1 ≤ d < 7$
$1 ≤ z < x < y ≤ 18$
------ Subtasks ------
Subtask #1 (100 points): Original constraints
----- Sample Input 1 ------
3
1 2 3 1
6 2 3 1
1 2 8 1
----- Sample Output 1 ------
14
19
14
----- explanation 1 ------
Test Case $1$: Using the first strategy, Chef does $2 \cdot 7 = 14$ units of work and using the second strategy Chef does $3 \cdot 1 + 1 \cdot 6 = 9$ units of work. So the maximum amount of work that Chef can do is $\max(14, 9) = 14$ units by using the first strategy.
Test Case $2$: Using the first strategy, Chef does $2 \cdot 7 = 14$ units of work and using the second strategy Chef does $3 \cdot 6 + 1 \cdot 1 = 19$ units of work. So the maximum amount of work that Chef can do is $\max(14, 19) = 19$ units by using the second strategy.
|
{"inputs": ["3\n1 2 3 1\n6 2 3 1\n1 2 8 1"], "outputs": ["14\n19\n14"]}
| 535
| 43
|
coding
|
Solve the programming task below in a Python markdown code block.
There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.
You can perform the following operation on this integer sequence any number of times:
Operation: Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.
Let B_1, B_2, ..., B_N be the integer sequence after your operations.
Find the maximum possible value of B_1 + B_2 + ... + B_N.
-----Constraints-----
- All values in input are integers.
- 2 \leq N \leq 10^5
- -10^9 \leq A_i \leq 10^9
-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
-----Output-----
Print the maximum possible value of B_1 + B_2 + ... + B_N.
-----Sample Input-----
3
-10 5 -4
-----Sample Output-----
19
If we perform the operation as follows:
- Choose 1 as i, which changes the sequence to 10, -5, -4.
- Choose 2 as i, which changes the sequence to 10, 5, 4.
we have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19, is the maximum possible result.
|
{"inputs": ["3\n0 1 1", "2\n-10 9\n", "3\n-1 5 1", "3\n-2 5 1", "3\n-1 1 1", "3\n-2 0 1", "3\n-10 5 0", "3\n-14 5 0"], "outputs": ["2\n", "1\n", "5\n", "6\n", "1\n", "3\n", "15\n", "19\n"]}
| 355
| 121
|
coding
|
Solve the programming task below in a Python markdown code block.
Even if it's a really easy question, she won't be able to answer it
— Perfect Memento in Strict Sense
Cirno's perfect bitmasks classroom has just started!
Cirno gave her students a positive integer $x$. As an assignment, her students need to find the minimum positive integer $y$, which satisfies the following two conditions:
$$x\ {and}\ y > 0$$ $$x\ {xor}\ y > 0$$
Where ${and}$ is the bitwise AND operation , and ${xor}$ is the bitwise XOR operation .
Among the students was Mystia, who was truly baffled by all these new operators. Please help her!
-----Input-----
The first line of input contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of input test cases.
For each test case, the only line of input contains one integer $x$ ($1 \leq x \leq 2^{30}$).
-----Output-----
For each test case, print a single integer — the minimum number of $y$.
-----Examples-----
Input
7
1
2
5
9
16
114514
1000000
Output
3
3
1
1
17
2
64
-----Note-----
Test case 1:
$1\; {and}\; 3=1>0$, $1\; {xor}\; 3=2>0$.
Test case 2:
$2\; {and}\; 3=2>0$, $2\; {xor}\; 3=1>0$.
|
{"inputs": ["1\n1073741824\n", "7\n1\n2\n5\n9\n16\n114514\n1000000\n"], "outputs": ["1073741825\n", "3\n3\n1\n1\n17\n2\n64\n"]}
| 369
| 82
|
coding
|
Solve the programming task below in a Python markdown code block.
To protect people from evil,
a long and tall wall was constructed a few years ago.
But just a wall is not safe, there should also be soldiers on it,
always keeping vigil.
The wall is very long and connects the left and the right towers.
There are exactly N spots (numbered 1 to N) on the wall for soldiers.
The Kth spot is K miles far from the left tower and (N+1-K) miles from the right tower.
Given a permutation of spots P of {1, 2, ..., N}, soldiers occupy the N spots in that order.
The P[i]th spot is occupied before the P[i+1]th spot.
When a soldier occupies a spot, he is connected to his nearest soldier already placed to his left.
If there is no soldier to his left, he is connected to the left tower. The same is the case with right side.
A connection between two spots requires a wire of length equal to the distance between the two.
The realm has already purchased a wire of M miles long from Nokia,
possibly the wire will be cut into smaller length wires.
As we can observe, the total length of the used wire depends on the permutation of the spots P. Help the realm in minimizing the length of the unused wire. If there is not enough wire, output -1.
-----Input-----
First line contains an integer T (number of test cases, 1 ≤ T ≤ 10 ). Each of the next T lines contains two integers N M, as explained in the problem statement (1 ≤ N ≤ 30 , 1 ≤ M ≤ 1000).
-----Output-----
For each test case, output the minimum length of the unused wire, or -1 if the the wire is not sufficient.
-----Example-----
Input:
4
3 8
3 9
2 4
5 25
Output:
0
0
-1
5
Explanation:
In the 1st case, for example, the permutation P = {2, 1, 3} will use the exact 8 miles wires in total.
In the 2nd case, for example, the permutation P = {1, 3, 2} will use the exact 9 miles wires in total.
To understand the first two cases, you can see the following figures:
In the 3rd case, the minimum length of wire required is 5, for any of the permutations {1,2} or {2,1}, so length 4 is not sufficient.
In the 4th case, for the permutation {1, 2, 3, 4, 5} we need the maximum length of the wire = 20. So minimum possible unused wire length = 25 - 20 = 5.
|
{"inputs": ["4\n3 8\n3 9\n2 4\n5 25"], "outputs": ["0\n0\n-1\n5"]}
| 603
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com).
It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots.
You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result.
Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at.
Input
The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols.
Output
Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages).
In the ASCII table the symbols go in this order: . @ ab...z
Examples
Input
vasyaatgmaildotcom
Output
vasya@gmail.com
Input
dotdotdotatdotdotat
Output
dot..@..at
Input
aatt
Output
a@t
|
{"inputs": ["aatt\n", "atatat\n", "doatdt\n", "taatta\n", "eoatdt\n", "taatua\n", "epatdt\n", "tbatua\n"], "outputs": ["a@t\n", "at@at\n", "do@dt\n", "ta@ta\n", "eo@dt\n", "ta@ua\n", "ep@dt\n", "tb@ua\n"]}
| 398
| 99
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A digit string is good if the digits (0-indexed) at even indices are even and the digits at odd indices are prime (2, 3, 5, or 7).
For example, "2582" is good because the digits (2 and 8) at even positions are even and the digits (5 and 2) at odd positions are prime. However, "3245" is not good because 3 is at an even index but is not even.
Given an integer n, return the total number of good digit strings of length n. Since the answer may be large, return it modulo 109 + 7.
A digit string is a string consisting of digits 0 through 9 that may contain leading zeros.
Please complete the following python code precisely:
```python
class Solution:
def countGoodNumbers(self, n: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 1) == 5\n assert candidate(n = 4) == 400\n assert candidate(n = 50) == 564908303\n\n\ncheck(Solution().countGoodNumbers)"}
| 206
| 67
|
coding
|
Solve the programming task below in a Python markdown code block.
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally...
Lee has $n$ integers $a_1, a_2, \ldots, a_n$ in his backpack and he has $k$ friends. Lee would like to distribute all integers in his backpack between his friends, such that the $i$-th friend will get exactly $w_i$ integers and each integer will be handed over to exactly one friend.
Let's define the happiness of a friend as the sum of the maximum and the minimum integer he'll get.
Lee would like to make his friends as happy as possible, in other words, he'd like to maximize the sum of friends' happiness. Now he asks you to calculate the maximum sum of friends' happiness.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
Next $3t$ lines contain test cases — one per three lines.
The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$; $1 \le k \le n$) — the number of integers Lee has and the number of Lee's friends.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$) — the integers Lee has.
The third line contains $k$ integers $w_1, w_2, \ldots, w_k$ ($1 \le w_i \le n$; $w_1 + w_2 + \ldots + w_k = n$) — the number of integers Lee wants to give to each friend.
It's guaranteed that the sum of $n$ over test cases is less than or equal to $2 \cdot 10^5$.
-----Output-----
For each test case, print a single integer — the maximum sum of happiness Lee can achieve.
-----Example-----
Input
3
4 2
1 13 7 17
1 3
6 2
10 10 10 10 11 11
3 3
4 4
1000000000 1000000000 1000000000 1000000000
1 1 1 1
Output
48
42
8000000000
-----Note-----
In the first test case, Lee should give the greatest integer to the first friend (his happiness will be $17 + 17$) and remaining integers to the second friend (his happiness will be $13 + 1$).
In the second test case, Lee should give $\{10, 10, 11\}$ to the first friend and to the second friend, so the total happiness will be equal to $(11 + 10) + (11 + 10)$
In the third test case, Lee has four friends and four integers, it doesn't matter how he distributes the integers between his friends.
|
{"inputs": ["3\n4 2\n1 13 7 0\n1 3\n6 2\n10 0 10 10 6 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 13 7 1\n1 3\n6 2\n7 10 11 0 11 19\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n0 18 12 1\n1 3\n6 2\n2 11 9 2 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 13 10 1\n1 3\n6 2\n7 10 3 0 11 19\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 2 17 1\n1 3\n6 2\n9 2 10 10 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 13 7 0\n1 3\n6 2\n10 0 10 10 8 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 13 2 1\n1 3\n6 2\n7 10 11 8 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n0 18 12 1\n1 3\n6 2\n2 11 9 10 5 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n"], "outputs": ["33\n31\n8000000000\n", "34\n40\n8000000000\n", "48\n33\n8000000000\n", "37\n37\n8000000000\n", "37\n34\n8000000000\n", "33\n31\n8000000000\n", "29\n39\n8000000000\n", "48\n33\n8000000000\n"]}
| 747
| 966
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n represented as a string, return the smallest good base of n.
We call k >= 2 a good base of n, if all digits of n base k are 1's.
Please complete the following python code precisely:
```python
class Solution:
def smallestGoodBase(self, n: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(n = \"13\") == \"3\"\n assert candidate(n = \"4681\") == \"8\"\n assert candidate(n = \"1000000000000000000\") == \"999999999999999999\"\n\n\ncheck(Solution().smallestGoodBase)"}
| 89
| 99
|
coding
|
Solve the programming task below in a Python markdown code block.
Simon has a prime number x and an array of non-negative integers a_1, a_2, ..., a_{n}.
Simon loves fractions very much. Today he wrote out number $\frac{1}{x^{a} 1} + \frac{1}{x^{a_{2}}} + \ldots + \frac{1}{x^{a_{n}}}$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: $\frac{s}{t}$, where number t equals x^{a}_1 + a_2 + ... + a_{n}. Now Simon wants to reduce the resulting fraction.
Help him, find the greatest common divisor of numbers s and t. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (10^9 + 7).
-----Input-----
The first line contains two positive integers n and x (1 ≤ n ≤ 10^5, 2 ≤ x ≤ 10^9) — the size of the array and the prime number.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_1 ≤ a_2 ≤ ... ≤ a_{n} ≤ 10^9).
-----Output-----
Print a single number — the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
2 2
2 2
Output
8
Input
3 3
1 2 3
Output
27
Input
2 2
29 29
Output
73741817
Input
4 5
0 0 0 0
Output
1
-----Note-----
In the first sample $\frac{1}{4} + \frac{1}{4} = \frac{4 + 4}{16} = \frac{8}{16}$. Thus, the answer to the problem is 8.
In the second sample, $\frac{1}{3} + \frac{1}{9} + \frac{1}{27} = \frac{243 + 81 + 27}{729} = \frac{351}{729}$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.
In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.
In the fourth sample $\frac{1}{1} + \frac{1}{1} + \frac{1}{1} + \frac{1}{1} = \frac{4}{1}$. Thus, the answer to the problem is 1.
|
{"inputs": ["2 2\n2 2\n", "2 2\n2 4\n", "2 4\n2 4\n", "2 5\n2 7\n", "2 4\n2 7\n", "2 2\n2 2\n", "2 2\n5 29\n", "2 2\n7 29\n"], "outputs": ["8\n", "4\n", "16\n", "25\n", "16\n", "8\n", "32\n", "128\n"]}
| 659
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|, where |s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".
String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| > |y| and x1 = y1, x2 = y2, ..., x|y| = y|y|, or there exists such number r (r < |x|, r < |y|) that x1 = y1, x2 = y2, ..., xr = yr and xr + 1 > yr + 1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".
String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s| - 1... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
Input
The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.
Output
Print the lexicographically largest palindromic subsequence of string s.
Examples
Input
radar
Output
rr
Input
bowwowwow
Output
wwwww
Input
codeforces
Output
s
Input
mississipp
Output
ssss
Note
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
|
{"inputs": ["b\n", "a\n", "z\n", "y\n", "c\n", "x\n", "d\n", "aa\n"], "outputs": ["b\n", "a\n", "z\n", "y\n", "c\n", "x\n", "d\n", "aa\n"]}
| 556
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
The Chef's latest idea is that some cooks might work better in pairs. So, he is going to experiment by pairing up some of his employees to see if the quality of the food prepared in his kitchen increases. However, only some pairs of employees are compatible. Two employees that are not compatible cannot be paired together.
For each pair of compatible employees, the Chef has assigned a number estimating how well the overall quality of the food might increase. Of course, each employee can only be paired with at most one other employee. Furthermore, it is ok to not pair some employees. So, your goal is to help the Chef decide how to pair the employees to maximize the total amount that the overall quality of food increases.
------ Input ------
The first line contains a single integer denoting the number of test cases (at most 50). Each test case begins with two integers n and m. Here, n is the number of employees (between 2 and 1000) and m is the number of compatible pairs of employees (between 1 and 10,000). The employees are numbered from 0 to n-1. The next m lines describe a pair of compatible employees, one per line. The i'th such line contains two distinct integers u_{i},v_{i} between 0 and n-1. Strangely enough, the Chef estimates that picking the i'th pair u_{i},v_{i} will increase the quality of food prepared in his kitchen by exactly 2^{i}.
No pair of employees will be given more than once in the input. That is, for distinct indices i and j, we do not have both u_{i} = u_{j} and v_{i} = v_{j}, nor do we have both u_{i} = v_{j} and v_{i} = u_{j}.
------ Output ------
The output for each test case consists of the indices of the pairs of employees that are used in a maximum total value pairing (the indices are between 0 and m-1). These indices should be given in increasing order with a single space between consecutive numbers. If there is more than one possible output, then any will do.
----- Sample Input 1 ------
2
4 5
0 1
1 2
2 3
1 3
3 0
4 3
0 1
2 3
2 1
----- Sample Output 1 ------
1 4
2
|
{"inputs": ["2\n4 5\n0 1\n1 2\n2 3\n1 3\n3 0\n4 3\n0 1\n2 3\n2 1", "2\n4 5\n0 1\n1 2\n2 3\n1 3\n3 0\n4 3\n0 1\n2 3\n2 0", "2\n4 5\n0 1\n1 2\n0 3\n1 3\n1 0\n4 3\n0 1\n2 3\n2 0", "2\n4 5\n0 1\n1 2\n1 3\n1 3\n2 0\n4 3\n0 1\n2 3\n2 0", "2\n4 5\n0 1\n1 2\n1 3\n0 3\n3 0\n4 1\n0 1\n2 3\n2 1", "2\n8 5\n0 1\n1 2\n1 3\n0 3\n4 0\n4 3\n0 1\n2 3\n2 1", "2\n6 5\n0 1\n1 2\n2 3\n1 3\n3 0\n8 3\n0 2\n2 3\n3 1", "2\n4 5\n1 1\n1 2\n1 3\n1 3\n2 0\n4 3\n0 1\n0 3\n2 1"], "outputs": ["1 4\n2", "1 4\n2\n", "4\n2\n", "3 4\n2\n", "1 4\n0\n", "2 4\n2\n", "1 4\n0 2\n", "3 4\n1 2\n"]}
| 533
| 415
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer sequence $a_1, a_2, \dots, a_n$.
Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$.
The median of a sequence is the value of an element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used.
For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence.
Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$.
-----Input-----
The first line contains integers $n$ and $m$ ($1 \le n,m \le 2\cdot10^5$) — the length of the given sequence and the required value of the median.
The second line contains an integer sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2\cdot10^5$).
-----Output-----
Print the required number.
-----Examples-----
Input
5 4
1 4 5 60 4
Output
8
Input
3 1
1 1 1
Output
6
Input
15 2
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
Output
97
-----Note-----
In the first example, the suitable pairs of indices are: $(1, 3)$, $(1, 4)$, $(1, 5)$, $(2, 2)$, $(2, 3)$, $(2, 5)$, $(4, 5)$ and $(5, 5)$.
|
{"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n2\n", "1 1\n1\n", "1 1\n0\n", "2 1\n1 2\n", "2 1\n2 1\n", "2 2\n1 2\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "2\n", "2\n", "1\n"]}
| 550
| 108
|
coding
|
Solve the programming task below in a Python markdown code block.
Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.
There are also n cards, each card has 2 attributes: length li and cost ci. If she pays ci dollars then she can apply i-th card. After applying i-th card she becomes able to make jumps of length li, i. e. from cell x to cell (x - li) or cell (x + li).
She wants to be able to jump to any cell on the tape (possibly, visiting some intermediate cells). For achieving this goal, she wants to buy some cards, paying as little money as possible.
If this is possible, calculate the minimal cost.
Input
The first line contains an integer n (1 ≤ n ≤ 300), number of cards.
The second line contains n numbers li (1 ≤ li ≤ 109), the jump lengths of cards.
The third line contains n numbers ci (1 ≤ ci ≤ 105), the costs of cards.
Output
If it is impossible to buy some cards and become able to jump to any cell, output -1. Otherwise output the minimal cost of buying such set of cards.
Examples
Input
3
100 99 9900
1 1 1
Output
2
Input
5
10 20 30 40 50
1 1 1 1 1
Output
-1
Input
7
15015 10010 6006 4290 2730 2310 1
1 1 1 1 1 1 10
Output
6
Input
8
4264 4921 6321 6984 2316 8432 6120 1026
4264 4921 6321 6984 2316 8432 6120 1026
Output
7237
Note
In first sample test, buying one card is not enough: for example, if you buy a card with length 100, you can't jump to any cell whose index is not a multiple of 100. The best way is to buy first and second card, that will make you be able to jump to any cell.
In the second sample test, even if you buy all cards, you can't jump to any cell whose index is not a multiple of 10, so you should output -1.
|
{"inputs": ["1\n2\n2\n", "1\n1\n1\n", "1\n4\n2\n", "1\n2\n1\n", "1\n3\n1\n", "1\n5\n1\n", "1\n5\n2\n", "1\n5\n0\n"], "outputs": ["-1", "1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 595
| 102
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is guaranteed to be unique.
You are also given k queries in a 2D array queries where queries[j] = [preferredj, minSizej]. The answer to the jth query is the room number id of a room such that:
The room has a size of at least minSizej, and
abs(id - preferredj) is minimized, where abs(x) is the absolute value of x.
If there is a tie in the absolute difference, then use the room with the smallest such id. If there is no such room, the answer is -1.
Return an array answer of length k where answer[j] contains the answer to the jth query.
Please complete the following python code precisely:
```python
class Solution:
def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]) == [3,-1,3]\n assert candidate(rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]) == [2,1,3]\n\n\ncheck(Solution().closestRoom)"}
| 246
| 113
|
coding
|
Solve the programming task below in a Python markdown code block.
On every CodeChef user's profile page, the list of problems that they have set, tested, and written editorials for, is listed at the bottom.
Given the number of problems in each of these 3 categories as X, Y, and Z respectively (where all three integers are distinct), find if the user has been most active as a Setter, Tester, or Editorialist.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of three space-separated integers X, Y, and Z - the number of problems they have set, tested, and written editorials for.
------ Output Format ------
For each test case, output in a new line:
- Setter, if the user has been most active as a setter.
- Tester, if the user has been most active as a tester.
- Editorialist, if the user has been most active as an editorialist.
Note that the output is case-insensitive. Thus, the strings SETTER, setter, seTTer, and Setter are all considered the same.
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ X, Y, Z ≤ 100$, where $X, Y,$ and $Z$ are distinct.
----- Sample Input 1 ------
4
5 3 2
1 2 4
2 5 1
9 4 5
----- Sample Output 1 ------
Setter
Editorialist
Tester
Setter
----- explanation 1 ------
Test case $1$: The number of problems that the user has set is greater than the number of problems tested or written editorials for. Thus, the user is most active as setter.
Test case $2$: The number of problems that the user has written editorials for, is greater than the number of problems set or tested. Thus, the user is most active as editorialist.
Test case $3$: The number of problems that the user has tested is greater than the number of problems set or written editorials for. Thus, the user is most active as tester.
Test case $4$: The number of problems that the user has set is greater than the number of problems tested or written editorials for. Thus, the user is most active as setter.
|
{"inputs": ["4\n5 3 2\n1 2 4\n2 5 1\n9 4 5\n"], "outputs": ["Setter\nEditorialist\nTester\nSetter"]}
| 495
| 45
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [ui, vi] denotes an edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.
Return the length of the shortest cycle in the graph. If no cycle exists, return -1.
A cycle is a path that starts and ends at the same node, and each edge in the path is used only once.
Please complete the following python code precisely:
```python
class Solution:
def findShortestCycle(self, n: int, edges: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]) == 3\n assert candidate(n = 4, edges = [[0,1],[0,2]]) == -1\n\n\ncheck(Solution().findShortestCycle)"}
| 182
| 87
|
coding
|
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game with $n$ piles of stones. It is guaranteed that $n$ is an even number. The $i$-th pile has $a_i$ stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exactly $\frac{n}{2}$ nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than $\frac{n}{2}$ nonempty piles).
Given the starting configuration, determine who will win the game.
-----Input-----
The first line contains one integer $n$ ($2 \leq n \leq 50$) — the number of piles. It is guaranteed that $n$ is an even number.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 50$) — the number of stones in the piles.
-----Output-----
Print a single string "Alice" if Alice wins; otherwise, print "Bob" (without double quotes).
-----Examples-----
Input
2
8 8
Output
Bob
Input
4
3 1 4 1
Output
Alice
-----Note-----
In the first example, each player can only remove stones from one pile ($\frac{2}{2}=1$). Alice loses, since Bob can copy whatever Alice does on the other pile, so Alice will run out of moves first.
In the second example, Alice can remove $2$ stones from the first pile and $3$ stones from the third pile on her first move to guarantee a win.
|
{"inputs": ["2\n8 8\n", "2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n2 0\n", "2\n8 8\n", "2\n15 8\n", "4\n3 1 4 1\n"], "outputs": ["Bob\n", "Bob\n", "Bob\n", "Alice\n", "Alice\n", "Bob\n", "Alice\n", "Alice\n"]}
| 391
| 107
|
coding
|
Solve the programming task below in a Python markdown code block.
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n.
You need to permute the array elements so that value $\sum_{i = 1}^{n - k}|A [ i ] - A [ i + k ]|$ became minimal possible. In particular, it is allowed not to change order of elements at all.
-----Input-----
The first line contains two integers n, k (2 ≤ n ≤ 3·10^5, 1 ≤ k ≤ min(5000, n - 1)).
The second line contains n integers A[1], A[2], ..., A[n] ( - 10^9 ≤ A[i] ≤ 10^9), separate by spaces — elements of the array A.
-----Output-----
Print the minimum possible value of the sum described in the statement.
-----Examples-----
Input
3 2
1 2 4
Output
1
Input
5 2
3 -5 3 -5 3
Output
0
Input
6 3
4 3 4 3 2 5
Output
3
-----Note-----
In the first test one of the optimal permutations is 1 4 2.
In the second test the initial order is optimal.
In the third test one of the optimal permutations is 2 3 4 4 3 5.
|
{"inputs": ["3 2\n1 2 4\n", "2 1\n1 100\n", "2 1\n1 100\n", "3 2\n1 2 4\n", "4 3\n1 2 4 8\n", "4 3\n1 2 4 8\n", "4 1\n1 2 4 8\n", "5 3\n1 2 6 0 2\n"], "outputs": ["1\n", "99\n", "99\n", "1\n", "1\n", "1\n", "7\n", "1\n"]}
| 317
| 146
|
coding
|
Solve the programming task below in a Python markdown code block.
Complete the solution so that it returns true if it contains any duplicate argument values. Any number of arguments may be passed into the function.
The array values passed in will only be strings or numbers. The only valid return values are `true` and `false`.
Examples:
```
solution(1, 2, 3) --> false
solution(1, 2, 3, 2) --> true
solution('1', '2', '3', '2') --> true
```
Also feel free to reuse/extend the following starter code:
```python
def solution(*args):
```
|
{"functional": "_inputs = [[1, 2, 3, 1, 2], [1, 1], [1, 0], ['a', 'b'], ['a', 'b', 'a'], [1, 2, 42, 3, 4, 5, 42], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'c'], ['a', 'b', 'c', 'd', 'e', 'f', 'f', 'b']]\n_outputs = [[True], [True], [False], [False], [True], [True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(solution(*i), o[0])"}
| 143
| 287
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.