message stringlengths 2 19.9k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 322 108k | cluster float64 15 15 | __index_level_0__ int64 644 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion:
* An 'L' indicates he should move one unit left.
* An 'R' indicates he should move one unit right.
* A 'U' indicates he should move one unit up.
* A 'D' indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.
Input
The first and only line contains the string s (1 β€ |s| β€ 100 000) β the instructions Memory is given.
Output
If there is a string satisfying the conditions, output a single integer β the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
Examples
Input
RRU
Output
-1
Input
UDUR
Output
1
Input
RUUR
Output
2
Note
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
Submitted Solution:
```
s=input()
U=0
D=0
L=0
R=0
for ch in s:
if ch=="U":
U+=1
if ch=="D":
D+=1
if ch=="L":
L+=1
if ch=="R":
R+=1
if (U+D+R+L)%2==1:
print ("-1")
else:
changeup=abs(U-D)/2
changel=abs(U-D)/2
print (int(changeup+changel))
``` | instruction | 0 | 35,626 | 15 | 71,252 |
No | output | 1 | 35,626 | 15 | 71,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion:
* An 'L' indicates he should move one unit left.
* An 'R' indicates he should move one unit right.
* A 'U' indicates he should move one unit up.
* A 'D' indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.
Input
The first and only line contains the string s (1 β€ |s| β€ 100 000) β the instructions Memory is given.
Output
If there is a string satisfying the conditions, output a single integer β the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
Examples
Input
RRU
Output
-1
Input
UDUR
Output
1
Input
RUUR
Output
2
Note
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
Submitted Solution:
```
import math
n = input()
if (len(n)%2==1):
print(-1)
exit(0)
x,y = 0,0
for i in n:
if (i=='R'):
y+=1
if (i=='U'):
x+=1
if (i=='D'):
x-=1
if (i=='L'):
y-=1
s = x + y
s = math.fabs(s)
s = int(s)
if (s>1):
s //=2
else:
s = 1
print(s)
``` | instruction | 0 | 35,627 | 15 | 71,254 |
No | output | 1 | 35,627 | 15 | 71,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,488 | 15 | 72,976 |
Tags: math
Correct Solution:
```
def gcd(a, b):
if b == 0:
return a, 1, 0
else:
d, x, y = gcd(b, a % b)
return d, y, x - y * (a // b)
n,m,dx,dy = map(int,input().split())
c = [0]*1000000
d, x, y = gcd(-n, dx)
mu = dy * y % n
for i in range(m):
a, b = map(int,input().split())
c[(b-a*mu)%n]+=1
print(0, c.index(max(c)))
``` | output | 1 | 36,488 | 15 | 72,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,489 | 15 | 72,978 |
Tags: math
Correct Solution:
```
from sys import stdin
def egcd(a, b):
x = v = 0
y = u = 1
while a:
q, r = divmod(b, a)
a, b, x, y, u, v = r, a, u, v, x - u * q, y - v * q
return x, y, b
def main():
n, m, dx, dy = map(int, stdin.readline().strip().split())
step = egcd(dx, n)[0] * dy
cnt = [0] * n
for _ in range(m):
x, y = map(int, stdin.readline().strip().split())
cnt[(y - step * x) % n] += 1
print(0, max(range(n), key=cnt.__getitem__))
main()
``` | output | 1 | 36,489 | 15 | 72,979 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,490 | 15 | 72,980 |
Tags: math
Correct Solution:
```
n, m, dx, dy = map(int, input().split())
zero = [0] * n
x, y = 0, 0
for i in range(n):
zero[x] = y
x = (x + dx) % n
y = (y + dy) % n
cnt = [0] * n
for _ in range(m):
x, y = map(int, input().split())
cnt[(y - zero[x]) % n] += 1
max_val = max(cnt)
max_pos = cnt.index(max_val)
print(0, max_pos)
``` | output | 1 | 36,490 | 15 | 72,981 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,491 | 15 | 72,982 |
Tags: math
Correct Solution:
```
import math
import itertools
def euclid_algorithm(a, b):
t1, t2 = abs(a), abs(b)
#saving equalities:
#t1 == x1 * a + y1 * b,
#t2 == x2 * a + y2 * b.
x1, y1, x2, y2 = int(math.copysign(1, a)), 0, 0, int(math.copysign(1, b))
if t1 < t2:
t1, t2 = t2, t1
x1, y1, x2, y2 = x2, y2, x1, y1
while t2 > 0:
if x1 * a + y1 * b != t1:
print('inshalla')
k = int(t1 // t2)
t1, t2 = t2, t1 % t2
#t1 - k * t2 == (x1 - k * x2) * a + (y1 - k * y2) * b
x1, y1, x2, y2 = x2, y2, x1 - k * x2, y1 - k * y2
return t1, x1, y1
def opposite_element(x, p):
gcd, k, l = euclid_algorithm(x, p)
if gcd != 1:
return -1
return k % p
n, m, dx, dy = [int(x) for x in input().split()]
k = opposite_element(dx, n)
dx1 = 1
dy1 = (dy*k) % n
D = {}
for i in range(m):
x, y = [int(x) for x in input().split()]
diag = (y - dy1 * x) % n
if not diag in D:
D[diag] = 1
else:
D[diag] += 1
diag = max(D, key = lambda k: D[k])
print(0, diag)
``` | output | 1 | 36,491 | 15 | 72,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,492 | 15 | 72,984 |
Tags: math
Correct Solution:
```
n, m, dx, dy = map(int, input().split())
y = [k * dy % n for k in range(n)]
k = [0] * n
for i in range(n):
k[y[i]] = i
trees = [0] * n
for i in range(m):
x, y = map(int, input().split())
trees[(x - k[y] * dx) % n] += 1
max = 0
best_x = 0
for i in range(n):
if trees[i] > max:
best_x = i
max = trees[i]
print(best_x, 0)
``` | output | 1 | 36,492 | 15 | 72,985 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,493 | 15 | 72,986 |
Tags: math
Correct Solution:
```
n, m, dx, dy = map(int, input().split())
rel = [0] * n
x, y = 0, 0
for i in range(n):
rel[x] = y
x = (x + dx) % n
y = (y + dy) % n
cnt = [0] * n
for _ in range(m):
x, y = map(int, input().split())
cnt[(y - rel[x]) % n] += 1
max_val = max(cnt)
max_pos = cnt.index(max_val)
print(0, max_pos)
``` | output | 1 | 36,493 | 15 | 72,987 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,494 | 15 | 72,988 |
Tags: math
Correct Solution:
```
def gcdex(a, b):
if a == 0:
return b, 0, 1
g, x, y = gcdex(b % a, a)
x, y = y - (b // a) * x, x
return g, x, y
s = input()
#s = "5 5 2 3"
n, m, dx, dy = map(int, s.split())
step = dy * n + dx
#ss = ("0 0", "1 2", "1 3", "2 4", "3 1")
ans = {}
for i in range(m):
s = input()
#s = ss[i]
x, y = map(int, s.split())
g, a, b = gcdex(dy, n)
k = y * a
x0 = (x + k * (n - dx)) % n
v = ans.get(x0, 0)
ans[x0] = v+1
c = max(ans, key=lambda k: ans[k])
print(c, 0)
``` | output | 1 | 36,494 | 15 | 72,989 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0) | instruction | 0 | 36,495 | 15 | 72,990 |
Tags: math
Correct Solution:
```
n,m,dx,dy = map(int,input().split())
x=y=0
a=[0]*n
c=[0]*n
for i in range(1,n):
x = (x+dx)%n
y = (y+dy)%n
a[x]=y
for i in range(m):
x,y = map(int,input().split())
index = (y-a[x]+n)%n;
c[index] += 1
ans = 0
for i in range(n):
if c[i] > c[ans]: ans = i
print(0, ans)
``` | output | 1 | 36,495 | 15 | 72,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0)
Submitted Solution:
```
f = lambda: map(int, input().split())
n, m, dx, dy = f()
p = [0] * n
for i in range(n): p[dx * i % n] = i
s = [0] * n
for j in range(m):
x, y = f()
s[(y - dy * p[x]) % n] += 1
print(0, s.index(max(s)))
``` | instruction | 0 | 36,496 | 15 | 72,992 |
Yes | output | 1 | 36,496 | 15 | 72,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0)
Submitted Solution:
```
__author__ = 'Bryan'
n,m,dx,dy = map(int, input().split())
x,y,j = 0,0,0
ans,ind = [0]*n,[0]*n
for i in range(1,n):
x,y = (x+dx)%n,(y+dy)%n
ind[x]=y
for i in range(m):
x,y = map(int, input().split())
ans[(y-ind[x]+n)%n]+=1
for i in range(n):
if ans[i]>ans[j]:
j = i
print(0,j)
``` | instruction | 0 | 36,497 | 15 | 72,994 |
Yes | output | 1 | 36,497 | 15 | 72,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0)
Submitted Solution:
```
n,m,dx,dy = map(int, input().split(' '))
L = []
for i in range(m) :
x,y = map(int, input().split(' '))
L.append([x,y])
L.sort(key = lambda x : x[0])
M = [0]*n
x = y = 0
for i in range(n) :
M[x] = y
x = (x+dx)%n
y = (y+dy)%n
A = [0]*n
for i in L :
d = i[1] - M[i[0]]
d %= n
A[d] += 1
ax = ay = 0
ay += A.index(max(A))
print(ax, ay)
``` | instruction | 0 | 36,498 | 15 | 72,996 |
Yes | output | 1 | 36,498 | 15 | 72,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0)
Submitted Solution:
```
n, m, dx, dy = map(int, input().split())
groups = [0] * n
for i in range(m):
x, y = map(int, input().split())
groups[(y - x) % n] += 1
print(0, max(range(n), key = lambda i: groups[i]))
``` | instruction | 0 | 36,499 | 15 | 72,998 |
No | output | 1 | 36,499 | 15 | 72,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0)
Submitted Solution:
```
s = input()
#s = "2 3 1 1"
#ss = ("0 0", "0 1", "1 1")
n, m, dx, dy = map(int, s.split())
step = dy * n + dx
ans = {}
for i in range(m):
s = input()
#s = ss[i]
x, y = map(int, s.split())
c = y * n + x
mod = c % step
v = ans.get(mod, 0)
ans[mod] = v+1
c = max(ans, key=lambda k: ans[k])
x, y = c % n, c // n
print(x, y)
``` | instruction | 0 | 36,500 | 15 | 73,000 |
No | output | 1 | 36,500 | 15 | 73,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya decided to walk in the field of size n Γ n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.
Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.
Input
The first line contains integers n, m, dx, dy(1 β€ n β€ 106, 1 β€ m β€ 105, 1 β€ dx, dy β€ n) β the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 β€ xi, yi β€ n - 1) β the coordinates of apples. One cell may contain multiple apple trees.
Output
Print two space-separated numbers β the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.
Examples
Input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
Output
1 3
Input
2 3 1 1
0 0
0 1
1 1
Output
0 0
Note
In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)
In the second sample: (0, 0) - (1, 1) - (0, 0)
Submitted Solution:
```
__author__ = 'Bryan'
n,m,dx,dy = map(int, input().split())
x,y,j = 0,0,0
ans,ind = [0]*n,[0]*n
for i in range(1,n):
x,y = (x+dx)%n,(y+dy)%n
ind[x]=y
for i in range(m):
x,y = map(int, input().split())
ans[(y-ind[x]+n)%n]+=1
for i in range(n):
if ans[i]>ans[j]:
j = i
print(j,0)
``` | instruction | 0 | 36,501 | 15 | 73,002 |
No | output | 1 | 36,501 | 15 | 73,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,864 | 15 | 73,728 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
N,M = map(int,input().split())
l = [0,1,2,3,2,1]
res = float('inf')
for (n,m) in ((N,M),(M,N)):
if l[n%6]==0:
print(n*m)
exit()
elif l[n%6]==1:
tmp = l[m%6]
res = min(res,tmp)
elif l[n%6]==2:
if m>=4 and m!=7:
print(n*m)
exit()
if m==2:
tmp = 4
else:
tmp = 2
res = min(res,tmp)
else:
if m==1:
tmp = 3
elif m==2:
tmp = 2
elif m%2==0:
print(n*m)
exit()
else:
tmp = 1
res = min(res,tmp)
print(n*m-res)
``` | output | 1 | 36,864 | 15 | 73,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,865 | 15 | 73,730 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
n, m = map(int, input().split())
if n > m:
n, m = m, n
if n == 1:
ans = (m//6)*6+2*max(m%6-3, 0)
print(ans)
elif n == 2:
if m == 2:
print(0)
elif m == 3:
print(4)
elif m == 7:
print(12)
else:
print(n*m)
else:
ans = ((n*m)//2)*2
print(ans)
``` | output | 1 | 36,865 | 15 | 73,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,866 | 15 | 73,732 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
n,m=map(int,input().split(" "))
if n==1 or m==1:
print((((n*m)//6)*6)+((n*m)%6>3)*((((n*m)%6)%3)*2))
elif n*m<6:
print(0)
elif n*m==6:
print(4)
elif n*m==14:
print(12)
# elif (n==2 and m%2==1) or (m==2 and n%2==1):
# print(n*m-2)
# elif((n==2 and m%2==0) or (m==2 and n%2==0)):
# print(n*m)
else:
print(n*m-(n*m)%2)
``` | output | 1 | 36,866 | 15 | 73,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,867 | 15 | 73,734 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
import math
from decimal import *
getcontext().prec = 30
n,m=map(int,input().split())
ans=0
if n<m:
n,m=m,n
if n<3 and m<3:
ans=0
elif m==1:
ans+=(n//6)*6
n%=6
if n>3:
ans+=(n-3)*2
elif n%4==0 or m%4==0 or n%6==0 or m%6==0:
ans=n*m
elif n<=5 and m<=5:
if n%2 and m%2:
ans=n*m-1
elif n==3:
ans=n*m-2
else :
ans=n*m
elif n*m==14:
ans=12
else :
ans=n*m//2*2
print(ans)
``` | output | 1 | 36,867 | 15 | 73,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,868 | 15 | 73,736 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
class Solution(object):
def run(self):
n, m = [int(x) for x in input().split()]
if n > m:
n, m = m, n
res = (n * m) // 2
if n == 1 and (m + 1) % 6 // 3:
res -= 1
elif n == 2:
if m == 2:
res = 0
elif m == 3:
res = 2
elif m == 7:
res = 6
print(res * 2)
if __name__ == '__main__':
Solution().run()
``` | output | 1 | 36,868 | 15 | 73,737 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,869 | 15 | 73,738 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
n,m=map(int,input().strip().split())
f=min(n,m)
f1=max(n,m)
def s(g):
if (g%6==1 or g%6==5):
return 1
if (g%6==2 or g%6==4):
return 2
if (g%6==0):
return 0
if (g%6==3):
return 3
if (f==1):
f3=s(f1)
print (n*m-f3)
exit(0)
if (f==2 and f1==3):
print (4)
exit(0)
if (f==2 and f1==2):
print (0)
exit(0)
if (f==2 and f1==7):
print (12)
exit(0)
if (f==3 and f1==3):
print (8)
exit(0)
if (f%2==0 and f1%2==0):
print (n*m)
exit(0)
if (f%2==1 and f1%2==0):
print (n*m)
exit(0)
if (f%2==0 and f1%2==1):
print (n*m)
exit(0)
if (f%2==1 and f1%2==1):
print (n*m-1)
exit(0)
``` | output | 1 | 36,869 | 15 | 73,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,870 | 15 | 73,740 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
n,m=map(int, input().split())
q=min(n,m)
w=max(n,m)
if ((q==1) and (w<=3)) or (q==2==w):
print ('0')
elif (q==1) and (w==4):
print ('2')
elif (q==1) and (w==5):
print ('4')
elif (q==1) and (w==6):
print ('6')
elif (q==2) and (w==3):
print ('4')
elif (q==1):
r=w//6
if w%6==0:
print (w)
elif w%6<=3:
print (r*6)
elif w%6==4:
print (r*6+2)
elif w%6==5:
print (r*6+4)
elif (q==2) and (w==7):
print ('12')
elif q*w%2==0:
print (q*w)
else:
print (q*w-1)
``` | output | 1 | 36,870 | 15 | 73,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). | instruction | 0 | 36,871 | 15 | 73,742 |
Tags: brute force, constructive algorithms, flows, graph matchings
Correct Solution:
```
n, m = map(int, input().split())
if n >= 4 and m >= 4:
print(n * m - (n * m % 2))
else:
if min(n, m) == 1:
if max(n, m) % 6 == 5:
print(max(n, m) // 6 * 6 + 4)
elif max(n, m) % 6 == 4:
print(max(n, m) // 6 * 6 + 2)
else:
print(max(n, m) // 6 * 6)
elif min(n, m) == 2 and max(n, m) == 7:
print(12)
elif min(n, m) == 2 and max(n, m) >= 4 or min(n, m) == 3 and max(n, m) >= 4:
print(n * m - (n * m % 2))
else:
d = [[0, 0, 0, 2, 4], [0, 0, 4, 8, 10], [0, 0, 8, 12, 14], [0, 0, 0, 16, 20], [0, 0, 0, 0, 24]]
print(d[min(n, m) - 1][max(n, m) - 1])
``` | output | 1 | 36,871 | 15 | 73,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
Submitted Solution:
```
a,b = map(int,input().split())
a,b = min(a,b),max(a,b)
if a==1:
c=b%6
if c==4:print((b//6)*6 + 2)
elif c==5:print((b//6)*6 + 4)
else:print((b//6)*6)
elif a==2:
if b<=2:print(0)
elif b==3 or b==7:print((a*b)-2)
else:
print((b) * 2)
else:
ans=a*b
if ans%2==0:
print(ans)
else:
print(ans-1)
``` | instruction | 0 | 36,872 | 15 | 73,744 |
Yes | output | 1 | 36,872 | 15 | 73,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
Submitted Solution:
```
#yeh dil maange more
n,m = map(int,input().split())
if n<m:n,m = m,n
ans = 0
d = {0:0,1:1,2:2,3:3,4:2,5:1}
if m==1:ans=d[n%6]
elif m==2:
if n==3:ans=2
elif n==2:ans=4
elif n==7:ans=2
else:ans =(n*m)%2
print(n*m-ans)
``` | instruction | 0 | 36,873 | 15 | 73,746 |
Yes | output | 1 | 36,873 | 15 | 73,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
Submitted Solution:
```
from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
x,y = map(int,input().split())
x1 = min(x,y)
y1 = max(x,y)
if(x1 == 1):
s = y1%6
if(s == 4):
s = 2
if(s == 5):
s = 1
print(y1-s)
exit(0)
if(x1 == 2):
if(y1 == 2):
print(0)
elif(y1 == 3):
print(4)
elif(y1 == 7):
print(12)
else:
print(2*y1)
else:
print(x1*y1 - (x1*y1)%2)
``` | instruction | 0 | 36,874 | 15 | 73,748 |
Yes | output | 1 | 36,874 | 15 | 73,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
Submitted Solution:
```
import math
from decimal import *
getcontext().prec = 30
n,m=map(int,input().split())
if n<3 and m<3:
print(0)
elif n==1 or m==1:
print(0)
elif n%2==0 and m%2==0:
print(n*m)
elif n%2 and m%2:
print(n*m-1)
else :
print(n*m-2)
``` | instruction | 0 | 36,875 | 15 | 73,750 |
No | output | 1 | 36,875 | 15 | 73,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
Submitted Solution:
```
import math
from decimal import *
getcontext().prec = 30
n,m=map(int,input().split())
if n<3 and m<3:
print(0)
elif n%2==0 and m%2==0:
print(n*m)
elif n%2 and m%2:
print(n*m-1)
else :
if n%2:
print(m*n-m)
else :
print(m*n-n)
``` | instruction | 0 | 36,876 | 15 | 73,752 |
No | output | 1 | 36,876 | 15 | 73,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
Submitted Solution:
```
n,m=map(int,input().split(" "))
if n*m<6:
print(0)
elif n*m==6:
print(4)
elif (n==2 and m%2==1) or (m==2 and n%2==1):
print(n*m-2)
elif((n==2 and m%2==0) or (m==2 and n%2==0)):
print(n*m)
else:
print(n*m-(n*m)%2)
``` | instruction | 0 | 36,877 | 15 | 73,754 |
No | output | 1 | 36,877 | 15 | 73,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little C loves number Β«3Β» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n Γ m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.
He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
Input
A single line contains two integers n and m (1 β€ n,m β€ 10^9) β the number of rows and the number of columns of the chessboard.
Output
Print one integer β the maximum number of chessmen Little C can place.
Examples
Input
2 2
Output
0
Input
3 3
Output
8
Note
In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.
In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
Submitted Solution:
```
n, m = map(int, input().split())
if n<= 2 and m <= 2:
print(0)
exit()
if n > m:
n, m = m, n
if n == 3:
if m == 3:
print(8)
elif m == 4:
print(10)
else:
ans = ((n*m)//6)*6
print(ans)
else:
ans = ((n*m)//6)*6
print(ans)
``` | instruction | 0 | 36,878 | 15 | 73,756 |
No | output | 1 | 36,878 | 15 | 73,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.
Your program should handle the queries of the following two types:
1. "1 x y" (x < y) β add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" (a β b) β answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
Input
The first line of the input contains integer n denoting the number of queries, (1 β€ n β€ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct.
Output
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
Examples
Input
5
1 1 5
1 5 11
2 1 2
1 2 9
2 1 2
Output
NO
YES | instruction | 0 | 37,148 | 15 | 74,296 |
Tags: dfs and similar, graphs
Correct Solution:
```
path = []
n = int(input())
for it in range(0, n):
data = list(map(int, input().split(' ')))
if data[0] == 1:
path.append(data[1:])
else:
vis = [False] * (len(path) + 1)
que = [data[1] - 1]
while len(que):
p = que[0]
del que[0]
for i, v in enumerate(path):
if (v[0] < path[p][0] < v[1] or v[0] < path[p][1] < v[1]) and not vis[i]:
vis[i] = True
que.append(i)
print('YES' if vis[data[2] -1] else 'NO')
# Made By Mostafa_Khaled
``` | output | 1 | 37,148 | 15 | 74,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.
Your program should handle the queries of the following two types:
1. "1 x y" (x < y) β add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" (a β b) β answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
Input
The first line of the input contains integer n denoting the number of queries, (1 β€ n β€ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct.
Output
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
Examples
Input
5
1 1 5
1 5 11
2 1 2
1 2 9
2 1 2
Output
NO
YES | instruction | 0 | 37,149 | 15 | 74,298 |
Tags: dfs and similar, graphs
Correct Solution:
```
def main():
intervals = []
condensed = []
index = 0
n = int(input())
for i in range(n):
query, start, end = [int(k) for k in input().split(" ")]
if query == 1:
intervals.append((index, start, end))
index += 1
else:
print("YES" if check_path(start, end, intervals) else "NO")
return 0
def check_path(source, dest, intervals):
visited = [False] * len(intervals)
stack = []
stack.append(intervals[source-1])
while stack:
curr = stack.pop()
visited[curr[0]] = True
for i in intervals:
if not visited[i[0]]:
if i[1] < curr[1] < i[2] or i[1] < curr[2] < i[2]:
if i == intervals[dest-1]:
return True
stack.append(i)
return False
if __name__ == '__main__':
main()
``` | output | 1 | 37,149 | 15 | 74,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.
Your program should handle the queries of the following two types:
1. "1 x y" (x < y) β add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" (a β b) β answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
Input
The first line of the input contains integer n denoting the number of queries, (1 β€ n β€ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct.
Output
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
Examples
Input
5
1 1 5
1 5 11
2 1 2
1 2 9
2 1 2
Output
NO
YES | instruction | 0 | 37,150 | 15 | 74,300 |
Tags: dfs and similar, graphs
Correct Solution:
```
n=int(input())
s=[]
ans=[]
def bfs(x,y,ans):
n=x
while 1:
for i in s:
if i not in vis and (i[0]<n[0]<i[1] or i[0]<n[1]<i[1]):
stack.append(i)
if i==y:ans.append('YES');return ans
if len(stack)==0:ans.append('NO');return ans
n=stack.pop(0);vis.append(n)
for i in range(n):
c,x,y=map(int,input().split())
if c==1:
s.append([x,y])
else:
vis=[s[x-1]];stack=[]
ans=bfs(s[x-1],s[y-1],ans)
print(*ans,sep='\n')
``` | output | 1 | 37,150 | 15 | 74,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.
Your program should handle the queries of the following two types:
1. "1 x y" (x < y) β add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" (a β b) β answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
Input
The first line of the input contains integer n denoting the number of queries, (1 β€ n β€ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct.
Output
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
Examples
Input
5
1 1 5
1 5 11
2 1 2
1 2 9
2 1 2
Output
NO
YES | instruction | 0 | 37,151 | 15 | 74,302 |
Tags: dfs and similar, graphs
Correct Solution:
```
def DFS(v,b,visited):
visited.add(v)
global count,matrix,ok
if v==b:
ok = True
return
for i in range(count):
if matrix[v][i]==1 and v!=i and i not in visited:
DFS(i,b,visited)
n = int(input())
matrix = [[0]*111 for i in range(111)]
count = 0
ok = False
intervals = []
for i in range(n):
t,a,b = map(int,input().split())
if t==1:
intervals.append((a,b))
for l in range(count):
c,d = intervals[l]
if c<a<d or c<b<d:
matrix[count][l]=1
if a<c<b or a<d<b:
matrix[l][count]=1
count+=1
if t==2:
visited = set()
ok = False
res = DFS(a-1,b-1,visited)
if ok:print("YES")
else:print("NO")
``` | output | 1 | 37,151 | 15 | 74,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.
Your program should handle the queries of the following two types:
1. "1 x y" (x < y) β add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" (a β b) β answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
Input
The first line of the input contains integer n denoting the number of queries, (1 β€ n β€ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct.
Output
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
Examples
Input
5
1 1 5
1 5 11
2 1 2
1 2 9
2 1 2
Output
NO
YES | instruction | 0 | 37,152 | 15 | 74,304 |
Tags: dfs and similar, graphs
Correct Solution:
```
from sys import stdin
input = stdin.readline
n = int(input())
r = [(0, 0)]
for _ in range(n):
q, x, y = [int(x) for x in input().split()]
if q == 1:
r.append((x, y))
else:
stack = []
stack.append(x)
visited = [False]*len(r)
visited[x] = True
found = False
while stack:
node = stack.pop()
if node == y:
found = True
break
for i in range(1, len(r)):
if not visited[i]:
if (r[i][0] < r[node][0] < r[i][1]) or (r[i][0] < r[node][1] < r[i][1]):
visited[i] = True
stack.append(i)
if found:
print("YES")
else:
print("NO")
``` | output | 1 | 37,152 | 15 | 74,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.
Your program should handle the queries of the following two types:
1. "1 x y" (x < y) β add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" (a β b) β answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
Input
The first line of the input contains integer n denoting the number of queries, (1 β€ n β€ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct.
Output
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
Examples
Input
5
1 1 5
1 5 11
2 1 2
1 2 9
2 1 2
Output
NO
YES | instruction | 0 | 37,153 | 15 | 74,306 |
Tags: dfs and similar, graphs
Correct Solution:
```
#!/usr/bin/env python3
import sys
num_queries = 0
visited = []
first = []
last = []
def dfs(start, end):
if start == end:
return True
for i in range(0, num_queries):
if visited[i] == 0:
if first[start] > first[i] and first[start] < last[i]:
visited[i] = 1
if dfs(i, end):
return True;
elif last[start] > first[i] and last[start] < last[i]:
visited[i] = 1
if dfs(i, end):
return True;
return False;
num_lines: sys.stdin.readline()
for line in sys.stdin:
temp = line.split()
temp = list(map(int, temp))
q_type = temp[0]
if q_type == 1:
first.append(temp[1])
last.append(temp[2])
num_queries += 1
else:
visited = [0 for j in range(0, num_queries)]
visited[temp[1]-1] = 1
if dfs(temp[1] - 1, temp[2] - 1):
print("{}".format("YES"))
else:
print("{}".format("NO"))
``` | output | 1 | 37,153 | 15 | 74,307 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,197 | 15 | 74,394 |
Tags: brute force, greedy
Correct Solution:
```
def main():
n = int(input())
mines = []
minx, miny, maxx, maxy = 1e9, 11e9, -1e9, -1e9
for _ in range(n):
x, y = map(int, input().split())
minx = min(minx, x)
maxx = max(maxx, x)
miny = min(miny, y)
maxy = max(maxy, y)
sidex = maxx - minx
sidey = maxy - miny
res = max(sidex, sidey) ** 2
print(res)
if __name__ == '__main__':
main()
``` | output | 1 | 37,197 | 15 | 74,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,198 | 15 | 74,396 |
Tags: brute force, greedy
Correct Solution:
```
# -*- coding: utf-8 -*-
# @Date : 2019-05-29 17:08:10
# @Author : raj lath (oorja.halt@gmail.com)
# @Link : link
# @Version : 1.0.0
import sys
sys.setrecursionlimit(10**5+1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb_mines = RI()
x_coord , y_coord = [], []
for _ in range(nb_mines):
x, y = RMI()
x_coord.append(x)
y_coord.append(y)
candidate_x = max(x_coord) - min(x_coord)
candidate_y = max(y_coord) - min(y_coord)
sides = max(candidate_x, candidate_y)
print(sides ** 2)
``` | output | 1 | 37,198 | 15 | 74,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,199 | 15 | 74,398 |
Tags: brute force, greedy
Correct Solution:
```
a=int(input())
x,y=map(int,input().split())
minx=x
maxx=x
miny=y
maxy=y
for i in range(a-1):
x,y=map(int,input().split())
minx=min(minx,x)
maxx=max(maxx,x)
miny=min(miny,y)
maxy=max(maxy,y)
print(max(maxx-minx,maxy-miny)**2)
``` | output | 1 | 37,199 | 15 | 74,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,200 | 15 | 74,400 |
Tags: brute force, greedy
Correct Solution:
```
n = int(input())
x, y = [], []
for j in range(n):
xj, yj = [int(j) for j in input().split()]
x.append(xj)
y.append(yj)
x_min = x[0]
y_min = y[0]
x_max = x[0]
y_max = y[0]
for j in range(1, n):
x_min = min(x_min, x[j])
y_min = min(y_min, y[j])
x_max = max(x_max, x[j])
y_max = max(y_max, y[j])
l = x_max - x_min
r = y_max - y_min
print(max(l, r) ** 2)
``` | output | 1 | 37,200 | 15 | 74,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,201 | 15 | 74,402 |
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
l,r,u,d=10**10,-10**10,10**10,-10**10
for i in range(n):
a,b=map(int,input().split())
l=min(a,l)
r=max(a,r)
u=min(u,b)
d=max(d,b)
print(max((d-u),(r-l))**2)
``` | output | 1 | 37,201 | 15 | 74,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,202 | 15 | 74,404 |
Tags: brute force, greedy
Correct Solution:
```
n = int(input())
p = []
s = []
for i in range(n):
x, y = map(int, input().split())
p.append(x)
s.append(y)
p.sort()
s.sort()
p = p[-1] - p[0]
s = s[-1] - s[0]
print(max(p, s) ** 2)
``` | output | 1 | 37,202 | 15 | 74,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,203 | 15 | 74,406 |
Tags: brute force, greedy
Correct Solution:
```
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter , defaultdict
from math import *
from itertools import permutations , accumulate
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
#visited = [[False for i in range(m)] for j in range(n)]
# primes = [2,11,101,1009,10007,100003,1000003,10000019,102345689]
#sys.stdin = open(r'input.txt' , 'r')
#sys.stdout = open(r'output.txt' , 'w')
#for tt in range(INT()):
#arr.sort(key=lambda x: (-d[x], x)) Sort with Freq
#Code
n = INT()
l1 = []
l2 = []
for i in range(n):
x,y = MAP()
l1.append(x)
l2.append(y)
minx = min(l1)
miny = min(l2)
maxx = max(l1)
maxy = max(l2)
k = max(maxx-minx , maxy - miny)
print(k**2)
``` | output | 1 | 37,203 | 15 | 74,407 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n β the number of mines on the map (2 β€ n β€ 1000). Each of the next n lines contains a pair of integers xi and yi β the coordinates of the corresponding mine ( - 109 β€ xi, yi β€ 109). All points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9 | instruction | 0 | 37,204 | 15 | 74,408 |
Tags: brute force, greedy
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy
n=int(input())
ox=[]
oy=[]
xmax=-10000000000000000000
xmin=10**10
ymax=-1000000000000000000
ymin=10**10
for i in range(n):
x,y=map(int,input().split())
if x>xmax:
xmax=copy(x)
if x<xmin:
xmin=copy(x)
if y>ymax:
ymax=copy(y)
if y<ymin:
ymin=copy(y)
dx=xmax-xmin
dy=ymax-ymin
a=max(dy,dx)
print(a**2)
``` | output | 1 | 37,204 | 15 | 74,409 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
<image>
Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.
You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.
A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.
Input
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.
The line after the table contains two integers x and y (1 β€ x, y β€ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.
It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
Examples
Input
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
... ... ...
... ... ...
... ... ...
6 4
Output
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
!!! ... ...
!!! ... ...
!!! ... ...
Input
xoo x.. x..
ooo ... ...
ooo ... ...
x.. x.. x..
... ... ...
... ... ...
x.. x.. x..
... ... ...
... ... ...
7 4
Output
xoo x!! x!!
ooo !!! !!!
ooo !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
Input
o.. ... ...
... ... ...
... ... ...
... xxx ...
... xox ...
... ooo ...
... ... ...
... ... ...
... ... ...
5 5
Output
o!! !!! !!!
!!! !!! !!!
!!! !!! !!!
!!! xxx !!!
!!! xox !!!
!!! ooo !!!
!!! !!! !!!
!!! !!! !!!
!!! !!! !!!
Note
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.
In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. | instruction | 0 | 37,427 | 15 | 74,854 |
Tags: implementation
Correct Solution:
```
a1 = input()
a2 = input()
a3 = input()
f=input()
b4 = input()
b5 = input()
b6 = input()
g=input()
c7 = input()
c8 = input()
c9 = input()
x,y=list(map(int,input().split()))
g=x % 3
h=y % 3
if g == 1:
if h == 1:
if '.' in a1[0:3] or '.' in a2[0:3] or '.' in a3[0:3]:
a1 = a1[0:3].replace('.', '!')+a1[3:]
a2 = a2[0:3].replace('.', '!')+a2[3:]
a3 = a3[0:3].replace('.', '!')+a3[3:]
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
if h==2:
if '.' in a1[4:7] or '.' in a2[4:7] or '.' in a3[4:7]:
a1 = a1[:4]+a1[4:7].replace('.', '!')+a1[7:]
a2 = a2[:4]+a2[4:7].replace('.', '!')+a2[7:]
a3 = a3[:4]+a3[4:7].replace('.', '!')+a3[7:]
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
if h==0:
if '.' in a1[8:11] or '.' in a2[8:11] or '.' in a3[8:11]:
a1 = a1[:8]+a1[8:11].replace('.', '!')
a2 = a2[:8]+a2[8:11].replace('.', '!')
a3 = a3[:8]+a3[8:11].replace('.', '!')
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
elif g==2:
if h == 1:
if '.' in b4[0:3] or '.' in b5[0:3] or '.' in b6[0:3]:
b4 = b4[0:3].replace('.', '!')+b4[3:]
b5 = b5[0:3].replace('.', '!')+b5[3:]
b6 = b6[0:3].replace('.', '!')+b6[3:]
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
if h == 2:
if '.' in b4[4:7] or '.' in b5[4:7] or '.' in b6[4:7]:
b4 = b4[:4]+b4[4:7].replace('.', '!')+b4[7:]
b5 = b5[:4]+b5[4:7].replace('.', '!')+b5[7:]
b6 = b6[:4]+b6[4:7].replace('.', '!')+b6[7:]
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
if h == 0:
if '.' in b4[8:11] or '.' in b5[8:11] or '.' in b6[8:11]:
b4 = b4[:8]+b4[8:11].replace('.', '!')
b5 = b5[:8]+b5[8:11].replace('.', '!')
b6 = b6[:8]+b6[8:11].replace('.', '!')
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
elif g==0:
if h == 1:
if '.' in c7[0:3] or '.' in c8[0:3] or '.' in c9[0:3]:
c7 = c7[0:3].replace('.', '!')+c7[3:]
c8 = c8[0:3].replace('.', '!')+c8[3:]
c9 = c9[0:3].replace('.', '!')+c9[3:]
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
if h == 2:
if '.' in c7[4:7] or '.' in c8[4:7] or '.' in c9[4:7]:
c7 = c7[:4]+c7[4:7].replace('.', '!')+c7[7:]
c8 = c8[:4]+c8[4:7].replace('.', '!')+c8[7:]
c9 = c9[:4]+c9[4:7].replace('.', '!')+c9[7:]
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
if h == 0:
if '.' in c7[8:11] or '.' in c8[8:11] or '.' in c9[8:11]:
c7 = c7[:8]+c7[8:11].replace('.', '!')
c8 = c8[:8]+c8[8:11].replace('.', '!')
c9 = c9[:8]+c9[8:11].replace('.', '!')
else:
a1 = a1.replace('.', '!')
a2 = a2.replace('.', '!')
a3 = a3.replace('.', '!')
b4 = b4.replace('.', '!')
b5 = b5.replace('.', '!')
b6 = b6.replace('.', '!')
c7 = c7.replace('.', '!')
c8 = c8.replace('.', '!')
c9 = c9.replace('.', '!')
print(a1)
print(a2)
print(a3)
print()
print(b4)
print(b5)
print(b6)
print()
print(c7)
print(c8)
print(c9)
``` | output | 1 | 37,427 | 15 | 74,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
<image>
Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.
You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.
A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.
Input
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.
The line after the table contains two integers x and y (1 β€ x, y β€ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.
It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
Examples
Input
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
... ... ...
... ... ...
... ... ...
6 4
Output
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
!!! ... ...
!!! ... ...
!!! ... ...
Input
xoo x.. x..
ooo ... ...
ooo ... ...
x.. x.. x..
... ... ...
... ... ...
x.. x.. x..
... ... ...
... ... ...
7 4
Output
xoo x!! x!!
ooo !!! !!!
ooo !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
Input
o.. ... ...
... ... ...
... ... ...
... xxx ...
... xox ...
... ooo ...
... ... ...
... ... ...
... ... ...
5 5
Output
o!! !!! !!!
!!! !!! !!!
!!! !!! !!!
!!! xxx !!!
!!! xox !!!
!!! ooo !!!
!!! !!! !!!
!!! !!! !!!
!!! !!! !!!
Note
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.
In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. | instruction | 0 | 37,428 | 15 | 74,856 |
Tags: implementation
Correct Solution:
```
R=input
g=[list(R()) for _ in range(11)]
r,c=map(int,R().split())
r,c=(r-1)%3*4,(c-1)%3*4
f,d='.!'
for i in range(9):
s,e=g[r+i//3],c+i%3
if s[e]<'o':
s[e]=f=d
for v in g:print(''.join(v).replace(f,d))
``` | output | 1 | 37,428 | 15 | 74,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
<image>
Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.
You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.
A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.
Input
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.
The line after the table contains two integers x and y (1 β€ x, y β€ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.
It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
Examples
Input
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
... ... ...
... ... ...
... ... ...
6 4
Output
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
!!! ... ...
!!! ... ...
!!! ... ...
Input
xoo x.. x..
ooo ... ...
ooo ... ...
x.. x.. x..
... ... ...
... ... ...
x.. x.. x..
... ... ...
... ... ...
7 4
Output
xoo x!! x!!
ooo !!! !!!
ooo !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
Input
o.. ... ...
... ... ...
... ... ...
... xxx ...
... xox ...
... ooo ...
... ... ...
... ... ...
... ... ...
5 5
Output
o!! !!! !!!
!!! !!! !!!
!!! !!! !!!
!!! xxx !!!
!!! xox !!!
!!! ooo !!!
!!! !!! !!!
!!! !!! !!!
!!! !!! !!!
Note
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.
In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. | instruction | 0 | 37,429 | 15 | 74,858 |
Tags: implementation
Correct Solution:
```
a = [""]*11
for i in range(11):
a[i]=list(input())
x,y = map(int, input().split())
k=0
x1=(x-1)%3
y1=(y-1)%3
if y1==0:
y2=2
if y1==1:
y2=6
y1=4
if y1==2:
y2=10
y1=8
if x1==0:
x2=2
if x1==1:
x2=6
x1=4
if x1==2:
x1=8
x2=10
for i in range(x1,x2+1):
for j in range(y1,y2+1):
if a[i][j]==".":
a[i][j]="!"
k=1
if k==0:
for i in range(11):
for j in range(11):
if i!=3 and i!=7 and j!=3 and j!=7:
if a[i][j]==".":
a[i][j]="!"
for row in a:
print(''.join([str(elem) for elem in row]))
print()
#οΏ½οΏ½οΏ½οΏ½οΏ½
``` | output | 1 | 37,429 | 15 | 74,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
<image>
Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.
You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.
A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.
Input
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.
The line after the table contains two integers x and y (1 β€ x, y β€ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.
It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
Examples
Input
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
... ... ...
... ... ...
... ... ...
6 4
Output
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
!!! ... ...
!!! ... ...
!!! ... ...
Input
xoo x.. x..
ooo ... ...
ooo ... ...
x.. x.. x..
... ... ...
... ... ...
x.. x.. x..
... ... ...
... ... ...
7 4
Output
xoo x!! x!!
ooo !!! !!!
ooo !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
Input
o.. ... ...
... ... ...
... ... ...
... xxx ...
... xox ...
... ooo ...
... ... ...
... ... ...
... ... ...
5 5
Output
o!! !!! !!!
!!! !!! !!!
!!! !!! !!!
!!! xxx !!!
!!! xox !!!
!!! ooo !!!
!!! !!! !!!
!!! !!! !!!
!!! !!! !!!
Note
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.
In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. | instruction | 0 | 37,430 | 15 | 74,860 |
Tags: implementation
Correct Solution:
```
import collections, math
local = False
if local:
file = open("inputt.txt", "r")
def inp():
if local:
return file.readline().rstrip()
else:
return input().rstrip()
def ints():
return [int(_) for _ in inp().split()]
fromTos = [(0,2), (3,5), (6,8)]
grid = []
for i in range(0, 9):
if i%3==0 and i!=0:
inp()
row = inp()
grid.append([])
for colbig in row.split():
grid[-1].append([])
for sign in colbig:
grid[-1][-1].append(sign)
x, y = ints()
x = (x-1)%3
y = (y-1)%3
foundFree = False
for i in range(x*3, x*3+3):
for k in range(0,3):
val = grid[i][y][k]
if val != 'x' and val != 'o':
foundFree = True
grid[i][y][k] = "!"
if not foundFree:
for i in range(0, 9):
for j in range(0,3):
for k in range(0,3):
val = grid[i][j][k]
if val != 'x' and val != 'o':
grid[i][j][k] = "!"
for i in range(0, 3):
row = ""
for j in range(0, 3):
row += "".join(grid[i][j])
if j<2:
row += " "
print(row)
print("")
for i in range(3, 6):
row = ""
for j in range(0, 3):
row += "".join(grid[i][j])
if j<2:
row += " "
print(row)
print("")
for i in range(6, 9):
row = ""
for j in range(0, 3):
row += "".join(grid[i][j])
if j<2:
row += " "
print(row)
print("")
``` | output | 1 | 37,430 | 15 | 74,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
<image>
Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.
You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.
A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.
Input
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.
The line after the table contains two integers x and y (1 β€ x, y β€ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.
It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
Examples
Input
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
... ... ...
... ... ...
... ... ...
6 4
Output
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
!!! ... ...
!!! ... ...
!!! ... ...
Input
xoo x.. x..
ooo ... ...
ooo ... ...
x.. x.. x..
... ... ...
... ... ...
x.. x.. x..
... ... ...
... ... ...
7 4
Output
xoo x!! x!!
ooo !!! !!!
ooo !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
x!! x!! x!!
!!! !!! !!!
!!! !!! !!!
Input
o.. ... ...
... ... ...
... ... ...
... xxx ...
... xox ...
... ooo ...
... ... ...
... ... ...
... ... ...
5 5
Output
o!! !!! !!!
!!! !!! !!!
!!! !!! !!!
!!! xxx !!!
!!! xox !!!
!!! ooo !!!
!!! !!! !!!
!!! !!! !!!
!!! !!! !!!
Note
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.
In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. | instruction | 0 | 37,431 | 15 | 74,862 |
Tags: implementation
Correct Solution:
```
l=[input() for _ in range(11)]
x,y=map(int, input().split())
x-=1
x+=x//3
y-=1
y+=y//3
a,b=x%4*4,y%4*4
f=1
for i in range(a,a+3):
r=l[i][b:b+3].replace('.','!')
if r!=l[i][b:b+3]:
l[i]=l[i][:b]+r+l[i][b+3:]
f=0
if f:
for i in range(11):
l[i]=l[i].replace('.','!')
print(*l,sep='\n')
``` | output | 1 | 37,431 | 15 | 74,863 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.