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
|
Solve the programming task below in a Python markdown code block.
You are given an array a consisting of n integers. We denote the subarray a[l..r] as the array [a_l, a_{l + 1}, ..., a_r] (1 ≤ l ≤ r ≤ n).
A subarray is considered good if every integer that occurs in this subarray occurs there exactly thrice. For example, the array [1, 2, 2, 2, 1, 1, 2, 2, 2] has three good subarrays:
* a[1..6] = [1, 2, 2, 2, 1, 1];
* a[2..4] = [2, 2, 2];
* a[7..9] = [2, 2, 2].
Calculate the number of good subarrays of the given array a.
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n).
Output
Print one integer — the number of good subarrays of the array a.
Examples
Input
9
1 2 2 2 1 1 2 2 2
Output
3
Input
10
1 2 3 4 1 2 3 1 2 3
Output
0
Input
12
1 2 3 4 3 4 2 1 3 4 2 1
Output
1
|
{"inputs": ["9\n2 2 2 2 1 1 2 2 2\n", "9\n4 2 2 2 1 1 2 2 2\n", "9\n4 2 2 1 1 1 2 2 2\n", "9\n1 2 2 2 1 1 2 2 2\n", "10\n1 2 3 4 1 2 5 1 2 3\n", "10\n1 2 3 4 1 2 7 1 2 3\n", "10\n1 2 5 4 1 2 7 1 2 3\n", "10\n2 2 5 4 1 2 7 1 2 3\n"], "outputs": ["3\n", "2\n", "5\n", "3", "0\n", "0\n", "0\n", "0\n"]}
| 355
| 225
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and a goal, determine the minmum number of moves to get to the goal.
Example.
$grid=[\text{'...'},\text{'.X.'},...\text{'}]$
$start X=0$
$start Y=0$
$goal X=1$
$goal Y=2$
The grid is shown below:
...
.X.
...
The starting position $(start X,start Y)=(0,0)$ so start in the top left corner. The goal is $(goal X,goal Y)=(1,2)$. The path is $(0,0)\to(0,2)\to(1,2)$. It takes $2$ moves to reach the goal.
Function Description
Complete the minimumMoves function in the editor.
minimumMoves has the following parameter(s):
string grid[n]: an array of strings that represent the rows of the grid
int startX: starting X coordinate
int startY: starting Y coordinate
int goalX: ending X coordinate
int goalY: ending Y coordinate
Returns
int: the minimum moves to reach the goal
Input Format
The first line contains an integer $n$, the size of the array grid.
Each of the next $n$ lines contains a string of length $n$.
The last line contains four space-separated integers, $startX,$start $\mathrm{Y}$ goalX, goalY
Constraints
$1\leq n\leq100$
$0\leq startX,$startY,goalX,goalY<n
Sample Input
STDIN FUNCTION
----- --------
3 grid[] size n = 3
.X. grid = ['.X.','.X.', '...']
.X.
...
0 0 0 2 startX = 0, startY = 0, goalX = 0, goalY = 2
Sample Output
3
Explanation
Here is a path that one could follow in order to reach the destination in $3$ steps:
$(0,0)\to(2,0)\to(2,2)\to(0,2)$.
|
{"inputs": ["3\n.X.\n.X.\n...\n0 0 0 2\n"], "outputs": ["3\n"]}
| 504
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
In this kata you will have to modify a sentence so it meets the following rules:
convert every word backwards that is:
longer than 6 characters
OR
has 2 or more 'T' or 't' in it
convert every word uppercase that is:
exactly 2 characters long
OR
before a comma
convert every word to a "0" that is:
exactly one character long
NOTES:
Punctuation must not be touched. if a word is 6 characters long, and a "." is behind it,
it counts as 6 characters so it must not be flipped, but if a word is 7 characters long,
it must be flipped but the "." must stay at the end of the word.
-----------------------------------------------------------------------------------------
Only the first transformation applies to a given word, for example 'companions,'
will be 'snoinapmoc,' and not 'SNOINAPMOC,'.
-----------------------------------------------------------------------------------------
As for special characters like apostrophes or dashes, they count as normal characters,
so e.g 'sand-colored' must be transformed to 'deroloc-dnas'.
Also feel free to reuse/extend the following starter code:
```python
def spin_solve(sentence):
```
|
{"functional": "_inputs = [['Welcome.'], ['If a man does not keep pace with his companions, perhaps it is because he hears a different drummer.'], ['As Grainier drove along in the wagon behind a wide, slow, sand-colored mare, clusters of orange butterflies exploded off the purple blackish piles of bear sign and winked and winked and fluttered magically like leaves without trees.'], [\"You should check the mileage on your car since you've been driving it so much, and because it's starting to make weird noises.\"], ['Wherever you go, you can always find beauty.'], ['Action is indeed, commmmmmmming.'], ['Mother, please, help, me.'], ['Jojojo, jojo, tata man kata.']]\n_outputs = [['emocleW.'], ['IF 0 man does not keep pace with his snoinapmoc, spahrep IT IS esuaceb HE hears 0 tnereffid remmurd.'], ['AS reiniarG drove along IN the wagon behind 0 WIDE, SLOW, deroloc-dnas MARE, sretsulc OF orange seilfrettub dedolpxe off the purple hsikcalb piles OF bear sign and winked and winked and derettulf yllacigam like leaves tuohtiw trees.'], [\"You should check the egaelim ON your car since you've been gnivird IT SO MUCH, and esuaceb it's gnitrats TO make weird noises.\"], ['reverehW you GO, you can always find beauty.'], ['Action IS INDEED, gnimmmmmmmmoc.'], ['MOTHER, PLEASE, HELP, ME.'], ['JOJOJO, JOJO, atat man kata.']]\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(spin_solve(*i), o[0])"}
| 275
| 519
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.
Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.
Please complete the following python code precisely:
```python
class Solution:
def findLHS(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,2,5,2,3,7]) == 5\n assert candidate(nums = [1,2,3,4]) == 2\n assert candidate(nums = [1,1,1,1]) == 0\n\n\ncheck(Solution().findLHS)"}
| 97
| 82
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.
In one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word from dictionary.
Return a list of all words from queries, that match with some word from dictionary after a maximum of two edits. Return the words in the same order they appear in queries.
Please complete the following python code precisely:
```python
class Solution:
def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]:
```
|
{"functional": "def check(candidate):\n assert candidate(queries = [\"word\",\"note\",\"ants\",\"wood\"], dictionary = [\"wood\",\"joke\",\"moat\"]) == [\"word\",\"note\",\"wood\"]\n assert candidate(queries = [\"yes\"], dictionary = [\"not\"]) == []\n\n\ncheck(Solution().twoEditWords)"}
| 159
| 83
|
coding
|
Solve the programming task below in a Python markdown code block.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
-----Input-----
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
-----Output-----
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
-----Examples-----
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
-----Note-----
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
|
{"inputs": ["xx..\n.oo.\nx...\noox.\n", "x.ox\nox..\nx.o.\noo.x\n", "x..x\n..oo\no...\nx.xo\n", "o.x.\no...\n.x..\nooxx\n", ".xox\no.x.\nx.o.\n..o.\n", "o.oo\n.x.o\nx.x.\n.x..\n", ".xx.\n.xoo\n.oox\n....\n", "xxox\no.x.\nx.oo\nxo.o\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
| 493
| 158
|
coding
|
Solve the programming task below in a Python markdown code block.
For a given polygon g, computes the area of the polygon.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon.
Note that the polygon is not necessarily convex.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point will occur more than once.
* Two sides can intersect only at a common endpoint.
Input
The input consists of coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point.
Examples
Input
3
0 0
2 2
-1 1
Output
2.0
Input
4
0 0
1 1
1 2
0 2
Output
1.5
|
{"inputs": ["3\n1 0\n2 4\n-1 1", "3\n2 0\n2 2\n-1 1", "3\n3 0\n2 2\n-1 0", "3\n0 0\n2 2\n-1 1", "3\n3 0\n2 2\n-2 -1", "3\n3 0\n2 2\n-2 -2", "3\n3 0\n1 2\n-2 -2", "3\n3 0\n1 2\n-2 -4"], "outputs": ["4.5\n", "3.0\n", "4.0\n", "2.0", "5.5\n", "6.0\n", "7.0\n", "9.0\n"]}
| 298
| 181
|
coding
|
Solve the programming task below in a Python markdown code block.
You are playing another computer game, and now you have to slay $n$ monsters. These monsters are standing in a circle, numbered clockwise from $1$ to $n$. Initially, the $i$-th monster has $a_i$ health.
You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targeted monster by $1$ (deals $1$ damage to it). Furthermore, when the health of some monster $i$ becomes $0$ or less than $0$, it dies and explodes, dealing $b_i$ damage to the next monster (monster $i + 1$, if $i < n$, or monster $1$, if $i = n$). If the next monster is already dead, then nothing happens. If the explosion kills the next monster, it explodes too, damaging the monster after it and possibly triggering another explosion, and so on.
You have to calculate the minimum number of bullets you have to fire to kill all $n$ monsters in the circle.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 150000$) — the number of test cases.
Then the test cases follow, each test case begins with a line containing one integer $n$ ($2 \le n \le 300000$) — the number of monsters. Then $n$ lines follow, each containing two integers $a_i$ and $b_i$ ($1 \le a_i, b_i \le 10^{12}$) — the parameters of the $i$-th monster in the circle.
It is guaranteed that the total number of monsters in all test cases does not exceed $300000$.
-----Output-----
For each test case, print one integer — the minimum number of bullets you have to fire to kill all of the monsters.
-----Examples-----
Input
1
3
7 15
2 14
5 3
Output
6
-----Note-----
None
|
{"inputs": ["1\n3\n7 4\n3 24\n5 3\n", "1\n3\n7 4\n2 24\n5 3\n", "1\n3\n7 14\n2 9\n6 3\n", "1\n3\n7 15\n2 14\n5 3\n", "1\n3\n7 15\n2 24\n5 3\n", "1\n3\n7 15\n2 22\n5 4\n", "1\n3\n7 15\n2 22\n5 3\n", "1\n3\n7 15\n2 22\n6 3\n"], "outputs": ["7\n", "6\n", "6\n", "6\n", "6\n", "5\n", "6\n", "6\n"]}
| 442
| 195
|
coding
|
Solve the programming task below in a Python markdown code block.
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
Input
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
Examples
Input
4
1 1 1 1
Output
12
Note
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
|
{"inputs": ["1\n1\n", "1\n2\n", "2\n1 1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 1\n", "2\n1 4\n", "2\n2 4\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "2\n", "0\n", "0\n", "0\n"]}
| 487
| 98
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the smallest prime palindrome greater than or equal to n.
An integer is prime if it has exactly two divisors: 1 and itself. Note that 1 is not a prime number.
For example, 2, 3, 5, 7, 11, and 13 are all primes.
An integer is a palindrome if it reads the same from left to right as it does from right to left.
For example, 101 and 12321 are palindromes.
The test cases are generated so that the answer always exists and is in the range [2, 2 * 108].
Please complete the following python code precisely:
```python
class Solution:
def primePalindrome(self, n: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 6) == 7\n assert candidate(n = 8) == 11\n assert candidate(n = 13) == 101\n\n\ncheck(Solution().primePalindrome)"}
| 187
| 59
|
coding
|
Solve the programming task below in a Python markdown code block.
Aklank is fond of numbers which are divisible by either P1 or P2. He termed those numbers as Bakku numbers. Recently his best friend gave him a range of numbers. Now he is wondering what is the probability of finding Bakku numbers from that range of numbers.
Input
First line of input contains two integers P1 and P2 (2 ≤ P1 ≤ 10000, 2 ≤ P2 ≤ 10000) — both P1 and P2 are prime numbers.
Second line of the input contains an integer T (1 ≤ T ≤ 100000) — the number of test cases.
Each of the next T lines contains two integers - L and R (1 ≤ L ≤ R ≤ 100,00,00,000) - the starting number and ending number of each range from where he will search for Bakku numbers (inclusive).
Output
Print T lines for each test case.
In each line print answer with up to 6 digits after decimal point.
SAMPLE INPUT
3 5
2
1 10
20 34
SAMPLE OUTPUT
0.500000
0.466667
Explanation
First Case : Numbers divisible by 3 or 5 are 3, 5, 6, 9, 10
Second Case : Numbers divisible by 3 or 5 are 20, 21, 24, 25, 27, 30, 33
|
{"inputs": ["7607 9769\n10\n1 1\n1 100000\n10000 100000\n999 1000\n7607 7607\n1 7605\n9770 10000\n15005 100000\n9 12345\n100000 100000"], "outputs": ["0.000000\n0.000230\n0.000233\n0.000000\n1.000000\n0.000000\n0.000000\n0.000247\n0.000162\n0.000000"]}
| 350
| 209
|
coding
|
Solve the programming task below in a Python markdown code block.
Abhiram needs to search for an antidote. He comes to know that clue for finding the antidote is carefully hidden by KrishnaMurthy in the form of a puzzle.
The puzzle consists of a string S and a keywordK. Abhiram needs to find the string of position of anagrams R of the keyword in the string which is the clue.
The antidote is found in the box numbered R. Help him find his clue R.
Anagram: A word or phrase that is made by arranging the letters of another word or phrase in a different order. Eg: 'elvis' and 'lives' are both anagrams of each other.
Note: Consider, Tac and act are not anagrams(case sensitive).
-----Input:-----
The first line contains a string S of length land the second line contains a keyword K.
-----Output:-----
Output contains a line"The antidote is found in R." Where R= string of positions of anagrams.(the position of the first word in the string is 1).
-----Constraints:-----
1<=l<=500
1<=k<=50
-----Example:-----
Input:
cat is the act of tac
cat
Output:
The antidote is found in 46.
|
{"inputs": ["cat is the act of tac\ncat"], "outputs": ["The antidote is found in 46."]}
| 269
| 29
|
coding
|
Solve the programming task below in a Python markdown code block.
JJ loves playing with medians. He has an array A of length N (N is odd). He wants to partition the array A into two non-empty subsets P and Q such that the value of |median(P) - median(Q)| is as small as possible. (Note that each A_{i} must belong to either subset P or subset Q).
Help him find this minimum value of |median(P) - median(Q)|.
As a reminder, the median of a subset X of size N is the element which occupies the \lfloor\frac{N+1}{2}\rfloor^{th} position after we sort the elements in non-decreasing order. For example, median([3, 1, 4]) = 3, median([3, 1, 4, 2]) = 2. (Here \lfloor x \rfloor denotes the largest integer which does not exceed x).
------ Input Format ------
- The first line contains T - the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N - the size of the array A.
- The second line of each test case contains N space separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A.
------ Output Format ------
Output the minimum value of |median(P) - median(Q)|.
------ Constraints ------
$1 ≤ T ≤ 100$
$3 ≤ N ≤ 999$
$1 ≤ A_{i} ≤ 10^{9}$
$N$ is odd.
----- Sample Input 1 ------
3
5
2 7 4 8 2
3
1 2 3
5
1 1 1 1 1
----- Sample Output 1 ------
2
1
0
----- explanation 1 ------
- Test case $1$: We can divide the array into following two subsets: $P = [2, 8], Q = [7, 4, 2]$, which has $|median(P) - median(Q)| = |2 - 4| = 2$. It can be proven that the answer can not be improved further.
- Test case $2$: We can divide the array into following two subsets: $P = [1, 3], Q = [2]$, which has $|median(P) - median(Q)| = |1 - 2| = 1$. It can be proven that the answer can not be improved further.
- Test case $3$: Observe that, for any partition of the array into any two non-empty subsets, the median of both the subsets will be $1$. Therefore the answer is $|1 - 1| = 0$.
|
{"inputs": ["3\n5\n2 7 4 8 2\n3\n1 2 3\n5\n1 1 1 1 1\n"], "outputs": ["2\n1\n0"]}
| 591
| 49
|
coding
|
Solve the programming task below in a Python markdown code block.
After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all. Now Fedor is going to change the essay using the synonym dictionary of the English language.
Fedor does not want to change the meaning of the essay. So the only change he would do: change a word from essay to one of its synonyms, basing on a replacement rule from the dictionary. Fedor may perform this operation any number of times.
As a result, Fedor wants to get an essay which contains as little letters «R» (the case doesn't matter) as possible. If there are multiple essays with minimum number of «R»s he wants to get the one with minimum length (length of essay is the sum of the lengths of all the words in it). Help Fedor get the required essay.
Please note that in this problem the case of letters doesn't matter. For example, if the synonym dictionary says that word cat can be replaced with word DOG, then it is allowed to replace the word Cat with the word doG.
-----Input-----
The first line contains a single integer m (1 ≤ m ≤ 10^5) — the number of words in the initial essay. The second line contains words of the essay. The words are separated by a single space. It is guaranteed that the total length of the words won't exceed 10^5 characters.
The next line contains a single integer n (0 ≤ n ≤ 10^5) — the number of pairs of words in synonym dictionary. The i-th of the next n lines contains two space-separated non-empty words x_{i} and y_{i}. They mean that word x_{i} can be replaced with word y_{i} (but not vise versa). It is guaranteed that the total length of all pairs of synonyms doesn't exceed 5·10^5 characters.
All the words at input can only consist of uppercase and lowercase letters of the English alphabet.
-----Output-----
Print two integers — the minimum number of letters «R» in an optimal essay and the minimum length of an optimal essay.
-----Examples-----
Input
3
AbRb r Zz
4
xR abRb
aA xr
zz Z
xr y
Output
2 6
Input
2
RuruRu fedya
1
ruruRU fedor
Output
1 10
|
{"inputs": ["1\nR\n0\n", "1\nr\n0\n", "1\nR\n0\n", "1\nr\n0\n", "1\nQ\n0\n", "1\ns\n0\n", "1\nffff\n1\nffff r\n", "1\nffff\n1\nffff r\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "0 1\n", "0 1\n", "0 4\n", "0 4\n"]}
| 565
| 124
|
coding
|
Solve the programming task below in a Python markdown code block.
The Professor is facing the North. Tokyo is in trouble, and she is facing the South. Professor being her guardian angel wants to help her.
So, The Professor will follow some instructions, given as a string S of length N, and will turn either left or right according to these instructions. He can save Tokyo only if after following a [substring] of instructions he will face in the same direction that Tokyo is facing.
Will the Professor be able to save Tokyo?
------ Input Format ------
- The first line contains an integer T denoting the number of test cases. The T test cases then follow.
- The first line of each test case contains N.
- The second line contains a string that contains only 'L' and 'R', where 'L' represents left and 'R' represents right.
------ Output Format ------
For each test case, output "YES" if the Professor will be able to save Tokyo and "NO" otherwise.
Output is case insensitive, which means that "yes", "Yes", "YEs", "no", "nO" - all such strings will be acceptable.
------ Constraints ------
$1 ≤ T ≤ 100$
$2 ≤ N ≤ 10^{5}$
- The string $S$ consists of uppercase characters 'L' and 'R' only.
- The sum of $N$ over all test cases does not exceed $10^{6}$.
----- Sample Input 1 ------
3
12
LRLRRRLRLLLL
2
LR
4
LRRL
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case $1$: Professor can select the substring "RLRLLL", after following the instructions given by it, Professor will face South.
Test case $2$: No matter which substring Professor selects, the final direction of Professor will never be that in which Tokyo is facing.
|
{"inputs": ["3\n12\nLRLRRRLRLLLL\n2\nLR\n4\nLRRL\n"], "outputs": ["YES\nNO\nYES\n"]}
| 407
| 37
|
coding
|
Solve the programming task below in a Python markdown code block.
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.
He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
-----Constraints-----
- 1 \leq K \leq N \leq 200000
- 1 \leq A_i \leq N
- All input values are integers.
-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N
-----Output-----
Print the minimum number of balls that Takahashi needs to rewrite the integers on them.
-----Sample Input-----
5 2
1 1 2 2 5
-----Sample Output-----
1
For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.
|
{"inputs": ["4 4\n1 1 2 2\n", "5 2\n1 1 2 2 5\n", "10 3\n5 1 3 2 4 1 1 2 3 4\n"], "outputs": ["0\n", "1\n", "3\n"]}
| 263
| 75
|
coding
|
Solve the programming task below in a Python markdown code block.
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.
You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.
-----Input-----
The only line contains an integer n (3 ≤ n ≤ 101; n is odd).
-----Output-----
Output a crystal of size n.
-----Examples-----
Input
3
Output
*D*
DDD
*D*
Input
5
Output
**D**
*DDD*
DDDDD
*DDD*
**D**
Input
7
Output
***D***
**DDD**
*DDDDD*
DDDDDDD
*DDDDD*
**DDD**
***D***
|
{"inputs": ["3\n", "5\n", "7\n", "9\n", "5\n", "7\n", "3\n", "11\n"], "outputs": ["*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n", "****D****\n***DDD***\n**DDDDD**\n*DDDDDDD*\nDDDDDDDDD\n*DDDDDDD*\n**DDDDD**\n***DDD***\n****D****\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n", "*D*\nDDD\n*D*\n", "*****D*****\n****DDD****\n***DDDDD***\n**DDDDDDD**\n*DDDDDDDDD*\nDDDDDDDDDDD\n*DDDDDDDDD*\n**DDDDDDD**\n***DDDDD***\n****DDD****\n*****D*****\n"]}
| 213
| 293
|
coding
|
Solve the programming task below in a Python markdown code block.
Mary loves binary strings.
Given a binary string S, she defines the *beauty* of the string as the [bitwise XOR] of decimal representations of all substrings of S.
Find the *beauty* of string S. Since the answer can be huge, print it modulo 998244353.
For example, the decimal representation of binary string 1101 is 1\cdot 2^{3} + 1\cdot 2^{2} + 0\cdot 2^{1} + 1\cdot 2^{0} = 8 + 4 + 0+1 = 13. Kindly refer sample explanation for more such examples.
A string A is a substring of a string B if A can be obtained from B by deleting several (possibly zero) characters from the beginning and several (possibly zero) characters from the end.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of test cases follow.
- First line of each test case contains one integer N - the length of the binary string.
- Second line of each test case contains the binary string S.
------ Output Format ------
For each test case, output in a single line, beauty of the string modulo 998244353.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
----- Sample Input 1 ------
3
2
10
3
101
4
1111
----- Sample Output 1 ------
3
6
12
----- explanation 1 ------
Test Case $1$: All substrings of the string $S = 10$ are $[1, 0, 10]$. The decimal representation of these substrings is denoted by the array $[1, 0, 2]$. Bitwise XOR of all these values is $1 \oplus 0 \oplus 2 = 3$.
Test Case $2$: All substrings of the string $S = 101$ are $[1, 0, 1, 10, 01, 101]$. The decimal representation of these substrings is denoted by the array $[1, 0, 1, 2, 1, 5]$. Bitwise XOR of all these values is: $1 \oplus 0 \oplus 1 \oplus 2 \oplus 1 \oplus 5 = 6$.
Test Case $3$: All substrings of the string $S = 1111$ are $[1, 1, 1, 1, 11, 11, 11, 111, 111, 1111]$. The decimal representation of these substrings is denoted by the array $[1, 1, 1, 1, 3, 3, 3, 7, 7, 15]$. Bitwise XOR of all these values is: $1 \oplus 1 \oplus 1 \oplus 1 \oplus 3 \oplus 3 \oplus 3 \oplus 7 \oplus 7 \oplus 15 = 12$.
|
{"inputs": ["3\n2\n10\n3\n101\n4\n1111"], "outputs": ["3\n6\n12\n"]}
| 765
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i.
For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows:
- Let S be the set of the vertices numbered L through R. f(L, R) represents the number of connected components in the subgraph formed only from the vertex set S and the edges whose endpoints both belong to S.
Compute \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R).
-----Constraints-----
- 1 \leq N \leq 2 \times 10^5
- 1 \leq u_i, v_i \leq N
- The given graph is a tree.
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N
u_1 v_1
u_2 v_2
:
u_{N-1} v_{N-1}
-----Output-----
Print \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R).
-----Sample Input-----
3
1 3
2 3
-----Sample Output-----
7
We have six possible pairs (L, R) as follows:
- For L = 1, R = 1, S = \{1\} and we have 1 connected component.
- For L = 1, R = 2, S = \{1, 2\} and we have 2 connected components.
- For L = 1, R = 3, S = \{1, 2, 3\} and we have 1 connected component, since S contains both endpoints of each of the edges 1, 2.
- For L = 2, R = 2, S = \{2\} and we have 1 connected component.
- For L = 2, R = 3, S = \{2, 3\} and we have 1 connected component, since S contains both endpoints of Edge 2.
- For L = 3, R = 3, S = \{3\} and we have 1 connected component.
The sum of these is 7.
|
{"inputs": ["2\n0 2", "2\n1 1", "2\n1 2", "2\n1 2\n", "2\n-1 1", "2\n-1 2", "2\n-3 0", "2\n-1 0"], "outputs": ["4\n", "2\n", "3", "3\n", "6\n", "5\n", "13\n", "7\n"]}
| 534
| 99
|
coding
|
Solve the programming task below in a Python markdown code block.
A binary string A is called *good* if it can be sorted (in non-decreasing order) using the following operation:
Select an i (1 ≤ i ≤ |A| - 1) and swap A_{i} with A_{i + 1}.
This operation can be performed on any i at most once.
For example, A = 10110 is *good* because we can perform the following operations: 10110 \xrightarrow{i = 1} 01110 \xrightarrow{i = 4} 01101 \xrightarrow{i = 3} 01011 \xrightarrow{i = 2} 00111. On the other hand, A = 11110000 is not *good*.
JJ has a binary string S of length N and wants to find the number of *good* substrings of S out of all its \frac{N \cdot (N + 1)}{2} non-empty substrings. Can you help him?
Note: A string X is a substring of a string Y if X can be obtained from Y by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N — the length of the binary string S.
- The second line of each test case contains a binary string S of length N containing 0s and 1s only.
------ Output Format ------
For each test case, output the number of good substrings of S.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
2
4
0011
6
111000
----- Sample Output 1 ------
10
17
----- explanation 1 ------
Test Case 1: $S$ is already sorted. So all its substrings are good.
Test Case 2: Some of the substrings of $S$ which are good are: $000$, $1110$, $100$, $111$.
|
{"inputs": ["2\n4\n0011\n6\n111000\n"], "outputs": ["10\n17\n"]}
| 540
| 34
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n couples sitting in 2n seats arranged in a row and want to hold hands.
The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat. The couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), and so on with the last couple being (2n - 2, 2n - 1).
Return the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats.
Please complete the following python code precisely:
```python
class Solution:
def minSwapsCouples(self, row: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(row = [0,2,1,3]) == 1\n assert candidate(row = [3,2,0,1]) == 0\n\n\ncheck(Solution().minSwapsCouples)"}
| 180
| 58
|
coding
|
Solve the programming task below in a Python markdown code block.
In this Kata, we will calculate the **minumum positive number that is not a possible sum** from a list of positive integers.
```
solve([1,2,8,7]) = 4 => we can get 1, 2, 3 (from 1+2), but we cannot get 4. 4 is the minimum number not possible from the list.
solve([4,1,2,3,12]) = 11. We can get 1, 2, 3, 4, 4+1=5, 4+2=6,4+3=7,4+3+1=8,4+3+2=9,4+3+2+1=10. But not 11.
solve([2,3,2,3,4,2,12,3]) = 1. We cannot get 1.
```
More examples in test cases.
Good luck!
Also feel free to reuse/extend the following starter code:
```python
def solve(arr):
```
|
{"functional": "_inputs = [[[1, 2, 8, 7]], [[2, 12, 3, 1]], [[4, 2, 8, 3, 1]], [[4, 2, 7, 3, 1]], [[4, 2, 12, 3]]]\n_outputs = [[4], [7], [19], [18], [1]]\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(solve(*i), o[0])"}
| 244
| 233
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
|
{"inputs": ["1 2\n", "2 1\n", "4 6\n", "6 7\n", "4 9\n", "7 3\n", "2 7\n", "7 4\n"], "outputs": ["Equal\n", "Equal\n", "Equal\n", "Equal\n", "Dasha\n", "Masha\n", "Dasha\n", "Masha\n"]}
| 615
| 90
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
**_Given_** *a number* , **_Return_** **_The Maximum number _** *could be formed from the digits of the number given* .
___
# Notes
* **_Only Natural numbers_** *passed to the function , numbers Contain digits [0:9] inclusive*
* **_Digit Duplications_** *could occur* , So also **_consider it when forming the Largest_**
____
# Input >> Output Examples:
```
maxNumber (213) ==> return (321)
```
## **_Explanation_**:
As `321` is **_The Maximum number _** *could be formed from the digits of the number **_213_*** .
___
```
maxNumber (7389) ==> return (9873)
```
## **_Explanation_**:
As `9873` is **_The Maximum number _** *could be formed from the digits of the number **_7389_*** .
___
```
maxNumber (63729) ==> return (97632)
```
## **_Explanation_**:
As `97632` is **_The Maximum number _** *could be formed from the digits of the number **_63729_*** .
___
```
maxNumber (566797) ==> return (977665)
```
## **_Explanation_**:
As `977665` is **_The Maximum number _** *could be formed from the digits of the number **_566797_*** .
**_Note_** : **_Digit duplications are considered when forming the largest_** .
___
```
maxNumber (17693284) ==> return (98764321)
```
## **_Explanation_**:
As `98764321` is **_The Maximum number _** *could be formed from the digits of the number **_17693284_*** .
___
___
___
# [Playing with Numbers Series](https://www.codewars.com/collections/playing-with-numbers)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
# [For More Enjoyable Katas](http://www.codewars.com/users/MrZizoScream/authored)
___
## ALL translations are welcomed
## Enjoy Learning !!
# Zizou
Also feel free to reuse/extend the following starter code:
```python
def max_number(n):
```
|
{"functional": "_inputs = [[213], [7389], [63792], [566797], [1000000]]\n_outputs = [[321], [9873], [97632], [977665], [1000000]]\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_number(*i), o[0])"}
| 606
| 218
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Nim is a well-known combinatorial game, based on removing stones from piles. In this problem, we'll deal with a similar game, which we'll call Dual Nim. The rules of this game are as follows:
Initially, there are N piles of stones, numbered 1 through N. The i-th pile contains a_{i} stones.
The players take alternate turns. If the bitwise XOR of all piles equals 0 before a player's turn, then that player wins the game.
In his/her turn, a player must choose one of the remaining piles and remove it. (Note that if there are no piles, that player already won.)
Decide which player wins, given that both play optimally.
------ Input ------
The first line of the input contains an integer T - the number of test cases.
The first line of each test case contains N - the number of piles.
The following line contains N space-separated integers a_{1},..,a_{N} - the sizes of piles.
------ Output ------
For each test case, output one string on a separate line - "First" (without quotes) if the first player wins, "Second" (without quotes) if the second player wins.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 500$
$1 ≤ a_{i} ≤ 500$
----- Sample Input 1 ------
3
4
1 2 4 8
3
2 3 3
5
3 3 3 3 3
----- Sample Output 1 ------
First
Second
Second
|
{"inputs": ["3\n4\n1 2 4 8\n3\n2 3 3\n5\n3 3 3 3 3", "3\n4\n1 2 4 8\n3\n2 3 3\n5\n1 3 3 3 3", "3\n4\n1 2 4 2\n3\n3 3 3\n5\n1 3 2 3 3", "3\n4\n1 2 8 7\n3\n2 1 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 8\n3\n3 3 3\n5\n1 3 3 3 3", "3\n4\n1 2 4 8\n3\n3 3 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 2\n3\n3 3 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 7\n3\n2 3 3\n5\n1 3 3 3 3"], "outputs": ["First\nSecond\nSecond", "First\nSecond\nSecond\n", "First\nSecond\nFirst\n", "First\nFirst\nSecond\n", "First\nSecond\nSecond\n", "First\nSecond\nSecond\n", "First\nSecond\nSecond\n", "First\nSecond\nSecond\n"]}
| 363
| 333
|
coding
|
Solve the programming task below in a Python markdown code block.
Some scientists are working on protein recombination, and during their research, they have found a remarkable fact: there are 4 proteins in the protein ring that mutate after every second according to a fixed pattern. For simplicity, proteins are called $A,B,C,D$ (you know, protein names can be very complicated). A protein mutates into another one depending on itself and the protein right after it. Scientists determined that the mutation table goes like this:
A B C D
_ _ _ _
A| A B C D
B| B A D C
C| C D A B
D| D C B A
Here rows denote the protein at current position, while columns denote the protein at the next position. And the corresponding value in the table denotes the new protein that will emerge. So for example, if protein i is A, and protein i + 1 is B, protein i will change to B. All mutations take place simultaneously. The protein ring is seen as a circular list, so last protein of the list mutates depending on the first protein.
Using this data, they have written a small simulation software to get mutations second by second. The problem is that the protein rings can be very long (up to 1 million proteins in a single ring) and they want to know the state of the ring after upto $\mathbf{10^{9}}$ seconds. Thus their software takes too long to report the results. They ask you for your help.
Input Format
Input contains 2 lines.
First line has 2 integers $N$ and $\mbox{K}$, $N$ being the length of the protein ring and $\mbox{K}$ the desired number of seconds.
Second line contains a string of length $N$ containing uppercase letters $\mbox{A}$,$\mbox{B}$, $\mbox{C}$ or $\mbox{D}$ only, describing the ring.
Constraints
$1\leq N\leq10^6$
$1\leq K\leq10^9$
Output Format
Output a single line with a string of length $N$, describing the state of the ring after $\mbox{K}$ seconds.
Sample Input 0
5 15
AAAAD
Sample Output 0
DDDDA
Explanation 0
The complete sequence of mutations is:
AAADD
AADAD
ADDDD
DAAAD
DAADA
DADDD
DDAAA
ADAAD
DDADD
ADDAA
DADAA
DDDAD
AADDA
ADADA
DDDDA
|
{"inputs": ["5 15\nAAAAD\n"], "outputs": ["DDDDA\n"]}
| 583
| 22
|
coding
|
Solve the programming task below in a Python markdown code block.
You have to create a function which receives 3 arguments: 2 numbers, and the result of an unknown operation performed on them (also a number).
Based on those 3 values you have to return a string, that describes which operation was used to get the given result.
The possible return strings are:
`"addition"`,
`"subtraction"`,
`"multiplication"`,
`"division"`.
## Example:
```
calcType(1, 2, 3) --> 1 ? 2 = 3 --> "addition"
```
## Notes
* In case of division you should expect that the result of the operation is obtained by using `/` operator on the input values - no manual data type conversion or rounding should be performed.
* Cases with just one possible answers are generated.
* Only valid arguments will be passed to the function.
Also feel free to reuse/extend the following starter code:
```python
def calc_type(a, b, res):
```
|
{"functional": "_inputs = [[1, 2, 3], [10, 5, 5], [10, 4, 40], [9, 5, 1.8]]\n_outputs = [['addition'], ['subtraction'], ['multiplication'], ['division']]\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(calc_type(*i), o[0])"}
| 218
| 204
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two sorted arrays of distinct integers nums1 and nums2.
A valid path is defined as follows:
Choose array nums1 or nums2 to traverse (from index-0).
Traverse the current array from left to right.
If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).
The score is defined as the sum of unique values in a valid path.
Return the maximum score you can obtain of all possible valid paths. Since the answer may be too large, return it modulo 109 + 7.
Please complete the following python code precisely:
```python
class Solution:
def maxSum(self, nums1: List[int], nums2: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]) == 30\n assert candidate(nums1 = [1,3,5,7,9], nums2 = [3,5,100]) == 109\n assert candidate(nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]) == 40\n\n\ncheck(Solution().maxSum)"}
| 189
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.
So, the goal of this kata is to wite a function that encodes a single word string to pig latin.
The rules themselves are rather easy:
1) The word starts with a vowel(a,e,i,o,u) -> return the original string plus "way".
2) The word starts with a consonant -> move consonants from the beginning of the word to the end of the word until the first vowel, then return it plus "ay".
3) The result must be lowercase, regardless of the case of the input. If the input string has any non-alpha characters, the function must return None, null, Nothing (depending on the language).
4) The function must also handle simple random strings and not just English words.
5) The input string has no vowels -> return the original string plus "ay".
For example, the word "spaghetti" becomes "aghettispay" because the first two letters ("sp") are consonants, so they are moved to the end of the string and "ay" is appended.
Also feel free to reuse/extend the following starter code:
```python
def pig_latin(s):
```
|
{"functional": "_inputs = [['Hello'], ['CCCC'], ['tes3t5'], ['ay'], [''], ['YA'], ['123'], ['ya1'], ['yaYAya'], ['YayayA']]\n_outputs = [['ellohay'], ['ccccay'], [None], ['ayway'], [None], ['ayay'], [None], [None], ['ayayayay'], ['ayayayay']]\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(pig_latin(*i), o[0])"}
| 272
| 230
|
coding
|
Solve the programming task below in a Python markdown code block.
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times. Find the minimum number of operations required. It can be proved that, Under the constraints of this problem, this objective is always achievable.
Constraints
* 2 \leq K \leq N \leq 100000
* A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.
Input
Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N
Output
Print the minimum number of operations required.
Examples
Input
4 3
2 3 1 4
Output
2
Input
3 3
1 2 3
Output
1
Input
8 3
7 3 1 8 4 6 2 5
Output
4
|
{"inputs": ["3 3\n2 2 3", "3 3\n2 2 2", "6 3\n2 2 2", "6 3\n0 2 2", "6 3\n0 3 2", "3 3\n1 2 4", "3 3\n2 2 0", "3 3\n2 2 1"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "1\n", "1\n", "1\n"]}
| 287
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ — the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
|
{"inputs": ["1\n2\n1 6\n", "1\n2\n1 3\n", "1\n2\n1 4\n", "1\n2\n1 1\n", "1\n2\n1 8\n", "1\n2\n2 1\n", "1\n2\n2 2\n", "1\n2\n1 9\n"], "outputs": ["T\n", "T\n", "T\n", "HL\n", "T\n", "T\n", "HL\n", "T\n"]}
| 393
| 118
|
coding
|
Solve the programming task below in a Python markdown code block.
One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution...
-----Input-----
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive.
-----Output-----
Reproduce the output of the reference solution, including the bug.
-----Examples-----
Input
8-7+6-5+4-3+2-1-0
Output
4
Input
2+2
Output
-46
Input
112-37
Output
375
|
{"inputs": ["2+2\n", "1+2\n", "2+2\n", "45+5\n", "45+5\n", "5+55\n", "5+54\n", "55+4\n"], "outputs": ["-46\n", "-47\n", "-46\n", "0\n", "0\n", "-440\n", "-441\n", "9\n"]}
| 184
| 99
|
coding
|
Solve the programming task below in a Python markdown code block.
Your task is to ___find the next higher number (int) with same '1'- Bits___.
I.e. as much `1` bits as before and output next higher than input. Input is always an int in between 1 and 1<<30 (inclusive). No bad cases or special tricks...
### Some easy examples:
```
Input: 129 => Output: 130 (10000001 => 10000010)
Input: 127 => Output: 191 (01111111 => 10111111)
Input: 1 => Output: 2 (01 => 10)
Input: 323423 => Output: 323439 (1001110111101011111 => 1001110111101101111)
```
First some static tests, later on many random tests too;-)!
### Hope you have fun! :-)
Also feel free to reuse/extend the following starter code:
```python
def next_higher(value):
```
|
{"functional": "_inputs = [[128], [1], [1022], [127], [1253343]]\n_outputs = [[256], [2], [1279], [191], [1253359]]\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(next_higher(*i), o[0])"}
| 276
| 205
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
John is new to spreadsheets. He is well aware of rows and columns, but he is not comfortable with spreadsheets numbering system.
```
Spreadsheet Row Column
A1 R1C1
D5 R5C4
AA48 R48C27
BK12 R12C63```
Since John has a lot of work to do both in row-column and spreadsheet systems, he needs a program that converts cell numbers from one system to another.
# Example
For `s = "A1"`, the result should be `"R1C1"`.
For `s = "R48C27"`, the result should be `"AA48"`.
- Input/Output
- `[input]` string `s`
The position (in spreadsheet or row-column numbering system).
`Spreadsheet : A1 to CRXO65535`
`Row-Column: R1C1 to R65535C65535`
- `[output]` a string
The position (in the opposite format; if input was in spreadsheet system, the output should be int row-column system, and vise versa).
Also feel free to reuse/extend the following starter code:
```python
def spreadsheet(s):
```
|
{"functional": "_inputs = [['A1'], ['R1C1'], ['R5C4'], ['AA48'], ['BK12'], ['R12C63'], ['R85C26'], ['R31C78'], ['BZ31']]\n_outputs = [['R1C1'], ['A1'], ['D5'], ['R48C27'], ['R12C63'], ['BK12'], ['Z85'], ['BZ31'], ['R31C78']]\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(spreadsheet(*i), o[0])"}
| 295
| 259
|
coding
|
Solve the programming task below in a Python markdown code block.
A gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\mbox{A}$, $\mbox{C}$, $\textbf{T}$, and $\mbox{G}$.
It is considered to be steady if each of the four letters occurs exactly $\frac{n}{4}$ times. For example, $\textbf{GACT}$ and $\textbf{AAGTGCCT}$ are both steady genes.
Bear Limak is a famous biotechnology scientist who specializes in modifying bear DNA to make it steady. Right now, he is examining a gene represented as a string $\textit{gene}$. It is not necessarily steady. Fortunately, Limak can choose one (maybe empty) substring of $\textit{gene}$ and replace it with any string of the same length.
Modifying a large substring of bear genes can be dangerous.
Given a string $\textit{gene}$, can you help Limak find the length of the smallest possible substring that he can replace to make $\textit{gene}$ a steady gene?
Note: A substring of a string $\boldsymbol{\mathrm{~S~}}$ is a subsequence made up of zero or more contiguous characters of $\boldsymbol{\mathrm{~S~}}$.
As an example, consider $\textit{gene}=\textit{ACTGAAAG}$. The substring $\boldsymbol{AA}$ just before or after $\mbox{G}$ can be replaced with $\textit{CT}$ or $\boldsymbol{TC}$. One selection would create $\textbf{ACTGACTG}$.
Function Description
Complete the $\textit{steadyGene}$ function in the editor below. It should return an integer that represents the length of the smallest substring to replace.
steadyGene has the following parameter:
gene: a string
Input Format
The first line contains an interger $n$ divisible by $4$, that denotes the length of a string $\textit{gene}$.
The second line contains a string $\textit{gene}$ of length $n$.
Constraints
$4\leq n\leq500000$
$n$ is divisible by $4$
$gene[i]\in[CGAT]$
Subtask
$4\leq n\leq2000$ in tests worth $30\%$ points.
Output Format
Print the length of the minimum length substring that can be replaced to make $\textit{gene}$ stable.
Sample Input
8
GAAATAAA
Sample Output
5
Explanation
One optimal solution is to replace $\textbf{AAATA}$ with $\textbf{TTCCG}$ resulting in $\textbf{GTTCCGAA}$.
The replaced substring has length $5$.
|
{"inputs": ["8 \nGAAATAAA\n"], "outputs": ["5\n"]}
| 615
| 21
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
Given n, calculate F(n).
Please complete the following python code precisely:
```python
class Solution:
def fib(self, n: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 2) == 1\n assert candidate(n = 3) == 2\n assert candidate(n = 4) == 3\n\n\ncheck(Solution().fib)"}
| 135
| 54
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
You had an array of integer numbers. You also had a beautiful operations called "Copy-Paste" which allowed you to copy any contiguous subsequence of your array and paste it in any position of your array. For example, if you have array [1, 2, 3, 4, 5] and copy it's subsequence from the second to the fourth element and paste it after the third one, then you will get [1, 2, 3, 2, 3, 4, 4, 5] array. You remember that you have done a finite(probably zero) number of such operations over your initial array and got an array A as a result. Unfortunately you don't remember the initial array itself, so you would like to know what could it be. You are interested by the smallest such array. So the task is to find the minimal size(length) of the array that A can be obtained from by using "Copy-Paste" operations.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of elements in obtained array A. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N} denoting the array.
------ Output ------
For each test case, output a single line containing the answer.
------ Constraints ------
$1 ≤ T ≤ 20$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 10^{5}$
----- Sample Input 1 ------
2
5
1 1 1 1 1
5
1 2 3 1 2
----- Sample Output 1 ------
1
3
----- explanation 1 ------
In the first case we could have only array [1] in the beginning and then obtain [1, 1], then [1, 1, 1, 1] and finally [1, 1, 1, 1, 1]. In the second one we could obtain A from [1, 2, 3] by copying it's first two elements to the end.
|
{"inputs": ["2\n5\n1 1 1 1 1\n5\n1 2 3 1 2", "2\n5\n1 1 1 1 1\n5\n1 2 6 1 2", "2\n5\n1 0 1 1 1\n5\n1 3 3 1 2", "2\n5\n1 0 1 2 1\n5\n1 3 3 1 2", "2\n5\n1 1 1 1 1\n5\n1 2 6 0 2", "2\n5\n1 0 1 1 1\n5\n0 3 3 1 2", "2\n5\n1 0 1 2 1\n5\n1 3 3 1 3", "2\n5\n1 1 1 1 1\n5\n1 2 1 1 2"], "outputs": ["1\n3", "1\n3\n", "2\n3\n", "3\n3\n", "1\n4\n", "2\n4\n", "3\n2\n", "1\n2\n"]}
| 502
| 269
|
coding
|
Solve the programming task below in a Python markdown code block.
# Introduction
There is a war and nobody knows - the alphabet war!
There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began.
# Task
Write a function that accepts `fight` string consists of only small letters and return who wins the fight. When the left side wins return `Left side wins!`, when the right side wins return `Right side wins!`, in other case return `Let's fight again!`.
The left side letters and their power:
```
w - 4
p - 3
b - 2
s - 1
```
The right side letters and their power:
```
m - 4
q - 3
d - 2
z - 1
```
The other letters don't have power and are only victims.
# Example
# Alphabet war Collection
Alphavet war
Alphabet war - airstrike - letters massacre
Alphabet wars - reinforces massacre
Alphabet wars - nuclear strike
Alphabet war - Wo lo loooooo priests join the war
Also feel free to reuse/extend the following starter code:
```python
def alphabet_war(fight):
```
|
{"functional": "_inputs = [['z'], ['zdqmwpbs'], ['wq'], ['zzzzs'], ['wwwwww']]\n_outputs = [['Right side wins!'], [\"Let's fight again!\"], ['Left side wins!'], ['Right side wins!'], ['Left side wins!']]\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(alphabet_war(*i), o[0])"}
| 264
| 205
|
coding
|
Solve the programming task below in a Python markdown code block.
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
{"inputs": ["1 1\n1\n", "1 4\n1\n", "1 1\n0\n", "1 6\n1\n", "1 2\n1\n", "2 1\n1 3\n", "2 8\n1 2\n", "2 6\n1 2\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "0", "0", "0\n"]}
| 564
| 104
|
coding
|
Solve the programming task below in a Python markdown code block.
Mr. Road Runner bought a piece of land in the middle of a desert for a nominal amount. It turns out that the piece of land is now worth millions of dollars as it has an oil reserve under it. Mr. Road Runner contacts the ACME corp to set up the oil wells on his land. Setting up oil wells is a costly affair and the charges of setting up oil wells are as follows.
The rectangular plot bought by Mr. Road Runner is divided into r * c blocks. Only some blocks are suitable for setting up the oil well and these blocks have been marked. ACME charges nothing for building the first oil well. For every subsequent oil well built, the cost would be the maximum ACME distance between the new oil well and the existing oil wells.
If (x,y) is the position of the block where a new oil well is setup and (x1, y1) is the position of the block of an existing oil well, the ACME distance is given by
max(|x-x1|, |y-y1|)
the maximum ACME distance is the maximum among all the ACME distance between existing oil wells and new wells.
If the distance of any two adjacent blocks (horizontal or vertical) is considered 1 unit, what is the minimum cost (E) in units it takes to set up oil wells across all the marked blocks?
Input Format
The first line of the input contains two space separated integers r *c*.
r lines follow each containing c space separated integers.
1 indicates that the block is suitable for setting up an oil well, whereas 0 isn't.
r c
M11 M12 ... M1c
M21 M22 ... M2c
...
Mr1 Mr2 ... Mrc
Constraints
1 <= r, c <= 50
Output Format
Print the minimum value E as the answer.
Sample Input
3 4
1 0 0 0
1 0 0 0
0 0 1 0
Sample Output
3
Explanation
(1, 1) (2, 1) (3, 3) are the places where are to be setup.
There are 3! = 6 ways to do it.
(1, 1) (2, 1) (3, 3) ==> cost = 0 + 1 + 2 = 3
(1, 1) (3, 3) (2, 1) ==> cost = 0 + 2 + 2 = 4
(2, 1) (1, 1) (3, 3) ==> cost = 0 + 1 + 2 = 3
(2, 1) (3, 3) (1, 1) ==> cost = 0 + 2 + 2 = 4
(3, 3) (1, 1) (2, 1) ==> cost = 0 + 2 + 2 = 4
(3, 3) (2, 1) (1, 1) ==> cost = 0 + 2 + 2 = 4
So E = 3
|
{"inputs": ["3 4\n1 0 0 0\n1 0 0 0\n0 0 1 0\n"], "outputs": ["3 \n"]}
| 688
| 42
|
coding
|
Solve the programming task below in a Python markdown code block.
We have a matrix of integers with m rows and n columns.
We want to calculate the total sum for the matrix:
As you can see, the name "alternating sum" of the title is due to the sign of the terms that changes from one term to its contiguous one and so on.
Let's see an example:
```
matrix = [[1, 2, 3], [-3, -2, 1], [3, - 1, 2]]
total_sum = (1 - 2 + 3) + [-(-3) + (-2) - 1] + [3 - (-1) + 2] = 2 + 0 + 6 = 8
```
You may be given matrixes with their dimensions between these values:```10 < m < 300``` and ```10 < n < 300```.
More example cases in the Example Test Cases.
Enjoy it!!
Also feel free to reuse/extend the following starter code:
```python
def score_matrix(matrix):
```
|
{"functional": "_inputs = [[[[1, 2, 3], [-3, -2, 1], [3, -1, 2]]]]\n_outputs = [[8]]\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(score_matrix(*i), o[0])"}
| 232
| 180
|
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 distinct substrings of s.
A substring of a string is obtained by deleting any number of characters (possibly zero) from the front of the string and any number (possibly zero) from the back of the string.
Please complete the following python code precisely:
```python
class Solution:
def countDistinct(self, s: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"aabbaba\") == 21\n assert candidate(s = \"abcdefg\") == 28\n\n\ncheck(Solution().countDistinct)"}
| 100
| 48
|
coding
|
Solve the programming task below in a Python markdown code block.
G: Tree
problem
Given a tree consisting of N vertices. Each vertex of the tree is numbered from 1 to N. Of the N-1 edges, the i \ (= 1, 2, ..., N-1) edge connects the vertex u_i and the vertex v_i.
Write a program to find the number of K non-empty subgraph sets of this tree, each of which is concatenated and no two different subgraphs share vertices. However, the answer can be very large, so answer the remainder divided by 998244353.
Note that if the set of K subgraphs is the same, the ones with different order of K subgraphs are also equated.
Input format
N K
u_1 v_1
::
u_ {N-1} v_ {N-1}
Constraint
* 2 \ leq N \ leq 10 ^ {5}
* 1 \ leq K \ leq min (N, 300)
* 1 \ leq u_i, v_i \ leq N
* u_i \ neq v_i
* For i \ neq j (u_i, v_i) \ neq (u_j, v_j)
* All inputs are given as integers.
* The graph given is guaranteed to be a tree.
Output format
Print the integer that represents the answer on one line. Note that it prints too much divided by 998244353.
Input example 1
3 2
1 2
13
Output example 1
Five
There are five ways:
* \\ {1 \\} and \\ {2 \\}
* \\ {1 \\} and \\ {3 \\}
* \\ {2 \\} and \\ {3 \\}
* \\ {1, 2 \\} and \\ {3 \\}
* \\ {1, 3 \\} and \\ {2 \\}
Input example 2
4 4
1 2
13
14
Output example 2
1
There is only one way (\\ {1 \\}, \\ {2 \\}, \\ {3 \\}, \\ {4 \\}).
Input example 3
7 4
1 7
twenty one
7 4
3 4
5 7
6 3
Output example 3
166
Example
Input
3 2
1 2
1 3
Output
5
|
{"inputs": ["3 4\n1 2\n1 3", "3 2\n1 2\n2 3", "3 2\n2 2\n1 3", "3 1\n1 2\n2 3", "3 1\n1 2\n3 3", "1 2\n1 2\n2 3", "3 4\n1 2\n2 3", "1 1\n1 2\n2 3"], "outputs": ["0\n", "5\n", "1\n", "6\n", "3\n", "0\n", "0\n", "1\n"]}
| 533
| 142
|
coding
|
Solve the programming task below in a Python markdown code block.
Given two matrices A and B. Both have N rows and M columns. In the matrix A, numbers from 1 to MN have been written in row major order. Row major order numbers cells from left to right, and top to bottom. That is,
1 2 3 ... M
A = M+1 M+2 M+3 ... 2M
2M+1 2M+2 2M+3 ... 3M
. . . ... .
. . . ... .
(N-1)M+1 (N-1)M+2 (N-1)M+3 ... NM
Similarly, in the matrix B, numbers from 1 to MN have been written in column major order. Column major order numbers cells from top to bottom and left to right.
You are to count number of pairs (i,j) such that A_{i,j}=B_{i,j}.
------ Input ------
The input consists of multiple test cases. The first line of input contains a single integer T, the number of test cases. T test cases follow. Each test case is described by one line containing two space separated integers, N and M
------ Output ------
Output T lines, i^{th} line containing answer of the i^{th} test case.
------ Constraints ------
1 ≤ T ≤ 10^{5} 1 ≤ N, M ≤ 10^{9}
----- Sample Input 1 ------
1
4 5
----- Sample Output 1 ------
2
----- explanation 1 ------
For the first case two matrices look as follows:
A=
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20B=
1 5 9 13 17
2 6 10 14 18
3 7 11 15 19
4 8 12 16 20
A1,1=B1,1A4,5=B4,5
|
{"inputs": ["1\n4 5", "1\n3 5", "1\n3 2", "1\n6 6", "1\n0 0", "1\n1 5", "1\n1 8", "1\n1 1"], "outputs": ["2", "3\n", "2\n", "6\n", "0\n", "5\n", "8\n", "1\n"]}
| 491
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ≠ b).
Find the number of pairs of cities x and y (x ≠ a, x ≠ b, y ≠ a, y ≠ b) such that if you go from x to y you will have to go through both fairs (the order of visits doesn't matter). Formally, you need to find the number of pairs of cities x,y such that any path from x to y goes through a and b (in any order).
Print the required number of pairs. The order of two cities in a pair does not matter, that is, the pairs (x,y) and (y,x) must be taken into account only once.
Input
The first line of the input contains an integer t (1 ≤ t ≤ 4⋅10^4) — the number of test cases in the input. Next, t test cases are specified.
The first line of each test case contains four integers n, m, a and b (4 ≤ n ≤ 2⋅10^5, n - 1 ≤ m ≤ 5⋅10^5, 1 ≤ a,b ≤ n, a ≠ b) — numbers of cities and roads in Berland and numbers of two cities where fairs are held, respectively.
The following m lines contain descriptions of roads between cities. Each of road description contains a pair of integers u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) — numbers of cities connected by the road.
Each road is bi-directional and connects two different cities. It is guaranteed that from any city you can pass to any other by roads. There can be more than one road between a pair of cities.
The sum of the values of n for all sets of input data in the test does not exceed 2⋅10^5. The sum of the values of m for all sets of input data in the test does not exceed 5⋅10^5.
Output
Print t integers — the answers to the given test cases in the order they are written in the input.
Example
Input
3
7 7 3 5
1 2
2 3
3 4
4 5
5 6
6 7
7 5
4 5 2 3
1 2
2 3
3 4
4 1
4 2
4 3 2 1
1 2
2 3
4 1
Output
4
0
1
|
{"inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 2\n4 1\n4 2\n4 3 3 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n3 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 4 5\n1 2\n4 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 1 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 3 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 1\n4 1\n4 2\n4 3 3 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 2\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n"], "outputs": ["4\n0\n1\n", "2\n0\n1\n", "0\n0\n1\n", "0\n0\n0\n", "6\n0\n1\n", "2\n0\n0\n", "4\n0\n0\n", "0\n0\n1\n"]}
| 611
| 774
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which the dolls come in pairs. One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!!
Help chef find which type of doll is missing..
------ Input ------
The first line contains an integer T, the number of test cases.
The first line of each test case contains an integer N, the number of dolls.
The next N lines are the types of dolls that are left.
------ Output ------
For each test case, display the type of doll that doesn't have a pair, in a new line.
------ Constraints ------
1≤T≤10
1≤N≤100000 (10^{5})
0≤type≤100000
----- Sample Input 1 ------
1
3
1
2
1
----- Sample Output 1 ------
2
----- explanation 1 ------
----- Sample Input 2 ------
1
5
1
1
2
2
3
----- Sample Output 2 ------
3
----- explanation 2 ------
|
{"inputs": ["1\n3\n1 \n2\n1", "1\n3\n2 \n2\n1", "1\n3\n0 \n2\n0", "1\n3\n1 \n4\n1", "1\n3\n1 \n8\n1", "1\n1\n7 \n6\n1", "1\n3\n2 \n1\n1", "1\n3\n0 \n1\n0"], "outputs": ["2", "1\n", "2\n", "4\n", "8\n", "7\n", "2\n", "1\n"]}
| 258
| 133
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0.
For every two consecutive 0's, merge all the nodes lying in between them into a single node whose value is the sum of all the merged nodes. The modified list should not contain any 0's.
Return the head of the modified linked list.
Please complete the following python code precisely:
```python
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:
```
|
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([0,3,1,0,4,5,2,0])), list_node([4,11]))\n assert is_same_list(candidate(head = list_node([0,1,0,3,0,2,2,0])), list_node([1,3,4]))\n\n\ncheck(Solution().mergeNodes)"}
| 180
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well.
Raja only participates in contests and does not upsolve, but he claims that he has been upsolving. Chef wants to test if he is really improving, so he asks Raja to solve the following problem.
The median of a sequence of numbers is computed in the following way:
sort the sequence in non-decreasing order
if the number of elements of this sequence is odd, the median is its middle element
if the number of elements is even, the median is the average (arithmetic mean) of its two middle elements
For example, the median of $[1, 3, 2]$ is $2$ and the median of $[2, 3, 3, 2]$ is $(2+3)/2 = 5/2$.
You are given a sequence $A_{1}, A_{2}, \dots, A_{N}$. Let's call a subsequence $A_{i_{1}}, A_{i_{2}}, \dots, A_{i_{k}}$ (for any $k > 0$, $1 ≤ i_{1} < i_{2} < \ldots < i_{k} ≤ N$) *good* if the median of this subsequence is an element of this subsequence. Find the number of good subsequences. Since this number may be large, compute it modulo $1000000007$ ($10^{9}+7$).
------ 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 a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer — the number of good subsequences modulo $10^{9}+7$.
------ Constraints ------
$1 ≤ T ≤ 30$
$1 ≤ N ≤ 1,000$
$1 ≤ A_{i} ≤ 2N$ for each valid $i$
------ Subtasks ------
Subtask #1 (5 points): $A$ is a permutation of integers $1$ through $N$
Subtask #2 (25 points): $1 ≤ N ≤ 100$
Subtask #3 (70 points): original constraints
----- Sample Input 1 ------
1
3
2 3 2
----- Sample Output 1 ------
5
----- explanation 1 ------
Example case 1: The good subsequences are $[2]$, $[3]$, $[2]$, $[2,2]$, $[2,3,2]$.
|
{"inputs": ["1\n3\n2 3 2"], "outputs": ["5"]}
| 637
| 20
|
coding
|
Solve the programming task below in a Python markdown code block.
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.
The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.
Input
The first line contains the only integer q (1 ≤ q ≤ 1013).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output
In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.
Examples
Input
6
Output
2
Input
30
Output
1
6
Input
1
Output
1
0
Note
Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.
|
{"inputs": ["9\n", "8\n", "4\n", "2\n", "5\n", "3\n", "7\n", "1\n"], "outputs": ["2", "1\n4", "2", "1\n0", "1\n0", "1\n0", "1\n0\n", "1\n0"]}
| 418
| 75
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya has recently got a job as a cashier at a local store. His day at work is $L$ minutes long. Vasya has already memorized $n$ regular customers, the $i$-th of which comes after $t_{i}$ minutes after the beginning of the day, and his service consumes $l_{i}$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.
Vasya is a bit lazy, so he likes taking smoke breaks for $a$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
-----Input-----
The first line contains three integers $n$, $L$ and $a$ ($0 \le n \le 10^{5}$, $1 \le L \le 10^{9}$, $1 \le a \le L$).
The $i$-th of the next $n$ lines contains two integers $t_{i}$ and $l_{i}$ ($0 \le t_{i} \le L - 1$, $1 \le l_{i} \le L$). It is guaranteed that $t_{i} + l_{i} \le t_{i + 1}$ and $t_{n} + l_{n} \le L$.
-----Output-----
Output one integer — the maximum number of breaks.
-----Examples-----
Input
2 11 3
0 1
1 1
Output
3
Input
0 5 2
Output
2
Input
1 3 2
1 2
Output
0
-----Note-----
In the first sample Vasya can take $3$ breaks starting after $2$, $5$ and $8$ minutes after the beginning of the day.
In the second sample Vasya can take $2$ breaks starting after $0$ and $2$ minutes after the beginning of the day.
In the third sample Vasya can't take any breaks.
|
{"inputs": ["0 5 2\n", "0 1 1\n", "0 1 1\n", "0 2 1\n", "0 0 2\n", "0 0 1\n", "0 0 4\n", "0 6 2\n"], "outputs": ["2", "1", "1\n", "2\n", "0\n", "0\n", "0\n", "3\n"]}
| 476
| 100
|
coding
|
Solve the programming task below in a Python markdown code block.
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
- For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
-----Constraints-----
- 3 \leq H \leq 10^9
- 3 \leq W \leq 10^9
- 0 \leq N \leq min(10^5,H×W)
- 1 \leq a_i \leq H (1 \leq i \leq N)
- 1 \leq b_i \leq W (1 \leq i \leq N)
- (a_i, b_i) \neq (a_j, b_j) (i \neq j)
-----Input-----
The input is given from Standard Input in the following format:
H W N
a_1 b_1
:
a_N b_N
-----Output-----
Print 10 lines.
The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.
-----Sample Input-----
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
-----Sample Output-----
0
0
0
2
4
0
0
0
0
0
There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.
|
{"inputs": ["1000000000 1000000001 0", "1000000000 1000001000 0", "1000000000 1001001000 0", "1000000000 1001001010 0", "1000100000 1001001010 0", "1000000000 1000000000 0", "1000000000 1000000000 0\n", "4 5 8\n1 1\n1 4\n0 5\n2 3\n3 1\n3 2\n3 4\n4 4"], "outputs": ["999999997000000002\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "1000000995999998004\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "1001000995997998004\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "1001001005997997984\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "1001101106098797984\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "999999996000000004\n0\n0\n0\n0\n0\n0\n0\n0\n0", "999999996000000004\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n3\n3\n0\n0\n0\n0\n0\n"]}
| 436
| 519
|
coding
|
Solve the programming task below in a Python markdown code block.
Joisino is about to compete in the final round of a certain programming competition.
In this contest, there are N problems, numbered 1 through N.
Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).
Also, there are M kinds of drinks offered to the contestants, numbered 1 through M.
If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.
It does not affect the time to solve the other problems.
A contestant is allowed to take exactly one of the drinks before the start of the contest.
For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.
Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.
Your task is to write a program to calculate it instead of her.
-----Constraints-----
- All input values are integers.
- 1≦N≦100
- 1≦T_i≦10^5
- 1≦M≦100
- 1≦P_i≦N
- 1≦X_i≦10^5
-----Input-----
The input is given from Standard Input in the following format:
N
T_1 T_2 ... T_N
M
P_1 X_1
P_2 X_2
:
P_M X_M
-----Output-----
For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.
-----Sample Input-----
3
2 1 4
2
1 1
2 3
-----Sample Output-----
6
9
If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.
If Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.
|
{"inputs": ["3\n2 1 4\n2\n1 1\n0 3", "3\n2 1 4\n2\n1 1\n0 6", "3\n2 1 4\n2\n1 0\n2 3", "3\n2 1 4\n2\n1 0\n0 3", "3\n1 1 4\n2\n1 1\n0 6", "3\n2 0 4\n2\n1 0\n0 3", "3\n1 1 0\n2\n1 1\n0 6", "3\n1 1 0\n2\n1 1\n0 8"], "outputs": ["6\n6\n", "6\n9\n", "5\n9\n", "5\n6\n", "6\n8\n", "4\n5\n", "2\n8\n", "2\n10\n"]}
| 477
| 207
|
coding
|
Solve the programming task below in a Python markdown code block.
Tim buy a string of length N from his friend which consist of ‘d’ and ‘u’ letters only
,but now Tim wants to sell the string at maximum cost.
The maximum cost of string is defined as the maximum length of a Substring (consecutive subsequence) consisting of equal letters.
Tim can change at most P characters of string (‘d’ to ‘u’ and ‘u’ to ‘d’) you have to find out the maximum cost of string?
-----Input:-----
- First line will contain $N$ and $P$ .
- Second line will contain the String $S$.
-----Output:-----
Maximum cost of string S.
-----Constraints-----
- $1 \leq N\leq 10^5$
- $0 \leq P \leq N$
-----Sample Input 1:-----
4 2
$duud$
-----Sample Output 1:-----
4
-----Sample Input 2 :-----
10 1
$dduddudddu$
-----Sample Output 2:-----
6
-----EXPLANATION:-----
In the first sample input , We can obtain both strings $dddd$ and $uuuu$ .
In the second sample, the optimal answer is obtained with the string $dddddudd$ or with the string $dduddddd$
|
{"inputs": ["4 2\nduud", "10 1\ndduddudddu"], "outputs": ["4", "6"]}
| 289
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given two positive integers $N$ and $K$, where $K \le N$. Find a sequence $A_1, A_2, \ldots, A_N$ such that:
- for each valid $i$, $A_i$ is either $i$ or $-i$
- there are exactly $K$ values of $i$ such that $1 \le i \le N$ and $A_1 + A_2 + \ldots + A_i > 0$
If there are multiple solutions, you may print any one of them. It can be proved that at least one solution always exists.
-----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 and only line of each test case contains two space-separated integers $N$ and $K$.
-----Output-----
For each test case, print a single line containing $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le K \le N \le 1,000$
-----Subtasks-----
Subtask #1 (10 points): $N \le 10$
Subtask #2 (90 points): original constraints
-----Example Input-----
1
3 3
-----Example Output-----
1 2 3
|
{"inputs": ["1\n3 3"], "outputs": ["1 2 3"]}
| 327
| 20
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings of the same length s and t. In one step you can choose any character of t and replace it with another character.
Return the minimum number of steps to make t an anagram of s.
An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.
Please complete the following python code precisely:
```python
class Solution:
def minSteps(self, s: str, t: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"bab\", t = \"aba\") == 1\n assert candidate(s = \"leetcode\", t = \"practice\") == 5\n assert candidate(s = \"anagram\", t = \"mangaar\") == 0\n\n\ncheck(Solution().minSteps)"}
| 120
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5.
|
{"inputs": ["3 4\n1 2 3"], "outputs": ["5"]}
| 350
| 20
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:$f(p) = \sum_{i = 1}^{n} \sum_{j = i}^{n} \operatorname{min}(p_{i}, p_{i + 1}, \ldots p_{j})$
Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).
-----Input-----
The single line of input contains two integers n and m (1 ≤ m ≤ cnt_{n}), where cnt_{n} is the number of permutations of length n with maximum possible value of f(p).
The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. In subproblem B1 (3 points), the constraint 1 ≤ n ≤ 8 will hold. In subproblem B2 (4 points), the constraint 1 ≤ n ≤ 50 will hold.
-----Output-----
Output n number forming the required permutation.
-----Examples-----
Input
2 2
Output
2 1
Input
3 2
Output
1 3 2
-----Note-----
In the first example, both permutations of numbers {1, 2} yield maximum possible f(p) which is equal to 4. Among them, (2, 1) comes second in lexicographical order.
|
{"inputs": ["2 2\n", "3 2\n", "1 1\n", "3 1\n", "3 3\n", "3 4\n", "4 1\n", "4 3\n"], "outputs": ["2 1 \n", "1 3 2 \n", "1 \n", "1 2 3 \n", "2 3 1 \n", "3 2 1 \n", "1 2 3 4 \n", "1 3 4 2 \n"]}
| 334
| 124
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ATM. Otherwise, the student withdraws $|a_i|$ rubles.
In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore.
More formally, the students that are served are forming a contiguous subsequence.
Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone.
In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue).
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) — the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) — elements of the $a$ array. Note that $a_i$ can be zero.
It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line.
If there are several possible answers, print any.
-----Examples-----
Input
3
4 10
-16 2 -6 8
3 1000
-100000 -100000 -100000
6 0
2 6 -164 1 -1 -6543
Output
2 4
-1
1 2
-----Note-----
In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served.
In the second test case, the answer is -1, as there is not enough money for any student at the ATM.
In the third test case, the answer can be either 1 2 or 4 5.
|
{"inputs": ["3\n4 10\n-16 2 -6 8\n3 1000\n-100000 -100000 -100000\n6 0\n2 6 -164 1 -1 -6543\n"], "outputs": ["2 4\n-1\n1 2\n"]}
| 748
| 88
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.
Please complete the following python code precisely:
```python
class Solution:
def arrayPairSum(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,4,3,2]) == 4\n assert candidate(nums = [6,2,6,5,1,2]) == 9\n\n\ncheck(Solution().arrayPairSum)"}
| 109
| 60
|
coding
|
Solve the programming task below in a Python markdown code block.
Comprised of a team of five incredibly brilliant women, "The ladies of ENIAC" were the first “computors” working at the University of Pennsylvania’s Moore School of Engineering (1945). Through their contributions, we gained the first software application and the first programming classes! The ladies of ENIAC were inducted into the WITI Hall of Fame in 1997!
Write a function which reveals "The ladies of ENIAC" names, so that you too can add them to your own hall of tech fame!
To keep: only alpha characters, space characters and exclamation marks.
To remove: numbers and these characters: ```%$&/£?@```
Result should be all in uppercase.
Also feel free to reuse/extend the following starter code:
```python
def rad_ladies(name):
```
|
{"functional": "_inputs = [['k?%35a&&/y@@@5599 m93753&$$$c$n///79u??@@%l?975$t?%5y%&$3$1!'], ['9?9?9?m335%$@a791%&$r$$$l@53$&y&n%$5@ $5577w&7e931%s$c$o%%%f351f??%!%%'], ['%&$557f953//1/$@%r%935$$a@3111$@???%n???5 $%157b%///$i%55&31@l?%&$$a%@$s5757!$$%%%%53'], ['///$%&$553791r357%??@$%u?$%@7993111@$%t$h3% 3$l$311i3%@?&c3h%&t&&?%11e%$?@11957r79%&m$$a55n1!111%%'], ['??@%&a5d15??e599713%l%%e%75913 1$%&@g@%o&$@13l5d11s$%&t15i9n&5%%@%e@$!%$']]\n_outputs = [['KAY MCNULTY!'], ['MARLYN WESCOFF!'], ['FRAN BILAS!'], ['RUTH LICHTERMAN!'], ['ADELE GOLDSTINE!']]\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(rad_ladies(*i), o[0])"}
| 189
| 531
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:
A cell containing a thief if grid[r][c] = 1
An empty cell if grid[r][c] = 0
You are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.
The safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.
Return the maximum safeness factor of all paths leading to cell (n - 1, n - 1).
An adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.
The Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.
Please complete the following python code precisely:
```python
class Solution:
def maximumSafenessFactor(self, grid: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(grid = [[1,0,0],[0,0,0],[0,0,1]]) == 0\n assert candidate(grid = [[0,0,1],[0,0,0],[0,0,0]]) == 2\n assert candidate(grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]) == 2\n\n\ncheck(Solution().maximumSafenessFactor)"}
| 288
| 120
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Leonid is developing new programming language. The key feature of his language is fast multiplication and raising to a power operations. He is asking you to help with the following task.
You have an expression S and positive integer M. S has the following structure: A_{1}*A_{2}*...*A_{n} where "*" is multiplication operation. Each A_{i} is an expression X_{i}Y_{i} where X_{i} and Y_{i} are non-negative integers and "" is raising X_{i} to power Y_{i} operation.
.
Your task is just to find the value of an expression S modulo M
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. Each of the following T testcases is described by one line which contains one positive integer M and expression S separated by whitespace.
------ Output ------
For each test case, output a single line containing one integer corresponding to value of S modulo M
------ Constraints ------
$1 ≤ T ≤ 20$
$ 1 ≤ M ≤ 10^{18}$
$ 1 ≤ length of S ≤ 10^{4}$
$ 0 ≤ X_{i}, Y_{i} ≤ 10^{9997} $
$It's guaranteed that there will not be 00 expression$
------ Subtasks ------
Subtask #1[30 points]: X_{i}, Y_{i} < 10, M < 10 ^{4}
Subtask #2[40 points]: M < 10^{9}
Subtask #3[30 points]: no additional conditions
------ Example ------
Input:
2
1000 23*31
100000 112*24
Output:
24
1936
|
{"inputs": ["2\n1000 2**3*3**1\n100000 11**2*2**4", "2\n1000 2**3*3**1\n100000 4**2*2**11", "2\n1001 2**3*2**1\n100000 4**2*2**11", "2\n1000 2**3*3**1\n101000 11**2*2**4", "2\n1001 1**3*3**2\n100000 4**2*2**11", "2\n1001 1**3*3**2\n100000 4**2*2**01", "2\n1001 1**3*3**1\n110000 11**2*2**4", "2\n1100 2**3*3**1\n110000 4**1*2**11"], "outputs": ["24\n1936", "24\n32768\n", "16\n32768\n", "24\n1936\n", "9\n32768\n", "9\n32\n", "3\n1936\n", "24\n8192\n"]}
| 422
| 339
|
coding
|
Solve the programming task below in a Python markdown code block.
A list of names is taken as input, in which a particular name can occur multiple times. You need to arrange these names as they will appear in the dictionary and also print the number of times the arranged names appear in the list taken as input.
Input:
The first line of input contains an integer, t, which denotes the number of names that will follow.
Then, t lines follow, each containing a name, in the form of a character string S.
Output:
The output contains the names as they would appear in the dictionary, followed by the frequency of that name in the list.
Constraints:
1 ≤ t ≤ 100000
1 ≤ |S| ≤30
S contains only lower case characters.
SAMPLE INPUT
3
ritesh
sahil
ritesh
SAMPLE OUTPUT
ritesh 2
sahil 1
Explanation
Test Case #1:
As the name starts from 'r' comes first then 's' in dictionary and in this case the 'ritesh' name is given 2 times and 'sahil' is given only once so their frequency is coming and remove the duplicate rows.
|
{"inputs": ["3\nritesh\nsahil\nritesh", "5\nritesh\nritesh\nritesh\nsahil\nsahil"], "outputs": ["ritesh 2\nsahil 1", "ritesh 3\nsahil 2"]}
| 252
| 63
|
coding
|
Solve the programming task below in a Python markdown code block.
At a break Vanya came to the class and saw an array of $n$ $k$-bit integers $a_1, a_2, \ldots, a_n$ on the board. An integer $x$ is called a $k$-bit integer if $0 \leq x \leq 2^k - 1$.
Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array $i$ ($1 \leq i \leq n$) and replace the number $a_i$ with the number $\overline{a_i}$. We define $\overline{x}$ for a $k$-bit integer $x$ as the $k$-bit integer such that all its $k$ bits differ from the corresponding bits of $x$.
Vanya does not like the number $0$. Therefore, he likes such segments $[l, r]$ ($1 \leq l \leq r \leq n$) such that $a_l \oplus a_{l+1} \oplus \ldots \oplus a_r \neq 0$, where $\oplus$ denotes the bitwise XOR operation. Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \leq n \leq 200\,000$, $1 \leq k \leq 30$).
The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 2^k - 1$), separated by spaces — the array of $k$-bit integers.
-----Output-----
Print one integer — the maximum possible number of segments with XOR not equal to $0$ that can be obtained by making several (possibly $0$) operations described in the statement.
-----Examples-----
Input
3 2
1 3 0
Output
5
Input
6 3
1 4 4 7 3 4
Output
19
-----Note-----
In the first example if Vasya does not perform any operations, he gets an array that has $5$ segments that Vanya likes. If he performs the operation with $i = 2$, he gets an array $[1, 0, 0]$, because $\overline{3} = 0$ when $k = 2$. This array has $3$ segments that Vanya likes. Also, to get an array with $5$ segments that Vanya likes, he can perform two operations with $i = 3$ and with $i = 2$. He then gets an array $[1, 0, 3]$. It can be proven that he can't obtain $6$ or more segments that he likes.
In the second example, to get $19$ segments that Vanya likes, he can perform $4$ operations with $i = 3$, $i = 4$, $i = 5$, $i = 6$ and get an array $[1, 4, 3, 0, 4, 3]$.
|
{"inputs": ["1 1\n1\n", "1 1\n0\n", "1 2\n3\n", "1 2\n3\n", "1 1\n1\n", "1 1\n0\n", "1 2\n4\n", "1 2\n0\n"], "outputs": ["1", "1", "1", "1", "1", "1", "1\n", "1\n"]}
| 740
| 96
|
coding
|
Solve the programming task below in a Python markdown code block.
Find the longest substring in alphabetical order.
Example: the longest alphabetical substring in `"asdfaaaabbbbcttavvfffffdf"` is `"aaaabbbbctt"`.
There are tests with strings up to `10 000` characters long so your code will need to be efficient.
The input will only consist of lowercase characters and will be at least one letter long.
If there are multiple solutions, return the one that appears first.
Good luck :)
Also feel free to reuse/extend the following starter code:
```python
def longest(s):
```
|
{"functional": "_inputs = [['asd'], ['nab'], ['abcdeapbcdef'], ['asdfaaaabbbbcttavvfffffdf'], ['asdfbyfgiklag'], ['z'], ['zyba']]\n_outputs = [['as'], ['ab'], ['abcde'], ['aaaabbbbctt'], ['fgikl'], ['z'], ['z']]\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(longest(*i), o[0])"}
| 128
| 216
|
coding
|
Solve the programming task below in a Python markdown code block.
Nature photographing may be fun for tourists, but it is one of the most complicated things for photographers. To capture all the facets of a bird, you might need more than one cameras. You recently encountered such a situation.
There are $n$ photographers, so there are $n$ cameras in a line on the x-axis. All the cameras are at distinct coordinates.
You want to pair up these cameras ($n$ is even) in such a way that the sum of angles subtended on the bird by the pair of cameras is maximized. Formally, let A, B be two cameras, and let P be the bird to be captured by these two cameras. The angle will APB.
Note: All angles are in radians.
-----Input-----
- The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases follows.
- The first line of each test case contains an integer $n$.
- The second line of each test case contains $n$ space-separated integers denoting the $x_i$ coordinates of the cameras.
- The third line of each test case contains two space-separated integers $P, Q$ denoting the x and y coordinates of the bird respectively.
-----Output-----
For each test case, output your answer in a single line. Your answer would be considered correct if its absolute error is less than or equal to 1e-6 of the actual answer.
-----Constraints-----
- $1 \le T \le 10$
- $2 \le n \leq 100$
- $1 \le x_i \leq 300$
- $0 \le P \leq 300$
- $1 \le Q \leq 300$
-----Example Input-----
2
2
0 1
0 1
2
0 1
100 1
-----Example Output-----
0.785398163397
0.000100999899
-----Explanation-----
Note: $1 \leq x_i$ is not being satisfied by the sample input, but will be satisfied in the actual test data.
Testcase 1: There are only 2 cameras, so they have to paired up with each other. And the angle subtended by then is 45 degrees. Converting this to radians gives the output.
|
{"inputs": ["2\n2\n0 1\n0 1\n2\n0 1\n100 1\n"], "outputs": ["0.785398163397\n0.000100999899"]}
| 523
| 63
|
coding
|
Solve the programming task below in a Python markdown code block.
Consider a currency system in which there are notes of six denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100.
If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.
-----Input-----
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
-----Output-----
For each test case, display the smallest number of notes that will combine to give N, in a new line.
-----Constraints-----
- 1 ≤ T ≤ 1000
- 1 ≤ N ≤ 1000000
-----Example-----
Input
3
1200
500
242
Output
12
5
7
|
{"inputs": ["3 \n7\n19\n43", "3 \n7\n17\n43", "3 \n7\n33\n43", "3 \n5\n33\n43", "3 \n6\n50\n80", "3 \n8\n50\n80", "3 \n1\n67\n25", "3 \n50\n0\n25"], "outputs": ["2\n4\n6\n", "2\n3\n6\n", "2\n5\n6\n", "1\n5\n6\n", "2\n1\n4\n", "3\n1\n4\n", "1\n4\n3\n", "1\n0\n3\n"]}
| 205
| 166
|
coding
|
Solve the programming task below in a Python markdown code block.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
-----Input-----
The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
-----Output-----
Print a single integer, denoting the minimum possible height of the tallest tower.
-----Examples-----
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
-----Note-----
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
|
{"inputs": ["1 3\n", "3 2\n", "5 0\n", "4 2\n", "6 4\n", "6 3\n", "7 3\n", "5 4\n"], "outputs": ["9\n", "8\n", "10\n", "9\n", "15\n", "14\n", "15\n", "14\n"]}
| 334
| 91
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a date, return the corresponding day of the week for that date.
The input is given as three integers representing the day, month and year respectively.
Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.
Please complete the following python code precisely:
```python
class Solution:
def dayOfTheWeek(self, day: int, month: int, year: int) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(day = 31, month = 8, year = 2019) == \"Saturday\"\n assert candidate(day = 18, month = 7, year = 1999) == \"Sunday\"\n assert candidate(day = 15, month = 8, year = 1993) == \"Sunday\"\n\n\ncheck(Solution().dayOfTheWeek)"}
| 120
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
-----Input-----
In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake.
Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
-----Output-----
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
-----Examples-----
Input
3
.CC
C..
C.C
Output
4
Input
4
CC..
C..C
.CC.
.CC.
Output
9
-----Note-----
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: (1, 2) and (1, 3) (3, 1) and (3, 3) Pieces that share the same column are: (2, 1) and (3, 1) (1, 3) and (3, 3)
|
{"inputs": ["1\n.\n", "1\n.\n", "1\n/\n", "1\n0\n", "1\n-\n", "1\n,\n", "1\n+\n", "1\n*\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 404
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Finish the solution so that it returns the sum of all the multiples of 3 or 5 **below** the number passed in.
> Note: If the number is a multiple of **both** 3 and 5, only count it *once*.
> Also, if a number is negative, return 0(for languages that do have them)
###### *Courtesy of projecteuler.net*
Also feel free to reuse/extend the following starter code:
```python
def solution(number):
```
|
{"functional": "_inputs = [[10], [20], [0], [1], [200]]\n_outputs = [[23], [78], [0], [0], [9168]]\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])"}
| 161
| 186
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and a positive integer k.
You can apply the following operation on the array any number of times:
Choose any subarray of size k from the array and decrease all its elements by 1.
Return true if you can make all the array elements equal to 0, or false otherwise.
A subarray is a contiguous non-empty part of an array.
Please complete the following python code precisely:
```python
class Solution:
def checkArray(self, nums: List[int], k: int) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [2,2,3,1,1,0], k = 3) == True\n assert candidate(nums = [1,3,1,1], k = 2) == False\n\n\ncheck(Solution().checkArray)"}
| 134
| 67
|
coding
|
Solve the programming task below in a Python markdown code block.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers x_{i} and y_{i} ( - 1000 ≤ x_{i}, y_{i} ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
-----Output-----
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
-----Examples-----
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
-----Note-----
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
|
{"inputs": ["1\n1 1\n", "1\n0 1\n", "1\n1 1\n", "1\n14 304\n", "1\n15 304\n", "2\n0 0\n1 1\n", "1\n-188 17\n", "1\n71 -740\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "1\n", "-1\n", "-1\n"]}
| 371
| 120
|
coding
|
Solve the programming task below in a Python markdown code block.
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.
A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1, and also exists an edge between vertices v1 and vt.
A simple path in a undirected graph is a sequence of not necessarily distinct vertices v1, v2, ..., vt (t > 0), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1 and furthermore each edge occurs no more than once. We'll say that a simple path v1, v2, ..., vt starts at vertex v1 and ends at vertex vt.
You've got a graph consisting of n vertices and m edges, that is a vertex cactus. Also, you've got a list of k pairs of interesting vertices xi, yi, for which you want to know the following information — the number of distinct simple paths that start at vertex xi and end at vertex yi. We will consider two simple paths distinct if the sets of edges of the paths are distinct.
For each pair of interesting vertices count the number of distinct simple paths between them. As this number can be rather large, you should calculate it modulo 1000000007 (109 + 7).
Input
The first line contains two space-separated integers n, m (2 ≤ n ≤ 105; 1 ≤ m ≤ 105) — the number of vertices and edges in the graph, correspondingly. Next m lines contain the description of the edges: the i-th line contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n) — the indexes of the vertices connected by the i-th edge.
The next line contains a single integer k (1 ≤ k ≤ 105) — the number of pairs of interesting vertices. Next k lines contain the list of pairs of interesting vertices: the i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ n; xi ≠ yi) — the indexes of interesting vertices in the i-th pair.
It is guaranteed that the given graph is a vertex cactus. It is guaranteed that the graph contains no loops or multiple edges. Consider the graph vertices are numbered from 1 to n.
Output
Print k lines: in the i-th line print a single integer — the number of distinct simple ways, starting at xi and ending at yi, modulo 1000000007 (109 + 7).
Examples
Input
10 11
1 2
2 3
3 4
1 4
3 5
5 6
8 6
8 7
7 6
7 9
9 10
6
1 2
3 5
6 9
9 2
9 3
9 10
Output
2
2
2
4
4
1
|
{"inputs": ["2 1\n1 2\n3\n1 2\n1 2\n2 1\n", "5 4\n1 3\n2 3\n4 3\n1 5\n3\n1 3\n2 4\n5 2\n", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n4\n1 2\n1 6\n6 5\n4 3\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n5 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n3 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n1 5\n5\n1 5\n3 1\n2 5\n4 2\n4 1\n", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n4\n1 2\n1 3\n6 5\n4 3\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n5 1\n1 5\n4 2\n4 1\n"], "outputs": ["1\n1\n1\n", "1\n1\n1\n", "2\n2\n2\n2\n", "2\n2\n2\n2\n2\n", "2\n2\n2\n2\n2\n", "1\n2\n2\n2\n2\n", "2\n2\n2\n2\n", "2\n2\n2\n2\n2\n"]}
| 674
| 438
|
coding
|
Solve the programming task below in a Python markdown code block.
An SNS has N users - User 1, User 2, \cdots, User N.
Between these N users, there are some relationships - M friendships and K blockships.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i.
We define User a to be a friend candidate for User b when all of the following four conditions are satisfied:
- a \neq b.
- There is not a friendship between User a and User b.
- There is not a blockship between User a and User b.
- There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1.
For each user i = 1, 2, ... N, how many friend candidates does it have?
-----Constraints-----
- All values in input are integers.
- 2 ≤ N ≤ 10^5
- 0 \leq M \leq 10^5
- 0 \leq K \leq 10^5
- 1 \leq A_i, B_i \leq N
- A_i \neq B_i
- 1 \leq C_i, D_i \leq N
- C_i \neq D_i
- (A_i, B_i) \neq (A_j, B_j) (i \neq j)
- (A_i, B_i) \neq (B_j, A_j)
- (C_i, D_i) \neq (C_j, D_j) (i \neq j)
- (C_i, D_i) \neq (D_j, C_j)
- (A_i, B_i) \neq (C_j, D_j)
- (A_i, B_i) \neq (D_j, C_j)
-----Input-----
Input is given from Standard Input in the following format:
N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K
-----Output-----
Print the answers in order, with space in between.
-----Sample Input-----
4 4 1
2 1
1 3
3 2
3 4
4 1
-----Sample Output-----
0 1 0 1
There is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.
However, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.
|
{"inputs": ["4 4 1\n2 1\n1 3\n3 3\n3 4\n4 1", "4 4 1\n2 0\n1 3\n3 3\n3 4\n4 1", "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1", "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n", "5 7 0\n1 2\n2 3\n2 4\n0 5\n0 2\n2 4\n2 0\n2 1\n1 2\n4 1", "5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n1 3\n4 5", "5 10 0\n1 2\n1 3\n2 4\n1 5\n3 2\n2 4\n2 5\n4 3\n1 3\n4 5", "5 10 0\n1 2\n1 3\n2 4\n1 5\n3 2\n2 4\n2 5\n4 1\n1 3\n4 5"], "outputs": ["0 2 -1 1\n", "0 0 -2 0\n", "0 1 0 1", "0 1 0 1\n", "4 -1 4 3 4\n", "-1 0 0 0 1\n", "0 -1 0 0 1\n", "-1 -1 1 0 1\n"]}
| 686
| 393
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef recently learned about ratios and proportions. He wrote some positive integers a, b, c, d on a paper. Chef wants to know whether he can shuffle these numbers so as to make some proportion? Formally, four numbers x, y, z, w are said to make a proportion if ratio of x : y is same as that of z : w.
-----Input-----
Only line of the input contains four space separated positive integers - a, b, c, d.
-----Output-----
Print "Possible" if it is possible to shuffle a, b, c, d to make proportion, otherwise "Impossible" (without quotes).
-----Constraints-----
- 1 ≤ a, b, c, d ≤ 1000
-----Example-----
Input:
1 2 4 2
Output:
Possible
-----Explanation-----
By swapping 4 and the second 2, we get 1 2 2 4. Note that 1 2 2 4 make proportion as 1 : 2 = 2 : 4. Hence answer is "Possible"
|
{"inputs": ["1 2 4 2"], "outputs": ["Possible"]}
| 236
| 18
|
coding
|
Solve the programming task below in a Python markdown code block.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
|
{"inputs": ["2\n", "1\n", "3\n", "5\n", "7\n", "37\n", "19\n", "30\n"], "outputs": ["2", "1", "3\n", "5\n", "7\n", "37", "19\n", "30\n"]}
| 455
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $2$) or determine that there is no such subset.
Both the given array and required subset may contain equal values.
-----Input-----
The first line contains a single integer $t$ ($1 \leq t \leq 100$), number of test cases to solve. Descriptions of $t$ test cases follow.
A description of each test case consists of two lines. The first line contains a single integer $n$ ($1 \leq n \leq 100$), length of array $a$.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 100$), elements of $a$. The given array $a$ can contain equal values (duplicates).
-----Output-----
For each test case output $-1$ if there is no such subset of elements. Otherwise output positive integer $k$, number of elements in the required subset. Then output $k$ distinct integers ($1 \leq p_i \leq n$), indexes of the chosen elements. If there are multiple solutions output any of them.
-----Example-----
Input
3
3
1 4 3
1
15
2
3 5
Output
1
2
-1
2
1 2
-----Note-----
There are three test cases in the example.
In the first test case, you can choose the subset consisting of only the second element. Its sum is $4$ and it is even.
In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.
In the third test case, the subset consisting of all array's elements has even sum.
|
{"inputs": ["1\n2\n1 1\n", "1\n2\n1 1\n", "1\n3\n1 1\n", "1\n3\n1 2\n", "1\n3\n0 2\n", "1\n3\n0 3\n", "1\n3\n0 1\n", "1\n4\n1 2\n"], "outputs": ["2\n1 2\n", "2\n1 2\n", "2\n1 2\n", "1\n2\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n2\n"]}
| 427
| 140
|
coding
|
Solve the programming task below in a Python markdown code block.
Mr. Das is a teacher teaching for several years in a school. He is not computer savvy. Due to lockdown, now he has to take classes online. Recently he took an online exam for students of different classes. Now, he will call parents of all the students who scored lower than average marks for the class. He has requested you to give the name $X$, parent's phone number $P$, and marks obtained $M$ to him.
-----Input:-----
- First line contains $T$ no. of test cases
- for every test case, first line contains an integer $N$, no. of students of his class
- Next $N$ lines contain $X$, $P$ , and $M$ separated by space
-----Output:-----
For every test case, find details of the students who scored below average, then print $X, P, M$ separated by space on a new line as per the increasing order of their marks. In case there are multiple students with the same marks, print them as per the order of their occurrence in the input
-----Constraints-----
- $1 \leq T \leq 20$
- X contains characters between a-z and A-Z with a maximum length of 20
- $1 \leq N \leq 100$
- P is 10 digits
- $0 \leq M \leq 100$
-----Sample Input:-----
2
3
Rahul 1345964789 47
Rupendra 1457856987 58
Priya 1478569820 45
2
Tanuja 4310779415 97
Akash 3689781245 43
-----Sample Output:-----
Priya 1478569820 45
Rahul 1345964789 47
Akash 3689781245 43
-----EXPLANATION:-----
In #1, Priya and Rahul's number was lower than average.
In #2, Akash's number was lower than average
|
{"inputs": ["2\n3\nRahul 1345964789 47\nRupendra 1457856987 58\nPriya 1478569820 45\n2\nTanuja 4310779415 97\nAkash 3689781245 43"], "outputs": ["Priya 1478569820 45\nRahul 1345964789 47\nAkash 3689781245 43"]}
| 497
| 153
|
coding
|
Solve the programming task below in a Python markdown code block.
Alice buys a toy with a selling price of 100 rupees. There is a discount of x percent on the toy. Find the amount Alice needs to pay for it.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- The first and only line of each test case contains a single integer, x — the discount on the toy.
------ Output Format ------
For each test case, output on a new line the price that Alice needs to pay.
------ Constraints ------
$1 ≤ T ≤ 100$
$0 ≤ x < 100$
----- Sample Input 1 ------
4
5
9
11
21
----- Sample Output 1 ------
95
91
89
79
----- explanation 1 ------
Test case $1$: The discount is $5$ percent, i.e. $5$ rupees. So, Alice will have to pay $100-5=95$ rupees.
|
{"inputs": ["4\n5\n9\n11\n21\n"], "outputs": ["95\n91\n89\n79\n"]}
| 233
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake a job that you have already done.
Find the maximum total reward that you can earn no later than M days from today.
You can already start working today.
-----Constraints-----
- All values in input are integers.
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq A_i \leq 10^5
- 1 \leq B_i \leq 10^4
-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N
-----Output-----
Print the maximum total reward that you can earn no later than M days from today.
-----Sample Input-----
3 4
4 3
4 1
2 2
-----Sample Output-----
5
You can earn the total reward of 5 by taking the jobs as follows:
- Take and complete the first job today. You will earn the reward of 3 after four days from today.
- Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.
|
{"inputs": ["1 1\n2 1", "1 1\n2 1\n", "3 4\n4 3\n4 1\n3 2", "3 4\n4 3\n3 0\n3 4", "3 4\n4 3\n3 1\n2 4", "3 0\n4 3\n3 1\n2 4", "3 5\n4 3\n4 1\n2 2", "3 4\n4 3\n4 1\n6 2"], "outputs": ["0", "0\n", "5\n", "7\n", "8\n", "0\n", "6\n", "3\n"]}
| 338
| 158
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is the judge of a competition. There are two players participating in this competition — Alice and Bob.
The competition consists of N races. For each i (1 ≤ i ≤ N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi minutes. The player with the smallest sum of finish times wins. If this total time is the same for Alice and for Bob, a draw is declared.
The rules of the competition allow each player to choose a race which will not be counted towards their total time. That is, Alice may choose an index x and her finish time in the race with this index will be considered zero; similarly, Bob may choose an index y and his finish time in the race with this index will be considered zero. Note that x can be different from y; the index chosen by Alice does not affect Bob's total time or vice versa.
Chef, as the judge, needs to announce the result of the competition. He knows that both Alice and Bob play optimally and will always choose the best option. Please help Chef determine the result!
-----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 a single integer N.
- The second line contains N space-separated integers A1, A2, ..., AN.
- The third line contains N space-separated integers B1, B2, ..., BN.
-----Output-----
For each test case, print a single line containing the string "Alice" if Alice wins, "Bob" if Bob wins or "Draw" if the result is a draw (without quotes).
-----Constraints-----
- 1 ≤ T ≤ 100
- 2 ≤ N ≤ 100
- 1 ≤ Ai ≤ 1000 for each valid i
- 1 ≤ Bi ≤ 1000 for each valid i
-----Example-----
Input:
3
5
3 1 3 3 4
1 6 2 5 3
5
1 6 2 5 3
3 1 3 3 4
3
4 1 3
2 2 7
Output:
Alice
Bob
Draw
-----Explanation-----
Example case 1: Alice will choose the finish time in the last race to be considered zero, which means her sum of finish times is 3 + 1 + 3 + 3 + 0 = 10, while Bob will choose the finish time of his second race to be considered zero, so his total sum of finish times is 1 + 0 + 2 + 5 + 3 = 11. Since Alice's sum is smaller, she is considered the winner.
Example case 2: We're dealing with the same situation as in the previous case, but finish times for the players are swapped, so Bob wins this time.
Example case 3: Alice will choose the finish time of the first race to be considered zero, which means her total time is 0 + 1 + 3 = 4. Bob will choose the finish time of his last race to be considered zero, which makes his total time 2 + 2 + 0 = 4. The competition is considered a draw because both players have equal sums of finish times.
|
{"inputs": ["3\n5\n3 1 3 3 4\n1 6 2 5 3\n5\n1 6 2 5 3\n3 1 3 3 4\n3\n4 1 3\n2 2 7"], "outputs": ["Alice\nBob\nDraw"]}
| 710
| 74
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i].
Given two nodes start and end, find the path with the maximum probability of success to go from start to end and return its success probability.
If there is no path from start to end, return 0. Your answer will be accepted if it differs from the correct answer by at most 1e-5.
Please complete the following python code precisely:
```python
class Solution:
def maxProbability(self, n: int, edges: List[List[int]], succProb: List[float], start_node: int, end_node: int) -> float:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2) == 0.25000\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2) == 0.30000\n assert candidate(n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2) == 0.00000\n\n\ncheck(Solution().maxProbability)"}
| 207
| 180
|
coding
|
Solve the programming task below in a Python markdown code block.
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer — the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$.
|
{"inputs": ["2\n1 5\n", "2\n1 0\n", "2\n0 5\n", "2\n1 1\n", "2\n1 5\n", "3\n1 2 3\n", "3\n1 1 3\n", "3\n0 1 9\n"], "outputs": ["4\n", "1\n", "4\n", "0\n", "4", "2\n", "2\n", "8\n"]}
| 310
| 107
|
coding
|
Solve the programming task below in a Python markdown code block.
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $1$ to $n$ and then $3n$ times takes a random pair of different elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex has also come up with a problem about random permutation. He generates a random permutation just like Petr but swaps elements $7n+1$ times instead of $3n$ times. Because it is more random, OK?!
You somehow get a test from one of these problems and now you want to know from which one.
-----Input-----
In the first line of input there is one integer $n$ ($10^{3} \le n \le 10^{6}$).
In the second line there are $n$ distinct integers between $1$ and $n$ — the permutation of size $n$ from the test.
It is guaranteed that all tests except for sample are generated this way: First we choose $n$ — the size of the permutation. Then we randomly choose a method to generate a permutation — the one of Petr or the one of Alex. Then we generate a permutation using chosen method.
-----Output-----
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
-----Example-----
Input
5
2 4 5 1 3
Output
Petr
-----Note-----
Please note that the sample is not a valid test (because of limitations for $n$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC.
Due to randomness of input hacks in this problem are forbidden.
|
{"inputs": ["5\n2 4 5 1 3\n", "5\n4 3 5 1 2\n", "5\n4 1 5 2 3\n", "5\n2 4 5 1 3\n"], "outputs": ["Petr\n", "Petr\n", "Petr\n", "Petr\n"]}
| 404
| 82
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of size $n$. Each element in this array is an integer between $1$ and $10^9$.
You can perform several operations to this array. During an operation, you can replace an element in the array with any integer between $1$ and $10^9$.
Output the minimum number of operations needed such that the resulting array doesn't contain any local maximums, and the resulting array after the operations.
An element $a_i$ is a local maximum if it is strictly larger than both of its neighbors (that is, $a_i > a_{i - 1}$ and $a_i > a_{i + 1}$). Since $a_1$ and $a_n$ have only one neighbor each, they will never be a local maximum.
-----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$ $(2 \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$ $(1 \leq a_i \leq 10^9)$, the elements of array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, first output a line containing a single integer $m$ — minimum number of operations required. Then ouput a line consist of $n$ integers — the resulting array after the operations. Note that this array should differ in exactly $m$ elements from the initial array.
If there are multiple answers, print any.
-----Examples-----
Input
5
3
2 1 2
4
1 2 3 1
5
1 2 1 2 1
9
1 2 1 3 2 3 1 2 1
9
2 1 3 1 3 1 3 1 3
Output
0
2 1 2
1
1 3 3 1
1
1 2 2 2 1
2
1 2 3 3 2 3 3 2 1
2
2 1 3 3 3 1 1 1 3
-----Note-----
In the first example, the array contains no local maximum, so we don't need to perform operations.
In the second example, we can change $a_2$ to $3$, then the array don't have local maximums.
|
{"inputs": ["5\n3\n2 1 2\n4\n1 2 3 1\n5\n1 2 1 2 1\n9\n1 2 1 3 2 3 1 2 1\n9\n2 1 3 1 3 1 3 1 3\n"], "outputs": ["0\n2 1 2 \n1\n1 2 3 3 \n1\n1 2 2 2 1 \n2\n1 2 3 3 2 3 3 2 1 \n2\n2 1 3 3 3 1 3 3 3 \n"]}
| 627
| 157
|
coding
|
Solve the programming task below in a Python markdown code block.
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a_1, a_2, ..., a_{m} of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f_1, f_2, ..., f_{n} of length n and for each number a_{i} got number b_{i} = f_{a}_{i}. To finish the prank he erased the initial sequence a_{i}.
It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible.
-----Input-----
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the lengths of sequences f_{i} and b_{i} respectively.
The second line contains n integers, determining sequence f_1, f_2, ..., f_{n} (1 ≤ f_{i} ≤ n).
The last line contains m integers, determining sequence b_1, b_2, ..., b_{m} (1 ≤ b_{i} ≤ n).
-----Output-----
Print "Possible" if there is exactly one sequence a_{i}, such that b_{i} = f_{a}_{i} for all i from 1 to m. Then print m integers a_1, a_2, ..., a_{m}.
If there are multiple suitable sequences a_{i}, print "Ambiguity".
If Spongebob has made a mistake in his calculations and no suitable sequence a_{i} exists, print "Impossible".
-----Examples-----
Input
3 3
3 2 1
1 2 3
Output
Possible
3 2 1
Input
3 3
1 1 1
1 1 1
Output
Ambiguity
Input
3 3
1 2 1
3 3 3
Output
Impossible
-----Note-----
In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique.
In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence.
In the third sample f_{i} ≠ 3 for all i, so no sequence a_{i} transforms into such b_{i} and we can say for sure that Spongebob has made a mistake.
|
{"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "3 1\n1 1 2\n2\n", "2 2\n1 1\n1 2\n", "2 2\n1 1\n1 2\n", "3 1\n1 1 2\n2\n", "3 1\n1 1 2\n3\n", "3 2\n1 1 3\n1 2\n"], "outputs": ["Possible\n1 \n", "Possible\n1 \n", "Possible\n3 \n", "Impossible\n", "Impossible\n", "Possible\n3 \n", "Impossible\n", "Impossible\n"]}
| 572
| 156
|
coding
|
Solve the programming task below in a Python markdown code block.
----- Statement -----
You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the shortest length. If there is still a tie, print the string which comes the lexicographically earliest (would occur earlier in a dictionary).
-----Input-----
The first line contains the number of test cases T. Each test case contains an integer K (≤ 100).
-----Output-----
Output T lines, one for each test case, containing the required string. Use only lower-case letters a-z.
-----Sample Input -----
2
1
2
-----Sample Output-----
ba
cba
|
{"inputs": ["2\n1\n2", "2\n2\n2", "2\n2\n3", "2\n3\n2", "2\n2\n5", "2\n4\n5", "2\n3\n5", "2\n5\n5"], "outputs": ["ba\ncba", "cba\ncba\n", "cba\ndcba\n", "dcba\ncba\n", "cba\nfedcba\n", "edcba\nfedcba\n", "dcba\nfedcba\n", "fedcba\nfedcba\n"]}
| 161
| 121
|
coding
|
Solve the programming task below in a Python markdown code block.
After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer the next obvious question: how does one compute the least common multiple (lcm) of Fibonacci numbers? Unfortunately, Derek found out that this wasn't as easy as the original problem, so he asked you to answer it for him.
The Fibonacci numbers are defined as:
$F_1=F_2=1$
$F_n=F_{n-1}+F_{n-2}$
Given $N$ integers $a_1,a_2,\ldots,a_N$, find $\text{lcm}(F_{a_1},F_{a_2},\ldots,F_{a_N})$, and give your answer modulo $10^9+7$.
Input Format
The first line of input contains $N$.
Each of the next $N$ lines contains a number: the $i^{th}$ line contains $a_i$.
Constraints
$1\leq N\leq100$
$1\leq a_i\leq10^9$
Output Format
Print a single integer, which is the least common multiple of the ${F}_{a_i}$, modulo $10^9+7$.
Sample Input
5
1
3
3
6
9
Sample Output
136
Explanation
$\text{lcm}(F_1,F_3,F_3,F_6,F_9)=\text{lcm}(1,2,2,8,34)=136$
|
{"inputs": ["5\n1\n3\n3\n6\n9\n"], "outputs": ["136\n"]}
| 349
| 26
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers and an integer k.
Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than or equal to k.
Return the number of distinct great partitions. Since the answer may be too large, return it modulo 109 + 7.
Two partitions are considered distinct if some element nums[i] is in different groups in the two partitions.
Please complete the following python code precisely:
```python
class Solution:
def countPartitions(self, nums: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], k = 4) == 6\n assert candidate(nums = [3,3,3], k = 4) == 0\n assert candidate(nums = [6,6], k = 2) == 2\n\n\ncheck(Solution().countPartitions)"}
| 153
| 83
|
coding
|
Solve the programming task below in a Python markdown code block.
For a non-negative integer N, define S(N) as the sum of the odd digits of N
plus twice the sum of the even digits of N.
For example, S(5)=5, S(456)=2*4+5+2*6=25, and S(314159)=3+1+2*4+1+5+9=27.
Define D(N) as the last digit of S(N).
So D(5)=5, D(456)=5, and D(314159)=7.
Given 2 non-negative integers A and B, compute the sum of D(N) over all N between A and B, inclusive.
------ Input ------
Input will begin with an integer T, the number of test cases.
T lines follow, each containing 2 integers A and B.
------ Output ------
For each test case, output a single integer indicating the corresponding sum.
------ Constraints ------
$T ≤ 1000$
$0 ≤ A ≤ B ≤ 400,000,000$
----- Sample Input 1 ------
3
1 8
28 138
314159 314159
----- Sample Output 1 ------
36
495
7
|
{"inputs": ["3\n2 8\n28 102\n1092 314159", "3\n2 8\n35 102\n1092 314159", "3\n2 8\n61 102\n1092 314159", "3\n0 9\n49 155\n4563 223113", "3\n2 8\n28 102\n1358 314159", "3\n2 8\n35 102\n1092 182073", "3\n2 8\n61 102\n1092 544927", "3\n0 9\n49 218\n2145 473966"], "outputs": ["35\n326\n1408814\n", "35\n302\n1408814\n", "35\n186\n1408814\n", "45\n484\n983475\n", "35\n326\n1407613\n", "35\n302\n814429\n", "35\n186\n2447276\n", "45\n768\n2123195\n"]}
| 297
| 348
|
coding
|
Solve the programming task below in a Python markdown code block.
------Read problems statements in Mandarin chinese
, Russian and Vietnamese as well. ------
Professor GukiZ decided to distribute all of his candies to his $N$ students (numbered $1$ through $N$). Let's denote the number of candies GukiZ gave to the $i$-th student by $p_{i}$. As GukiZ has a lot of students, he does not remember all the exact numbers of candies he gave to the students. He only remembers the following properties of the sequence $p$:
The numbers of candies given to each of the first $K$ students ($p_{1}, p_{2}, \dots, p_{K}$) are known exactly.
All elements of the sequence $p$ are distinct.
The difference between the maximum and minimum element of the sequence $p$ does not exceed $x$.
The professor gave out the biggest possible total number of candies, i.e. $S = p_{1} + p_{2} + p_{3} + \ldots + p_{N}$ is maximum possible.
Normally, professors never lie, so the information provided by GukiZ is valid and there is at least one sequence that satisfies all conditions. GukiZ would like to know the total number of candies $S$ he had at the beginning. Can you help him find this number?
------ 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 three space-separated integers $N$, $K$ and $x$.
The second line contains $K$ space-separated integers $p_{1}, p_{2}, \dots, p_{K}$.
------ Output ------
For each test case, print a single line containing one integer — the number of candies GukiZ had.
------ Constraints ------
$1 ≤ T ≤ 50$
$1 ≤ N ≤ 10^{9}$
$1 ≤ K ≤ \mathrm{min}(N, 2 \cdot 10^{4})$
$0 ≤ x ≤ 10^{9}$
$1 ≤ p_{i} ≤ 10^{9}$ for each valid $i$
there is at least one valid distribution of candies to students
----- Sample Input 1 ------
2
4 3 4
2 1 5
2 2 9
3 6
----- Sample Output 1 ------
12
9
----- explanation 1 ------
Example case 1: There are four students. We know that the first student got $p_{1} = 2$ candies, the second student got $p_{2} = 1$ and the third got $p_{3} = 5$ candies; we don't know the number of candies given to the last student. The difference between the maximum and minimum number of candies given to students is already $5-1 = 4 = x$, so the fourth student could only have been given between $1$ and $5$ candies. It can't be $5$ either, so we maximize the number of candies if we give $4$ candies to the fourth student. In total, there are $2 + 1 + 5 + 4 = 12$ candies.
Example case 2: We know the number of candies given to each of the two students, so we know that GukiZ had $3 + 6 = 9$ candies.
|
{"inputs": ["2\n4 3 4 \n2 1 5\n2 2 9\n3 6"], "outputs": ["12\n9"]}
| 752
| 38
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of queries.
Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≤ p ≤ 10^{18}, 1 ≤ q ≤ 10^{18}, 2 ≤ b ≤ 10^{18}). All numbers are given in notation with base 10.
Output
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
Examples
Input
2
6 12 10
4 3 10
Output
Finite
Infinite
Input
4
1 1 2
9 36 2
4 12 3
3 5 4
Output
Finite
Finite
Finite
Infinite
Note
6/12 = 1/2 = 0,5_{10}
4/3 = 1,(3)_{10}
9/36 = 1/4 = 0,01_2
4/12 = 1/3 = 0,1_3
|
{"inputs": ["2\n9 12 10\n4 3 10\n", "2\n9 12 10\n4 6 10\n", "2\n47 23 4\n3 6 16\n", "2\n6 12 10\n4 3 10\n", "2\n25 12 10\n3 6 15\n", "2\n47 23 10\n3 6 20\n", "2\n18 12 10\n4 6 10\n", "2\n18 12 10\n5 6 10\n"], "outputs": ["Finite\nInfinite\n", "Finite\nInfinite\n", "Infinite\nFinite\n", "Finite\nInfinite\n", "Infinite\nInfinite\n", "Infinite\nFinite\n", "Finite\nInfinite\n", "Finite\nInfinite\n"]}
| 343
| 219
|
coding
|
Solve the programming task below in a Python markdown code block.
Given a binary number $S$ containing only of 1's and 0's, find two binary numbers $A$ and $B$ such that the sum of the number of 1's in $A$ and $B$ is minimum and $A-B=S$. If there are many such numbers, you can print any.
The binary number $S$ has some properties. See the Constraints section for details.
------ Input: ------
The only line of input contains a single binary number $S$ without leading zeroes.
------ Output: ------
Print two numbers $A$ and $B$ in one line without leading zeroes. If any number is zero, just print $0$.
------ Constraints ------
$2 ≤$ number of bits in $S ≤ 10^{6}$
The string $S$ has at least 1 one and 1 zero and has exactly two parts: all 1's followed by all 0's.
----- Sample Input 1 ------
1110000
----- Sample Output 1 ------
10000000 10000
----- explanation 1 ------
1110000 is 112 in decimal.
10000000 is 128 in decimal. 10000 is 16 in decimal. 128 - 16 = 112. Hence the given output is valid. The sum of the number of 1's in $A$ and $B$ is 1 + 1 = 2. You can check that this cannot be decreased. Hence this is a correct answer.
|
{"inputs": ["1110000"], "outputs": ["10000000 10000"]}
| 361
| 31
|
coding
|
Solve the programming task below in a Python markdown code block.
Like any unknown mathematician, Yuri has favourite numbers: $A$, $B$, $C$, and $D$, where $A \leq B \leq C \leq D$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $x$, $y$, and $z$ exist, such that $A \leq x \leq B \leq y \leq C \leq z \leq D$ holds?
Yuri is preparing problems for a new contest now, so he is very busy. That's why he asked you to calculate the number of triangles with described property.
The triangle is called non-degenerate if and only if its vertices are not collinear.
-----Input-----
The first line contains four integers: $A$, $B$, $C$ and $D$ ($1 \leq A \leq B \leq C \leq D \leq 5 \cdot 10^5$) — Yuri's favourite numbers.
-----Output-----
Print the number of non-degenerate triangles with integer sides $x$, $y$, and $z$ such that the inequality $A \leq x \leq B \leq y \leq C \leq z \leq D$ holds.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----Note-----
In the first example Yuri can make up triangles with sides $(1, 3, 3)$, $(2, 2, 3)$, $(2, 3, 3)$ and $(2, 3, 4)$.
In the second example Yuri can make up triangles with sides $(1, 2, 2)$, $(2, 2, 2)$ and $(2, 2, 3)$.
In the third example Yuri can make up only one equilateral triangle with sides equal to $5 \cdot 10^5$.
|
{"inputs": ["1 2 3 4\n", "1 2 2 5\n", "1 2 2 3\n", "1 0 2 5\n", "1 2 2 5\n", "1 2 3 4\n", "32 89 451 476\n", "32 89 451 476\n"], "outputs": ["4\n", "3\n", "3\n", "0\n", "3", "4", "72384\n", "72384"]}
| 471
| 135
|
coding
|
Solve the programming task below in a Python markdown code block.
For a given polygon g and target points t, print "2" if g contains t, "1" if t is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Note that the polygon is not necessarily convex.
Constraints
* 3 ≤ n ≤ 100
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
The entire input looks like:
g (the sequence of the points of the polygon)
q (the number of queris = the number of target points)
1st query
2nd query
:
qth query
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Each query consists of the coordinate of a target point t. The coordinate is given by two intgers x and y.
Output
For each query, print "2", "1" or "0".
Example
Input
4
0 0
3 1
2 3
0 3
3
2 1
0 2
3 2
Output
2
1
0
|
{"inputs": ["4\n0 0\n3 1\n2 3\n0 3\n3\n2 1\n0 2\n0 2", "4\n0 0\n3 0\n2 3\n0 1\n3\n2 1\n0 2\n0 2", "4\n0 0\n3 0\n2 3\n0 3\n3\n2 0\n0 2\n0 2", "4\n0 0\n3 1\n4 3\n0 3\n3\n2 0\n0 3\n0 2", "4\n0 0\n2 1\n2 2\n0 3\n3\n2 1\n0 1\n3 2", "4\n1 0\n3 0\n2 3\n0 3\n3\n2 0\n0 0\n0 4", "4\n0 1\n3 1\n6 3\n0 3\n3\n2 0\n0 5\n0 2", "4\n0 0\n3 1\n2 3\n0 3\n3\n2 1\n0 2\n3 1"], "outputs": ["2\n1\n1\n", "2\n0\n0\n", "1\n1\n1\n", "0\n1\n1\n", "1\n1\n0\n", "1\n0\n0\n", "0\n0\n1\n", "2\n1\n1\n"]}
| 390
| 334
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.
You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
Remove two distinct edges of the tree to form three connected components. For a pair of removed edges, the following steps are defined:
Get the XOR of all the values of the nodes for each of the three components respectively.
The difference between the largest XOR value and the smallest XOR value is the score of the pair.
For example, say the three components have the node values: [4,5,7], [1,9], and [3,3,3]. The three XOR values are 4 ^ 5 ^ 7 = 6, 1 ^ 9 = 8, and 3 ^ 3 ^ 3 = 3. The largest XOR value is 8 and the smallest XOR value is 3. The score is then 8 - 3 = 5.
Return the minimum score of any possible pair of edge removals on the given tree.
Please complete the following python code precisely:
```python
class Solution:
def minimumScore(self, nums: List[int], edges: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]) == 9\n assert candidate(nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]) == 0\n\n\ncheck(Solution().minimumScore)"}
| 328
| 104
|
coding
|
Solve the programming task below in a Python markdown code block.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 ≤ bj ≤ 109) — positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys.
|
{"inputs": ["1 1 1\n1\n1\n", "1 1 13\n2\n3\n", "1 1 13\n2\n2\n", "1 1 10\n5\n15\n", "1 1 10\n2\n15\n", "1 1 13\n2\n15\n", "1 1 10\n10\n10\n", "1 1 10\n10\n15\n"], "outputs": ["0", "11\n", "11\n", "15", "18\n", "15\n", "0", "10\n"]}
| 494
| 151
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots a_n$. Count the number of pairs of indices $1 \leq i, j \leq n$ such that $a_i < i < a_j < j$.
-----Input-----
The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.
The first line of each test case contains an integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \leq a_i \leq 10^9$) — the elements of the array.
It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a single integer — the number of pairs of indices satisfying the condition in the statement.
Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
-----Examples-----
Input
5
8
1 1 2 3 8 2 1 4
2
1 2
10
0 2 1 6 3 4 1 2 8 3
2
1 1000000000
3
0 1000000000 2
Output
3
0
10
0
1
-----Note-----
For the first test cases the pairs are $(i, j)$ = $\{(2, 4), (2, 8), (3, 8)\}$.
The pair $(2, 4)$ is true because $a_2 = 1$, $a_4 = 3$ and $1 < 2 < 3 < 4$.
The pair $(2, 8)$ is true because $a_2 = 1$, $a_8 = 4$ and $1 < 2 < 4 < 8$.
The pair $(3, 8)$ is true because $a_3 = 2$, $a_8 = 4$ and $2 < 3 < 4 < 8$.
|
{"inputs": ["5\n8\n1 1 2 3 8 2 1 4\n2\n1 2\n10\n0 2 1 6 3 4 1 2 8 3\n2\n1 1000000000\n3\n0 1000000000 2\n"], "outputs": ["3\n0\n10\n0\n1\n"]}
| 550
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2.
At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.
Compute the number of pairs of viewers (x, y) such that y will hate x forever.
Constraints
* 2 \le N \le 500
* The sequence P_1, P_2, \dots, P_{N^2} is a permutation of \\{1, 2, \dots, N^2\\}.
Input
The input is given from Standard Input in the format
N
P_1 P_2 \cdots P_{N^2}
Output
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output
ans
Output
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output
ans
Examples
Input
3
1 3 7 9 5 4 8 6 2
Output
1
Input
4
6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8
Output
3
Input
6
11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30
Output
11
|
{"inputs": ["3\n2 3 7 9 5 4 8 6 1", "3\n1 3 7 9 5 8 4 6 2", "3\n1 6 7 9 5 4 8 3 2", "3\n2 4 7 9 5 3 8 6 1", "3\n1 3 7 9 4 8 5 6 2", "3\n2 3 7 9 5 4 8 6 1", "3\n1 3 7 9 5 4 8 6 2", "4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1", "3"]}
| 627
| 225
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.