text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n × m consisting of integers.
You can choose no more than \left⌊m/2\right⌋ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m, k ≤ 70) — the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 ≤ a_{i, j} ≤ 70).
Output
Print one integer — the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
INF=10**6
dp=[-INF]*k
dp[0]=0
for i in range(n):
a=list(map(int,input().split()))
pre=dp[:]
dp=[[-INF]*k for i in range(m//2+1)]
dp[0]=pre[:]
for j in range(m):
for l in range(1,m//2+1)[::-1]:
for h in range(k):
dp[l][h]=max(dp[l][h],dp[l-1][(h-a[j])%k]+a[j])
dp=dp[m//2][:]
print(dp[0])
```
No
| 103,100 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a player can take any positive number of stones from either one of the heaps. A player who is unable to move loses the game.
To make the game easier to playtest, you've introduced developer shortcuts. There are n shortcut positions (x_1, y_1), …, (x_n, y_n). These change the game as follows: suppose that before a player's turn the first and second heap contain x and y stones respectively. If the pair (x, y) is equal to one of the pairs (x_i, y_i), then the player about to move loses instantly, otherwise they are able to make moves as normal. Note that in the above explanation the two heaps and all pairs are ordered, that is, x must refer to the size of the first heap, and y must refer to the size of the second heap.
The game release was followed by too much celebration, and next thing you know is developer shortcuts made their way to the next official update of the game! Players now complain that the AI opponent has become unbeatable at certain stages of the game. You now have to write a program to figure out which of the given initial positions can be won by the starting player, assuming both players act optimally.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of shortcut positions, and the number of initial positions that need to be evaluated.
The following n lines describe shortcut positions. The i-th of these lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^9). It is guaranteed that all shortcut positions are distinct.
The following m lines describe initial positions. The i-th of these lines contains two integers a_i, b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of stones in the first and second heap respectively. It is guaranteed that all initial positions are distinct. However, initial positions are not necessarily distinct from shortcut positions.
Output
For each initial position, on a separate line print "WIN" if the starting player is able to win from this position, and "LOSE" otherwise.
Example
Input
3 5
3 0
0 1
2 2
0 0
1 1
2 2
3 3
5 4
Output
LOSE
WIN
LOSE
WIN
LOSE
Tags: data structures, games
Correct Solution:
```
def fun(n,m):
l1 = []
l2 = []
set1 = set()
var = 15 * 10 ** 8
for k1 in range(n):
x, y = map(int, input().split())
heappush(l1, (x,y))
heappush(l2, (y,x))
set1.add((x,y))
cx = cy = 0
X2=[]
Y2=[]
for i in range(2 * n):
tl = tr = var
tlp = trp = (var, var)
if l1:
tl = l1[0][0] - cx
tlp = (l1[0][0] - cx, l1[0][1] - cy)
if l2:
tr = l2[0][0] - cy
trp = (l2[0][0] - cy, l2[0][1] - cx)
if tlp < trp:
x, y = heappop(l1)
if tl < 0:
continue
cx+=tl;cy+=tl
assert x == cx
if y < cy:
X2.append(x)
cx += 1
else:
y, x = heappop(l2)
if tr < 0:
continue
cx+=tr;cy+=tr
assert y == cy
if x < cx:
Y2.append(y)
cy += 1
ans = []
from bisect import bisect_left
for k2 in range(m):
x, y = map(int, input().split())
if (x, y) in set1:
ans.append('LOSE')
continue
cs1 = bisect_left(X2, x)
cs2 = bisect_left(Y2, y)
if cs1 < len(X2) and X2[cs1] == x:
ans.append('WIN')
continue
if cs2 < len(Y2) and Y2[cs2] == y:
ans.append('WIN')
continue
if x-cs1==y-cs2:
ans.append('LOSE')
else:
ans.append('WIN')
print('\n'.join(map(str,ans)))
from heapq import *
a1, a2 = map(int, input().split())
fun(a1,a2)
```
| 103,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a player can take any positive number of stones from either one of the heaps. A player who is unable to move loses the game.
To make the game easier to playtest, you've introduced developer shortcuts. There are n shortcut positions (x_1, y_1), …, (x_n, y_n). These change the game as follows: suppose that before a player's turn the first and second heap contain x and y stones respectively. If the pair (x, y) is equal to one of the pairs (x_i, y_i), then the player about to move loses instantly, otherwise they are able to make moves as normal. Note that in the above explanation the two heaps and all pairs are ordered, that is, x must refer to the size of the first heap, and y must refer to the size of the second heap.
The game release was followed by too much celebration, and next thing you know is developer shortcuts made their way to the next official update of the game! Players now complain that the AI opponent has become unbeatable at certain stages of the game. You now have to write a program to figure out which of the given initial positions can be won by the starting player, assuming both players act optimally.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of shortcut positions, and the number of initial positions that need to be evaluated.
The following n lines describe shortcut positions. The i-th of these lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^9). It is guaranteed that all shortcut positions are distinct.
The following m lines describe initial positions. The i-th of these lines contains two integers a_i, b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of stones in the first and second heap respectively. It is guaranteed that all initial positions are distinct. However, initial positions are not necessarily distinct from shortcut positions.
Output
For each initial position, on a separate line print "WIN" if the starting player is able to win from this position, and "LOSE" otherwise.
Example
Input
3 5
3 0
0 1
2 2
0 0
1 1
2 2
3 3
5 4
Output
LOSE
WIN
LOSE
WIN
LOSE
Tags: data structures, games
Correct Solution:
```
from heapq import *
from bisect import bisect_left
n, m = map(int, input().split())
inf = 15 * 10 ** 8
norm = []
rev = []
slow = set()
for _ in range(n):x, y = map(int, input().split());heappush(norm, (x,y));heappush(rev, (y,x));slow.add((x,y))
cx = cy = 0
skipX=[]
skipY=[]
for i in range(2 * n):
tl = tr = inf
tlp = trp = (inf, inf)
if norm:tl = norm[0][0] - cx;tlp = (norm[0][0] - cx, norm[0][1] - cy)
if rev:tr = rev[0][0] - cy;trp = (rev[0][0] - cy, rev[0][1] - cx)
if tlp < trp:
x, y = heappop(norm)
if tl < 0:continue
cx+=tl;cy+=tl
assert x == cx
if y < cy:skipX.append(x);cx += 1
else:
y, x = heappop(rev)
if tr < 0:
continue
cx+=tr;cy+=tr
assert y == cy
if x < cx:
skipY.append(y)
cy += 1
out = []
for _ in range(m):
x, y = map(int, input().split())
if (x, y) in slow: out.append('LOSE'); continue
csx = bisect_left(skipX, x); csy = bisect_left(skipY, y)
if csx < len(skipX) and skipX[csx] == x: out.append('WIN'); continue
if csy < len(skipY) and skipY[csy] == y: out.append('WIN'); continue
out.append('LOSE' if x-csx==y-csy else 'WIN')
print('\n'.join(map(str,out)))
```
| 103,102 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a player can take any positive number of stones from either one of the heaps. A player who is unable to move loses the game.
To make the game easier to playtest, you've introduced developer shortcuts. There are n shortcut positions (x_1, y_1), …, (x_n, y_n). These change the game as follows: suppose that before a player's turn the first and second heap contain x and y stones respectively. If the pair (x, y) is equal to one of the pairs (x_i, y_i), then the player about to move loses instantly, otherwise they are able to make moves as normal. Note that in the above explanation the two heaps and all pairs are ordered, that is, x must refer to the size of the first heap, and y must refer to the size of the second heap.
The game release was followed by too much celebration, and next thing you know is developer shortcuts made their way to the next official update of the game! Players now complain that the AI opponent has become unbeatable at certain stages of the game. You now have to write a program to figure out which of the given initial positions can be won by the starting player, assuming both players act optimally.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of shortcut positions, and the number of initial positions that need to be evaluated.
The following n lines describe shortcut positions. The i-th of these lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^9). It is guaranteed that all shortcut positions are distinct.
The following m lines describe initial positions. The i-th of these lines contains two integers a_i, b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of stones in the first and second heap respectively. It is guaranteed that all initial positions are distinct. However, initial positions are not necessarily distinct from shortcut positions.
Output
For each initial position, on a separate line print "WIN" if the starting player is able to win from this position, and "LOSE" otherwise.
Example
Input
3 5
3 0
0 1
2 2
0 0
1 1
2 2
3 3
5 4
Output
LOSE
WIN
LOSE
WIN
LOSE
Tags: data structures, games
Correct Solution:
```
from heapq import *;from bisect import bisect_left
n, m = map(int, input().split());inf = 15 * 10 ** 8;norm = [];rev = [];slow = set();cx = cy = 0;skipX=[];skipY=[];out = []
for _ in range(n):x, y = map(int, input().split());heappush(norm, (x,y));heappush(rev, (y,x));slow.add((x,y))
for i in range(2 * n):
tl = tr = inf;tlp = trp = (inf, inf)
if norm:tl = norm[0][0] - cx;tlp = (norm[0][0] - cx, norm[0][1] - cy)
if rev:tr = rev[0][0] - cy;trp = (rev[0][0] - cy, rev[0][1] - cx)
if tlp < trp:
x, y = heappop(norm)
if tl < 0:continue
cx+=tl;cy+=tl
assert x == cx
if y < cy:skipX.append(x);cx += 1
else:
y, x = heappop(rev)
if tr < 0: continue
cx+=tr;cy+=tr
assert y == cy
if x < cx:skipY.append(y); cy += 1
for _ in range(m):
x, y = map(int, input().split())
if (x, y) in slow: out.append('LOSE'); continue
csx = bisect_left(skipX, x); csy = bisect_left(skipY, y)
if csx < len(skipX) and skipX[csx] == x: out.append('WIN'); continue
if csy < len(skipY) and skipY[csy] == y: out.append('WIN'); continue
out.append('LOSE' if x-csx==y-csy else 'WIN')
print('\n'.join(map(str,out)))
```
| 103,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a player can take any positive number of stones from either one of the heaps. A player who is unable to move loses the game.
To make the game easier to playtest, you've introduced developer shortcuts. There are n shortcut positions (x_1, y_1), …, (x_n, y_n). These change the game as follows: suppose that before a player's turn the first and second heap contain x and y stones respectively. If the pair (x, y) is equal to one of the pairs (x_i, y_i), then the player about to move loses instantly, otherwise they are able to make moves as normal. Note that in the above explanation the two heaps and all pairs are ordered, that is, x must refer to the size of the first heap, and y must refer to the size of the second heap.
The game release was followed by too much celebration, and next thing you know is developer shortcuts made their way to the next official update of the game! Players now complain that the AI opponent has become unbeatable at certain stages of the game. You now have to write a program to figure out which of the given initial positions can be won by the starting player, assuming both players act optimally.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of shortcut positions, and the number of initial positions that need to be evaluated.
The following n lines describe shortcut positions. The i-th of these lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^9). It is guaranteed that all shortcut positions are distinct.
The following m lines describe initial positions. The i-th of these lines contains two integers a_i, b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of stones in the first and second heap respectively. It is guaranteed that all initial positions are distinct. However, initial positions are not necessarily distinct from shortcut positions.
Output
For each initial position, on a separate line print "WIN" if the starting player is able to win from this position, and "LOSE" otherwise.
Example
Input
3 5
3 0
0 1
2 2
0 0
1 1
2 2
3 3
5 4
Output
LOSE
WIN
LOSE
WIN
LOSE
Tags: data structures, games
Correct Solution:
```
import sys
input = sys.stdin.readline
from heapq import *
n, m = map(int, input().split())
inf = 15 * 10 ** 8
norm = []
rev = []
slow = set()
for _ in range(n):
x, y = map(int, input().split())
heappush(norm, (x,y))
heappush(rev, (y,x))
slow.add((x,y))
cx = cy = 0
skipX=[]
skipY=[]
for i in range(2 * n):
tl = tr = inf
tlp = trp = (inf, inf)
if norm:
tl = norm[0][0] - cx
tlp = (norm[0][0] - cx, norm[0][1] - cy)
if rev:
tr = rev[0][0] - cy
trp = (rev[0][0] - cy, rev[0][1] - cx)
if tlp < trp:
x, y = heappop(norm)
if tl < 0:
continue
cx+=tl;cy+=tl
assert x == cx
if y < cy:
skipX.append(x)
cx += 1
else:
y, x = heappop(rev)
if tr < 0:
continue
cx+=tr;cy+=tr
assert y == cy
if x < cx:
skipY.append(y)
cy += 1
out = []
from bisect import bisect_left
for _ in range(m):
x, y = map(int, input().split())
if (x, y) in slow:
out.append('LOSE')
continue
csx = bisect_left(skipX, x)
csy = bisect_left(skipY, y)
if csx < len(skipX) and skipX[csx] == x:
out.append('WIN')
continue
if csy < len(skipY) and skipY[csy] == y:
out.append('WIN')
continue
if x-csx==y-csy:
out.append('LOSE')
else:
out.append('WIN')
print('\n'.join(map(str,out)))
```
| 103,104 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a player can take any positive number of stones from either one of the heaps. A player who is unable to move loses the game.
To make the game easier to playtest, you've introduced developer shortcuts. There are n shortcut positions (x_1, y_1), …, (x_n, y_n). These change the game as follows: suppose that before a player's turn the first and second heap contain x and y stones respectively. If the pair (x, y) is equal to one of the pairs (x_i, y_i), then the player about to move loses instantly, otherwise they are able to make moves as normal. Note that in the above explanation the two heaps and all pairs are ordered, that is, x must refer to the size of the first heap, and y must refer to the size of the second heap.
The game release was followed by too much celebration, and next thing you know is developer shortcuts made their way to the next official update of the game! Players now complain that the AI opponent has become unbeatable at certain stages of the game. You now have to write a program to figure out which of the given initial positions can be won by the starting player, assuming both players act optimally.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of shortcut positions, and the number of initial positions that need to be evaluated.
The following n lines describe shortcut positions. The i-th of these lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^9). It is guaranteed that all shortcut positions are distinct.
The following m lines describe initial positions. The i-th of these lines contains two integers a_i, b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of stones in the first and second heap respectively. It is guaranteed that all initial positions are distinct. However, initial positions are not necessarily distinct from shortcut positions.
Output
For each initial position, on a separate line print "WIN" if the starting player is able to win from this position, and "LOSE" otherwise.
Example
Input
3 5
3 0
0 1
2 2
0 0
1 1
2 2
3 3
5 4
Output
LOSE
WIN
LOSE
WIN
LOSE
Submitted Solution:
```
import sys
input = sys.stdin.readline
from heapq import *
n, m = map(int, input().split())
inf = 15 * 10 ** 8
norm = []
rev = []
slow = set()
for _ in range(n):
x, y = map(int, input().split())
heappush(norm, (x,y))
heappush(rev, (y,x))
slow.add((x,y))
cx = cy = 0
skipX=[]
skipY=[]
for i in range(2 * n):
tl = tr = inf
if norm:
tl = norm[0][0] - cx
if rev:
tr = rev[0][0] - cy
if tl < tr:
x, y = heappop(norm)
if tl < 0:
continue
cx+=tl;cy+=tl
assert x == cx
if y < cy:
skipX.append(x)
cx += 1
else:
y, x = heappop(rev)
if tr < 0:
continue
cx+=tr;cy+=tr
assert y == cy
if x < cx:
skipY.append(y)
cy += 1
out = []
from bisect import bisect_left
for _ in range(m):
x, y = map(int, input().split())
if (x, y) in slow:
out.append('LOSE')
continue
csx = bisect_left(skipX, x)
csy = bisect_left(skipY, y)
if csx < len(skipX) and skipX[csx] == x:
out.append('WIN')
continue
if csy < len(skipY) and skipY[csy] == y:
out.append('WIN')
continue
if x-csx==y-csy:
out.append('LOSE')
else:
out.append('WIN')
print('\n'.join(map(str,out)))
```
No
| 103,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a player can take any positive number of stones from either one of the heaps. A player who is unable to move loses the game.
To make the game easier to playtest, you've introduced developer shortcuts. There are n shortcut positions (x_1, y_1), …, (x_n, y_n). These change the game as follows: suppose that before a player's turn the first and second heap contain x and y stones respectively. If the pair (x, y) is equal to one of the pairs (x_i, y_i), then the player about to move loses instantly, otherwise they are able to make moves as normal. Note that in the above explanation the two heaps and all pairs are ordered, that is, x must refer to the size of the first heap, and y must refer to the size of the second heap.
The game release was followed by too much celebration, and next thing you know is developer shortcuts made their way to the next official update of the game! Players now complain that the AI opponent has become unbeatable at certain stages of the game. You now have to write a program to figure out which of the given initial positions can be won by the starting player, assuming both players act optimally.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of shortcut positions, and the number of initial positions that need to be evaluated.
The following n lines describe shortcut positions. The i-th of these lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^9). It is guaranteed that all shortcut positions are distinct.
The following m lines describe initial positions. The i-th of these lines contains two integers a_i, b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of stones in the first and second heap respectively. It is guaranteed that all initial positions are distinct. However, initial positions are not necessarily distinct from shortcut positions.
Output
For each initial position, on a separate line print "WIN" if the starting player is able to win from this position, and "LOSE" otherwise.
Example
Input
3 5
3 0
0 1
2 2
0 0
1 1
2 2
3 3
5 4
Output
LOSE
WIN
LOSE
WIN
LOSE
Submitted Solution:
```
def ii():
return tuple(int(s) for s in input().split())
if __name__ == '__main__':
n, m = ii()
shortcuts = []
queries = []
for _ in range(n):
shortcuts.append(ii())
for _ in range(m):
queries.append(ii())
shortcuts_set = set(shortcuts)
delta = 0
result = [None] * len(queries)
x_list = []
y_list = []
for i, (x, y) in enumerate(shortcuts):
x_list.append((x, 0, i))
y_list.append((y, 0, i))
for i, (x, y) in enumerate(queries):
if (x, y) in shortcuts_set:
result[i] = False
else:
x_list.append((x, 1, i))
y_list.append((y, 1, i))
x_list.sort(reverse=True)
y_list.sort(reverse=True)
#print(x_list)
#print(y_list)
delta = 0
while x_list or y_list:
#print(x_list[-1] if x_list else None, y_list[-1] if y_list else None)
if x_list and (not y_list or x_list[-1][0] + delta < y_list[-1][0] or (x_list[-1][0] + delta == y_list[-1][0] and y_list[-1][1] == 1)):
if x_list[-1][1] == 1:
x, _, i = x_list.pop()
if result[i] is None:
y = queries[i][1]
if x + delta == y:
result[i] = False
else:
result[i] = True
#print("result0", i, result[i])
continue
if x_list and (not y_list or x_list[-1][0] + delta <= y_list[-1][0]):
if x_list[-1][1] == 0:
x, _, i = x_list[-1]
if shortcuts[i][1] > x + delta:
x_list.pop()
continue
if y_list and (not x_list or x_list[-1][0] + delta > y_list[-1][0]):
if y_list[-1][1] == 1:
y, _, i = y_list.pop()
if result[i] is None:
x = queries[i][0]
if x + delta == y:
result[i] = False
else:
result[i] = True
#print("result1", i, result[i])
continue
if y_list and (not x_list or x_list[-1][0] + delta >= y_list[-1][0]):
if y_list[-1][1] == 0:
y, _, i = y_list[-1]
if shortcuts[i][0] + delta > y:
y_list.pop()
continue
if x_list and y_list and (x_list[-1][0] + delta == y_list[-1][0] and x_list[-1][1] == y_list[-1][1] == 0):
x, _, _ = x_list.pop()
y, _, _ = y_list.pop()
while x_list and x_list[-1][0] == x:
_, t, i = x_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result2", i, result[i])
while y_list and y_list[-1][0] == y:
_, t, i = y_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result3", i, result[i])
#print("next lose", x + 1, y + 1)
elif x_list and (not y_list or x_list[-1][0] + delta < y_list[-1][0] or y_list[-1][1] == 1):
x, _, _ = x_list.pop()
while x_list and x_list[-1][0] == x:
_, t, i = x_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result4", i, result[i])
delta -= 1
#print("next lose", x + 1, x + 1 + delta)
else:
y, _, _ = y_list.pop()
while y_list and y_list[-1][0] == y:
_, t, i = y_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result5", i, result[i])
delta += 1
#print("next lose", y + 1 - delta, y + 1)
for r in result:
print("WIN" if r else "LOSE")
```
No
| 103,106 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a player can take any positive number of stones from either one of the heaps. A player who is unable to move loses the game.
To make the game easier to playtest, you've introduced developer shortcuts. There are n shortcut positions (x_1, y_1), …, (x_n, y_n). These change the game as follows: suppose that before a player's turn the first and second heap contain x and y stones respectively. If the pair (x, y) is equal to one of the pairs (x_i, y_i), then the player about to move loses instantly, otherwise they are able to make moves as normal. Note that in the above explanation the two heaps and all pairs are ordered, that is, x must refer to the size of the first heap, and y must refer to the size of the second heap.
The game release was followed by too much celebration, and next thing you know is developer shortcuts made their way to the next official update of the game! Players now complain that the AI opponent has become unbeatable at certain stages of the game. You now have to write a program to figure out which of the given initial positions can be won by the starting player, assuming both players act optimally.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of shortcut positions, and the number of initial positions that need to be evaluated.
The following n lines describe shortcut positions. The i-th of these lines contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^9). It is guaranteed that all shortcut positions are distinct.
The following m lines describe initial positions. The i-th of these lines contains two integers a_i, b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of stones in the first and second heap respectively. It is guaranteed that all initial positions are distinct. However, initial positions are not necessarily distinct from shortcut positions.
Output
For each initial position, on a separate line print "WIN" if the starting player is able to win from this position, and "LOSE" otherwise.
Example
Input
3 5
3 0
0 1
2 2
0 0
1 1
2 2
3 3
5 4
Output
LOSE
WIN
LOSE
WIN
LOSE
Submitted Solution:
```
def ii():
return tuple(int(s) for s in input().split())
if __name__ == '__main__':
n, m = ii()
shortcuts = []
queries = []
for _ in range(n):
shortcuts.append(ii())
for _ in range(m):
queries.append(ii())
shortcuts_set = set(shortcuts)
delta = 0
result = [None] * len(queries)
x_list = []
y_list = []
for i, (x, y) in enumerate(shortcuts):
x_list.append((x, 0, i))
y_list.append((y, 0, i))
for i, (x, y) in enumerate(queries):
if (x, y) in shortcuts_set:
result[i] = False
else:
x_list.append((x, 1, i))
y_list.append((y, 1, i))
x_list.sort(reverse=True)
y_list.sort(reverse=True)
#print(x_list)
#print(y_list)
delta = 0
while x_list or y_list:
#print(x_list[-1] if x_list else None, y_list[-1] if y_list else None)
if x_list and (not y_list or x_list[-1][0] + delta < y_list[-1][0] or (x_list[-1][0] + delta == y_list[-1][0] and y_list[-1][1] == 1)):
if x_list[-1][1] == 1:
x, _, i = x_list.pop()
if result[i] is None:
y = queries[i][1]
if x + delta == y:
result[i] = False
else:
result[i] = True
#print("result0", i, result[i])
continue
if x_list and (not y_list or x_list[-1][0] + delta <= y_list[-1][0]):
if x_list[-1][1] == 0:
x, _, i = x_list[-1]
if shortcuts[i][1] > x + delta:
x_list.pop()
continue
if y_list and (not x_list or x_list[-1][0] + delta > y_list[-1][0]):
if y_list[-1][1] == 1:
y, _, i = y_list.pop()
if result[i] is None:
x = queries[i][0]
if x + delta == y:
result[i] = False
else:
result[i] = True
#print("result1", i, result[i])
continue
if y_list and (not x_list or x_list[-1][0] + delta >= y_list[-1][0]):
if y_list[-1][1] == 0:
y, _, i = y_list[-1]
if shortcuts[i][0] + delta > y:
y_list.pop()
continue
if x_list and y_list and (x_list[-1][0] + delta == y_list[-1][0] and x_list[-1][1] == y_list[-1][1] == 0):
x, _, _ = x_list.pop()
y, _, _ = y_list.pop()
while x_list and x_list[-1][0] == x:
_, t, i = x_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result2", i, result[i])
while y_list and y_list[-1][0] == y:
_, t, i = y_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result3", i, result[i])
#print("next lose", x + 1, y + 1)
elif x_list and x_list[-1][1] == 0 and (not y_list or x_list[-1][0] + delta < y_list[-1][0] or y_list[-1][1] == 1):
x, _, _ = x_list.pop()
while x_list and x_list[-1][0] == x:
_, t, i = x_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result4", i, result[i])
delta -= 1
#print("next lose", x + 1, x + 1 + delta)
else:
y, _, _ = y_list.pop()
while y_list and y_list[-1][0] == y:
_, t, i = y_list.pop()
if t == 1:
if result[i] is None:
result[i] = True
#print("result5", i, result[i])
delta += 1
#print("next lose", y + 1 - delta, y + 1)
for r in result:
if r is None:
print("???")
else:
print("WIN" if r is True else "LOSE")
```
No
| 103,107 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
n = int(input())
a = [int(t)-1 for t in input().split()]
l, r = [-1]*n, [-1]*n
for i, x in enumerate(a):
if l[x] == -1:
l[x] = i
r[x] = i
dp = [0]*(n+1)
cnt = [0]*n
for i in reversed(range(n)):
x = a[i]
cnt[x] += 1
dp[i] = dp[i+1]
if i == l[x]:
dp[i] = max(dp[i], dp[r[x]+1]+cnt[x])
else:
dp[i] = max(dp[i], cnt[x])
print(n - dp[0])
```
| 103,108 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
import bisect
n = int(input())
arr = list(map(int,input().split()))
#arr = arr[::-1]
dp = [-1]*n+[0]
rear = n-1
indexlist = [[] for i in range(n+1)]
for i in range(n):
indexlist[ arr[i] ].append(i)
def getnext(index):
if index>=rear: return 0
if dp[index]>=0: return dp[index]
if index==indexlist[arr[index]][0]:
end = indexlist[arr[index]][-1]
num1 = end-index+1-len(indexlist[arr[index]]) + getnext(end+1)
else:
loc = bisect.bisect_left(indexlist[arr[index]], index )
num1 = n-index-len(indexlist[arr[index]]) + loc
num2 = 1 + getnext(index+1)
dp[index] = min(num1,num2)
return min(num1,num2)
for index in range(n-1,-1,-1):
if index==indexlist[arr[index]][0]:
end = indexlist[arr[index]][-1]
num1 = end-index+1-len(indexlist[arr[index]]) + dp[end+1]
else:
loc = bisect.bisect_left(indexlist[arr[index]], index )
num1 = n-index-len(indexlist[arr[index]]) + loc
num2 = 1 + dp[index+1]
dp[index] = min(num1,num2)
print(dp[0])
```
| 103,109 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
"""
#If FastIO not needed, use this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
self.os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
#start_time = time.time()
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
def getMat(n):
return [getInts() for _ in range(n)]
def isInt(s):
return '0' <= s[0] <= '9'
MOD = 10**9 + 7
"""
"""
def solve():
N = getInt()
A = getInts()
left, right, counts, tmp_counts = [-1]*(N+1), [-1]*(N+1), [0]*(N+1), [0]*(N+1)
for i in range(N-1,-1,-1):
left[A[i]] = i
counts[A[i]] += 1
if counts[A[i]] == 1: right[A[i]] = i
dp = [-1]*(N+1)
dp[N] = 0
for i in range(N-1,-1,-1):
dp[i] = dp[i+1]
tmp_counts[A[i]] += 1
if i == left[A[i]]:
dp[i] = max(dp[i],dp[right[A[i]]+1]+counts[A[i]])
else:
dp[i] = max(dp[i],tmp_counts[A[i]])
return N - dp[0]
#for _ in range(getInt()):
print(solve())
#solve()
#print(time.time()-start_time)
```
| 103,110 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
left, right = {}, {}
for i, a in enumerate(A):
left.setdefault(a, i)
right[a] = i
dp = [0] * (n + 1)
cnt = Counter()
for i in range(n - 1, -1, -1):
dp[i] = dp[i + 1]
cnt[A[i]] += 1
if i == left[A[i]]:
dp[i] = max(dp[i], dp[right[A[i]] + 1] + cnt[A[i]])
else:
dp[i] = max(dp[i], cnt[A[i]])
print(n - dp[0])
```
| 103,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
from bisect import *
from collections import *
from math import gcd,ceil,sqrt,floor,inf
from heapq import *
from itertools import *
from operator import add,mul,sub,xor,truediv,floordiv
from functools import *
#------------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#------------------------------------------------------------------------
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def A(n):return [0]*n
def AI(n,x): return [x]*n
def G(n): return [[] for i in range(n)]
def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)]
#------------------------------------------------------------------------
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
mod=10**9+7
farr=[1]
ifa=[]
def fact(x,mod=0):
if mod:
while x>=len(farr):
farr.append(farr[-1]*len(farr)%mod)
else:
while x>=len(farr):
farr.append(farr[-1]*len(farr))
return farr[x]
def ifact(x,mod):
global ifa
fact(x,mod)
ifa.append(pow(farr[-1],mod-2,mod))
for i in range(x,0,-1):
ifa.append(ifa[-1]*i%mod)
ifa.reverse()
def per(i,j,mod=0):
if i<j: return 0
if not mod:
return fact(i)//fact(i-j)
return farr[i]*ifa[i-j]%mod
def com(i,j,mod=0):
if i<j: return 0
if not mod:
return per(i,j)//fact(j)
return per(i,j,mod)*ifa[j]%mod
def catalan(n):
return com(2*n,n)//(n+1)
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
def floorsum(a,b,c,n):#sum((a*i+b)//c for i in range(n+1))
if a==0:return b//c*(n+1)
if a>=c or b>=c: return floorsum(a%c,b%c,c,n)+b//c*(n+1)+a//c*n*(n+1)//2
m=(a*n+b)//c
return n*m-floorsum(c,c-b-1,a,m-1)
def inverse(a,m):
a%=m
if a<=1: return a
return ((1-inverse(m,a)*m)//a)%m
def lowbit(n):
return n&-n
class BIT:
def __init__(self,arr):
self.arr=arr
self.n=len(arr)-1
def update(self,x,v):
while x<=self.n:
self.arr[x]+=v
x+=x&-x
def query(self,x):
ans=0
while x:
ans+=self.arr[x]
x&=x-1
return ans
class ST:
def __init__(self,arr):#n!=0
n=len(arr)
mx=n.bit_length()#取不到
self.st=[[0]*mx for i in range(n)]
for i in range(n):
self.st[i][0]=arr[i]
for j in range(1,mx):
for i in range(n-(1<<j)+1):
self.st[i][j]=max(self.st[i][j-1],self.st[i+(1<<j-1)][j-1])
def query(self,l,r):
if l>r:return -inf
s=(r+1-l).bit_length()-1
return max(self.st[l][s],self.st[r-(1<<s)+1][s])
'''
class DSU:#容量+路径压缩
def __init__(self,n):
self.c=[-1]*n
def same(self,x,y):
return self.find(x)==self.find(y)
def find(self,x):
if self.c[x]<0:
return x
self.c[x]=self.find(self.c[x])
return self.c[x]
def union(self,u,v):
u,v=self.find(u),self.find(v)
if u==v:
return False
if self.c[u]>self.c[v]:
u,v=v,u
self.c[u]+=self.c[v]
self.c[v]=u
return True
def size(self,x): return -self.c[self.find(x)]'''
class UFS:#秩+路径
def __init__(self,n):
self.parent=[i for i in range(n)]
self.ranks=[0]*n
def find(self,x):
if x!=self.parent[x]:
self.parent[x]=self.find(self.parent[x])
return self.parent[x]
def union(self,u,v):
pu,pv=self.find(u),self.find(v)
if pu==pv:
return False
if self.ranks[pu]>=self.ranks[pv]:
self.parent[pv]=pu
if self.ranks[pv]==self.ranks[pu]:
self.ranks[pu]+=1
else:
self.parent[pu]=pv
def Prime(n):
c=0
prime=[]
flag=[0]*(n+1)
for i in range(2,n+1):
if not flag[i]:
prime.append(i)
c+=1
for j in range(c):
if i*prime[j]>n: break
flag[i*prime[j]]=prime[j]
if i%prime[j]==0: break
return flag
def dij(s,graph):
d={}
d[s]=0
heap=[(0,s)]
seen=set()
while heap:
dis,u=heappop(heap)
if u in seen:
continue
seen.add(u)
for v,w in graph[u]:
if v not in d or d[v]>d[u]+w:
d[v]=d[u]+w
heappush(heap,(d[v],v))
return d
def lcm(a,b): return a*b//gcd(a,b)
def lis(nums):
res=[]
for k in nums:
i=bisect.bisect_left(res,k)
if i==len(res):
res.append(k)
else:
res[i]=k
return len(res)
def RP(nums):#逆序对
n = len(nums)
s=set(nums)
d={}
for i,k in enumerate(sorted(s),1):
d[k]=i
bi=BIT([0]*(len(s)+1))
ans=0
for i in range(n-1,-1,-1):
ans+=bi.query(d[nums[i]]-1)
bi.update(d[nums[i]],1)
return ans
class DLN:
def __init__(self,val):
self.val=val
self.pre=None
self.next=None
def nb(i,j,n,m):
for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]:
if 0<=ni<n and 0<=nj<m:
yield ni,nj
def topo(n):
q=deque()
res=[]
for i in range(1,n+1):
if ind[i]==0:
q.append(i)
res.append(i)
while q:
u=q.popleft()
for v in g[u]:
ind[v]-=1
if ind[v]==0:
q.append(v)
res.append(v)
return res
@bootstrap
def gdfs(r,p):
if len(g[r])==1 and p!=-1:
yield None
for ch in g[r]:
if ch!=p:
yield gdfs(ch,r)
yield None
t=1
for i in range(t):
n=N()
a=RLL()
l=AI(n+1,n)
r=AI(n+1,0)
for i in range(n):
l[a[i]]=min(i,l[a[i]])
r[a[i]]=max(i,r[a[i]])
dp=A(n+1)
c=A(n+1)
for i in range(n-1,-1,-1):
c[a[i]]+=1
dp[i]=max(dp[i+1],c[a[i]])
if(i==l[a[i]]):
dp[i]=max(dp[i],c[a[i]]+dp[r[a[i]]+1])
ans=n-max(dp)
print(ans)
'''
sys.setrecursionlimit(200000)
import threading
threading.stack_size(10**8)
t=threading.Thr
ead(target=main)
t.start()
t.join()
'''
'''
sys.setrecursionlimit(200000)
import threading
threading.stack_size(10**8)
t=threading.Thread(target=main)
t.start()
t.join()
'''
```
| 103,112 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
left, right = {}, {}
for i, a in enumerate(A):
left.setdefault(a, i)
right[a] = i
dp = [0] * (n + 1)
cnt = Counter()
for i in range(n - 1, -1, -1):
dp[i] = dp[i + 1]
cnt[A[i]] += 1
if i == left[A[i]]:
dp[i] = max(dp[i], dp[right[A[i]] + 1] + cnt[A[i]])
else:
dp[i] = max(dp[i], cnt[A[i]])
print(n - dp[0])
```
| 103,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline
'''
for CASES in range(int(input())):
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
sys.stdout.write(" ".join(map(str,ANS))+"\n")
'''
inf = 100000000000000000 # 1e17
mod = 998244353
n = int(input())
A = list(map(int, input().split()))
# print(*A)
l=[-1]*(n+1)
r=[-1]*(n+1)
F=[0]*(n+1)
cnt=[0]*(n+1)
for num,a in enumerate(A):
if l[a]==-1:
l[a]=num
r[a]=num
for i in range(n-1,-1,-1):
F[i]=F[i+1]
nowcol=A[i]
cnt[nowcol]+=1
if i==l[nowcol]:
F[i]=max(F[i],F[r[nowcol]+1]+cnt[nowcol])
else:
F[i]=max(F[i],cnt[nowcol])
print(n-F[0])
```
| 103,114 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Tags: data structures, dp, greedy
Correct Solution:
```
import sys
from sys import stdin
n = int(stdin.readline())
a = list(map(int,stdin.readline().split()))
clis = [ [] for i in range(n+1) ]
for i in range(n):
clis[a[i]].append(i)
dp = [0] * (n+1)
app = [0] * (n+1)
for i in range(n-1,-1,-1):
app[a[i]] += 1
dp[i] = max(dp[i] , dp[i+1], app[a[i]])
if clis[a[i]][0] == i:
dp[i] = max(dp[i] , dp[clis[a[i]][-1] + 1] + len(clis[a[i]]))
print (n - dp[0])
```
| 103,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
# From Tutorial
from collections import defaultdict, Counter
from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
fq = Counter()
fl = defaultdict(lambda: [n+1, -1])
for i, el in enumerate(a):
fl[el][0] = min(fl[el][0], i)
fl[el][1] = i
fq[el] += 1
cnt = Counter()
dp = [0] * (n+1)
for i in range(n-1, -1, -1):
el = a[i]
cnt[el] += 1
dp[i] = dp[i+1]
if i == fl[el][0]:
dp[i] = max(dp[i], dp[fl[el][1] + 1] + fq[el])
else:
dp[i] = max(dp[i], cnt[el])
print(max(n - dp[0], 0))
```
Yes
| 103,116 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline()
# ------------------------------
def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def S(): return input().strip()
def print_list(l):
print(' '.join(map(str, l)))
# sys.setrecursionlimit(100000)
# import random
# from functools import reduce
# from functools import lru_cache
# from heapq import *
# from collections import deque as dq
# import math
# import bisect as bs
# from collections import Counter
from collections import defaultdict as dc
n = N()
a = RLL()
count = [0] * (n + 1)
first = {}
last = {}
for i in range(n):
if a[i] not in first:
first[a[i]] = i
last[a[i]] = i
dp = [0] * (n + 1)
for i in range(n - 1, -1, -1):
count[a[i]] += 1
tail = dp[last[a[i]] + 1] if i == first[a[i]] else 0
dp[i] = max(dp[i + 1], count[a[i]] + tail)
print(n - dp[0])
```
Yes
| 103,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n = int(input())
a = [int(x) - 1 for x in input().split()]
l = [-1 for _ in range(n + 1)]
r = [-1 for _ in range(n + 1)]
freq = [0 for _ in range(n + 1)]
dp = [0 for _ in range(n + 1)]
for i in range(n):
if(l[a[i]] == -1): l[a[i]] = i
r[a[i]] = i
for i in range(n - 1, -1, -1):
dp[i] = dp[i + 1]
freq[a[i]] += 1
if (i == l[a[i]]): dp[i] = max(dp[i], dp[r[a[i]] + 1] + freq[a[i]])
else : dp[i] = max(dp[i], freq[a[i]])
print(n - dp[0])
```
Yes
| 103,118 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
left, right = {}, {}
for i, a in enumerate(A):
left.setdefault(a, i)
right[a] = i
dp = [0] * (n + 1)
cnt2 = Counter()
for i in range(n - 1, -1, -1):
dp[i] = dp[i + 1]
cnt2[A[i]] += 1
if i == left[A[i]]:
dp[i] = max(dp[i], dp[right[A[i]] + 1] + cnt[A[i]])
else:
dp[i] = max(dp[i], cnt2[A[i]])
print(n - dp[0])
```
Yes
| 103,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
def show_key(book):
c_book = book
keys = []
s = 0
for key, i in enumerate(c_book):
if i!=0:
keys.append([])
for key1, i1 in enumerate(c_book):
if i == i1:
keys[s].append(key1)
c_book[key1] = 0
s += 1
return keys
def search_key(keys, key):
for i in keys:
for key1, j in enumerate(i):
if j==key:
return keys.index(i), key1
def if_sorted(mas):
mas.sort()
for key, i in enumerate(mas):
if key!=len(mas)-1:
if abs(i - mas[key+1])!=1:
return False
return True
def move_books(keys, key):
for i in keys:
for key1, j in enumerate(i):
if j==key:
i[key1] = len(book)-1
if j>key and j!=key:
i[key1]-=1
return keys
def find_min(keys):
min = 9999
for i in keys:
if len(i)>1 and not if_sorted(i) and len(i) < min:
min = len(i)
out = i
if min == 9999:
return False
else:
return out
def if_keys_sorted(keys):
for i in keys:
if not if_sorted(i):
return False
return True
_ = input()
book = input().split()
book = [int(n) for n in book]
keys = show_key(book)
s = 0
for i in keys:
if i == find_min(keys) and not if_sorted(i) and not if_keys_sorted(keys):
for j in i:
if not if_sorted(i) and not if_keys_sorted(keys):
move_books(keys, j)
s+=1
else:
break
print(s)
```
No
| 103,120 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
from collections import Counter
n = int(input())
books = input().split()
act = 0
co = dict(Counter(books))
#print(co)
onln = 1
for i in range(0, len(books) - 1):
if books[i] == books[-1]:
if books[i] != books[i + 1]:
act += onln
#print(books)
books = books[: i - onln + 1] + books[i + 1: ] + books[i - onln + 1: i + 1]
#print(books)
onln = 1
else:
onln += 1
#print(act)
onln = 1
for i in range(0, len(books) - 1):
if books[i] != books[i + 1]:
#print(books[i], '-', i)
if onln != co[books[i]]:
act += onln
onln = 1
else:
onln += 1
print(act)
```
No
| 103,121 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
def bookself(a):
count=0
for i in range(len(a)-1,-1,-1):
key=i
for j in range(i-1,-1,-1):
if(a[key]>a[j]):
key=j
if key!=i:
count+=1
a[i],a[key]=a[key],a[i]
return count
n=input()
s=list(map(int,input().split(" ")))
print(bookself(s))
```
No
| 103,122 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has color a_i.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.
Output
Output the minimum number of operations to make the shelf beautiful.
Examples
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
Note
In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:
1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].
In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].
Submitted Solution:
```
from collections import defaultdict, deque, Counter
# t = int(input())
t = 1
while t:
t-=1
n= int(input())
arr = [int(x) for x in input().split()]
for i in range(n-1,0,-1):
if arr[i] == arr[i-1]:
arr.pop()
else:
arr.pop()
break
c = Counter(arr)
maxx = -1
for key in c:
if c[key] > maxx:
remove = key
maxx = c[key]
res = len(arr) - maxx
print(res)
```
No
| 103,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Annie has gotten bored of winning every coding contest and farming unlimited rating. Today, she is going to farm potatoes instead.
Annie's garden is an infinite 2D plane. She has n potatoes to plant, and the i-th potato must be planted at (x_i,y_i). Starting at the point (0, 0), Annie begins walking, in one step she can travel one unit right or up (increasing her x or y coordinate by 1 respectively). At any point (X,Y) during her walk she can plant some potatoes at arbitrary points using her potato gun, consuming max(|X-x|,|Y-y|) units of energy in order to plant a potato at (x,y). Find the minimum total energy required to plant every potato.
Note that Annie may plant any number of potatoes from any point.
Input
The first line contains the integer n (1 ≤ n ≤ 800 000).
The next n lines contain two integers x_i and y_i (0 ≤ x_i,y_i ≤ 10^9), representing the location of the i-th potato. It is possible that some potatoes should be planted in the same location.
Output
Print the minimum total energy to plant all potatoes.
Examples
Input
2
1 1
2 2
Output
0
Input
2
1 1
2 0
Output
1
Input
3
5 5
7 7
4 9
Output
2
Input
10
5 1
4 0
9 6
0 2
10 1
9 10
3 10
0 10
8 9
1 5
Output
19
Input
10
1 1
2 2
2 0
4 2
4 0
2 0
0 2
4 0
4 2
5 1
Output
6
Note
In example 1, Annie can travel to each spot directly and plant a potato with no energy required.
In example 2, moving to (1,0), Annie plants the second potato using 1 energy. Next, she travels to (1,1) and plants the first potato with 0 energy.
Submitted Solution:
```
n=int(input())
lst_x=[]
lst_y=[]
for i in range(n):
x,y=map(int,input().split())
lst_x.append(x)
lst_y.append(y)
print(0)
```
No
| 103,124 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Tags: combinatorics, constructive algorithms
Correct Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from math import gcd, ceil
def prod(a, mod=10**9+7):
ans = 1
for each in a:
ans = (ans * each) % mod
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
#n = int(input())
#n, k = map(int, input().split())
n,m,x1,y1,x2,y2 = map(int, input().split())
#c, d = map(int, input().split())
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#s = input()
x, y = abs(x2-x1), abs(y2-y1)
x, y = min(x,y), max(x,y)
if [x,y] in [[0,0], [0,1], [0,2], [0,3], [0,4],
[1,1], [1,2], [1,3], [1,4],
[2,2], [2,3], [2,4],
[3,3]]:
print("First")
else:
print("Second")
```
| 103,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Tags: combinatorics, constructive algorithms
Correct Solution:
```
n,m,x1,y1,x2,y2 = map(int, input().split())
n = abs(x1 - x2)
m = abs(y1 - y2)
if n > 4 or m > 4:
print("Second")
elif n <= 3 and m <= 3:
print("First")
elif min(n, m) <= 2:
print("First")
else:
print("Second")
```
| 103,126 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Tags: combinatorics, constructive algorithms
Correct Solution:
```
# METO Bot 0.9.9
n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[1]<5 and a[0]+a[1]<7 else "Second")
```
| 103,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Tags: combinatorics, constructive algorithms
Correct Solution:
```
n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[1]<5 and a[0]+a[1]<7 else "Second")
```
| 103,128 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Tags: combinatorics, constructive algorithms
Correct Solution:
```
# METO Bot 0.9.9.1
n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[1]<5 and a[0]+a[1]<7 else "Second")
```
| 103,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Tags: combinatorics, constructive algorithms
Correct Solution:
```
n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[1]<5 and a[0]+a[1]<7 else "Second")
# Made By Mostafa_Khaled
```
| 103,130 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Submitted Solution:
```
n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[0]<5 and a[0]+a[1]<7 else "Second")
```
No
| 103,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe the rules of the game in more detail.
The players move in turns. The first player begins.
With every move the first player chooses one of his unglued chips, and shifts it one square to the left, to the right, up or down. It is not allowed to move a chip beyond the board edge. At the beginning of a turn some squares of the board may be covered with a glue. The first player can move the chip to such square, in this case the chip gets tightly glued and cannot move any longer.
At each move the second player selects one of the free squares (which do not contain a chip or a glue) and covers it with superglue. The glue dries long and squares covered with it remain sticky up to the end of the game.
If, after some move of the first player both chips are in the same square, then the first player wins. If the first player cannot make a move (both of his chips are glued), then the second player wins. Note that the situation where the second player cannot make a move is impossible — he can always spread the glue on the square from which the first player has just moved the chip.
We will further clarify the case where both chips are glued and are in the same square. In this case the first player wins as the game ends as soon as both chips are in the same square, and the condition of the loss (the inability to move) does not arise.
You know the board sizes and the positions of the two chips on it. At the beginning of the game all board squares are glue-free. Find out who wins if the players play optimally.
Input
The first line contains six integers n, m, x1, y1, x2, y2 — the board sizes and the coordinates of the first and second chips, correspondingly (1 ≤ n, m ≤ 100; 2 ≤ n × m; 1 ≤ x1, x2 ≤ n; 1 ≤ y1, y2 ≤ m). The numbers in the line are separated by single spaces.
It is guaranteed that the chips are located in different squares.
Output
If the first player wins, print "First" without the quotes. Otherwise, print "Second" without the quotes.
Examples
Input
1 6 1 2 1 6
Output
First
Input
6 5 4 3 2 1
Output
First
Input
10 10 1 1 10 10
Output
Second
Submitted Solution:
```
n,m,x1,y1,x2,y2 = map(int, input().split())
n = abs(x1 - x2)
m = abs(y1 - y2)
if n > 2 or m > 2:
print("Second")
elif n == 2 and m == 2:
print("Second")
else:
print("First")
```
No
| 103,132 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
#rOkY
#FuCk
################################## kOpAl #####################################
t=int(input())
l=list(map(int,input().split()))
t1=l[0]
sum=0
for i in range(1,t,1):
if(l[i]<t1):
sum+=(t1-l[i])
t1=l[i]
print(sum)
```
| 103,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
list1=list(map(int,input().split()))
s=0
for i in range(1,n):
if(list1[i]<list1[i-1]):
s+=abs(list1[i]-list1[i-1])
print(s)
```
| 103,134 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
"""
Author : co_devil Chirag Garg
Institute : JIIT
"""
from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from builtins import str as __str__
str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._buffer = BytesIO()
self._fd = file.fileno()
self._writable = 'x' in file.mode or 'r' not in file.mode
self.write = self._buffer.write if self._writable else None
def read(self):
return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)
def readline(self):
while self.newlines == 0:
b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
self.newlines += b.count(b'\n') + (not b)
self.newlines -= 1
return self._buffer.readline()
def flush(self):
if self._writable:
os.write(self._fd, self._buffer.getvalue())
self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')
def print(*args, **kwargs):
sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop('end', b'\n'))
if kwargs.pop('flush', False):
file.flush()
"""
def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
res = 1
x %= p
while y > 0:
if y & 1:
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
if visited[v]:
if col[v] != c:
print('-1')
exit()
return
col[v] = c
visited[v] = 1
for i in graph[v]:
dfs(i, c ^ 1)
def bfs(d,v):
q=[]
q.append(v)
visited[v]=1
while len(q)!=0:
x=q[0]
q.pop(0)
for i in d[x]:
if visited[i]!=1:
visited[i]=1
q.append(i)
print(x)
print(l)
def make_graph(e):
d={}
for i in range(e):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
if y not in d.keys():
d[y] = [x]
else:
d[y].append(x)
return d
def gr2(n):
d={}
for i in range(n):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
return d
def connected_components(graph):
seen = set()
def dfs(v):
vs = set([v])
component=[]
while vs:
v = vs.pop()
seen.add(v)
vs |= set(graph[v]) - seen
component.append(v)
return component
ans=[]
for v in graph:
if v not in seen:
d=dfs(v)
ans.append(d)
return ans
n=ii()
s=li()
c=0
for i in range(1,n):
c+=max(s[i],s[i-1])-s[i]
print(c)
```
| 103,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
a=[int(x) for x in input().split()]
ans=0
for i in range(n-1):
if a[i+1]<a[i]:
ans+=a[i]-a[i+1]
print(ans)
```
| 103,136 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
#coding=utf-8
import sys
n=int(input())
a=[int(i) for i in input().split()]
i=n-1
sum=0
while i>0:
if a[i]<a[i-1]:
sum+=a[i-1]-a[i]
i-=1
print(sum)
```
| 103,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
cnt=0
ans=0
for i in range(1,n):
if l[i]+cnt<l[i-1]:
ans+=abs(l[i]+cnt-l[i-1])
cnt+=ans
l[i]+=cnt
print(ans)
```
| 103,138 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
print(sum(max(0,a[i-1]-a[i]) for i in range(1,n)))
# Made By Mostafa_Khaled
```
| 103,139 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
a=[int(i) for i in input().split()]
sm = 0
for i in range(n-1):
sm+=max(a[i]-a[i+1],0)
print(sm)
'''
7 4 1 47
7->4.... 1 47
add 1 from 4 3 times
7->7->4->50
.....
add 1 from 4 is 3 times
7->7->7->47
sorted
6 times added
'''
```
| 103,140 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
b = list()
for i in range(1, n): b.append(a[i] - a[i-1])
print(sum([-ele for ele in b if ele < 0]))
```
Yes
| 103,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
ans+=max(a[i-1]-a[i],0)
print(ans)
```
Yes
| 103,142 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
n=int(input())
a=list(map(int,input().rstrip().split()))
carry=0
oper=0
for i in range(1,n):
a[i]=a[i]+carry
if a[i]<a[i-1]:
carry+=abs(a[i-1]-a[i])
oper+=abs(a[i-1]-a[i])
a[i]=a[i-1]
#print(a)
print(oper)
```
Yes
| 103,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
m=int(input())
l=list(map(int,input().split()))
t=0
for i in range(m-1):
if l[i]>l[i+1]:
t+=l[i]-l[i+1]
print(t)
```
Yes
| 103,144 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
"""
Author : co_devil Chirag Garg
Institute : JIIT
"""
from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from builtins import str as __str__
str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._buffer = BytesIO()
self._fd = file.fileno()
self._writable = 'x' in file.mode or 'r' not in file.mode
self.write = self._buffer.write if self._writable else None
def read(self):
return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)
def readline(self):
while self.newlines == 0:
b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
self.newlines += b.count(b'\n') + (not b)
self.newlines -= 1
return self._buffer.readline()
def flush(self):
if self._writable:
os.write(self._fd, self._buffer.getvalue())
self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')
def print(*args, **kwargs):
sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop('end', b'\n'))
if kwargs.pop('flush', False):
file.flush()
"""
def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
res = 1
x %= p
while y > 0:
if y & 1:
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
if visited[v]:
if col[v] != c:
print('-1')
exit()
return
col[v] = c
visited[v] = 1
for i in graph[v]:
dfs(i, c ^ 1)
def bfs(d,v):
q=[]
q.append(v)
visited[v]=1
while len(q)!=0:
x=q[0]
q.pop(0)
for i in d[x]:
if visited[i]!=1:
visited[i]=1
q.append(i)
print(x)
print(l)
def make_graph(e):
d={}
for i in range(e):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
if y not in d.keys():
d[y] = [x]
else:
d[y].append(x)
return d
def gr2(n):
d={}
for i in range(n):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
return d
def connected_components(graph):
seen = set()
def dfs(v):
vs = set([v])
component=[]
while vs:
v = vs.pop()
seen.add(v)
vs |= set(graph[v]) - seen
component.append(v)
return component
ans=[]
for v in graph:
if v not in seen:
d=dfs(v)
ans.append(d)
return ans
n=ii()
s=li()
c=0
x=s[0]
y=s[0]
for i in range(1,n):
if s[i]<x:
x=s[i]
if i==n-1:
c+=y-s[i]
break
elif s[i]>x:
x=s[i]
c+=y-s[i-1]
y=s[i]
print(c)
```
No
| 103,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
cnt=0
ans=0
for i in range(1,n):
if l[i]+cnt<l[i-1]:
ans+=abs(l[i]+cnt-l[i-1])
l[i]=l[i-1]
cnt+=ans
print(ans)
```
No
| 103,146 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
"""
Template written to be used by Python Programmers.
Use at your own risk!!!!
Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import heapq
from math import ceil, floor, gcd, fabs, factorial, fmod
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(var)
def l(): return list(map(int, data().split()))
def sl(): return list(map(str, data().split()))
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]
n = int(data())
arr = l()
m = arr[0]
answer = 0
for i in range(1, n):
if arr[i] < m:
answer = max(answer, m-arr[i])
else:
m = max(arr[i], m)
out(str(answer))
```
No
| 103,147 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer — the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
m=a.index(max(a))
d=[0]
if(m==n-1):
for i in range(n-2):
if(a[i]>a[i+1]):
d.append(a[i]-a[i+1])
a[i+1]=a[i]
else:
for i in range(n-1):
if(a[i]>a[i+1]):
d.append(a[i]-a[i+1])
a[i+1]=a[i]
print(max(d))
```
No
| 103,148 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
notused, inp = 0*int(input()), sorted(list(set(map(int, input().split(" ")))))
print(inp[1]) if len(inp) > 1 else print("NO")
```
| 103,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
n = int(input())
a = set(map(int,input().split(" ")))
if len(a)>1:
a= sorted(a)
print(a[1])
else:
print("NO")
```
| 103,150 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
while i < n:
if a[i] == a[i-1]:
i += 1
else:
break
if i == n:
print ('NO')
else:
print (a[i])
```
| 103,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
#################################################
n=RI()[0]
a=RI()
a.sort()
i=0
while i<n and a[i]==a[0]:
i+=1
if i==n:
print("NO")
else:
print(a[i])
```
| 103,152 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
n = int(input())
nums = list(map(int, input().split()))
u_nums = list(set(nums))
u_nums.sort()
if len(u_nums)>1:
print(u_nums[1])
else:
print("NO")
```
| 103,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
n = int(input())
l = list(map(int, input().split()))
k = sorted(list(set(l)))
if len(k) < 2:
print("NO")
else:
print(k[1])
```
| 103,154 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
n = int(input())
ls = list(map(int, input().split()))
def second_order(ls):
if len(list(dict.fromkeys(sorted(ls)))) > 1:
return list(dict.fromkeys(sorted(ls)))[1]
else:
return "NO"
print(second_order(ls))
```
| 103,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Tags: brute force
Correct Solution:
```
n = int(input())
mas = {int(x) for x in input().split()}
smas = sorted(mas)
if smas == mas or len(smas) < 2:
print("NO")
else:
print(smas[1])
```
| 103,156 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
s = set([int(x) for x in input().split()])
print('NO' if len(s) == 1 else sorted(s)[1])
```
Yes
| 103,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
n=input()
l=list(map(int,input().split()))
a=set(l)
f=list(a)
f.sort()
n=len(f)
if(n>1):
print(f[1],end="")
else:
print("NO",end="")
```
Yes
| 103,158 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
n = int(input())
ai = list(map(int,input().split()))
ai.sort()
ans = "NO"
for i in range(1,n):
if ai[i] != ai[i-1]:
ans = ai[i]
break
print(ans)
```
Yes
| 103,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
n=int(input())
s=[int(i) for i in input().split()]
p=set(s)
q=sorted(p)
if len(q)>1:
print(q[1])
else:
print('NO')
```
Yes
| 103,160 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
n=int(input())
n1=list(map(int,input().split()))
n1.sort()
s=set(n1)
l=list(s)
l.sort()
if(l==n1):
print('NO')
else:
print(l[1])
```
No
| 103,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
l.sort()
print(l[1])
```
No
| 103,162 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
n = int(input())
ar = input()
def remove(ar):
return ar.replace(" ", "")
def convert(ar):
a=[]
a[:]=remove(ar)
if len(a)!=n:
return 'NO'
b = []
for i in a:
if i not in b:
b.append(i)
answer=sorted(b)
return answer[1]
print(convert(ar))
```
No
| 103,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Examples
Input
4
1 2 2 -4
Output
1
Input
5
1 2 3 1 1
Output
2
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
first = float("inf")
second = float("inf")
for i in range(n):
if a[i] < first:
second = first
first = a[i]
elif a[i] < second:
second = a[i]
if second == first:
print("NO")
else:
print(second)
```
No
| 103,164 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integers a1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Examples
Input
3
20 30 10 30 20 10
Output
4 2
1 5
6 3
Input
1
1 2
Output
-1
Tags: constructive algorithms, sortings
Correct Solution:
```
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict,Counter
from os import path
import bisect as bi
import heapq
mod=10**9+7
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime--------------------------------------#
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def inp():return (int(input()))
def minp():return(map(int,input().split()))
else:
#------------------PYPY FAst I/o--------------------------------#
def inp():return (int(stdin.readline()))
def minp():return(map(int,stdin.readline().split()))
####### ---- Start Your Program From Here ---- #######
n=inp()
a=list(minp())
d=Counter(a)
flag=0
for keys in d:
if d[keys]&1:
flag=1
break
if flag:
print(-1)
exit(0)
d={}
for i in range(2*n):
try:
d[a[i]].append(i+1)
except:
d[a[i]]=[i+1]
for keys in d:
print(*d[keys])
```
| 103,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integers a1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Examples
Input
3
20 30 10 30 20 10
Output
4 2
1 5
6 3
Input
1
1 2
Output
-1
Submitted Solution:
```
f=open("input.txt", "r")
text = f.readlines()
f.close()
n = int(text[0])
cards = [int(c) for c in text[1].split()]
f = open("output.txt", "w")
if len(set(cards)) > n:
f.write(str(-1))
exit()
pairs = []
bruhcards = sorted(set(cards))
for x in bruhcards:
pairs.append(cards.index(x)+1)
cards[cards.index(x)] += 5000
pairs.append(cards.index(x)+1)
cards[cards.index(x)] += 5000
pairsinpairs = [pairs[i:i + 2] for i in range(0, len(pairs), 2)]
for pair in pairsinpairs:
f.write(' '.join([str(bruhytho) for bruhytho in pair]))
f.write('\n')
f.close()
```
No
| 103,166 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integers a1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Examples
Input
3
20 30 10 30 20 10
Output
4 2
1 5
6 3
Input
1
1 2
Output
-1
Submitted Solution:
```
import os
inputFile=open("input.txt",'r')
outputFile=open("output.txt",'w')
from collections import defaultdict
n=int(inputFile.readline())
hashTable=defaultdict(list)
array=list(map(int,inputFile.readline().split()))
ans=[]
for idx,val in enumerate(array,1):
hashTable[val].append(idx)
for i in hashTable.values():
if len(i)%2!=0:
os.remove("output.txt")
outputFile=open("output.txt",'w')
outputFile.writelines("-1")
break
else:
outputFile.writelines((" ".join([str(i)for i in i])+"\n"))
```
No
| 103,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integers a1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Examples
Input
3
20 30 10 30 20 10
Output
4 2
1 5
6 3
Input
1
1 2
Output
-1
Submitted Solution:
```
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
cat=''.join
catn='\n'.join
mod=1000000007
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################
inp=list(open('input.txt'))
out=open('output.txt','w')
n=int(inp[0])
a=list(map(int,inp[1].split()))
d=ddict(set)
for i in range(2*n):
d[a[i]].add(i)
ans=[]
for x in d:
if len(d[x])%2:
out.write(str(-1)+'\n')
exit()
while d[x]:
j=d[x].pop()
i=d[x].pop()
ans.append(f'{1+i} {1+j}')
out.write(cat(ans))
```
No
| 103,168 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integers a1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Examples
Input
3
20 30 10 30 20 10
Output
4 2
1 5
6 3
Input
1
1 2
Output
-1
Submitted Solution:
```
import sys
try:
sys.exit(0)
f = open('./output.txt', 'w')
f.write('0')
f.close()
f = open('./input.txt', 'r')
n = int(f.readline())
a = list(map(int, f.readline().split()))
f.close()
for i in range(1, 2*n+1):
a[i-1] = [a[i-1], i]
a.sort(key=lambda x: x[0])
flag = True
ans = []
for i in range(1, 2*n+1, 2):
if a[i][0] == a[i-1][0]:
ans.append((a[i-1][1], a[i][1]))
else:
flag = False
break
f = open('./output.txt', 'w')
if flag:
for it in ans:
f.write('{} {}\n'.format(*it))
else:
f.write('-1')
f.close()
except SystemExit:
pass
```
No
| 103,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.
Obviously, the game ends when the entire sheet is cut into 1 × 1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.
You are given an n × m piece of paper, somebody has already made k cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.
Input
The first line contains three integers n, m, k (1 ≤ n, m ≤ 109, 0 ≤ k ≤ 105) — the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xbi, ybi, xei, yei (0 ≤ xbi, xei ≤ n, 0 ≤ ybi, yei ≤ m) — the coordinates of the ends of the existing cuts.
It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border.
The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.
Output
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
Examples
Input
2 1 0
Output
FIRST
1 0 1 1
Input
2 2 4
0 1 2 1
0 1 2 1
1 2 1 0
1 1 1 2
Output
SECOND
Submitted Solution:
```
from functools import reduce
from itertools import groupby
from operator import xor
width, height, cuts = list(map(int, input().split()))
if width == 1 and height == 1:
print("SECOND")
exit()
c = [height] * (width - 1) + [width] * (height - 1)
cu = []
for i in range(cuts):
x1, y1, x2, y2 = list(map(int, input().split()))
if x1 == x2:
cu.append((x1 - 1,) + tuple(sorted((y1, y2))))
else:
cu.append((width - 1 + y1 - 1,) + tuple(sorted((x1, x2))))
cu.sort()
for k, g in groupby(cu, key=lambda x: x[0]):
lastEnd = 0
for cur in g:
c[k] -= max(cur[2] - max(cur[1], lastEnd), 0)
lastEnd = cur[2]
x = reduce(xor, c)
if x > 0:
print("FIRST")
for j, i in enumerate(c):
if i >= x:
for k, g in groupby(cu, key=lambda x: x[0]):
if k != j:
continue
lastEnd = 0
num = 0
for cur in g:
if cur[1] > lastEnd:
num += cur[1] - lastEnd
lastEnd = cur[2]
if num >= x:
if k >= width - 1:
print("aa%s %s %s %s" % (k - width + 2, 0, k - width + 2, cur[1] - num + x))
else:
print("aa%s %s %s %s" % (0, k + 1, cur[1] - num + x, k + 1))
exit()
if k >= width - 1:
print("AA%s %s %s %s" % (k - width + 2, 0, k - width + 2, height - c[k] + x))
else:
print("AA%s %s %s %s" % (0, k + 1, width - c[k] + x, k + 1))
exit()
if i >= width - 1:
print("%s %s %s %s" % (i - width + 2, 0, i - width + 2, x))
else:
print("%s %s %s %s" % (0, i + 1, x, i + 1))
exit()
else:
print("SECOND")
```
No
| 103,170 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.
Obviously, the game ends when the entire sheet is cut into 1 × 1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.
You are given an n × m piece of paper, somebody has already made k cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.
Input
The first line contains three integers n, m, k (1 ≤ n, m ≤ 109, 0 ≤ k ≤ 105) — the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xbi, ybi, xei, yei (0 ≤ xbi, xei ≤ n, 0 ≤ ybi, yei ≤ m) — the coordinates of the ends of the existing cuts.
It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border.
The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.
Output
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
Examples
Input
2 1 0
Output
FIRST
1 0 1 1
Input
2 2 4
0 1 2 1
0 1 2 1
1 2 1 0
1 1 1 2
Output
SECOND
Submitted Solution:
```
from functools import reduce
from itertools import groupby
from operator import xor
width, height, cuts = list(map(int, input().split()))
if width == 1 and height == 1:
print("SECOND")
exit()
cache = {}
widths = 0
heights = 0
def get(a):
if a in cache:
return cache[a]
if a < width - 1:
return height
return width
def set(a, b):
global widths, heights
if a not in cache:
if a < width - 1:
widths += 1
else:
heights += 1
cache[a] = b
cu = []
for i in range(cuts):
x1, y1, x2, y2 = list(map(int, input().split()))
if x1 == x2:
cu.append((x1 - 1,) + tuple(sorted((y1, y2))))
else:
cu.append((width - 1 + y1 - 1,) + tuple(sorted((x1, x2))))
cu.sort()
for k, g in groupby(cu, key=lambda x: x[0]):
lastEnd = 0
for cur in g:
set(k, get(k) - max(cur[2] - max(cur[1], lastEnd), 0))
lastEnd = cur[2]
x = 0
for i in cache.values():
x ^= i
if (width - 1 - widths) % 2 == 1:
x ^= height
if (height - 1 - heights) % 2 == 1:
x ^= width
if x > 0:
print("FIRST")
for j in range(width + height - 2):
i = get(j)
if i ^ x < i:
x = i - (i ^ x)
for k, g in groupby(cu, key=lambda z: z[0]):
if k != j:
continue
lastEnd = 0
num = 0
for cur in g:
if cur[1] > lastEnd:
num += cur[1] - lastEnd
lastEnd = max(cur[2], lastEnd)
if num >= x:
if k < width - 1:
print("%s %s %s %s" % (k + 1, 0, k + 1, cur[1] - num + x))
else:
print("%s %s %s %s" % (0, k - width + 2, cur[1] - num + x, k - width + 2))
exit()
if k < width - 1:
print("%s %s %s %s" % (k + 1, 0, k + 1, height - get(k) + x))
else:
print("%s %s %s %s" % (0, k - width + 2, width - get(k) + x, k - width + 2))
exit()
if j < width - 1:
print("%s %s %s %s" % (j + 1, 0, j + 1, x))
else:
print("%s %s %s %s" % (0, j - width + 2, x, j - width + 2))
exit()
else:
print("SECOND")
```
No
| 103,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.
Obviously, the game ends when the entire sheet is cut into 1 × 1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.
You are given an n × m piece of paper, somebody has already made k cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.
Input
The first line contains three integers n, m, k (1 ≤ n, m ≤ 109, 0 ≤ k ≤ 105) — the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xbi, ybi, xei, yei (0 ≤ xbi, xei ≤ n, 0 ≤ ybi, yei ≤ m) — the coordinates of the ends of the existing cuts.
It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border.
The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.
Output
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
Examples
Input
2 1 0
Output
FIRST
1 0 1 1
Input
2 2 4
0 1 2 1
0 1 2 1
1 2 1 0
1 1 1 2
Output
SECOND
Submitted Solution:
```
from functools import reduce
from itertools import groupby
from operator import xor
width, height, cuts = list(map(int, input().split()))
if width == 1 and height == 1:
print("SECOND")
exit()
cache = {}
widths = 0
heights = 0
def get(a):
if a in cache:
return cache[a]
if a < width - 1:
return height
return width
def set(a, b):
global widths, heights
if a < width - 1:
widths += 1
else:
heights += 1
cache[a] = b
cu = []
for i in range(cuts):
x1, y1, x2, y2 = list(map(int, input().split()))
if x1 == x2:
cu.append((x1 - 1,) + tuple(sorted((y1, y2))))
else:
cu.append((width - 1 + y1 - 1,) + tuple(sorted((x1, x2))))
cu.sort()
for k, g in groupby(cu, key=lambda x: x[0]):
lastEnd = 0
for cur in g:
set(k, get(k) - max(cur[2] - max(cur[1], lastEnd), 0))
lastEnd = cur[2]
x = 0
for i in cache.values():
x ^= i
if (width - 1 - widths) % 2 == 1:
x ^= height
if (height - 1 - heights) % 2 == 1:
x ^= width
if x > 0:
print("FIRST")
for j in range(width + height - 2):
i = get(j)
if i ^ x <= i:
x = i - (i ^ x)
for k, g in groupby(cu, key=lambda z: z[0]):
if k != j:
continue
lastEnd = 0
num = 0
for cur in g:
if cur[1] > lastEnd:
num += cur[1] - lastEnd
lastEnd = max(cur[2], lastEnd)
if num >= x:
if k < width - 1:
print("%s %s %s %s" % (k + 1, 0, k + 1, cur[1] - num + x))
else:
print("%s %s %s %s" % (0, k - width + 2, cur[1] - num + x, k - width + 2))
exit()
if k < width - 1:
print("%s %s %s %s" % (k + 1, 0, k + 1, height - get(k) + x))
else:
print("%s %s %s %s" % (0, k - width + 2, width - get(k) + x, k - width + 2))
exit()
if j < width - 1:
print("%s %s %s %s" % (j + 1, 0, j + 1, x))
else:
print("%s %s %s %s" % (0, j - width + 2, x, j - width + 2))
exit()
else:
print("SECOND")
```
No
| 103,172 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.
Obviously, the game ends when the entire sheet is cut into 1 × 1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.
You are given an n × m piece of paper, somebody has already made k cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.
Input
The first line contains three integers n, m, k (1 ≤ n, m ≤ 109, 0 ≤ k ≤ 105) — the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xbi, ybi, xei, yei (0 ≤ xbi, xei ≤ n, 0 ≤ ybi, yei ≤ m) — the coordinates of the ends of the existing cuts.
It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border.
The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.
Output
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
Examples
Input
2 1 0
Output
FIRST
1 0 1 1
Input
2 2 4
0 1 2 1
0 1 2 1
1 2 1 0
1 1 1 2
Output
SECOND
Submitted Solution:
```
from functools import reduce
from itertools import groupby
from operator import xor
width, height, cuts = list(map(int, input().split()))
if width == 1 and height == 1:
print("SECOND")
exit()
cache = {}
widths = 0
heights = 0
def get(a):
if a in cache:
return cache[a]
if a < width - 1:
return height
return width
def set(a, b):
global widths, heights
if a < width - 1:
widths += 1
else:
heights += 1
cache[a] = b
cu = []
for i in range(cuts):
x1, y1, x2, y2 = list(map(int, input().split()))
if x1 == x2:
cu.append((x1 - 1,) + tuple(sorted((y1, y2))))
else:
cu.append((width - 1 + y1 - 1,) + tuple(sorted((x1, x2))))
cu.sort()
for k, g in groupby(cu, key=lambda x: x[0]):
lastEnd = 0
for cur in g:
set(k, get(k) - max(cur[2] - max(cur[1], lastEnd), 0))
lastEnd = cur[2]
x = 0
for i in cache.values():
x ^= i
if width - 1 - widths % 2 == 1:
x ^= height
if height - 1 - heights % 2 == 1:
x ^= width
if x > 0:
print("FIRST")
for j in range(width + height - 2):
i = get(j)
if i ^ x <= i:
x = i - (i ^ x)
for k, g in groupby(cu, key=lambda z: z[0]):
if k != j:
continue
lastEnd = 0
num = 0
for cur in g:
if cur[1] > lastEnd:
num += cur[1] - lastEnd
lastEnd = cur[2]
if num >= x:
if k < width - 1:
print("%s %s %s %s" % (k + 1, 0, k + 1, cur[1] - num + x))
else:
print("%s %s %s %s" % (0, k - width + 2, cur[1] - num + x, k - width + 2))
exit()
if k < width - 1:
print("%s %s %s %s" % (k + 1, 0, k + 1, height - get(k) + x))
else:
print("%s %s %s %s" % (0, k - width + 2, width - get(k) + x, k - width + 2))
exit()
if j < width - 1:
print("%s %s %s %s" % (j + 1, 0, j + 1, x))
else:
print("%s %s %s %s" % (0, j - width + 2, x, j - width + 2))
exit()
else:
print("SECOND")
```
No
| 103,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasily the bear has got a large square white table of n rows and n columns. The table has got a black border around this table.
<image> The example of the initial table at n = 5.
Vasily the bear wants to paint his square table in exactly k moves. Each move is sequence of actions:
1. The bear chooses some square inside his table. At that the square must have a black border painted around it. Also, the square shouldn't contain a black cell. The number of cells in the square shouldn't be less than 2.
2. The bear chooses some row and some column inside the chosen square. Then he paints each cell of this row and this column inside the chosen square. After that the rectangles, formed by the square's border and the newly painted cells, must be squares of a non-zero area.
<image> An example of correct painting at n = 7 и k = 2.
The bear already knows numbers n and k. Help him — find the number of ways to paint the square in exactly k moves. Two ways to paint are called distinct if the resulting tables will differ in at least one cell. As the answer can be rather large, print the remainder after dividing it by 7340033.
Input
The first line contains integer q (1 ≤ q ≤ 105) — the number of test data.
Each of the following q lines contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 1000) — the size of the initial table and the number of moves for the corresponding test.
Output
For each test from the input print the answer to the problem modulo 7340033. Print the answers to the tests in the order in which the tests are given in the input.
Examples
Input
8
1 0
1 1
3 0
3 1
2 0
2 1
3 2
7 2
Output
1
0
1
1
1
0
0
4
Note
All possible painting ways for the test n = 7 and k = 2 are:
<image>
Submitted Solution:
```
print(1)
```
No
| 103,174 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
def genPrimes(n):
sieve = [True]*(n+1)
p = 2
while p*p <= n:
if sieve[p]:
for i in range(p*p, n+1, p):
sieve[i] = False
p += 1
primes = []
for i in range(2, n+1):
if sieve[i]:
primes.append(i)
return primes
primes = genPrimes(2000000)
n = int(input().strip())
print(*primes[:n])
```
| 103,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
n = int(input())
for i in range(n):
print((3*n)+i, end='\t')
```
| 103,176 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
def print_first_N_primes(n):
start = 9000001
temp = start
for i in range(start,start+n):
print(i,end=" ")
num = int(input())
print_first_N_primes(num)
print("")
```
| 103,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
import sys
n = int(input())
for i in range(10000000-n, 9999999):
sys.stdout.write(str(i) + " ")
sys.stdout.write("9999999")
```
| 103,178 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
n=int(input())
for i in range(100000,100000+n):
print(i,end=" ")
```
| 103,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
n = int(input())
a = 1000000
for i in range(n):
print(a, end = " ")
a += 1
```
| 103,180 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
len = int(input())
for i in range(0, len):
print(len*2+i, end=' ')
```
| 103,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Tags: math
Correct Solution:
```
n=int(input())
y=0
a=[3*n]
while(len(a)!=n):
a.append(a[-1]+1)
if(len(a)>n):
a.pop()
for i in a:
print(i,end=" ")
print()
```
| 103,182 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
n = int(input())
for i in range(n) :
print(5*n + i, end = " ")
```
Yes
| 103,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
n = int(input())
for i in range(n):
print(100000+i, end=' ')
print('')
```
Yes
| 103,184 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/327/B
n = int(input())
for i in range(n):
print(3 * n + i, end = " ")
```
Yes
| 103,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
import sys
#f = sys.stdin
#f = open("input.txt", "r")
n = int(input())
# a = [2]
# k = 3
# for i in range(1, n):
# a.append(a[i-1] + 1)
# j = 0
# while j < i:
# if a[i]%a[j] == 0:
# a[i] += 1
# j = 0
# else:
# j += 1
# print(a[i])
# print(" ".join(map(str, a)))
for i in range(n, n+n):
print(i, end=" ")
```
Yes
| 103,186 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
from functools import reduce
ans = [3, 5]
n = int(input())
for i in range(n):
flag = reduce(lambda a, b:a*b + 1, ans)
ans.append(flag)
print(*ans[:n])
```
No
| 103,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
#!/usr/bin/env python
# coding: utf-8
# In[204]:
# # n = int(input())
# # line = list(map(int, input().split()))
# # line = list(str(input()))
# In[224]:
import math
# In[213]:
n = int(input())
# In[ ]:
# In[233]:
# est_upper = n * 6
sqrt_val = round(math.sqrt(n * 10))
not_prime = [i * j for j in range(2, sqrt_val) for i in range(2, sqrt_val)]
# In[234]:
count = 0
res = []
for i in range(len(not_prime)-1):
if count >= n:
break
a = not_prime[i+1]
b = not_prime[i]
if a - b > 1:
for j in range(b+1, a):
res.append(str(j))
count += 1
if count >= n:
break
print(" ".join(res))
# In[171]:
# count = 0
# c = 0
# for i in range(2, est_upper):
# c += 1
# if count >= n:
# break
# if i not in not_prime:
# # print(i, end = " ")
# count += 1
# print(c)
# In[146]:
# count = 0
# for i in range(2, 1420):
# for j in range(2, 1420):
# val = i*j
# if val < 2000000:
# prime[val] = False
# In[135]:
# prime = [True] * 2000000
# flag = 0
# for i in range(2, 1410):
# for j in range(2, 1410):
# if i*j > 500000:
# flag = 1
# break
# prime[i*j] = False
# if flag:
# break
# In[147]:
# count = 0
# print(2, end = ' ')
# for i in range(3, 5000000):
# if count >= n - 1:
# break
# if prime[i] == True:
# print(i, end = ' ')
# count += 1
# # print(" ".join(res))
# In[ ]:
# In[ ]:
```
No
| 103,188 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
a = int(input())
v,w = [],(a//2)+1
for i in range(1,(a//2)+1):
v.append((6*i)-1)
v.append((6*i)+1)
if a%2!=0:
v.append((6*w)-1)
print(*v)
```
No
| 103,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 ≤ n ≤ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
n=int(input())
if(n==1):
print(1)
else:
print(5,end=" ")
i=1
while(i<n):
print('1'*(i+1),end=" ")
i+=1
```
No
| 103,190 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
import math
n=int(input())
arr=list(map(int,input().split()))
print(max(max(arr),math.ceil(sum(arr)/(n-1))))
```
| 103,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
"""
pppppppppppppppppppp
ppppp ppppppppppppppppppp
ppppppp ppppppppppppppppppppp
pppppppp pppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppp pppppppp
ppppppppppppppppppppp ppppppp
ppppppppppppppppppp ppppp
pppppppppppppppppppp
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
s = sum(arr)
answer = max(arr)
out(max(answer, ceil(s / (n-1))))
```
| 103,192 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
#!/usr/bin/env python
#coding:utf-8
import sys
if __name__ == "__main__":
n = int( input() )
l = list(map(int, input().split()))
s = sum(l)
n = n - 1
res = (s%n == 0) and s // n or s // n + 1
res = max(res, max(l))
print(res)
```
| 103,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
res = max((sum(a)+(n-2))//(n-1), max(a))
print(res)
```
| 103,194 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
n = int(input())
a = [int(s) for s in input().split()]
sum, b = 0, 0
for i in a:
b = max(b, i)
sum += i
if b * n - sum >= b:
print(b)
else:
print((sum + n - 2) // (n - 1))
```
| 103,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
import sys
import math
#sys.stdin = open('in.txt')
n = int(input())
a = list(map(int, input().split()))
ans= max(math.ceil(sum(a)/(n-1)),max(a))
print(ans)
```
| 103,196 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
import math
n=int(input())
inp=[int(x) for x in input().split()]
print(max(max(inp), math.ceil(sum(inp)/(n-1))))
```
| 103,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Tags: binary search, math, sortings
Correct Solution:
```
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############
n=inp()
ara=inara()
ara.sort()
lo=ara[-1]
hi=100000000000000000000000000000
ans=hi
while hi>=lo:
mid=(hi+lo)//2
tot=0
for num in ara:
tot+=mid-num
if tot>=mid:
break
if tot>=mid:
ans=mid
hi=mid-1
else:
lo=mid+1
print(ans)
```
| 103,198 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
m = max(l)
n = n - 1
if s%n == 0:
e = s // n
else:
e = s // n + 1
if e < m:
e = m
print(e)
```
Yes
| 103,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.