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.
Bob is a duck. He wants to get to Alice's nest, so that those two can duck!
<image> Duck is the ultimate animal! (Image courtesy of See Bang)
The journey can be represented as a straight line, consisting of n segments. Bob is located to the left of the first segment, while Alice's nest is on the right of the last segment. Each segment has a length in meters, and also terrain type: grass, water or lava.
Bob has three movement types: swimming, walking and flying. He can switch between them or change his direction at any point in time (even when he is located at a non-integer coordinate), and doing so doesn't require any extra time. Bob can swim only on the water, walk only on the grass and fly over any terrain. Flying one meter takes 1 second, swimming one meter takes 3 seconds, and finally walking one meter takes 5 seconds.
Bob has a finite amount of energy, called stamina. Swimming and walking is relaxing for him, so he gains 1 stamina for every meter he walks or swims. On the other hand, flying is quite tiring, and he spends 1 stamina for every meter flown. Staying in place does not influence his stamina at all. Of course, his stamina can never become negative. Initially, his stamina is zero.
What is the shortest possible time in which he can reach Alice's nest?
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of segments of terrain.
The second line contains n integers l_1, l_2, ..., l_n (1 ≤ l_i ≤ 10^{12}). The l_i represents the length of the i-th terrain segment in meters.
The third line contains a string s consisting of n characters "G", "W", "L", representing Grass, Water and Lava, respectively.
It is guaranteed that the first segment is not Lava.
Output
Output a single integer t — the minimum time Bob needs to reach Alice.
Examples
Input
1
10
G
Output
30
Input
2
10 10
WL
Output
40
Input
2
1 2
WL
Output
8
Input
3
10 10 10
GLW
Output
80
Note
In the first sample, Bob first walks 5 meters in 25 seconds. Then he flies the remaining 5 meters in 5 seconds.
In the second sample, Bob first swims 10 meters in 30 seconds. Then he flies over the patch of lava for 10 seconds.
In the third sample, the water pond is much smaller. Bob first swims over the water pond, taking him 3 seconds. However, he cannot fly over the lava just yet, as he only has one stamina while he needs two. So he swims back for half a meter, and then half a meter forward, taking him 3 seconds in total. Now he has 2 stamina, so he can spend 2 seconds flying over the lava.
In the fourth sample, he walks for 50 seconds, flies for 10 seconds, swims for 15 seconds, and finally flies for 5 seconds.
Submitted Solution:
```
def read(type = 1):
if type:
file = open("input.dat", "r")
n = int(file.readline())
a = list(map(int, file.readline().split()))
b = file.readline()
file.close()
else:
n = int(input().strip())
a = list(map(int, input().strip().split()))
b = input().strip()
return n, a, b
def solve():
sol = 0
e = 0
big = 0
g = 0
lvls = []
for i in range(n):
if b[i] == "W":
big = 1
sol += 3 * a[i]
e += a[i]
if b[i] == "G":
sol += 5 * a[i]
e += a[i]
g += a[i]
if b[i] == "L":
sol += a[i]
e -= a[i]
if e < 0:
if big:
sol -= 3 * e
else:
sol -= 5 * e
e = 0
if e < 2*g:
g = e/2
if e:
sol -= 4*g
sol -= 2 * (e-2*g)/2
return int(sol)
n, a, b = read(0)
sol = solve()
print(sol)
```
No
| 88,400 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
"""
x: i-2,i-1,i
y: i-1,i,i+1
z: i,i+1,i+2
dp[y][z] denotes the number of triples using the first i denominations. since the number of y and z
affects the number of tile i+1 and i+2, so they need to be considered.
Transition:
new_dp[y][z] = max(new_dp[y][z], pre_dp[x][y] + z + (a[i] - x-y-z)//3)
Boundary condition:
dp[0][0] = 0
"""
from sys import stdin
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, stdin.readline().strip().split()))
c = Counter(
a) # using counter is slow, 2074 ms compared to 1341ms of direct counter
c = [0] * (m + 3)
for i in a:
c[i] += 1
dp = [[float('-inf')] * 3 for _ in range(3)]
dp[0][0] = 0
for i in range(1, m + 1):
new_dp = [[float('-inf')] * 3 for _ in range(3)]
for x in range(0, 3):
for y in range(0, 3):
for z in range(0, 3):
if c[i] >= x + y + z:
remaining = c[i] - x - y - z
new_dp[y][z] = max(new_dp[y][z],
dp[x][y] + z + remaining // 3)
dp = new_dp
print(dp[0][0])
```
| 88,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
n, m = map(int, input().split())
a = map(int, input().split())
c = [0] * (m+4)
for x in a:
c[x] += 1
d_old = [0] + [-999999] * 14
for x in range(1, m+4):
p = 0
q = c[x-1]
r = c[x]
if x-2 >= 0:
p = c[x-2]
d_nu = [-999999] * 15
for i in range(5):
for j in range(3):
for k in range(3):
if i+k <= p and j+k <= q and k <= r:
idx = 3*(j+k) + k
d_nu[idx] = max([d_nu[idx], k + d_old[3*i + j] + (p-i-k) // 3])
d_old = d_nu
print(max(d_old))
```
| 88,402 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
"""
x: i-2,i-1,i
y: i-1,i,i+1
z: i,i+1,i+2
dp[y][z] denotes the number of triples using the first i denominations. since the number of y and z
affects the number of tile i+1 and i+2, so they need to be considered.
Transition:
new_dp[y][z] = max(new_dp[y][z], pre_dp[x][y] + z + (a[i] - x-y-z)//3)
Boundary condition:
dp[0][0] = 0
"""
from sys import stdin
from collections import Counter
from copy import deepcopy
n, m = map(int, input().split())
a = list(map(int, stdin.readline().strip().split()))
c = Counter(a)
dp = [[float('-inf')] * 3 for _ in range(3)]
dp[0][0] = 0
for i in range(1, m + 1):
new_dp = [[float('-inf')] * 3 for _ in range(3)]
for x in range(0, 3):
for y in range(0, 3):
for z in range(0, 3):
if c[i] >= x + y + z and c[i + 1] >= y + z and c[i + 2] >= z:
remaining = c[i] - x - y - z
new_dp[y][z] = max(new_dp[y][z],
dp[x][y] + z + remaining // 3)
dp = new_dp
print(max(sum(dp, [])))
```
| 88,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
from collections import Counter
l1 = input().split(" ")
n, m = int(l1[0]), int(l1[1])
tiles = Counter(map(int, input().split(" ")))
nums = sorted(tiles)
dp = {(0, 0): 0}
for num in nums:
v0, v1 = tiles[num], tiles[num+1]
new_dp = Counter()
for (d0, d1), c in dp.items():
t0, t1 = v0 - d0, v1 - d1
for d in range(min(t0, t1, 2) + 1):
k = (d1 + d, d)
new_dp[k] = max(new_dp[k], c + d + (t0 - d) // 3)
dp = new_dp
print(max(dp.values()))
```
| 88,404 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
from collections import Counter
n, m = map(int, input().split())
B = list(map(int, input().split()))
cnt = Counter(B)
A = sorted(cnt.keys())
n = len(A)
dp = [[0] * 3 for _ in range(3)]
for i, a in enumerate(A):
dp2 = [[0] * 3 for _ in range(3)]
for x in range(1 if i >= 2 and a - 2 != A[i - 2] else 3):
for y in range(1 if i >= 1 and a - 1 != A[i - 1] else 3):
for z in range(3):
if x + y + z <= cnt[a]:
dp2[y][z] = max(dp2[y][z], dp[x][y] + z + (cnt[a] - x - y - z) // 3)
dp = dp2
print (dp[0][0])
```
| 88,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
from array import array
def main():
n,m = map(int,input().split())
a = array('i',map(int,input().split()))
x = array('i',[0]*(m+1))
for i in a:
x[i] += 1
dp = [array('i',[-10**9]*9) for _ in range(m)]
# dp[i][j][k] : number i+1 forms j 2-seg and k 1-seg
for i in range(3):
dp[0][i] = (x[1]-i)//3
for i in range(1,m):
for j in range(3):
for k in range(3):
for spe in range(j+k,min(x[i+1],j+k+2)+1):
dp[i][k*3+spe-j-k] = max(dp[i][k*3+spe-j-k],
dp[i-1][j*3+k]+j+(x[i+1]-spe)//3)
print(max(dp[m-1]))
# Fast IO Region
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")
if __name__ == "__main__":
main()
```
| 88,406 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
"""
x: i-2,i-1,i
y: i-1,i,i+1
z: i,i+1,i+2
dp[y][z] denotes the number of triples using the first i denominations. since the number of y and z
affects the number of tile i+1 and i+2, so they need to be considered.
Transition:
new_dp[y][z] = max(new_dp[y][z], pre_dp[x][y] + z + (a[i] - x-y-z)//3)
Boundary condition:
dp[0][0] = 0
"""
from sys import stdin
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, stdin.readline().strip().split()))
c = [0] * (m + 3)
for i in a:
c[i] += 1
dp = [[float('-inf')] * 3 for _ in range(3)]
dp[0][0] = 0
for i in range(1, m + 1):
new_dp = [[float('-inf')] * 3 for _ in range(3)]
for x in range(0, 3):
for y in range(0, 3):
for z in range(0, 3):
if c[i] >= x + y + z and c[i + 1] >= y + z and c[i + 2] >= z:
remaining = c[i] - x - y - z
new_dp[y][z] = max(new_dp[y][z],
dp[x][y] + z + remaining // 3)
dp = new_dp
print(max(sum(dp, [])))
```
| 88,407 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Tags: dp
Correct Solution:
```
# -*- coding: utf-8 -*-
# @Time : 2019/2/11 11:02
# @Author : LunaFire
# @Email : gilgemesh2012@gmail.com
# @File : D. Jongmah.py
def main():
n, m = map(int, input().split())
a = list(map(int, input().split()))
counter = [0] * (m + 1)
for x in a:
counter[x] += 1
pre_dp = [[float('-inf')] * 3 for _ in range(3)]
pre_dp[0][0] = 0
for i in range(1, m + 1):
cur_dp = [[float('-inf')] * 3 for _ in range(3)]
for x in range(3):
for y in range(3):
for z in range(3):
if counter[i] >= x + y + z:
remain = counter[i] - x - y - z
cur_dp[y][z] = max(cur_dp[y][z], pre_dp[x][y] + z + remain // 3)
pre_dp = cur_dp
print(pre_dp[0][0])
if __name__ == '__main__':
main()
```
| 88,408 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Submitted Solution:
```
import sys
class Reader:
def __init__(self):
self.in_strs = list(reversed(sys.stdin.read().split()))
def read_int(self):
out = self.in_strs.pop()
return int(out)
def main():
r = Reader()
cc = r.read_int()
n = r.read_int()
a = [0 for i in range(n)]
for i in range(cc):
a[r.read_int() - 1] += 1
dp = [[0 for j in range(3)] for i in range(3)]
for c in a:
new_dp = [[0 for j in range(3)] for i in range(3)]
for x in range(3):
for y in range(3):
for z in range(3):
if x + y + z <= c:
new_dp[y][z] = max([new_dp[y][z], dp[x][y] + z + (c - x - y - z) // 3])
new_dp, dp = dp, new_dp
print(dp[0][0])
if __name__ == "__main__":
main()
```
Yes
| 88,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Submitted Solution:
```
"""
x: i-2,i-1,i
y: i-1,i,i+1
z: i,i+1,i+2
dp[y][z] denotes the number of triples using the first i denominations. since the number of y and z
affects the number of tile i+1 and i+2, so they need to be considered.
Transition:
new_dp[y][z] = max(new_dp[y][z], pre_dp[x][y] + z + (a[i] - x-y-z)//3)
Boundary condition:
dp[0][0] = 0
"""
from sys import stdin
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, stdin.readline().strip().split()))
# c = Counter(
# a) # using counter is slow, 2074 ms compared to 1341ms of direct counter
c = [0] * (m + 3)
for i in a:
c[i] += 1
dp = [[float('-inf')] * 3 for _ in range(3)]
dp[0][0] = 0
for i in range(1, m + 1):
new_dp = [[float('-inf')] * 3 for _ in range(3)]
for x in range(0, 3):
for y in range(0, 3):
for z in range(0, 3):
if c[i] >= x + y + z:
remaining = c[i] - x - y - z
new_dp[y][z] = max(new_dp[y][z],
dp[x][y] + z + remaining // 3)
dp = new_dp
print(dp[0][0])
```
Yes
| 88,410 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Submitted Solution:
```
n, m = map(int, input().split())
A = list(map(int, input().split()))
qu = n
hek = dict()
for i in range(1, m + 1):
hek[i] = 0
for j in A:
hek[j] += 1
cnt = 0
for u in range(1, m + 1):
if hek[u]:
f = 1
V = [0, 0]
for i in range(1, m + 1):
V.append(hek[i])
V.append(0)
V.append(0)
A = V
for i in range(2, m + 2):
z = A[i] % 3
if z == 0:
continue
elif z == 1:
if (A[i - 1] and A[i - 2]) or (A[i - 1] and A[i + 1]) or (A[i + 1] and A[i + 2]):
continue
else:
qu -= 1
else:
if (A[i - 1] >= 2 and A[i - 2] >= 2) or (A[i - 1] >= 2 and A[i + 1] >= 2) or (A[i + 1] >= 2 and A[i + 2] >= 2):
continue
else:
qu -= 1
if (A[i - 1] and A[i - 2]) or (A[i - 1] and A[i + 1]) or (A[i + 1] and A[i + 2]):
continue
else:
qu -= 1
print(qu // 3)
```
No
| 88,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Submitted Solution:
```
n,m=map(int,input().split())
s=list(map(int,input().split()))
ans=0
t=[0]*(m+1)
for i in range(n):
t[s[i]]+=1
for i in range(1,m+1):
if i+2<=m:
mm = min(t[i],t[i+1],t[i+2])
if mm>0:
ans+=mm
t[i]-=mm
t[i+1]-=mm
t[i+2]-=mm
ans+=(t[i]//3)
print(ans)
```
No
| 88,412 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Submitted Solution:
```
n,m=map(int,input().split())
s=list(map(int,input().split()))
ans=0
t=[0]*(m+1)
for i in range(n):
t[s[i]]+=1
for i in range(1,m+1):
if i+2<=m:
if t[i]%3==2 and (t[i+1]%3==2 or t[i+2]%3==2):
mm = min(2,t[i+1],t[i+2])
ans += mm
t[i]-=mm
t[i+1]-=mm
t[i+2]-=mm
if t[i]%3>=1 and t[i+1]%3>=1 and t[i+2]%3>=1:
ans+=1
t[i]-=1
t[i+1]-=1
t[i+2]-=1
ans+=(t[i]//3)
print(ans)
```
No
| 88,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, 7, 7, 7 is a valid triple, and so is 12, 13, 14, but 2,2,3 or 2,4,6 are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple.
To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand.
Input
The first line contains two integers integer n and m (1 ≤ n, m ≤ 10^6) — the number of tiles in your hand and the number of tiles types.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the number written on the i-th tile.
Output
Print one integer: the maximum number of triples you can form.
Examples
Input
10 6
2 3 3 3 4 4 4 5 5 6
Output
3
Input
12 6
1 5 3 3 3 4 3 5 3 2 3 3
Output
3
Input
13 5
1 1 5 1 2 3 3 2 4 2 3 4 5
Output
4
Note
In the first example, we have tiles 2, 3, 3, 3, 4, 4, 4, 5, 5, 6. We can form three triples in the following way: 2, 3, 4; 3, 4, 5; 4, 5, 6. Since there are only 10 tiles, there is no way we could form 4 triples, so the answer is 3.
In the second example, we have tiles 1, 2, 3 (7 times), 4, 5 (2 times). We can form 3 triples as follows: 1, 2, 3; 3, 3, 3; 3, 4, 5. One can show that forming 4 triples is not possible.
Submitted Solution:
```
from collections import Counter
m,n=map(int,input().split())
mst=Counter(int(x) for x in input().split())
sst=sorted(list(mst.keys()))
length=len(sst)
pairs=0
if m > 2:
if length==1:
print(m//3)
elif length==2:
a,b=mst[sst[0]],mst[sst[1]]
print(a//3+b//3)
elif length > 2:
for x in range(0,length-2):
if sst[x+1]-sst[x]==sst[x+2]-sst[x+1] and mst[sst[x]]>0 and mst[sst[x+1]]>0 and mst[sst[x+2]]>0:
ans=min(mst[sst[x]],mst[sst[x+1]],mst[sst[x+2]])
mst[sst[x]],mst[sst[x+1]],mst[sst[x+2]]=mst[sst[x]]-ans,mst[sst[x+1]]-ans,mst[sst[x+2]]-ans
pairs+=ans
if mst[sst[x]]>2:
pairs+=(mst[sst[x]]//3)
mst[sst[x]]%=3
elif mst[sst[x]]>2:
pairs+=(mst[sst[x]]//3)
mst[sst[x]]%=3
print(pairs)
else:
print(pairs)
```
No
| 88,414 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
c=0
l.sort()
for i in range(n):
if i+1==l[i]:
c+=1
print(c)
```
| 88,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
#!/usr/bin/env python3
import sys
def rint():
return map(int, sys.stdin.readline().split())
#lines = stdin.readlines()
n = int(input())
a = list(rint())
a = [0] + a
m = 0
cnt = 0
for i in range(1, n+1):
m = max(m, a[i])
if m <= i:
cnt += 1
print(cnt)
```
| 88,416 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
n = int(input())
*a, = map(int, input().split())
ans, counter = 0, 0
for i in range(n):
counter = max(a[i], counter)
if counter == i +1:
ans += 1
print(ans)
```
| 88,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
a = int(input())
b = list(map(int, input().split()))
count = 0
now = 1
last_clue = 1
while (a + 1 > now):
last_clue = max(last_clue, b[now - 1])
if(last_clue <= now):
count +=1
#print(now, last_clue, count)
now += 1
print(count)
```
| 88,418 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
R = lambda: map(int, input().split())
n = int(input())
L = list(R())
i = 0
ma = 0
res = 0
while i < n:
ma = max(ma,L[i])
if ma == i+1:
res += 1
i += 1
print(res)
```
| 88,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
days=0
mys=[]
for i in range(1,n+1):
mys.append(a[i-1])
ll=len(mys)
j=0
while(j<ll):
if(mys[j]==i):
del mys[j]
ll-=1
continue
j+=1
if len(mys)==0:
days+=1
print(days)
```
| 88,420 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
day = [i + 1 for i in range(n)]
pre = [arr[0]]
for i in range(1, n):
pre.append(max(pre[-1], arr[i]))
ans = 0
for i in range(n):
if day[i] == pre[i]:
ans += 1
print(ans)
```
| 88,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Tags: implementation
Correct Solution:
```
#
import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
isdebug = False
try :
#raise ModuleNotFoundError
import pylint
import numpy
def dprint(*args, **kwargs):
#print(*args, **kwargs, file=sys.stderr)
# in python 3.4 **kwargs is invalid???
print(*args, file=sys.stderr)
dprint('debug mode')
isdebug = True
except Exception:
def dprint(*args, **kwargs):
pass
def red_inout():
inId = 0
outId = 0
if not isdebug:
inId = 0
outId = 0
if inId>0:
dprint('use input', inId)
try:
f = open('input'+ str(inId) + '.txt', 'r')
sys.stdin = f #标准输出重定向至文件
except Exception:
dprint('invalid input file')
if outId>0:
dprint('use output', outId)
try:
f = open('stdout'+ str(outId) + '.txt', 'w')
sys.stdout = f #标准输出重定向至文件
except Exception:
dprint('invalid output file')
atexit.register(lambda :sys.stdout.close()) #idle 中不会执行 atexit
if isdebug and len(sys.argv) == 1:
red_inout()
def getIntList():
return list(map(int, input().split()))
def solve():
pass
T_ = 1
#T_, = getIntList()
for iii_ in range(T_):
#solve()
N, = getIntList()
#print(N)
za = getIntList()
now = 0
r = 0
for i in range(N):
now = max(now,za[i]-1)
if now ==i:
r+=1
print(r)
```
| 88,422 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
n=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
C=set()
d=0
for i in range(1,n+1):
C.add(A[i])
C.discard(i)
if len(C) == 0 :
d+=1
print(d)
```
Yes
| 88,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
m = 0
i=0
days = 0
while(i<n):
m = max(m,l[i])
if m>i+1:
i+=1
elif m==l[i]:
days+=1
i+=1
print(days)
```
Yes
| 88,424 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
page=input()
page=int(page)
secret=input().split()
day=0
for i in range(0,page):
secret[i]=int(secret[i])
#print(secret, page)
i=0
while i<page:
x=max(secret[:i+1])-1
if i==x:
day=day+1
i=i+1
else:
i=x
print(day)
```
Yes
| 88,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
n = int(input())
a = [int(i) for i in input().split()]
start = time.time()
end = a[0]
ans = 0
for i in range(n):
if a[i] > end:
end = a[i]
if end == i+1:
ans += 1
print(ans)
finish = time.time()
#print(finish - start)
```
Yes
| 88,426 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = [] * n
ans = 0
for i in range(n):
if len(s) > 0 and i in s:
s.remove(i)
ans += 1
else:
s.append(a[i])
print(ans)
```
No
| 88,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
n=int(input())
lst1=list(map(int,input().split()))
count=0
for i in range(len(lst1)):
if lst1[i]==i+1:
count+=1
print(count-1)
```
No
| 88,428 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
ma=l[0]
c=0
for i in range(n):
if ma<l[i]:
ma=l[i]
if ma<=i+1:
print(l[i])
c+=1
if i!=n-1:
ma=l[i+1]
print(c)
```
No
| 88,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page i such that Ivan already has read it, but hasn't read page a_i). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer n (1 ≤ n ≤ 10^4) — the number of pages in the book.
The second line contains n integers a_1, a_2, ..., a_n (i ≤ a_i ≤ n), where a_i is the number of page which contains the explanation of the mystery on page i.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
9
1 3 3 6 7 6 8 8 9
Output
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.
Submitted Solution:
```
n = int(input())
L = [int(x)-1 for x in input().split()]
currentPage = 0
latestMystery = 0
days = 0
while currentPage < n:
days += 1
latestMystery = L[currentPage]
while latestMystery > currentPage:
temp = currentPage
currentPage = latestMystery
for i in range(temp,max(temp,latestMystery)+1):
latestMystery = max(L[i],latestMystery)
print(currentPage,latestMystery)
print(currentPage,latestMystery)
currentPage += 1
print(days)
```
No
| 88,430 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
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")
#######################################
n,m=map(int,input().split())
cnt=0
i1=0
j1=0
i2=n-1
j2=m-1
while(cnt<n*m):
if(cnt%2==0):
print(i1+1,j1+1)
if(j1==m-1):
i1+=1
j1=0
else:
j1+=1
else:
print(i2+1,j2+1)
if(j2==0):
j2=m-1
i2-=1
else:
j2-=1
cnt+=1
```
| 88,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
n, m = tuple(map(int, input().split()))
if n==1 and m==1:
print('1 1')
exit()
def onerow(r, m):
for i in range(1, (m+1)//2 + 1):
# print('Here', i)
print(str(r) + ' ' + str(i))
if m%2 == 0 or i != (m+1)//2:
print(str(r) + ' ' + str(m+1-i))
def tworow(r1, r2, m):
for i in range(1, m+1):
print(str(r1) + ' ' + str(i))
print(str(r2) + ' ' + str(m+1-i))
if n%2 == 0:
for i in range(1, n//2 + 1):
tworow(i, n+1-i, m)
if n%2 == 1:
for i in range(1, n//2 + 1):
tworow(i, n+1-i, m)
onerow(n//2 + 1, m)
```
| 88,432 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
if __name__ == "__main__":
n, m = [int(x) for x in input().split()]
#n, m = map(int, input().split())
answer = []
for i in range((n + 1) // 2):
for j in range(m):
if i == n // 2 and j == m // 2:
if m % 2 == 0:
break
answer.append("{} {}".format(i + 1, j + 1))
break
answer.append("{} {}".format(i + 1, j + 1))
answer.append("{} {}".format(n - i, m - j))
print("\n".join(answer))
```
| 88,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
inp = list(map(int,input().split(" ")))
n = int(inp[0])
m = int(inp[1])
x = 1
y = 1
cells = n * m
up = n
down = 1
upiter = m
downiter = 1
flag = 0
count = 0
Ans = []
while(up >= down):
# print("up and down are ", up, down)
while(upiter >= 1 or downiter <= m):
if(flag == 0):
# print(str(down) + " " + str(downiter))
Ans.append(str(down) + " " + str(downiter))
downiter += 1
else:
# print(str(up) + " " + str(upiter))
Ans.append(str(up) + " " + str(upiter))
upiter -= 1
count += 1
if(count == cells):
break
flag = flag ^ 1
flag = 0
up -= 1
down += 1
upiter = m
downiter = 1
# print("count is " ,count)
if(count != cells):
print(-1)
else:
for x in Ans:
print(x)
```
| 88,434 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
n,m = list(map(int, input().strip().split()))
for row in range(1, n // 2 + 1):
for col in range(1, m+1):
print(str(row) + " " + str(col))
print(str(n+1-row) + " " + str(m+1-col))
if n % 2 == 1:
row = n // 2 + 1
for col in range(1, m // 2 + 1):
print(str(row) + " " + str(col))
print(str(row) + " " + str(m+1-col))
if m % 2 == 1:
print(str(row) + " " + str(m // 2 + 1))
```
| 88,435 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
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")
#######################################
n,m=map(int,input().split())
ans=[]
i,j=1,1
x,y=n,m
for k in range(n*m//2):
ans.append([i,j])
ans.append([x,y])
j+=1
if j==m+1:
i+=1
j=1
y-=1
if y==0:
x-=1
y=m
if (n*m)%2:
ans.append([i,j])
for i in ans:
print(*i)
```
| 88,436 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
import sys
import time
input = sys.stdin.readline
n,m=map(int,input().split())
x1=1
y1=1
x2=n
y2=m
arr=[]
for i in range(n*m):
if i%2==0:
arr.append(str(x1)+" "+str(y1))
if x1%2==1:
if y1<m:
y1+=1
else:
x1+=1
else:
if y1>1:
y1-=1
else:
x1+=1
else:
arr.append(str(x2)+" "+str(y2))
if (n-x2)%2==0:
if y2>1:
y2-=1
else:
x2-=1
else:
if y2<m:
y2+=1
else:
x2-=1
print("\n".join(arr))
```
| 88,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Tags: constructive algorithms
Correct Solution:
```
import sys
n, m = list(map(int,sys.stdin.readline().strip().split()))
for i in range (0, n * m):
if i % 2 == 0:
c = i // (2 * n)
r = (i % (2 * n)) // 2
else:
c = m - 1 - i // (2 * n)
r = n - 1 - (i % (2 * n)) // 2
sys.stdout.write(str(r+1) + " " + str(c + 1) + "\n")
```
| 88,438 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
import sys
IS_LOCAL = False
def readMultiple(f):
return f(map(int, input().split()))
def main():
n, m = 2, 3
if not IS_LOCAL:
n, m = readMultiple(tuple)
if n * m == 1:
print(1, 1)
return
res = []
for row in range((n+1)//2):
rev_row = n - row
cell_cnt = m if rev_row != row + 1 else (m + 1) // 2
for i in range(cell_cnt):
res.append(f'{row + 1} {i + 1}')
if not (row + 1 == rev_row and i + 1 == m - i):
res.append(f'{rev_row} {m - i}')
print('\n'.join(res))
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == 'True':
IS_LOCAL = True
main()
```
Yes
| 88,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
n, m = list(map(int,input().split()))
for i in range (0, n * m):
if i % 2 == 0:
c = i // (2 * n)
r = (i % (2 * n)) // 2
else:
c = m - 1 - i // (2 * n)
r = n - 1 - (i % (2 * n)) // 2
print(str(r+1) + " " + str(c + 1))
```
Yes
| 88,440 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
from sys import stdout as so
n, m = [int(x) for x in input().split()]
def printa(x1, x2):
so.write(str(x1) + " " + str(x2) + "\n")
mn = 1
mx = n
while mn < mx:
for i in range(1, m+1):
printa(mn, i)
printa(mx, m-i+1)
mn += 1
mx -= 1
if mn == mx:
for i in range(1, m//2+1):
printa(mn, i)
printa(mn, m-i+1)
if m%2 == 1:
printa(mn, m//2+1)
```
Yes
| 88,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
import sys
m, n = [int(i) for i in input().split()]
data = [0] * (m+1)
for i in range((m+1)//2 ):
data[2*i] = i+1
data[2*i+1] = m - i
for x in range(n//2):
for i in range(m):
sys.stdout.write(str(i+1) + ' ' + str(x+1) + '\n')
sys.stdout.write(str(m-i) + ' ' + str(n-x) + '\n')
#print(i+1, x+1)
#print(m - i, n - x)
if n % 2 == 1:
q = (n+1)//2
s = " " + str(q) + '\n'
for i in range(m):
#print(data[i], q)
sys.stdout.write(str(data[i]) + s)
```
Yes
| 88,442 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
n, m = map(int, input().split())
for i in range(n // 2):
for j in range(m):
if j+1 != m-j:
print(i+1, j+1)
print(n-i, m-j)
else:
print(i+1, j+1)
if n % 2 == 1:
i = n // 2 + 1
for j in range(m):
if j+1 != m-j:
print(i, j+1)
print(i, m-j)
else:
print(i, j+1)
```
No
| 88,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
n, m = map(int, input().split())
for i in range(n // 2):
for j in range(m):
print(i+1, j+1)
print(n-i, m-j)
if n % 2 == 1:
i = n // 2 + 1
for j in range(m):
print(i+1, j+1)
print(i+1, m-j+1)
```
No
| 88,444 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
if __name__ == "__main__":
n, m = [int(x) for x in input().split()]
#n, m = map(int, input().split())
answer = []
for i in range((n + 1) // 2):
for j in range(m):
if i == n // 2 and j == m // 2:
answer.append("{} {}".format(i + 1, j + 1))
break
answer.append("{} {}".format(i + 1, j + 1))
answer.append("{} {}".format(n - i, m - j))
print("\n".join(answer))
```
No
| 88,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n ⋅ m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≤ x ≤ n, 1 ≤ y ≤ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
Input
The first and only line contains two positive integers n, m (1 ≤ n ⋅ m ≤ 10^{6}) — the number of rows and columns of the field respectively.
Output
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n ⋅ m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1, 1) coordinates, according to the statement.
Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
Note
The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2).
Submitted Solution:
```
# [0,0,0]
# [0,0,0]
# [0,0,0]
# [1,0,0]
# [0,0,0]
# [0,0,0]
# [1,0,1]
# [0,0,0]
# [0,0,0]
# [1,1,1]
# [0,0,0]
# [0,0,0]
# [1,1,1]
# [0,0,1]
# [0,0,0]
# [0,0,0] 3,2
#
# 0,0 3,2
# 0,1 3,1
# 0,2 3,0
# 1,0 2,2
# 1,1 2,1
# 1,2 2,0
n, m = map(int, input().split())
if n % 2 == 0:
for i in range(int(n / 2)):
for j in range(m):
print(f'{i+1} {j+1}')
print(f'{n-i} {m-j}')
else:
for i in range(int(n / 2)):
for j in range(m):
print(f'{i+1} {j+1}')
print(f'{n-i} {m-j}')
mid = int(n/2)
for j in range(m//2):
print(f'{mid+1} {j+1}')
print(f'{mid+1} {m-j}')
if m % 2 != 0:
print(f'{n//2+1} {m//2+1}')
"""
0 0 0
0 0 0
1 0 0
0 0 0
1 0 0
0 0 1
1 1 0
0 0 1
1 1 0
0 1 1
1 1 1
0 1 1
1 1 1
1 1 1
"""
```
No
| 88,446 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
# import numpy as np
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return 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
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
def solve():
# for _ in range(ii()):
n=ii()
a=li()
q=ii()
p=[0]*n
suff=[0]*q
for i in range(q):
tc=li()
if tc[0]==1:
x=tc[1]
y=tc[2]
a[x-1]=y
p[x-1]=i
else:
suff[i]=tc[1]
for i in range(q-2,-1,-1):
suff[i]=max(suff[i],suff[i+1])
for i in range(n):
x=p[i]
mx=suff[x]
if a[i]<mx:
a[i]=mx
print(*a)
if __name__ =="__main__":
if path.exists('input.txt'):
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
else:
input=sys.stdin.readline
solve()
```
| 88,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
n = int(input())
a = [[int(q), 0] for q in input().split()]
k = int(input())
was, changes = 0, []
for _ in range(k):
s = list(map(int, input().split()))
if s[0] == 1:
a[s[1]-1] = [s[2], was]
else:
changes.append(s[1])
was += 1
max1 = [-1]
for q in range(len(changes)-1, -1, -1):
max1.append(max(max1[-1], changes[q]))
max1.reverse()
print(*[max(q[0], max1[q[1]]) for q in a])
```
| 88,448 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
from sys import *
from math import *
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
q=int(stdin.readline())
m=[]
mx=0
mx1=0
j=0
for i in range(q):
x=list(map(int,stdin.readline().split()))
m.append(x)
x=[0]*q
for i in range(q):
if m[i][0]==2:
if mx<m[i][1]:
mx=m[i][1]
x[i]=mx
mx=0
if mx1<m[i][1]:
mx1=m[i][1]
mx=x[len(x)-1]
for i in range(len(x)-1,-1,-1):
if x[i]!=0:
if x[i]>mx:
mx=x[i]
x[i]=mx
for i in range(n):
if a[i]<mx1:
a[i]=mx1
for i in range(q):
if m[i][0]==1:
a[m[i][1]-1]=m[i][2]
if a[m[i][1]-1]<x[i]:
a[m[i][1]-1]=x[i]
print(*a)
```
| 88,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
def main():
n = int(input())
money = list(map(int,input().split()))
last_change = [-1]*n
dp = []
q = int(input())
second = []
for i in range(q):
query = list(map(int,input().split()))
if query[0] == 1:
dp.append(-1)
p,x = query[1],query[2]
money[p-1] = x
last_change[p-1] = i
else:
second.append(query[1])
dp.append(query[1])
for i in range(len(dp)-2,-1,-1):
dp[i] = max(dp[i+1],dp[i])
for i in range(n):
if last_change[i] == -1:
money[i] = max(dp[0],money[i])
else:
change = last_change[i]
if change+1 < len(dp):
max_val = dp[change+1]
else:
max_val = -1
money[i] = max(max_val,money[i])
for i in money:
print(i,end = ' ')
main()
```
| 88,450 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
import sys
import math as mt
input=sys.stdin.buffer.readline
t=1
#t=int(input())
for _ in range(t):
n=int(input())
#n,I=map(int,input().split())
l=list(map(int,input().split()))
q=int(input())
l1=[]
for ____ in range(q):
l2=list(map(int,input().split()))
l1.append(l2)
X=-1
#print(l1)
ind={}
ind1={}
suff=[0]*(q+1)
pos=[0]*(n+1)
for i in range(q):
if l1[i][0]==1:
pos[l1[i][1]-1]=i
l[l1[i][1]-1]=l1[i][2]
for i in range(q-1,-1,-1):
if l1[i][0]==2:
suff[i]=l1[i][1]
suff[i]=max(suff[i+1],suff[i])
for i in range(n):
if suff[pos[i]]>l[i]:
l[i]=suff[pos[i]]
print(*l)
```
| 88,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
def main():
n = int(input())
a = list(map(int, input().split()))
q = int(input())
events = []
for _ in range(q):
events.append(list(map(int, input().split())))
max_x2_right = [-1] * len(events)
pos = q-1
while pos >= 0:
if events[pos][0] == 2:
if pos < q-1:
max_x2_right[pos] = max(max_x2_right[pos+1], events[pos][1])
else:
max_x2_right[pos] = events[pos][1]
else:
if pos < q - 1:
max_x2_right[pos] = max_x2_right[pos+1]
pos -= 1
for i in range(n):
a[i] = max(a[i], max_x2_right[0])
for i, e in enumerate(events):
if e[0] == 1:
p = e[1]-1
a[p] = max(e[2], max_x2_right[i])
print(*a)
if __name__ == '__main__':
main()
```
| 88,452 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
"""
Code Forces Template
"""
import os
import sys
import string
import math
def main(balances, events):
"""Algrithm"""
payouts = [0] * len(events)
last_change = [0] * len(balances)
for i in range(len(events)):
if events[i][0] == 1:
_, index, value = events[i]
index -= 1
last_change[index] = i
balances[index] = value
elif events[i][0] == 2:
payouts[i] = events[i][1]
for i in range(len(events) - 2, -1, -1):
payouts[i] = max(payouts[i], payouts[i + 1])
for i in range(len(balances)):
yield max(balances[i], payouts[last_change[i]])
def parse():
"""Load Input"""
n = int(input())
balances = [int(s) for s in input().split(' ')]
event_count = int(input())
events = []
for line in sys.stdin:
if len(events) < event_count:
events.append([int(s) for s in line.split(' ')])
return balances, events
def output(ans):
print(' '.join([str(i) for i in ans]))
if __name__ == '__main__':
output(main(*parse()))
```
| 88,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
n = int(input())
a = [int(s) for s in input().split()]
q = int(input())
b = [None]*n
rnd = 0
xs = []
for i in range(q):
qi = [int(s) for s in input().split()]
if qi[0] == 1:
b[qi[1]-1] = (qi[2], rnd)
else:
xs.append(qi[1])
rnd += 1
maxx = 0
if xs:
maxx = xs[-1]
for i in range(len(xs)-2, -1, -1):
if xs[i] < maxx:
xs[i] = maxx
else:
maxx = xs[i]
xs.append(0)
for i in range(n):
if not b[i]:
a[i] = max(maxx, a[i])
else:
a[i] = max(b[i][0], xs[b[i][1]])
print(*a)
```
| 88,454 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
import sys
n=int(sys.stdin.readline())
a=[int(i) for i in sys.stdin.readline().split()]
q=int(sys.stdin.readline())
# maxi=-2
# ind=-2
arr=[0]*n
upd=[-2]*q
for w in range(q):
event=[int(j) for j in sys.stdin.readline().split()]
if(event[0]==1):
p=event[1]
x=event[2]
a[p-1]=x
arr[p-1]=w
else:
x=event[1]
upd[w]=x
# if(maxi<=x):
# maxi=x
# ind=w
for h in range(q-2,-1,-1):
upd[h]=max(upd[h],upd[h+1])
for g in range(n):
a[g]=max(a[g],upd[arr[g]])
a[g]=str(a[g])
print(" ".join(a))
```
Yes
| 88,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
# @author
import sys
class DWelfareState:
def solve(self):
n = int(input())
a = [int(_) for _ in input().split()]
q = int(input())
queries = []
v = [[-1, a[i]] for i in range(n)]
x_max = [-float('inf')] * (q + 1)
for qi in range(q):
query = [int(_) for _ in input().split()]
queries.append(query)
type = query[0]
if type == 1:
i, x = query[1:]
i -= 1
v[i] = [qi, x]
# x_max[qi] = x_max[qi - 1]
else:
x = query[1]
x_max[qi] = max(x_max[qi - 1], x)
suff = [0] * (q + 1)
suff[-1] = -float('inf')
for i in range(q - 1, -1, -1):
suff[i] = max(suff[i + 1], x_max[i])
ans = [0] * n
for i in range(n):
ans[i] = max(suff[v[i][0] + 1], v[i][1])
# print(v)
# print(x_max)
print(*ans)
solver = DWelfareState()
input = sys.stdin.readline
solver.solve()
```
Yes
| 88,456 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
import bisect,sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
a = inl()
q = inn()
spend = []
pay = []
mx = 0
for i in range(q):
c = inl()
if c[0]==1:
spend.append((i,c[1],c[2]))
else:
pay.append((i,c[1]))
if c[1]>mx:
mx = c[1]
m = len(pay)
accpay = [(0,0)] * (m+1)
for i in range(m-1,-1,-1):
accpay[i] = (pay[i][0], max(accpay[i+1][1], pay[i][1]))
accpay[m] = (999999999,0)
b = [0]*n
for i in range(n):
b[i] = max(a[i],mx)
for z in spend:
idx = bisect.bisect_left(accpay, (z[0],z[1]))
if idx >= m:
b[z[1]-1] = z[2]
else:
b[z[1]-1] = max(z[2], accpay[idx][1])
for i in range(n):
printn(("" if i==0 else " ") + str(b[i]))
print("")
```
Yes
| 88,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import log2, ceil
from bisect import bisect_right as br, bisect_left as bl
n, = I()
l = I()
q, = I()
p = 0
t = []
while q:
q -= 1
t.append(I())
mx = 0
ans = [-1]*n
for i in t[::-1]:
if i[0] == 1:
i[1] -= 1
if ans[i[1]] == -1:
ans[i[1]] = max(mx, i[2])
else:
mx = max(mx, i[1])
for i in range(n):
if ans[i] == -1:
ans[i] = max(mx, l[i])
print(*ans)
```
Yes
| 88,458 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
from sys import *
from math import *
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
q=int(stdin.readline())
m=[]
mx=0
j=0
for i in range(q):
x=list(map(int,stdin.readline().split()))
m.append(x)
for i in range(q):
if m[i][0]==2:
if mx<m[i][1]:
mx=m[i][1]
j=i
for i in range(j):
if m[i][0]==1:
a[m[i][1]-1]=m[i][2]
for i in range(n):
if a[i]<mx:
a[i]=mx
for i in range(j,q):
if m[i][0]==1:
a[m[i][1]-1]=m[i][2]
print(*a)
```
No
| 88,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
import sys
import math as mt
input=sys.stdin.buffer.readline
t=1
#t=int(input())
for _ in range(t):
n=int(input())
#n,I=map(int,input().split())
l=list(map(int,input().split()))
q=int(input())
l1=[]
for ____ in range(q):
l2=list(map(int,input().split()))
l1.append(l2)
X=-1
#print(l1)
ind={}
for i in range(q-1,-1,-1):
if l1[i][0]==2:
X=max(l1[i][1],X)
else:
#print(111,l1[i],X)
if l1[i][2]>X:
ind[l1[i][1]-1]=1
l[l1[i][1]-1]=l1[i][2]
else:
l[l1[i][1]-1]=-1
#print(ind)
for i in range(n):
if l[i]<X and ind.get(i,-1)==-1:
l[i]=X
print(*l)
```
No
| 88,460 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
def main():
n = int(input())
money = list(map(int,input().split()))
last_change = [-1]*n
dp = []
q = int(input())
second = []
for i in range(q):
query = list(map(int,input().split()))
if query[0] == 1:
if dp:
dp.append(dp[-1])
else:
dp.append(0)
p,x = query[1],query[2]
money[p-1] = x
last_change[p-1] = i
else:
second.append(query[1])
dp.append(query[1])
for i in range(len(dp)-2,-1,-1):
dp[i] = max(dp[i-1],dp[i])
for i in range(n):
if last_change[i] == -1:
money[i] = max(dp[0],money[i])
else:
change = last_change[i]
if change+1 < len(dp):
max_val = dp[change+1]
else:
max_val = -1
money[i] = max(max_val,money[i])
for i in money:
print(i,end = ' ')
main()
```
No
| 88,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
n = int(input())
lis=list(map(int,input().split()))
lis=[[0,i] for i in lis]
k = int(input())
mmm=0
c=sss=0
for i in range(k):
m = input()
if m[0]=='1':
c+=1
l,q,o=m.split()
q=int(q)
o=int(o)
lis[q-1][1]=o
lis[q-1][0]=c
else:
q,o=m.split()
o=int(o)
if o>=mmm:
sss=c
mmm=o
for i in range(n):
if lis[i][1]<mmm and lis[i][0]<=sss:
lis[i][1]=mmm
for i in range(n):
print(lis[i][1],sep=' ',end=' ')
```
No
| 88,462 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
import sys
def over_lap(rect1, rect2):
x1, y1, x2, y2 = rect1
x3, y3, x4, y4 = rect2
if x2 < x3 or x4 < x1 or y2 < y3 or y4 < y1:
return (0, 0, 0, 0)
else:
return (max(x1, x3), max(y1, y3), min(x2, x4), min(y2, y4))
def get_area(rect):
x1, y1, x2, y2 = rect
return (x2-x1) * (y2-y1)
def is_all_cover(rect1, rect2, rect3):
over1 = over_lap(rect1, rect2)
over2 = over_lap(rect1, rect3)
over3 = over_lap(over1, over2)
area = get_area(over1) + get_area(over2) - get_area(over3)
if area == get_area(rect1):
return "NO"
else:
return "YES"
rect1 = [int(i) for i in sys.stdin.readline().strip().split(' ')]
rect2 = [int(i) for i in sys.stdin.readline().strip().split(' ')]
rect3 = [int(i) for i in sys.stdin.readline().strip().split(' ')]
print(is_all_cover(rect1, rect2, rect3))
```
| 88,463 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
import sys
def intersection(x1,y1,x2,y2,x3,y3,x4,y4):
a1=max(x1,x3)
b1=max(y1,y3)
a2=min(x2,x4)
b2=min(y2,y4)
x_dist=min(x2,x4)-max(x1,x3)
y_dist=min(y2,y4)-max(y1,y3)
if(x_dist<=0 or y_dist<=0):
return [0,0,0,0]
return [a1,b1,a2,b2]
def area(x1,y1,x2,y2):
return (x2-x1)*(y2-y1)
[x1,y1,x2,y2]=[int(i) for i in sys.stdin.readline().split()]
[x3,y3,x4,y4]=[int(j) for j in sys.stdin.readline().split()]
[x5,y5,x6,y6]=[int(k) for k in sys.stdin.readline().split()]
wb1=intersection(x1,y1,x2,y2,x3,y3,x4,y4)
wb2=intersection(x1,y1,x2,y2,x5,y5,x6,y6)
wb1b2=intersection(wb1[0],wb1[1],wb1[2],wb1[3],wb2[0],wb2[1],wb2[2],wb2[3])
# wb1b2=intersection(x3,y3,x4,y4,x5,y5,x6,y6)
# print(area(x1,y1,x2,y2),area(wb1[0],wb1[1],wb1[2],wb1[3]),area(wb2[0],wb2[1],wb2[2],wb2[3]),area(wb1b2[0],wb1b2[1],wb1b2[2],wb1b2[3]))
if(area(x1,y1,x2,y2)>area(wb1[0],wb1[1],wb1[2],wb1[3])+area(wb2[0],wb2[1],wb2[2],wb2[3])-area(wb1b2[0],wb1b2[1],wb1b2[2],wb1b2[3])):
print("YES")
else:
print("NO")
```
| 88,464 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
c = lambda s: [(s[0 if (i&1) else 2], s[1 if (i&2) else 3]) for i in range(4)]
ins = lambda p,s: s[0] <= p[0] <= s[2] and s[1] <= p[1] <= s[3]
w = list(map(int,input().split()))
b = [list(map(int,input().split())) for _ in '12']
cn = [set(i for i,p in enumerate(c(w)) if ins(p, s)) for s in b]
if len(cn[0]|cn[1]) < 4: print('YES')
elif len(cn[0])==4 or len(cn[1])==4: print('NO')
elif min(b[0][2], b[1][2]) < max(b[0][0], b[1][0]): print('YES')
else: print('YES' if min(b[0][3], b[1][3]) < max(b[0][1], b[1][1]) else 'NO')
```
| 88,465 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
x5, y5, x6, y6 = map(int, input().split())
def per(a):
x1, y1, x2, y2, x3, y3, x4, y4 = a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]
left = max(x1, x3)
right = min(x2, x4)
top = min(y2, y4)
bottom = max(y1, y3)
if left > right or bottom > top:
return([0, 0, 0, 0])
return([left, bottom, right, top])
def s(a):
x1, y1, x2, y2 = a[0], a[1], a[2], a[3]
return (x2 - x1) * (y2 - y1)
s1 = s(per([x1, y1, x2, y2, x3, y3, x4, y4]))
s2 = s(per([x1, y1, x2, y2, x5, y5, x6, y6]))
s3 = s(per([x1, y1, x2, y2] + per([x3, y3, x4, y4, x5, y5, x6, y6])))
if s1 + s2 - s3 >= s([x1, y1, x2, y2]):
print('NO')
else:
print('YES')
#print(s1, s2, s3)
```
| 88,466 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
i1 = input('').split(' ')
x1 = int(i1[0])
y1 = int(i1[1])
x2 = int(i1[2])
y2 = int(i1[3])
i1 = input('').split(' ')
x3 = int(i1[0])
y3 = int(i1[1])
x4 = int(i1[2])
y4 = int(i1[3])
i1 = input('').split(' ')
x5 = int(i1[0])
y5 = int(i1[1])
x6 = int(i1[2])
y6 = int(i1[3])
def chk(x1,y1,x2,y2,x3,y3):
if(x3 <= x2 and x3 >= x1 and y3 >= y1 and y3 <= y2):
return True
else:
return False
r11 = chk(x3,y3,x4,y4,x1,y1)
r12 = chk(x5,y5,x6,y6,x1,y1)
r21 = chk(x3,y3,x4,y4,x2,y1)
r22 = chk(x5,y5,x6,y6,x2,y1)
r31 = chk(x3,y3,x4,y4,x1,y2)
r32 = chk(x5,y5,x6,y6,x1,y2)
r41 = chk(x3,y3,x4,y4,x2,y2)
r42 = chk(x5,y5,x6,y6,x2,y2)
def car(x1,y1,x2,y2,x3,y3,x4,y4):
yy1 = max(y1,y3)
yy2 = min(y2,y4)
xx1 = max(x1,x3)
xx2 = min(x2,x4)
area = (abs(yy1 - yy2))*(abs(xx1 - xx2))
return area
if((r11 or r12) and (r21 or r22) and (r31 or r32) and (r41 or r42)):
a1 = car(x1,y1,x2,y2,x3,y3,x4,y4)
a2 = car(x1,y1,x2,y2,x5,y5,x6,y6)
ta = a1 + a2
if(ta >= (x2-x1)*(y2-y1)):
print('NO')
else:
print('YES')
else:
print('YES')
```
| 88,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
def inside(x1, y1, x2, y2, x3, y3, x4, y4):
return x3 <= x1 <= x4 and y3 <= y1 <= y4 and x3 <= x2 <= x4 and y3 <= y2 <= y4
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
x5, y5, x6, y6 = map(int, input().split())
ok = False
if inside(x1, y1, x2, y2, x3, y3, x4, y4) or inside(x1, y1, x2, y2, x5, y5, x6, y6):
ok = True
if y3 <= y1 <= y4 and y3 <= y2 <= y4 and x3 <= x1 <= x4 and y5 <= y1 <= y6 and y5 <= y2 <= y6 and x5 <= x2 <= x6 and x5 <= x4:
ok = True
if y3 <= y1 <= y4 and y3 <= y2 <= y4 and x3 <= x2 <= x4 and y5 <= y1 <= y6 and y5 <= y2 <= y6 and x5 <= x1 <= x6 and x3 <= x6:
ok = True
if x3 <= x1 <= x4 and x3 <= x2 <= x4 and y3 <= y1 <= y4 and x5 <= x1 <= x6 and x5 <= x2 <= x6 and y5 <= y2 <= y6 and y5 <= y4:
ok = True
if x3 <= x1 <= x4 and x3 <= x2 <= x4 and y3 <= y2 <= y4 and x5 <= x1 <= x6 and x5 <= x2 <= x6 and y5 <= y1 <= y6 and y3 <= y6:
ok = True
if ok:
print("NO")
else:
print("YES")
```
| 88,468 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
def cut(A, B):
"""
B interior in A
"""
return [(max([A[0][0], B[0][0]]), max([A[0][1], B[0][1]])),
(min([A[1][0], B[1][0]]), min([A[1][1], B[1][1]]))]
def area(A):
if A[1][0] < A[0][0] or A[1][1] < A[0][1]:
return 0
return max([(A[1][0] - A[0][0]) * (A[1][1] - A[0][1]), 0])
def common_area(A, B):
return area(cut(A, B))
A = [int(x) for x in input().split()]
A = [[A[0], A[1]], [A[2], A[3]]]
B = [int(x) for x in input().split()]
B = [[B[0], B[1]], [B[2], B[3]]]
C = [int(x) for x in input().split()]
C = [[C[0], C[1]], [C[2], C[3]]]
print("YES" if area(A) - common_area(A, B) - common_area(A, C) +
common_area(cut(A, B), cut(A, C)) > 0 else "NO")
```
| 88,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Tags: geometry, math
Correct Solution:
```
def intersection(a, b):
return max(a[0], b[0]), max(a[1], b[1]), min(a[2], b[2]), min(a[3], b[3])
def area(lst):
return max(lst[2] - lst[0], 0) * max(lst[3] - lst[1], 0)
w = [int(i) for i in input().split()]
lst1 = [int(i) for i in input().split()]
lst2 = [int(i) for i in input().split()]
if area(intersection(w, lst1)) + area(intersection(w, lst2)) - area(intersection(w, intersection(lst1, lst2))) == area(
w):
print("NO")
else:
print("YES")
```
| 88,470 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
def intersect(x1, y1, x2, y2, x3, y3, x4, y4):
ax = max(x1, x3)
bx = min(x2, x4)
ay = max(y1, y3)
by = min(y2, y4)
if bx < ax or by < ay:
return 0, 0, 0, 0
else:
return ax, ay, bx, by
def square(x1, y1, x2, y2):
return (x2 - x1) * (y2 - y1)
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
x5, y5, x6, y6 = map(int, input().split())
px1, py1, px2, py2 = intersect(x1, y1, x2, y2, x3, y3, x4, y4)
px3, py3, px4, py4 = intersect(x1, y1, x2, y2, x5, y5, x6, y6)
ax, ay, bx, by = intersect(px1, py1, px2, py2, px3, py3, px4, py4)
if square(x1, y1, x2, y2) > square(px1, py1, px2, py2) + square(px3, py3, px4, py4) - square(ax, ay, bx, by):
print('YES')
else:
print('NO')
```
Yes
| 88,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
import datetime
def count_time(func):
def int_time(*args, **kwargs):
print('*' * 10,'Code start running!')
start_time = datetime.datetime.now() # 程序开始时间
func()
over_time = datetime.datetime.now() # 程序结束时间
total_time = (over_time-start_time).total_seconds()
print('*' * 10, 'Total time: %s' % total_time)
return int_time
def area(rec):
x1, y1, x2, y2 = rec
return (x2 - x1) * (y2 - y1)
def compute_iou(rec1, rec2):
S_rec1 = (rec1[2] - rec1[0]) * (rec1[3] - rec1[1])
S_rec2 = (rec2[2] - rec2[0]) * (rec2[3] - rec2[1])
sum_area = S_rec1 + S_rec2
left_line = max(rec1[1], rec2[1])
right_line = min(rec1[3], rec2[3])
top_line = max(rec1[0], rec2[0])
bottom_line = min(rec1[2], rec2[2])
if left_line >= right_line or top_line >= bottom_line:
return 0
else:
intersect = (right_line - left_line) * (bottom_line - top_line)
return intersect
def min_rec(rec1, rec2):
rec2[0] = max(rec1[0], rec2[0])
rec2[1] = max(rec1[1], rec2[1])
rec2[2] = min(rec1[2], rec2[2])
rec2[3] = min(rec1[3], rec2[3])
if rec2[0] >= rec2[2] or rec2[1] >= rec2[3]:
return (0, 0, 0, 0)
return rec2
#@count_time
def main():
rec1 = list(map(int, input().strip().split()))
rec2 = list(map(int, input().strip().split()))
rec3 = list(map(int, input().strip().split()))
rec2 = min_rec(rec1, rec2)
rec3 = min_rec(rec1, rec3)
a = compute_iou(rec1, rec2)
b = compute_iou(rec1, rec3)
c = compute_iou(rec2, rec3)
ans = area(rec1) - a - b + c
if ans > 0:
print('YES')
else :
print('NO')
if __name__ == '__main__':
main()
```
Yes
| 88,472 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
x1,y1,x2,y2=list(map(int,input().split()))
x3,y3,x4,y4=list(map(int,input().split()))
x5,y5,x6,y6=list(map(int,input().split()))
px1=max(0,min(x2,x4)-max(x1,x3))#пересечение по х белого и 1-го чёрного
py1=max(0,min(y2,y4)-max(y1,y3))#пересечение по y белого и 1-го чёрного
px2=max(0,min(x2,x6)-max(x1,x5))#пересечение по х белого и 2-го чёрного
py2=max(0,min(y2,y6)-max(y1,y5))#пересечение по y белого и 2-го чёрного
px=max(0,min(x2,x4,x6)-max(x1,x3,x5))#общее пересечение по х
py=max(0,min(y2,y4,y6)-max(y1,y3,y5))#общее пересечение по y
if px1*py1+px2*py2-px*py==(x2-x1)*(y2-y1):print('NO')
else:print('YES')
```
Yes
| 88,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
a = [list(map(int, input().split())) for _ in range(3)]
def area(v):
return max(0, v[2] - v[0]) * max(0, v[3] - v[1])
def clip(v1, v2):
return [max(v1[0], v2[0]), max(v1[1], v2[1]), min(v1[2], v2[2]), min(v1[3], v2[3])]
print('YES' if area(clip(a[0], a[1])) + area(clip(a[0], a[2])) - area(clip(a[0], clip(a[1], a[2]))) < area(a[0]) else 'NO')
```
Yes
| 88,474 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
a= list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
if(b[0]<=a[0]and b[1]<=a[1]):
if(b[2]>=a[2] and b[3]>=a[3]):
print('NO')
elif (b[2]>=a[2]):
x=a[0]
y=b[3]
if(c[0]<=x and c[1]<=y):
if(c[2]>=a[2] and c[3]>=a[3]):
print('NO')
else:
print('YES')
else:
print('YES')
elif b[3]>=a[3]:
x = b[2]
y = a[1]
# print(x,y)
if (c[0] <= x and c[1] <= y):
if (c[2] >= a[2] and c[3] >= a[3]):
print('NO')
else:
print('YES')
else:
print('YES')
elif(c[0]<=a[0]and c[1]<=a[1]):
if(c[2]>=a[2] and c[3]>=a[3]):
print('NO')
elif (c[2]>=a[2]):
x=a[0]
y=c[3]
if(b[0]<=x and b[1]<=y):
if(b[2]>=a[2] and b[3]>=a[3]):
print('NO')
else:
print('YES')
else:
print('YES')
elif c[3]>=a[3]:
x = c[2]
y = a[1]
if (b[0] <= x and b[1] <= y):
if (b[2] >= a[2] and b[3] >= a[3]):
print('NO')
else:
print('YES')
else:
print('YES')
else:
print('YES')
```
No
| 88,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
import sys
x1, y1, x2, y2 = map(int, sys.stdin.readline().split())
x3, y3, x4, y4 = map(int, sys.stdin.readline().split())
x5, y5, x6, y6 = map(int, sys.stdin.readline().split())
con1 = x1 >= x3 and x2 <= x4 and y1 >= y3 and y2 <= y4
con2 = x1 >= x5 and x2 <= x6 and y1 >= y5 and y2 <= y6
if con1 or con2:
# print("call1")
print("NO")
else:
con3 = y6 <= y4 and x3 <= x6
con4 = y6 >= y4 and x4 >= x5
con5 = x6 >= x4 and y4 >= y5
con6 = x6 <= x4 and y6 >= y3
if con3 or con4:
if con4:
x4, y4 = x6, y6
x3, y3 = x5, y5
con7 = x5 <= x1 and x3 <= x1 and x6 >= x2 and x4 >= x2 and y5 <= y1 and y4 >= y2 and y6 >= y3
if con7:
# print("call2")
print("NO")
else:
# print("call3")
print("YES")
elif con5 or con6:
if con6:
x4, y4 = x6, y6
x3, y3 = x5, y5
con8 = y4 >= y2 and y6 >= y2 and y3 >= y1 and y5 >= y1 and x3 >= x1 and x6 >= x2 and x4 >= x5
if con8:
# print("call4")
print("NO")
else:
# print("call5")
print("YES")
```
No
| 88,476 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
a = [list(map(int, input().split())) for _ in range(3)]
def area(v):
return max(0, v[2] - v[0]) * max(0, v[3] - v[1])
def clip(v1, v2):
return area([max(v1[0], v2[0]), max(v1[1], v2[1]), min(v1[2], v2[2]), min(v1[3], v2[3])])
print('YES' if clip(a[0], a[1]) + clip(a[0], a[2]) - clip(a[1], a[2]) < area(a[0]) else 'NO')
```
No
| 88,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x_1, y_1), and the top right — (x_2, y_2).
After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x_3, y_3), and the top right — (x_4, y_4). Coordinates of the bottom left corner of the second black sheet are (x_5, y_5), and the top right — (x_6, y_6).
<image> Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.
Input
The first line of the input contains four integers x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 10^{6}, 0 ≤ y_1 < y_2 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the white sheet.
The second line of the input contains four integers x_3, y_3, x_4, y_4 (0 ≤ x_3 < x_4 ≤ 10^{6}, 0 ≤ y_3 < y_4 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the first black sheet.
The third line of the input contains four integers x_5, y_5, x_6, y_6 (0 ≤ x_5 < x_6 ≤ 10^{6}, 0 ≤ y_5 < y_6 ≤ 10^{6}) — coordinates of the bottom left and the top right corners of the second black sheet.
The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.
Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".
Examples
Input
2 2 4 4
1 1 3 5
3 1 5 5
Output
NO
Input
3 3 7 5
0 0 4 6
0 0 7 4
Output
YES
Input
5 2 10 5
3 1 7 6
8 1 11 7
Output
YES
Input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
Output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5, 4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
Submitted Solution:
```
import random
a=random.randint(1,2)
if a == 1:
print('YES')
if a == 2:
print('NO')
```
No
| 88,478 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are n residents and n cats in the Catowice, and each resident has exactly one cat living in his house. The residents and cats are numbered with integers from 1 to n, where the i-th cat is living in the house of i-th resident.
Each Catowice resident is in friendship with several cats, including the one living in his house. In order to conduct a contest, at least one jury member is needed and at least one cat contestant is needed. Of course, every jury member should know none of the contestants. For the contest to be successful, it's also needed that the number of jury members plus the number of contestants is equal to n.
Please help Catowice residents to select the jury and the contestants for the upcoming competition, or determine that it's impossible to do.
Input
The first line contains an integer t (1 ≤ t ≤ 100 000), the number of test cases. Then description of t test cases follow, where each description is as follows:
The first line contains integers n and m (1 ≤ n ≤ m ≤ 10^6), the number of Catowice residents and the number of friendship pairs between residents and cats.
Each of the next m lines contains integers a_i and b_i (1 ≤ a_i, b_i ≤ n), denoting that a_i-th resident is acquaintances with b_i-th cat. It's guaranteed that each pair of some resident and some cat is listed at most once.
It's guaranteed, that for every i there exists a pair between i-th resident and i-th cat.
Different test cases are separated with an empty line.
It's guaranteed, that the sum of n over all test cases is at most 10^6 and that the sum of m over all test cases is at most 10^6.
Output
For every test case print:
* "No", if it's impossible to select the jury and contestants.
* Otherwise print "Yes".
In the second line print two integers j and p (1 ≤ j, 1 ≤ p, j + p = n) — the number of jury members and the number of contest participants.
In the third line print j distinct integers from 1 to n, the indices of the residents forming a jury.
In the fourth line print p distinct integers from 1 to n, the indices of the cats, which will participate in the contest.
In case there are several correct answers, print any of them.
Example
Input
4
3 4
1 1
2 2
3 3
1 3
3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3
1 1
1 1
2 4
1 1
1 2
2 1
2 2
Output
Yes
2 1
1 3
2
Yes
1 2
2
1 3
No
No
Note
In the first test case, we can select the first and the third resident as a jury. Both of them are not acquaintances with a second cat, so we can select it as a contestant.
In the second test case, we can select the second resident as a jury. He is not an acquaintances with a first and a third cat, so they can be selected as contestants.
In the third test case, the only resident is acquaintances with the only cat, so they can't be in the contest together. So it's not possible to make a contest with at least one jury and at least one cat.
In the fourth test case, each resident is acquaintances with every cat, so it's again not possible to make a contest with at least one jury and at least one cat.
Submitted Solution:
```
import sys
def dfs1(v):
used[v] = True
for u in graph[v]:
if not used[u]:
dfs1(u)
order.append(v)
def dfs2(v, c):
comp[v] = c
for u in transparent_graph[v]:
if comp[u] is None:
dfs2(u, c)
"""
fin = open("fin.txt", "r")
fout = open("fout.txt", "w")
"""
fin = sys.stdin
fout = sys.stdout
t = int(fin.readline())
for test in range(t):
n, m = map(int, fin.readline().split())
graph = [list() for i in range(n)]
transparent_graph = [list() for i in range(n)]
for i in range(m):
w, c = map(int, fin.readline().split())
w -= 1
c -= 1
# !w or !c
# it means that w => !c
# or c => !w
graph[w].append(c)
transparent_graph[c].append(w)
order = list()
used = [False] * n
for i in range(n):
if not used[i]:
dfs1(i)
order.reverse()
comp = [None] * n
c = 1
for v in order:
if comp[v] is None:
dfs2(v, c)
c += 1
if c == 2:
print("No", file=fout)
fin.readline()
continue
villagers = list()
cats = list()
for i in range(n):
if comp[i] == 1:
villagers.append(i + 1)
else:
cats.append(i + 1)
if len(villagers) == 0 or len(cats) == 0:
print("No", file=fout)
fin.readline()
continue
print("Yes", file=fout)
print(len(villagers), len(cats), file=fout)
for i in villagers:
print(i, end=" ", file=fout)
print(file=fout)
for i in cats:
print(i, end=" ", file=fout)
print(file=fout)
fin.readline()
```
No
| 88,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are n residents and n cats in the Catowice, and each resident has exactly one cat living in his house. The residents and cats are numbered with integers from 1 to n, where the i-th cat is living in the house of i-th resident.
Each Catowice resident is in friendship with several cats, including the one living in his house. In order to conduct a contest, at least one jury member is needed and at least one cat contestant is needed. Of course, every jury member should know none of the contestants. For the contest to be successful, it's also needed that the number of jury members plus the number of contestants is equal to n.
Please help Catowice residents to select the jury and the contestants for the upcoming competition, or determine that it's impossible to do.
Input
The first line contains an integer t (1 ≤ t ≤ 100 000), the number of test cases. Then description of t test cases follow, where each description is as follows:
The first line contains integers n and m (1 ≤ n ≤ m ≤ 10^6), the number of Catowice residents and the number of friendship pairs between residents and cats.
Each of the next m lines contains integers a_i and b_i (1 ≤ a_i, b_i ≤ n), denoting that a_i-th resident is acquaintances with b_i-th cat. It's guaranteed that each pair of some resident and some cat is listed at most once.
It's guaranteed, that for every i there exists a pair between i-th resident and i-th cat.
Different test cases are separated with an empty line.
It's guaranteed, that the sum of n over all test cases is at most 10^6 and that the sum of m over all test cases is at most 10^6.
Output
For every test case print:
* "No", if it's impossible to select the jury and contestants.
* Otherwise print "Yes".
In the second line print two integers j and p (1 ≤ j, 1 ≤ p, j + p = n) — the number of jury members and the number of contest participants.
In the third line print j distinct integers from 1 to n, the indices of the residents forming a jury.
In the fourth line print p distinct integers from 1 to n, the indices of the cats, which will participate in the contest.
In case there are several correct answers, print any of them.
Example
Input
4
3 4
1 1
2 2
3 3
1 3
3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3
1 1
1 1
2 4
1 1
1 2
2 1
2 2
Output
Yes
2 1
1 3
2
Yes
1 2
2
1 3
No
No
Note
In the first test case, we can select the first and the third resident as a jury. Both of them are not acquaintances with a second cat, so we can select it as a contestant.
In the second test case, we can select the second resident as a jury. He is not an acquaintances with a first and a third cat, so they can be selected as contestants.
In the third test case, the only resident is acquaintances with the only cat, so they can't be in the contest together. So it's not possible to make a contest with at least one jury and at least one cat.
In the fourth test case, each resident is acquaintances with every cat, so it's again not possible to make a contest with at least one jury and at least one cat.
Submitted Solution:
```
print('NO')
```
No
| 88,480 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are n residents and n cats in the Catowice, and each resident has exactly one cat living in his house. The residents and cats are numbered with integers from 1 to n, where the i-th cat is living in the house of i-th resident.
Each Catowice resident is in friendship with several cats, including the one living in his house. In order to conduct a contest, at least one jury member is needed and at least one cat contestant is needed. Of course, every jury member should know none of the contestants. For the contest to be successful, it's also needed that the number of jury members plus the number of contestants is equal to n.
Please help Catowice residents to select the jury and the contestants for the upcoming competition, or determine that it's impossible to do.
Input
The first line contains an integer t (1 ≤ t ≤ 100 000), the number of test cases. Then description of t test cases follow, where each description is as follows:
The first line contains integers n and m (1 ≤ n ≤ m ≤ 10^6), the number of Catowice residents and the number of friendship pairs between residents and cats.
Each of the next m lines contains integers a_i and b_i (1 ≤ a_i, b_i ≤ n), denoting that a_i-th resident is acquaintances with b_i-th cat. It's guaranteed that each pair of some resident and some cat is listed at most once.
It's guaranteed, that for every i there exists a pair between i-th resident and i-th cat.
Different test cases are separated with an empty line.
It's guaranteed, that the sum of n over all test cases is at most 10^6 and that the sum of m over all test cases is at most 10^6.
Output
For every test case print:
* "No", if it's impossible to select the jury and contestants.
* Otherwise print "Yes".
In the second line print two integers j and p (1 ≤ j, 1 ≤ p, j + p = n) — the number of jury members and the number of contest participants.
In the third line print j distinct integers from 1 to n, the indices of the residents forming a jury.
In the fourth line print p distinct integers from 1 to n, the indices of the cats, which will participate in the contest.
In case there are several correct answers, print any of them.
Example
Input
4
3 4
1 1
2 2
3 3
1 3
3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3
1 1
1 1
2 4
1 1
1 2
2 1
2 2
Output
Yes
2 1
1 3
2
Yes
1 2
2
1 3
No
No
Note
In the first test case, we can select the first and the third resident as a jury. Both of them are not acquaintances with a second cat, so we can select it as a contestant.
In the second test case, we can select the second resident as a jury. He is not an acquaintances with a first and a third cat, so they can be selected as contestants.
In the third test case, the only resident is acquaintances with the only cat, so they can't be in the contest together. So it's not possible to make a contest with at least one jury and at least one cat.
In the fourth test case, each resident is acquaintances with every cat, so it's again not possible to make a contest with at least one jury and at least one cat.
Submitted Solution:
```
import sys
def dfs1(v):
used[v] = True
for u in graph[v]:
if not used[u]:
dfs1(u)
order.append(v)
def dfs2(v, c):
comp[v] = c
for u in transparent_graph[v]:
if comp[u] is None:
dfs2(u, c)
"""
fin = open("fin.txt", "r")
fout = open("fout.txt", "w")
"""
fin = sys.stdin
fout = sys.stdout
t = int(fin.readline())
for test in range(t):
n, m = map(int, fin.readline().split())
graph = [list() for i in range(n)]
transparent_graph = [list() for i in range(n)]
for i in range(m):
w, c = map(int, fin.readline().split())
w -= 1
c -= 1
# !w or !c
# it means that w => !c
# or c => !w
graph[w].append(c)
transparent_graph[c].append(w)
order = list()
used = [False] * n
for i in range(n):
if not used[i]:
dfs1(i)
order.reverse()
comp = [None] * n
c = 1
for v in order:
if comp[v] is None:
dfs2(v, c)
c += 1
if c == 1:
print("No", file=fout)
fin.readline()
continue
villagers = list()
cats = list()
for i in range(n):
if comp[i] == 1:
villagers.append(i + 1)
else:
cats.append(i + 1)
if len(villagers) == 0 or len(cats) == 0:
print("No", file=fout)
fin.readline()
continue
print("Yes", file=fout)
print(len(villagers), len(cats), file=fout)
for i in villagers:
print(i, end=" ", file=fout)
print(file=fout)
for i in cats:
print(i, end=" ", file=fout)
print(file=fout)
fin.readline()
```
No
| 88,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are n residents and n cats in the Catowice, and each resident has exactly one cat living in his house. The residents and cats are numbered with integers from 1 to n, where the i-th cat is living in the house of i-th resident.
Each Catowice resident is in friendship with several cats, including the one living in his house. In order to conduct a contest, at least one jury member is needed and at least one cat contestant is needed. Of course, every jury member should know none of the contestants. For the contest to be successful, it's also needed that the number of jury members plus the number of contestants is equal to n.
Please help Catowice residents to select the jury and the contestants for the upcoming competition, or determine that it's impossible to do.
Input
The first line contains an integer t (1 ≤ t ≤ 100 000), the number of test cases. Then description of t test cases follow, where each description is as follows:
The first line contains integers n and m (1 ≤ n ≤ m ≤ 10^6), the number of Catowice residents and the number of friendship pairs between residents and cats.
Each of the next m lines contains integers a_i and b_i (1 ≤ a_i, b_i ≤ n), denoting that a_i-th resident is acquaintances with b_i-th cat. It's guaranteed that each pair of some resident and some cat is listed at most once.
It's guaranteed, that for every i there exists a pair between i-th resident and i-th cat.
Different test cases are separated with an empty line.
It's guaranteed, that the sum of n over all test cases is at most 10^6 and that the sum of m over all test cases is at most 10^6.
Output
For every test case print:
* "No", if it's impossible to select the jury and contestants.
* Otherwise print "Yes".
In the second line print two integers j and p (1 ≤ j, 1 ≤ p, j + p = n) — the number of jury members and the number of contest participants.
In the third line print j distinct integers from 1 to n, the indices of the residents forming a jury.
In the fourth line print p distinct integers from 1 to n, the indices of the cats, which will participate in the contest.
In case there are several correct answers, print any of them.
Example
Input
4
3 4
1 1
2 2
3 3
1 3
3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3
1 1
1 1
2 4
1 1
1 2
2 1
2 2
Output
Yes
2 1
1 3
2
Yes
1 2
2
1 3
No
No
Note
In the first test case, we can select the first and the third resident as a jury. Both of them are not acquaintances with a second cat, so we can select it as a contestant.
In the second test case, we can select the second resident as a jury. He is not an acquaintances with a first and a third cat, so they can be selected as contestants.
In the third test case, the only resident is acquaintances with the only cat, so they can't be in the contest together. So it's not possible to make a contest with at least one jury and at least one cat.
In the fourth test case, each resident is acquaintances with every cat, so it's again not possible to make a contest with at least one jury and at least one cat.
Submitted Solution:
```
from collections import deque
t=int(input())
def bfs():
global check,ans
ans=0
d=deque()
check=[0]*(n+1)
d.append(1)
while(len(d)>0):
for i in range(len(v[d[0]])):
if check[v[d[0]][i]]==0:
check[v[d[0]][i]]=1
ans+=1
d.append(v[d[0]][i])
d.pop()
def bfs2():
global check2, ans2
ans2= 0
d=deque()
check2=[0]*(n+1)
d.append(1)
while (len(d) > 0):
for i in range(len(v2[d[0]])):
if check2[v2[d[0]][i]]==0:
check2[v2[d[0]][i]]=1
ans2+= 1
d.append(v2[d[0]][i])
d.pop()
for i2 in range(t):
n,m=map(int,input().split())
v=[[]for i in range(n+1)]
v2=[[]for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
v[a].append(b)
v2[b].append(a)
bfs()
bfs2()
if i2<t-1:
s=str(input())
if 0<ans<n:
print("YES")
print(ans,n-ans)
for i in range(1,n+1):
if check[i]==1:
print(i,end=" ")
print("")
for i in range(1,n+1):
if check[i]==0:
print(i,end=" ")
print("")
elif 0<ans2<n:
print("YES")
print(n-ans2,ans2)
for i in range(1, n + 1):
if check2[i] == 0:
print(i, end=" ")
print("")
for i in range(1, n + 1):
if check2[i] == 1:
print(i, end=" ")
print("")
else:
print("NO")
```
No
| 88,482 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
n = int(input())
d = [int(i) for i in input().split()]
# [print(bin(ff)) for ff in d]
l1 = [[1] * n for i in range(15)]
l2 = [[1] * n for i in range(15)]
vec_const1 = [0]*n
vec_const2 = [0]*n
for j in range(n):
dd = d[j]
for i in range(30):
if dd & (1 << i):
if i < 15:
vec_const1[j] += 1
l1[i][j] = -1
else:
vec_const2[j] += 1
l2[i-15][j] = -1
ub = (1 << 15)
dic = {}
# st = set()
for msk in range(ub):
mask = msk
vec = vec_const1[:]
for i in range(15):
if mask & 1:
for j in range(n):
vec[j] += l1[i][j]
mask >>= 1
# st.add(tuple(vec))
dic[tuple([vec[i+1] - vec[i] for i in range(n-1)])] = msk
# [print(ky, bin(dic[ky])) for ky in dic]
# print('#####')
# print(st)
for msk in range(ub):
vec = vec_const2[:]
mask = msk
for i in range(15):
if mask & 1:
for j in range(n):
vec[j] += l2[i][j]
mask >>= 1
dif = tuple([vec[i] - vec[i+1] for i in range(n-1)])
if dif in dic:
# print(msk)
# print(dif)
print((msk << 15) + dic[dif])
exit()
print(-1)
```
| 88,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
H = 15
n = int(input())
a = list(map(int, input().split()))
def pc(v):
v = v - ((v >> 1) & 0x55555555)
v = (v & 0x33333333) + ((v >> 2) & 0x33333333)
return (((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) & 0xFFFFFFFF) >> 24
mask = (1 << H) - 1
rec = {}
for x in range(1 << H):
r = [pc((ai & mask) ^ x) for ai in a]
d = tuple(r[-1] - ri for ri in r[:-1])
rec.setdefault(d, x)
ans = None
mask = ((1 << H) - 1) << H
for x in range(1 << H):
x <<= H
r = [pc((ai & mask) ^ x) for ai in a]
y = rec.get(tuple(ri - r[-1] for ri in r[:-1]), None)
if y is not None:
ans = x | y
break
print(-1 if ans is None else ans)
```
| 88,484 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
def main():
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
dic1 = {}
dic2 = {}
A1 = [0] * N
for i, a in enumerate(A):
A1[i] = a>>15
for i in range(2**15):
tmp = [0] * N
for j, a in enumerate(A1):
a ^= i
tmp[j] = bin(a).count('1')
t0 = tmp[0]
for j in range(N):
tmp[j] -= t0
dic1[i] = tuple(tmp)
A2 = [0] * N
for i, a in enumerate(A):
A2[i] = a % (2**15)
for i in range(2 ** 15):
tmp = [0] * N
for j, a in enumerate(A2):
a ^= i
tmp[j] = -(bin(a).count('1'))
t0 = tmp[0]
for j in range(N):
tmp[j] -= t0
dic2[tuple(tmp)] = i
for i in range(2**15):
if dic1[i] in dic2:
# ans = i*(2**15) + dic2[dic1[i]]
# print([bin(a^ans).count('1') for a in A])
print(i*(2**15) + dic2[dic1[i]])
exit()
print(-1)
if __name__ == '__main__':
main()
```
| 88,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def solve():
n = ni()
a = nl()
mask = (1 << 15) - 1
ab = [x & mask for x in a]
at = [x >> 15 for x in a]
d = dict()
for bit in range(mask, -1, -1):
b = [bin(bit^x).count('1') for x in ab]
g = tuple([x - b[0] for x in b[1:]])
d[g] = bit
for bit in range(mask + 1):
b = [bin(bit^x).count('1') for x in at]
g = tuple([b[0] - x for x in b[1:]])
if g in d:
print((bit << 15) | d[g])
return
print(-1)
return
solve()
# T = ni()
# for _ in range(T):
# solve()
```
| 88,486 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
def bitcount(x):
return (
0 if x == 0 else
x%2 + bitcount(x//2)
)
###
def core():
_ = int(input()) # n
A = [int(v) for v in input().split()]
# 222222222211111111110000000000
# 987654321098765432109876543210
Hmask = 0b111111111111111000000000000000
Lmask = 0b000000000000000111111111111111
H = [a>>15 for a in A]
L = [a&Lmask for a in A]
Hcnt = {}
Lcnt = {}
for x in range(2**15):
hkey = [bitcount(h^x) for h in H]
shift = min(hkey)
hkey = tuple(v-shift for v in hkey)
Hcnt.setdefault(hkey, x)
Hcnt[hkey] = min(Hcnt[hkey], x)
lkey = tuple(bitcount(l^x) for l in L)
Lcnt.setdefault(lkey, x)
Lcnt[lkey] = min(Lcnt[lkey], x)
for t in Lcnt:
reverse_t = tuple(max(t)-v for v in t)
shift = min(reverse_t)
shifted_rt = tuple(shift+v for v in reverse_t)
if shifted_rt in Hcnt:
ans = (Hcnt[shifted_rt] << 15) | Lcnt[t]
return ans
return -1
###
print(core())
```
| 88,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
H = 15
MASK = (1 << H) - 1
n = int(input())
a = list(map(int, input().split()))
rec = {}
for x in range(1 << H):
r = [bin(ai & MASK ^ x).count('1') for ai in a]
d = tuple(r[-1] - ri for ri in r[:-1])
rec.setdefault(d, x)
ans = None
for x in range(1 << H):
r = [bin(ai >> H ^ x).count('1') for ai in a]
y = rec.get(tuple(ri - r[-1] for ri in r[:-1]), None)
if y is not None:
ans = x << H | y
break
print(-1 if ans is None else ans)
```
| 88,488 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
import sys
from array import array # noqa: F401
import typing as Tp # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def popcnt_32(x):
x = (x & 0x55555555) + ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = (x + (x >> 8))
return (x + (x >> 16)) & 0x3f
def hash(a, mod1=10**9 + 7, mod2=10**9 + 9):
base = 123456789
res1 = 0
res2 = 0
for x in a:
res1 = (res1 * base + x) % mod1
res2 = (res2 * base + x) % mod2
return int(str(res1)), int(str(res2))
def main():
n = int(input())
mask, lower, upper = 2**15 - 1, [], []
for x in map(int, input().split()):
lower.append(x & mask)
upper.append(x >> 15)
d = {}
delta1, delta2 = hash([1] * n)
mod1, mod2 = 10**9 + 7, 10**9 + 9
for bit in range(1 << 15):
d[hash(map(lambda x: popcnt_32(x ^ bit), lower))] = bit
for bit in range(1 << 15):
pc = [popcnt_32(x ^ bit) for x in upper]
key1, key2 = hash(-p for p in pc)
for base in range(30):
if (key1, key2) in d:
print((bit << 15) + d[key1, key2])
exit()
key1 = (key1 + delta1) % mod1
key2 = (key2 + delta2) % mod2
print(-1)
if __name__ == '__main__':
main()
```
| 88,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Tags: bitmasks, brute force, hashing, meet-in-the-middle
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
msbs_achieved_by = {tuple(
bin((num>>15) ^ x).count("1")
for num in arr
) : x
for x in range(1<<15)
}
def main():
for x in range(1<<15):
counts = [bin(x ^ (num & ((1<<15)-1))).count("1") for num in arr]
for common_count in range(max(counts), 31):
other_counts = tuple(common_count - s for s in counts)
found = msbs_achieved_by.get(other_counts)
if found:
result = (found<<15) | x
print(result)
arr2 = [result ^ num for num in arr]
# assert len(set(bin(num).count("1") for num in arr2))==1
return
print(-1)
if __name__ == '__main__':
main()
```
| 88,490 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Submitted Solution:
```
def main():
n = int(input())
a = list(map(int,input().split()))
for x in range(1, (2**20) - 1):
numOnes = bin(a[0] ^ x).count('1')
count = 1
for i in range(1, n):
if((bin(a[i] ^ x)).count('1') == numOnes):
count+=1
else:
break
if(count == n):
print(x)
return 0
print(-1)
if __name__ == "__main__":
main()
```
No
| 88,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Submitted Solution:
```
def main():
n = int(input())
a = list(map(int,input().split()))
for x in range(1, (2**30) - 1):
numOnes = bin(a[0] ^ x).count('1')
count = 1
for i in range(1, n):
if((bin(a[i] ^ x)).count('1') == numOnes):
count+=1
else:
break
if(count == n):
print(x)
break
print(-1)
if __name__ == "__main__":
main()
```
No
| 88,492 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Submitted Solution:
```
import sys
from array import array # noqa: F401
import typing as Tp # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def popcnt_32(x):
x = (x & 0x55555555) + ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = (x + (x >> 8))
return (x + (x >> 16)) & 0x3f
def hash(a, mod=10**9 + 7):
base = 123456789
res = 0
for x in a:
res = (res * base + x) % mod
return int(str(res))
def main():
n = int(input())
mask, lower, upper = 2**15 - 1, [], []
for x in map(int, input().split()):
lower.append(x & mask)
upper.append(x >> 15)
d = {}
delta, mod = hash([1] * n), 10**9 + 7
for bit in range(1 << 15):
d[hash(map(lambda x: popcnt_32(x ^ bit), lower))] = bit
for bit in range(1 << 15):
pc = [popcnt_32(x ^ bit) for x in upper]
key = hash(-p for p in pc)
for base in range(30):
if key in d:
print((bit << 15) + d[key])
exit()
key = (key + delta) % mod
print(-1)
if __name__ == '__main__':
main()
```
No
| 88,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
* 2 and 4 are similar (binary representations are 10 and 100);
* 1337 and 4213 are similar (binary representations are 10100111001 and 1000001110101);
* 3 and 2 are not similar (binary representations are 11 and 10);
* 42 and 13 are similar (binary representations are 101010 and 1101).
You are given an array of n integers a_1, a_2, ..., a_n. You may choose a non-negative integer x, and then get another array of n integers b_1, b_2, ..., b_n, where b_i = a_i ⊕ x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
Input
The first line contains one integer n (2 ≤ n ≤ 100).
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30} - 1).
Output
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer -1.
Otherwise, print any non-negative integer not exceeding 2^{30} - 1 that can be used as x so that all elements in the resulting array are similar.
Examples
Input
2
7 2
Output
1
Input
4
3 17 6 0
Output
5
Input
3
1 2 3
Output
-1
Input
3
43 12 12
Output
1073709057
Submitted Solution:
```
from sys import stdin, stdout
import time
def main(start_time):
n = int(input())
a = list(map(int,input().split()))
Found = False
total = 10000
for x in range(1, total):
if(time.time() - start_time > 3800):
exit(1)
b = []
for i in range(n):
if(time.time() - start_time > 3800):
exit(1)
num = a[i] ^ x
b.append(bin(num))
numOfOnes = b[0].count('1')
count = 1
for i in range(1,n):
if(b[i].count('1') == numOfOnes):
count+=1
else:
break
if(count == n):
print(x)
Found = True
break
if(not Found):
print(-1)
if __name__ == "__main__":
start_time = time.time()
main(start_time)
```
No
| 88,494 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.
Let us tell you how it works.
* If a sentence ends with "po" the language is Filipino.
* If a sentence ends with "desu" or "masu" the language is Japanese.
* If a sentence ends with "mnida" the language is Korean.
Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.
Oh, did I say three suffixes? I meant four.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 30) denoting the number of test cases. The next lines contain descriptions of the test cases.
Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least 1 and at most 1000 characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.
Output
For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.
Example
Input
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu
Output
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE
Note
The first sentence ends with "po", so it is written in Filipino.
The second and third sentences end with "desu" and "masu", so they are written in Japanese.
The fourth sentence ends with "mnida", so it is written in Korean.
Tags: implementation
Correct Solution:
```
x=int(input())
for i in range(x):
st=input()
# print(st[-2:])
if "po" in st[-2:] :
print("FILIPINO")
elif "desu" in st[-5:] or "masu" in st[-5:] :
print("JAPANESE")
else:
print("KOREAN")
```
| 88,495 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.
Let us tell you how it works.
* If a sentence ends with "po" the language is Filipino.
* If a sentence ends with "desu" or "masu" the language is Japanese.
* If a sentence ends with "mnida" the language is Korean.
Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.
Oh, did I say three suffixes? I meant four.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 30) denoting the number of test cases. The next lines contain descriptions of the test cases.
Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least 1 and at most 1000 characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.
Output
For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.
Example
Input
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu
Output
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE
Note
The first sentence ends with "po", so it is written in Filipino.
The second and third sentences end with "desu" and "masu", so they are written in Japanese.
The fourth sentence ends with "mnida", so it is written in Korean.
Tags: implementation
Correct Solution:
```
n = int(input())
i = 0
string1 = ''
while i<n:
string1= string1+ input()
i= i+1
if n-i>=1:
string1= string1+ ' '
list1= string1.split(' ')
for n in range(len(list1)):
if list1[n].endswith('po'):
print('FILIPINO')
elif list1[n].endswith('desu') or list1[n].endswith('masu'):
print('JAPANESE')
elif list1[n].endswith('mnida'):
print('KOREAN')
```
| 88,496 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.
Let us tell you how it works.
* If a sentence ends with "po" the language is Filipino.
* If a sentence ends with "desu" or "masu" the language is Japanese.
* If a sentence ends with "mnida" the language is Korean.
Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.
Oh, did I say three suffixes? I meant four.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 30) denoting the number of test cases. The next lines contain descriptions of the test cases.
Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least 1 and at most 1000 characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.
Output
For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.
Example
Input
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu
Output
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE
Note
The first sentence ends with "po", so it is written in Filipino.
The second and third sentences end with "desu" and "masu", so they are written in Japanese.
The fourth sentence ends with "mnida", so it is written in Korean.
Tags: implementation
Correct Solution:
```
t=int(input())
while t!=0:
t-=1
s=input()
if s[-2:]=="po":
print("FILIPINO")
elif s[-4:]=="desu" or s[-4:]=="masu":
print("JAPANESE")
else:
print("KOREAN")
```
| 88,497 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.
Let us tell you how it works.
* If a sentence ends with "po" the language is Filipino.
* If a sentence ends with "desu" or "masu" the language is Japanese.
* If a sentence ends with "mnida" the language is Korean.
Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.
Oh, did I say three suffixes? I meant four.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 30) denoting the number of test cases. The next lines contain descriptions of the test cases.
Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least 1 and at most 1000 characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.
Output
For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.
Example
Input
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu
Output
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE
Note
The first sentence ends with "po", so it is written in Filipino.
The second and third sentences end with "desu" and "masu", so they are written in Japanese.
The fourth sentence ends with "mnida", so it is written in Korean.
Tags: implementation
Correct Solution:
```
def main():
N = int(input())
for _ in range(N):
S = str(input())
if S.endswith("po"):
print("FILIPINO")
elif S.endswith("desu") or S.endswith("masu"):
print("JAPANESE")
else:
print("KOREAN")
if __name__ == "__main__":
main()
```
| 88,498 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.
Let us tell you how it works.
* If a sentence ends with "po" the language is Filipino.
* If a sentence ends with "desu" or "masu" the language is Japanese.
* If a sentence ends with "mnida" the language is Korean.
Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.
Oh, did I say three suffixes? I meant four.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 30) denoting the number of test cases. The next lines contain descriptions of the test cases.
Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least 1 and at most 1000 characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.
Output
For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.
Example
Input
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu
Output
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE
Note
The first sentence ends with "po", so it is written in Filipino.
The second and third sentences end with "desu" and "masu", so they are written in Japanese.
The fourth sentence ends with "mnida", so it is written in Korean.
Tags: implementation
Correct Solution:
```
for i in range(int(input())):
n = input()
if "po" == n[-2:]:
print("FILIPINO")
elif "desu" == n[-4:] or "masu" == n[-4:]:
print("JAPANESE")
#elif "mnid" == n[-4:]:
else:
print("KOREAN")
```
| 88,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.