message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 β€ x_1, x_2, x_3 β€ n, 0 β€ y_1, y_2, y_3 β€ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1β€ n, m β€ 10^9, 2 β€ k β€ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i β coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
p=input().split()
n=int(p[0])
m=int(p[1])
k=int(p[2])
cnt=0
if (2*n*m%k)!=0:
print('NO')
else:
print('YES')
if k%2==0:
k//=2
cnt=1
n1=n
k1=k
if n1<k1:
n1,k1=k1,n1
while k1!=0:
n1,k1=k1,n1%k1
kk=k/n1
a=n/n1
b=m/kk
if cnt==0:
if a<n:
a*=2
else:
b*=2
a=int(a)
b=int(b)
print(0,0)
print(a,0)
print(0,b)
``` | instruction | 0 | 33,346 | 23 | 66,692 |
Yes | output | 1 | 33,346 | 23 | 66,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 β€ x_1, x_2, x_3 β€ n, 0 β€ y_1, y_2, y_3 β€ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1β€ n, m β€ 10^9, 2 β€ k β€ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i β coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
n, m, k = map(int, input().split())
if 2 * n * m % k != 0:
print("NO")
exit(0)
g = n
b = k
while g > 0 and b > 0:
if g > b:
g %= b
else:
b %= g
g = g + b
k1 = k // g
p = False
if k1 % 2 == 0:
k1 //= 2
p = True
a = n // g
b = m // k1
if not p:
if a < n:
a *= 2
else:
b *= 2
print("YES")
# print(a * b // 2, n * m // k)
print(0, 0)
print(a, 0)
print(0, b)
``` | instruction | 0 | 33,347 | 23 | 66,694 |
Yes | output | 1 | 33,347 | 23 | 66,695 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 β€ x_1, x_2, x_3 β€ n, 0 β€ y_1, y_2, y_3 β€ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1β€ n, m β€ 10^9, 2 β€ k β€ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i β coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
from fractions import gcd
pr = stdout.write
mod=10**9+7
def ni():
return int(raw_input())
def li():
return map(int,raw_input().split())
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
# main code
n,m,k=li()
if (2*n*m)%k:
pr('NO')
exit()
f=0
pr('YES\n')
if k%2==0:
k/=2
f=1
g=gcd(k,n)
k1=k/g
a=n/g
b=m/k1
if not f:
if a*2<n:
a*=2
else:
b*=2
pa([0,0])
pa([a,0])
pa([0,b])
``` | instruction | 0 | 33,348 | 23 | 66,696 |
Yes | output | 1 | 33,348 | 23 | 66,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 β€ x_1, x_2, x_3 β€ n, 0 β€ y_1, y_2, y_3 β€ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1β€ n, m β€ 10^9, 2 β€ k β€ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i β coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
def gcd(a, b):
while b:
a, b = b, a % b
return a
a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
print('NO')
bul = False
if k % 2 == 0:
k = k // 2
bu = False
if bul:
print('YES')
print('0 0')
g = gcd(n, k)
ai = n // g
g = gcd(m, k)
bi = m // g
if bu:
if ai < n:
ai = ai * 2
else:
bi = bi * 2
print('{} 0'.format(ai))
print('0 {}'.format(bi))
``` | instruction | 0 | 33,349 | 23 | 66,698 |
No | output | 1 | 33,349 | 23 | 66,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 β€ x_1, x_2, x_3 β€ n, 0 β€ y_1, y_2, y_3 β€ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1β€ n, m β€ 10^9, 2 β€ k β€ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i β coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
from math import gcd
n,m,k=map(int,input().split())
tt,pp=n,m
xx=gcd(n,k)
k=k//xx
n=n//xx
xx=gcd(m,k)
k=k//xx
m=m//xx
if k>2:
print('NO')
else:
x=0
print('YES')
print(0,0)
if 2*n<=tt:
print(2*n,0)
x=1
else:
print(n,0)
if 2*m<=pp and not x:
print(0,2*m)
else:
print(0,m)
``` | instruction | 0 | 33,350 | 23 | 66,700 |
No | output | 1 | 33,350 | 23 | 66,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 β€ x_1, x_2, x_3 β€ n, 0 β€ y_1, y_2, y_3 β€ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1β€ n, m β€ 10^9, 2 β€ k β€ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i β coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
read = lambda: map(int, input().split())
gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
n, m, k = read()
if (2 * n * m) % k:
print("NO")
exit()
nk = gcd(n, k)
n1 = n // nk
m1 = 2 * n * m // n1 // k
print("YES")
print(0, 0)
print(n1, 0)
print(0, m1)
``` | instruction | 0 | 33,351 | 23 | 66,702 |
No | output | 1 | 33,351 | 23 | 66,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 β€ x_1, x_2, x_3 β€ n, 0 β€ y_1, y_2, y_3 β€ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1β€ n, m β€ 10^9, 2 β€ k β€ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i β coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
def GCD(a, b):
while a != 0 and b != 0:
if a > b:
a %= b
else:
b %= a
return a + b
s = input().split(' ')
n = int(s[0])
m = int(s[1])
k = int(s[2])
if 2 * n * m % k != 0:
print("NO")
exit()
k1 = GCD(n,k);
k2 = k // k1;
x = n // k1;
y = m // k2;
if 2 * x <= n:
x *= 2
elif 2 * y <= m:
y *= 2
else:
print("NO")
exit()
print("YES")
print(0, y)
print(0, 0)
print(x, 0)
``` | instruction | 0 | 33,352 | 23 | 66,704 |
No | output | 1 | 33,352 | 23 | 66,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,369 | 23 | 66,738 |
Tags: brute force, geometry
Correct Solution:
```
import math
class Solve(object):
def solve(self, T):
for i in range(T):
n = int(input())
gcd = math.gcd(n, 180)
ans = 180 // gcd
if ans - n // gcd <= 1:
ans *= 2
print(ans)
if __name__ == '__main__':
T = int(input())
s = Solve()
s.solve(T)
``` | output | 1 | 33,369 | 23 | 66,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,370 | 23 | 66,740 |
Tags: brute force, geometry
Correct Solution:
```
import math
for _ in range(int(input())):
a=int(input())
g=math.gcd(180,a)
k=a//g
n=180//g
if k+1==n:
n*=2
print(n)
``` | output | 1 | 33,370 | 23 | 66,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,371 | 23 | 66,742 |
Tags: brute force, geometry
Correct Solution:
```
from math import gcd
n = int(input())
for t in range(n):
ang = int(input())
if ang == 179:
print(360)
elif ang == 178:
print(180)
elif ang == 90:
print(4)
else:
z = gcd(ang, 180)
if 180%(180-ang) == 0:
print(360//z)
else:
print(180//z)
``` | output | 1 | 33,371 | 23 | 66,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,372 | 23 | 66,744 |
Tags: brute force, geometry
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
for i in range(3,10001):
deg = 180/i
if n%deg==0 and n<=(i-2)*(deg):
print(i)
break
``` | output | 1 | 33,372 | 23 | 66,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,373 | 23 | 66,746 |
Tags: brute force, geometry
Correct Solution:
```
import math
T = int(input())
for _ in range(T):
ang = int(input())
d = math.gcd(180,ang)
n = 180 // d
k = ang // d
if (n == k + 1): n *= 2
print(n)
``` | output | 1 | 33,373 | 23 | 66,747 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,374 | 23 | 66,748 |
Tags: brute force, geometry
Correct Solution:
```
def compute_gcd(a, b):
while b:
a, b = b, a%b
return a
T = int(input())
while T:
x = int(input())
gcd = compute_gcd(180, x)
if 180%gcd > 0:
print(-1)
else:
n = int(180/gcd)
if n * gcd == 180:
y = (x * n) / 180
if y == n-1:
n = 2*n
else:
n=-1
print(n)
T-=1
``` | output | 1 | 33,374 | 23 | 66,749 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,375 | 23 | 66,750 |
Tags: brute force, geometry
Correct Solution:
```
import sys
prev = {}
def mprint(ang):
if ang in prev:
print(prev[ang])
return
for i in range(3, 361):
for j in range(1, i-1):
if abs((j * 180 / i) - ang) < 1e-6:
print(i)
prev[ang] = i
return
t = int(input())
for i in range(t):
ang = float(input())
mprint(ang)
``` | output | 1 | 33,375 | 23 | 66,751 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90). | instruction | 0 | 33,376 | 23 | 66,752 |
Tags: brute force, geometry
Correct Solution:
```
def mingon(angle):
if angle == 90:
return 4
elif angle < 90:
for i in range(1,2*angle +1):
if 360 % (2*angle/i) == 0:
return int(360/(2*angle/i))
else:
for i in range(2,2*(180-angle) +1):
if 360 % (2*(180-angle)/i) == 0:
return int(360/(2*(180-angle)/i))
t = int(input())
for i in range(t):
ang = int(input())
print(mingon(ang))
``` | output | 1 | 33,376 | 23 | 66,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
for a0 in range(int(input())):
t=int(input())
flag=0
for n in range(2,361):
for k in range(1,n-1):
if (k*180)/t==n:
flag=1
print(n)
break
if flag:
break
if flag==0:
print(-1)
``` | instruction | 0 | 33,377 | 23 | 66,754 |
Yes | output | 1 | 33,377 | 23 | 66,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
from fractions import gcd
t = int(input())
ans = []
start = time.time()
for i in range(t):
ang = int(input())
g = gcd (180, ang)
n = 180//g
k = ang//g
if k == n - 1 :
n *= 2
ans.append(n)
for i in range(t):
print(ans[i])
finish = time.time()
#print(finish - start)
``` | instruction | 0 | 33,378 | 23 | 66,756 |
Yes | output | 1 | 33,378 | 23 | 66,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
t = int(input())
for i in range(t):
ang = int(input())
for n in range(3, 361):
ang1 = 360. / (2 * n)
tt = int(ang / ang1)
while tt * 360 < ang * 2 * n:
tt += 1
while tt * 360 > ang * 2 * n:
tt -= 1
if tt <= n - 2 and tt * 360 == ang * 2 * n:
print(n)
break
``` | instruction | 0 | 33,379 | 23 | 66,758 |
Yes | output | 1 | 33,379 | 23 | 66,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
def gcd(a, b):
if(not b):
return a
return gcd(b, a % b)
t = int(input())
for i in range(t):
ang = int(input())
g = gcd(ang, 180)
n = 180 // g
k = ang // g
if(k == n - 1):
n *= 2
k *= 2
print(n)
``` | instruction | 0 | 33,380 | 23 | 66,760 |
Yes | output | 1 | 33,380 | 23 | 66,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
import math
import sys
amount = int(input())
for i in range(amount):
angle = int(input())
if angle == 179:
print(360)
continue
divisors = []
for j in range(1, int(math.sqrt(angle)) + 1):
if angle % j == 0:
divisors.append(j)
divisors.append(angle // j)
max_ = -1
#print(divisors)
for k in range(len(divisors)):
if 360 % (2 * divisors[k]) == 0:
if divisors[k] > max_ and ((360 // (2 * divisors[k])) >= ((angle // divisors[k]) + 2)):
max_ = divisors[k]
if max_ == -1:
print(-1)
else:
print(360 // (2 * max_))
#998244353
``` | instruction | 0 | 33,381 | 23 | 66,762 |
No | output | 1 | 33,381 | 23 | 66,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
import math
n = int(input())
q = list(range(n))
for i in range(0,n):
ang = int(input())
q1 = pow(ang,1/2)
for j in range(0,math.ceil(q1)):
if math.ceil(ang/(j+1)) == math.floor(ang/(j+1)):
t = 360 / (ang*2 / (j + 1))
if math.ceil(t) == math.floor(t):
if math.ceil(360/t) == math.floor(360/t):
q[i] = t
break
for i in range(0,n):
print(int(q[i]))
``` | instruction | 0 | 33,382 | 23 | 66,764 |
No | output | 1 | 33,382 | 23 | 66,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
from math import gcd
for _ in range(int(input())):
x = int(input())
y = gcd(180, x)
if(x > 90):
print(180)
else:
print(int(180/y))
``` | instruction | 0 | 33,383 | 23 | 66,766 |
No | output | 1 | 33,383 | 23 | 66,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1 β€ T β€ 180) β the number of queries.
Each of the next T lines contains one integer ang (1 β€ ang < 180) β the angle measured in degrees.
Output
For each query print single integer n (3 β€ n β€ 998244353) β minimal possible number of vertices in the regular n-gon or -1 if there is no such n.
Example
Input
4
54
50
2
178
Output
10
18
90
180
Note
The answer for the first query is on the picture above.
The answer for the second query is reached on a regular 18-gon. For example, \angle{v_2 v_1 v_6} = 50^{\circ}.
The example angle for the third query is \angle{v_{11} v_{10} v_{12}} = 2^{\circ}.
In the fourth query, minimal possible n is 180 (not 90).
Submitted Solution:
```
from math import gcd
n = int(input())
for t in range(n):
ang = int(input())
if ang >= 90:
print(int(360 / (180-ang)))
else:
print(int(180/(gcd(ang, 180))))
``` | instruction | 0 | 33,384 | 23 | 66,768 |
No | output | 1 | 33,384 | 23 | 66,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya learned that, given two points with different x coordinates, you can draw through them exactly one parabola with equation of type y = x^2 + bx + c, where b and c are reals. Let's call such a parabola an U-shaped one.
Vasya drew several distinct points with integer coordinates on a plane and then drew an U-shaped parabola through each pair of the points that have different x coordinates. The picture became somewhat messy, but Vasya still wants to count how many of the parabolas drawn don't have any drawn point inside their internal area. Help Vasya.
The internal area of an U-shaped parabola is the part of the plane that lies strictly above the parabola when the y axis is directed upwards.
Input
The first line contains a single integer n (1 β€ n β€ 100 000) β the number of points.
The next n lines describe the points, the i-th of them contains two integers x_i and y_i β the coordinates of the i-th point. It is guaranteed that all points are distinct and that the coordinates do not exceed 10^6 by absolute value.
Output
In the only line print a single integer β the number of U-shaped parabolas that pass through at least two of the given points and do not contain any of the given points inside their internal area (excluding the parabola itself).
Examples
Input
3
-1 0
0 2
1 0
Output
2
Input
5
1 0
1 -1
0 -1
-1 0
-1 -1
Output
1
Note
On the pictures below all U-shaped parabolas that pass through at least two given points are drawn for each of the examples. The U-shaped parabolas that do not have any given point inside their internal area are drawn in red.
<image> The first example. <image> The second example. | instruction | 0 | 33,401 | 23 | 66,802 |
Tags: geometry
Correct Solution:
```
import sys
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
N = int(input())
A = [None]*N
for i in range(N):
x, y = map(int, sys.stdin.readline().split())
A[i] = (x, y-x*x)
A.sort()
upper = []
for p in reversed(A):
while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:
upper.pop()
upper.append(p)
while len(upper) >= 2 and upper[-1][0] == upper[-2][0]:
upper.pop()
print(len(upper) - 1)
``` | output | 1 | 33,401 | 23 | 66,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,646 | 23 | 67,292 |
Tags: brute force, implementation
Correct Solution:
```
na, ma = map(int, input().split())
A = [[0] * 50 for i in range(50)]
for i in range(50 - na, 50):
t = int(input(), 2)
for j in range(50):
A[i][49 - j] = t
t //= 2
nb, mb = map(int, input().split())
B = [[0] * 50 for i in range(50)]
for i in range(50 - nb, 50):
t = int(input(), 2)
for j in range(50):
B[i][49 - j] = t
t //= 2
x, y, ans = 0, 0, -1
for i in range(50):
for j in range(50):
s = sum(bin(A[k][j] & B[49 - i + k][49]).count('1') for k in range(i + 1))
if s > ans:
ans = s
x, y = i, j
for i in range(50, 99):
for j in range(50):
s = sum(bin(A[k][j] & B[49 - i + k][49]).count('1') for k in range(i - 49, 50))
if s > ans:
ans = s
x, y = i, j
for i in range(50):
for j in range(50, 99):
s = sum(bin(A[k][49] & B[49 - i + k][98 - j]).count('1') for k in range(i + 1))
if s > ans:
ans = s
x, y = i, j
for i in range(50, 99):
for j in range(50, 99):
s = sum(bin(A[k][49] & B[49 - i + k][98 - j]).count('1') for k in range(i - 49, 50))
if s > ans:
ans = s
x, y = i, j
print(49 - x + nb - na, 49 - y + mb - ma)
``` | output | 1 | 33,646 | 23 | 67,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,647 | 23 | 67,294 |
Tags: brute force, implementation
Correct Solution:
```
n,m=map(int,input().split())
ar=[]
for i in range(n):
ar.append(list(map(int,list(input()))))
a,b=map(int,input().split())
arr=[]
for j in range(a):
arr.append(list(map(int,list(input()))))
def check(x,y):
res=0
for i in range(n):
for j in range(m):
if i+x<a and j+y<b and i+x>=0 and j+y>=0:
res+=ar[i][j]*arr[i+x][j+y]
return res
z=0
ay=[0,0]
for i in range(-50,51):
for j in range(-50,51):
ans=check(i,j)
if ans>z:
z=ans
ay[0]=i
ay[1]=j
print(*ay)
``` | output | 1 | 33,647 | 23 | 67,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,648 | 23 | 67,296 |
Tags: brute force, implementation
Correct Solution:
```
na, ma = map(int, input().split())
ta = [int(input(), 2) for i in range(na)]
nb, mb = map(int, input().split())
tb = [input() for i in range(nb)]
sz1, sz2 = ma - 1, na - 1
x, y = '0' * sz1, '0' * (2 * sz1 + mb)
t = [y] * sz2 + [x + tb[i] + x for i in range(nb)] + [y] * sz2
res = -1
for i in range(na + nb - 1):
for j in range(ma + mb - 1):
lst = [bin(int(t[i+k][j:j+ma], 2) & ta[k]).count('1') for k in range(na)]
s = sum(lst)
if s > res:
res = s
x, y = j, i
print(y-na+1, x-ma+1)
``` | output | 1 | 33,648 | 23 | 67,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,649 | 23 | 67,298 |
Tags: brute force, implementation
Correct Solution:
```
def mi():
return map(int, input().split())
def mi1():
return map(int, list(input()))
'''
3 2
01
10
00
2 3
001
111
'''
na, ma = mi()
a = [0]*na
for i in range(na):
a[i] = list(mi1())
nb, mb = mi()
b = [0]*nb
for i in range(nb):
b[i] = list(mi1())
ans = -10**10
ax, ay = 0, 0
n, m = max(na, nb), max(ma, mb)
for x in range(-n, n+1):
for y in range(-m, m+1):
res = 0
for i in range(na):
for j in range(ma):
if x+i>=0 and y+j>=0 and x+i<nb and y+j<mb:
res+=a[i][j]*b[x+i][y+j]
if res>=ans:
ax, ay = x, y
ans = res
print (ax, ay)
``` | output | 1 | 33,649 | 23 | 67,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,650 | 23 | 67,300 |
Tags: brute force, implementation
Correct Solution:
```
na,ma=[int(x) for x in input().split()]
a=[]
for i in range(na):
a.append([int(x) for x in list(input())])
nb,mb=[int(x) for x in input().split()]
b=[]
for i in range(nb):
b.append([int(x) for x in list(input())])
def cal(x,y):
ans=0
for i in range(na):
for j in range(ma):
if i+x<nb and i+x>-1 and j+y<mb and j+y>-1:
v1=int(b[i+x][j+y])
v2=int(a[i][j])
ans+=v1*v2
return ans
ans=-1
X=100
Y=100
for x in range(-50,51):
for y in range(-50,51):
if cal(x,y)>ans:
ans=cal(x,y)
X=x
Y=y
print(X,Y)
``` | output | 1 | 33,650 | 23 | 67,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,651 | 23 | 67,302 |
Tags: brute force, implementation
Correct Solution:
```
na,ma=map(int,input().split())
tab_a=list();tab_b=list();minx=0;mx=0;my=0;
for i in range(na):
tab_a.append([int(i) for i in list(input())])
nb,mb=map(int,input().split())
for i in range(nb):
tab_b.append([int(i) for i in list(input())])
for x in range(-50,51):
for y in range(-50,51):
tot=0
for i in range(na):
for j in range(ma):
if(i+x>=nb or j+y>=mb or j+y<0 or i+x<0):
continue
#print(tab_a[i][j],tab_b[i+x][j+y])
tot+=tab_a[i][j]*tab_b[i+x][j+y]
if(tot>minx):
mx=x
my=y
minx=tot
print(mx,my)
``` | output | 1 | 33,651 | 23 | 67,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,652 | 23 | 67,304 |
Tags: brute force, implementation
Correct Solution:
```
n1,m1=map(int,input().split())
a=[]
for i in range(n1):
a.append([int(i) for i in input()])
n2,m2=map(int,input().split())
b=[]
for i in range(n2):
b.append([int(i) for i in input()])
ans1=0
ans2=0
maxi=-1000000000000
for x in range(-50,51):
for y in range(-50,51):
curr=0
for i in range(n1):
for j in range(m1):
if i+x<n2 and j+y<m2 and i+x>=0 and j+y>=0 :
curr+=a[i][j]*b[i+x][j+y]
if curr>maxi:
maxi=curr
ans1=x
ans2=y
print(ans1,ans2)
``` | output | 1 | 33,652 | 23 | 67,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1 | instruction | 0 | 33,653 | 23 | 67,306 |
Tags: brute force, implementation
Correct Solution:
```
na, ma = map(int, input().split())
A = [[0] * 50 for i in range(50)]
for i in range(50 - na, 50):
t = int(input(), 2)
for j in range(50):
A[i][49 - j] = t
t //= 2
nb, mb = map(int, input().split())
B = [[0] * 50 for i in range(50)]
for i in range(50 - nb, 50):
t = int(input(), 2)
for j in range(50):
B[i][49 - j] = t
t //= 2
x, y, ans = 0, 0, -1
for i in range(50):
for j in range(50):
s = sum(bin(A[k][j] & B[49 - i + k][49]).count('1') for k in range(i + 1))
if s > ans:
ans = s
x, y = i, j
for i in range(50, 99):
for j in range(50):
s = sum(bin(A[k][j] & B[49 - i + k][49]).count('1') for k in range(i - 49, 50))
if s > ans:
ans = s
x, y = i, j
for i in range(50):
for j in range(50, 99):
s = sum(bin(A[k][49] & B[49 - i + k][98 - j]).count('1') for k in range(i + 1))
if s > ans:
ans = s
x, y = i, j
for i in range(50, 99):
for j in range(50, 99):
s = sum(bin(A[k][49] & B[49 - i + k][98 - j]).count('1') for k in range(i - 49, 50))
if s > ans:
ans = s
x, y = i, j
print(49 - x + nb - na, 49 - y + mb - ma)
# Made By Mostafa_Khaled
``` | output | 1 | 33,653 | 23 | 67,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
"""http://codeforces.com/problemset/problem/228/Bv"""
def f():
return list(map(int, input().split()))
def count_1(n, m):
s = set()
for i in range(n):
l = input()
for j in range(m):
if l[j] == '1':
s.add((i, j))
return s
def solve():
res = 0, 0
best = -1
a = count_1(*f())
b = count_1(*f())
mapping = [ [0] * 100 for _ in range(100) ]
for ai, aj in a:
for bi, bj in b:
i, j = bi - ai, bj - aj
mapping[i][j] += 1
for i in range(-50, 50):
for j in range(-50, 50):
if mapping[i][j] > best:
best = mapping[i][j]
res = i, j
print(res[0], res[1])
if __name__ == '__main__':
solve()
``` | instruction | 0 | 33,654 | 23 | 67,308 |
Yes | output | 1 | 33,654 | 23 | 67,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
class CodeforcesTask228BSolution:
def __init__(self):
self.result = ''
self.n1_m1 = []
self.matrix1 = []
self.n2_m2 = []
self.matrix2 = []
def read_input(self):
self.n1_m1 = [int(x) for x in input().split(" ")]
for x in range(self.n1_m1[0]):
self.matrix1.append([int(y) for y in input()])
self.n2_m2 = [int(x) for x in input().split(" ")]
for x in range(self.n2_m2[0]):
self.matrix2.append([int(y) for y in input()])
def process_task(self):
mx_factor = 0
mx_choose = (0, 0)
for x in range(-50, 51):
for y in range(-50, 51):
factor = 0
for i in range(self.n1_m1[0]):
if 0 <= i + x < self.n2_m2[0]:
for j in range(self.n1_m1[1]):
if 0 <= j + y < self.n2_m2[1]:
factor += self.matrix1[i][j] * self.matrix2[x + i][y + j]
if factor > mx_factor:
mx_factor = factor
mx_choose = (x, y)
self.result = "{0} {1}".format(*mx_choose)
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask228BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | instruction | 0 | 33,655 | 23 | 67,310 |
Yes | output | 1 | 33,655 | 23 | 67,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
na, ma = map(int, input().split())
a = [list(map(int, input())) for _ in range(na)]
nb, mb = map(int, input().split())
b = [list(map(int, input())) for _ in range(nb)]
best = 0
points = (0, 0)
for x in range(-50, 51):
for y in range(-50, 51):
ct = 0
for i in range(na):
if x+i < 0:
continue
if x+i >= nb:
break
for j in range(ma):
if y+j < 0:
continue
if y+j >= mb:
break
ct += a[i][j] * b[i+x][j+y]
if ct >= best:
best = ct
points = (x, y)
print(points[0], points[1])
``` | instruction | 0 | 33,656 | 23 | 67,312 |
Yes | output | 1 | 33,656 | 23 | 67,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
from sys import stdin,stdout
from math import gcd
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
na, ma = iia()
a1 = []
for _ in range(na):
a1.append(list(map(int,list(is1()))))
nb, mb = iia()
a2 = []
for _ in range(nb):
a2.append(list(map(int, list(is1()))))
res = [0,-1,-1]
shift = max(na, ma, nb, mb)
for x in range(-shift, shift + 1):
for y in range(-shift, shift + 1):
temp = 0
for i in range(na):
for j in range(ma):
if i + x >= 0 and i + x < nb and j + y >= 0 and j + y < mb:
temp += a1[i][j] * a2[i + x][j + y]
if temp > res[0]:
res[0] = temp
res[1], res[2] = x, y
print(res[1],res[2])
``` | instruction | 0 | 33,657 | 23 | 67,314 |
Yes | output | 1 | 33,657 | 23 | 67,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
n,m=[int(X) for X in input().split()]
arr1=[]
for i in range(n):
temp=input()
arr1.append(temp)
q,w=[int(x) for x in input().split()]
arr2=[]
for i in range(q):
temp=input()
arr2.append(temp)
#print(n,m,q,w)
#print(len(arr1),len(arr1[0]))
shift=0
maxy,maxx=-1,-1
for i in range(q):
for j in range(w):
curr=0
for a in range(n):
for b in range(m):
if i+a<q and j+b<w:
curr+=(int(arr1[a][b])*int(arr2[a+i][b+j]))
if curr>shift:
maxx=i
maxy=j
shift=curr
print(maxx,maxy)
``` | instruction | 0 | 33,658 | 23 | 67,316 |
No | output | 1 | 33,658 | 23 | 67,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
def main():
rowA,colA = map(int,input().split())
a = []
for i in range (0,rowA):
t = str(input())
a.append(t)
rowB,colB = map(int,input().split())
b = []
for i in range (0,rowB):
b.append(str(input()))
x = 0
y = 0
i = 0
j = 0
temp = 0
ans = 0
for x in range (-rowB,rowB):
for y in range (-colB,colB):
for i in range(0,rowA):
for j in range(0,colA):
#print(i,j,x,y)
if( i + x < rowB and j + y < colB and i + x > -1 and j + y > -1):
ans = ans + int(a[i][j]) * int(b[i + x][j + y])
if(temp < ans):
temp = ans
a1,a2 = x,y
ans = 0
print(a1,a2)
main()
``` | instruction | 0 | 33,659 | 23 | 67,318 |
No | output | 1 | 33,659 | 23 | 67,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
na, ma = map(int, input().split())
A = [[0] * 50 for i in range(50)]
for i in range(50 - na, 50):
t = int(input(), 2)
for j in range(50):
A[i][49 - j] = t
t //= 2
nb, mb = map(int, input().split())
B = [[0] * 50 for i in range(50)]
for i in range(50 - nb, 50):
t = int(input(), 2)
for j in range(50):
B[i][49 - j] = t
t //= 2
x, y, ans = 0, 0, -1
for i in range(50):
for j in range(50):
s = sum(bin(A[k][j] & B[49 - i + k][49]).count('1') for k in range(i + 1))
if s > ans:
ans = s
x, y = i, j
for i in range(50, 99):
for j in range(50):
s = sum(bin(A[k][j] & B[49 - i + k][49]).count('1') for k in range(i - 50, 50))
if s > ans:
ans = s
x, y = i, j
for i in range(50):
for j in range(50, 99):
s = sum(bin(A[k][49] & B[49 - i + k][98 - j]).count('1') for k in range(i + 1))
if s > ans:
ans = s
x, y = i, j
for i in range(50, 99):
for j in range(50, 99):
s = sum(bin(A[k][49] & B[49 - i + k][98 - j]).count('1') for k in range(i - 50, 50))
if s > ans:
ans = s
x, y = i, j
print(49 - x + nb - na, 49 - y + mb - ma)
``` | instruction | 0 | 33,660 | 23 | 67,320 |
No | output | 1 | 33,660 | 23 | 67,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two rectangular tables with sizes na Γ ma and nb Γ mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.
We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value:
<image>
where the variables i, j take only such values, in which the expression ai, jΒ·bi + x, j + y makes sense. More formally, inequalities 1 β€ i β€ na, 1 β€ j β€ ma, 1 β€ i + x β€ nb, 1 β€ j + y β€ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.
Your task is to find the shift with the maximum overlap factor among all possible shifts.
Input
The first line contains two space-separated integers na, ma (1 β€ na, ma β€ 50) β the number of rows and columns in the first table. Then na lines contain ma characters each β the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separated integers nb, mb (1 β€ nb, mb β€ 50) β the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.
It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".
Output
Print two space-separated integers x, y (|x|, |y| β€ 109) β a shift with maximum overlap factor. If there are multiple solutions, print any of them.
Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
Submitted Solution:
```
na,ma=map(int,input().split())
tab_a=list();tab_b=list();minx=0;mx=0;my=0;
for i in range(na):
tab_a.append([int(i) for i in list(input())])
nb,mb=map(int,input().split())
for i in range(nb):
tab_b.append([int(i) for i in list(input())])
for x in range(-50,51):
for y in range(-50,51):
for i in range(na):
tot=0
for j in range(ma):
if(i+x>=nb or j+y>=mb or j+y<0 or i+x<0):
continue
#print(tab_a[i][j],tab_b[i+x][j+y])
tot+=tab_a[i][j]*tab_b[i+x][j+y]
if(tot>minx):
mx=x
my=y
minx=tot
print(mx,my)
``` | instruction | 0 | 33,661 | 23 | 67,322 |
No | output | 1 | 33,661 | 23 | 67,323 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,752 | 23 | 67,504 |
Tags: brute force, geometry
Correct Solution:
```
import itertools
from itertools import permutations as perm
l = [[int(x) for x in input().split()] for i in range(8)]
def dist2(p0,p1):
return sum([(p0[i]-p1[i])**2 for i in range(3)])
def check(c):
dists = [[(c[i][0]-c[j][0])**2+(c[i][1]-c[j][1])**2+(c[i][2]-c[j][2])**2 for i in range(8)] for j in range(8)]
s2 = min([min(l) for l in dists])
return all([sorted(l) == [0,s2,s2,s2,2*s2,2*s2,2*s2,3*s2] for l in dists])
def sub(p0,p1):
return [p0[i]-p1[i] for i in range(3)]
def add(p0,p1):
return [p0[i]+p1[i] for i in range(3)]
def div(p0,x):
return [p0[i]//x for i in range(3)]
def cross(p0,p1):
return [p0[(i+1)%3]*p1[(i+2)%3]-p0[(i+2)%3]*p1[(i+1)%3] for i in range(3)]
def match(p0,p1):
return sorted(p0) == sorted(p1)
def poss(i,prior,s):
if i == len(l): return check(prior)
for p in perm(l[i]):
if i == 1: print(p)
possible = True
for p2 in prior:
if dist2(p,p2) not in [s,2*s,3*s]:
possible = False
break
if possible:
if poss(i+1,prior+[p]): return True
return False
solved = False
for l2 in perm(l,3):
p0 = l2[0]
for p1 in perm(l2[1]):
s2 = dist2(p0,p1)
if s2 == 0: continue
s = round(s2**.5)
if s**2 != s2: continue
for p2 in perm(l2[2]):
if dist2(p0,p2) != s2 or dist2(p1,p2) != 2*s2: continue
p3 = sub(add(p1,p2),p0)
x = div(cross(sub(p1,p0),sub(p2,p0)),s)
p4,p5,p6,p7 = add(p0,x),add(p1,x),add(p2,x),add(p3,x)
l3 = [p0,p1,p2,p3,p4,p5,p6,p7]
if sorted([sorted(p) for p in l]) == sorted([sorted(p) for p in l3]):
print("YES")
used = [False for i in range(8)]
for p in l:
for i in range(8):
if used[i]: continue
if match(p,l3[i]):
print(l3[i][0],l3[i][1],l3[i][2])
used[i] = True
break
solved = True
break
if solved: break
if solved: break
if not solved: print("NO")
#if not poss(1,[l[0]]): print("NO")
``` | output | 1 | 33,752 | 23 | 67,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,753 | 23 | 67,506 |
Tags: brute force, geometry
Correct Solution:
```
from itertools import permutations as p
d = lambda a, b: sum((i - j) ** 2 for i, j in zip(a, b))
f = lambda a, b: [i + j - k for i, j, k in zip(a, b, q)]
g = lambda t: sorted(sorted(q) for q in t)
v = [sorted(map(int, input().split())) for i in range(8)]
q = v.pop()
u = g(v)
for a, b, c in p(v, 3):
for x in p(a):
s = 2 * d(q, x)
if not s: continue
for y in p(b):
if not 2 * d(q, y) == d(x, y) == s: continue
for z in p(c):
if not 2 * d(q, z) == d(x, z) == d(y, z) == s: continue
t = [x, y, z] + [f(x, y), f(x, z), f(y, z), f(f(x, y), z)]
if g(t) == u:
print('YES')
d = [str(sorted(i)) for i in t]
for j in v:
i = d.index(str(j))
k = t.pop(i)
print(*k)
d.pop(i)
print(*q)
exit()
print('NO')
``` | output | 1 | 33,753 | 23 | 67,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,754 | 23 | 67,508 |
Tags: brute force, geometry
Correct Solution:
```
from itertools import permutations as p
d = lambda a, b: sum((i - j) ** 2 for i, j in zip(a, b))
f = lambda a, b: [i + j - k for i, j, k in zip(a, b, q)]
g = lambda t: sorted(sorted(q) for q in t)
v = [sorted(map(int, input().split())) for i in range(8)]
q = v.pop()
def yes(t, v):
print('YES')
d = {}
for q in t:
s = str(sorted(q))
d[s] = d.get(s, []) + [q]
for q in v:
i, j, k = d[str(q)].pop()
print(i, j, k)
exit()
u = g(v)
for a, b, c in p(v, 3):
for x in p(a):
s = 2 * d(q, x)
if s == 0: continue
for y in p(b):
if not 2 * d(q, y) == d(x, y) == s: continue
for z in p(c):
if not 2 * d(q, z) == d(x, z) == d(y, z) == s: continue
t = [x, y, z] + [f(x, y), f(x, z), f(y, z), f(f(x, y), z)]
if g(t) == u: yes(t + [q], v + [q])
print('NO')
``` | output | 1 | 33,754 | 23 | 67,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,755 | 23 | 67,510 |
Tags: brute force, geometry
Correct Solution:
```
import itertools
from itertools import permutations as perm
import copy
def getPerm(it, index):
if index == 0:
return it
elif index == 1:
return [it[0], it[2], it[1]]
elif index == 2:
return [it[1], it[0], it[2]]
elif index == 3:
return [it[1], it[2], it[0]]
elif index == 4:
return [it[2], it[0], it[1]]
elif index == 5:
return [it[2], it[1], it[0]]
def distance(coord1, coord2):
return ((coord2[0] - coord1[0])**2 + (coord2[1] - coord1[1])**2 + (coord2[2] - coord1[2])**2)
dists = ([0]*6)*7
pointList = [[int(x) for x in input().split()] for y in range(0, 8)]
p0 = pointList[0]
for x in range(0, 7):
y = 0
for pt in perm(pointList[x + 1], 3):
# print(pt, p0)
dists[x*6 + y] = distance(p0, pt)
# print(dists)
y += 1
# print(pointList)
# print(dists)
done = False
final = None
def same(it1, it2):
# print(it1, it2)
if list(it1) == list(it2):
return True
return False
def checkNotSame(indicesSoFar, newIndex):
global pointList
ptToComp = getPerm(pointList[len(indicesSoFar) + 1], newIndex)
for c in range(len(indicesSoFar)):
if same(getPerm(pointList[c + 1], indicesSoFar[c]), ptToComp):
# print(getPerm(pointList[c + 1], indicesSoFar[c]), getPerm(pointList[len(indicesSoFar)], newIndex), False)
return False
return True
def checkCompatible(a, b):
if a == b or a*2 == b or a == 2*b or a*3 == b or a ==3*b or 2*a == 3*b or 3*a== 2*b:
return True
return False
def getSeven(distList, soFar, index):
global done
global final
if done == True:
return
if index == 7:
# for h in range(0,7):
# print(getPerm(pointList[h+1], soFar[h]), end=" ")
# print()
# for i in range(0,7):
# print(dists[i*6+soFar[i]], end=" ")
# print()
# print(soFar)
distsSoFar = [dists[i*6+soFar[i]] for i in range(0, 7)]
# print(distsSoFar)
lowest = min(distsSoFar)
lows = 0
twos = 0
threes = 0
for a in range(0, 7):
if distsSoFar[a] == lowest:
lows += 1
elif distsSoFar[a] == lowest*2:
twos += 1
elif distsSoFar[a] == lowest*3:
threes += 1
if lows == 3 and twos == 3 and threes == 1:
done = True
final = soFar
return
for x in range(0, 6):
if done == True:
return
if soFar == []:
curList = copy.copy(soFar)
curList.append(x)
getSeven(distList, curList, index + 1)
else:
# and checkNotSame(soFar, x)
# print(getPerm(pointList[index], soFar[index - 1]), getPerm(pointList[index + 1], x))
# print(distList[x+(index)*6], distList[soFar[index - 1]+(index - 1)*6])
if checkCompatible(distList[x+(index)*6], distList[soFar[index - 1]+(index-1)*6]):
if checkNotSame(soFar, x):
# print("Enters")
curList = copy.copy(soFar)
curList.append(x)
# print(curList)
getSeven(distList, curList, index+1)
# else:
getSeven(dists, [], 0)
if final is None:
print("NO")
else:
print("YES")
print(p0[0], p0[1], p0[2])
for b in range(0, 7):
x, y, z = getPerm(pointList[b+1], final[b])
print(x, y, z)
# print(combosList)
``` | output | 1 | 33,755 | 23 | 67,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,756 | 23 | 67,512 |
Tags: brute force, geometry
Correct Solution:
```
import itertools
from itertools import permutations as perm
l = [[int(x) for x in input().split()] for i in range(8)]
def dist2(p0,p1):
return sum([(p0[i]-p1[i])**2 for i in range(3)])
def sub(p0,p1):
return [p0[i]-p1[i] for i in range(3)]
def add(p0,p1):
return [p0[i]+p1[i] for i in range(3)]
def div(p0,x):
return [p0[i]//x for i in range(3)]
def cross(p0,p1):
return [p0[(i+1)%3]*p1[(i+2)%3]-p0[(i+2)%3]*p1[(i+1)%3] for i in range(3)]
def match(p0,p1):
return sorted(p0) == sorted(p1)
solved = False
for l2 in perm(l,3):
p0 = l2[0]
for p1 in perm(l2[1]):
s2 = dist2(p0,p1)
if s2 == 0: continue
s = round(s2**.5)
if s**2 != s2: continue
for p2 in perm(l2[2]):
if dist2(p0,p2) != s2 or dist2(p1,p2) != 2*s2: continue
p3 = sub(add(p1,p2),p0)
x = div(cross(sub(p1,p0),sub(p2,p0)),s)
p4,p5,p6,p7 = add(p0,x),add(p1,x),add(p2,x),add(p3,x)
l3 = [p0,p1,p2,p3,p4,p5,p6,p7]
if sorted([sorted(p) for p in l]) == sorted([sorted(p) for p in l3]):
print("YES")
used = [False for i in range(8)]
for p in l:
for i in range(8):
if used[i]: continue
if match(p,l3[i]):
print(l3[i][0],l3[i][1],l3[i][2])
used[i] = True
break
solved = True
break
if solved: break
if solved: break
if not solved: print("NO")
#if not poss(1,[l[0]]): print("NO")
``` | output | 1 | 33,756 | 23 | 67,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,757 | 23 | 67,514 |
Tags: brute force, geometry
Correct Solution:
```
import itertools
from itertools import permutations as perm
l = [[int(x) for x in input().split()] for i in range(8)]
def dist2(p0,p1):
return sum([(p0[i]-p1[i])**2 for i in range(3)])
def sub(p0,p1):
return [p0[i]-p1[i] for i in range(3)]
def add(p0,p1):
return [p0[i]+p1[i] for i in range(3)]
def div(p0,x):
return [p0[i]//x for i in range(3)]
def cross(p0,p1):
return [p0[(i+1)%3]*p1[(i+2)%3]-p0[(i+2)%3]*p1[(i+1)%3] for i in range(3)]
def match(p0,p1):
return sorted(p0) == sorted(p1)
solved = False
for l2 in perm(l,3):
p0 = l2[0]
for p1 in perm(l2[1]):
s2 = dist2(p0,p1)
if s2 == 0: continue
s = round(s2**.5)
# if s**2 != s2: continue
for p2 in perm(l2[2]):
if dist2(p0,p2) != s2 or dist2(p1,p2) != 2*s2: continue
p3 = sub(add(p1,p2),p0)
x = div(cross(sub(p1,p0),sub(p2,p0)),s)
p4,p5,p6,p7 = add(p0,x),add(p1,x),add(p2,x),add(p3,x)
l3 = [p0,p1,p2,p3,p4,p5,p6,p7]
if sorted([sorted(p) for p in l]) == sorted([sorted(p) for p in l3]):
print("YES")
used = [False for i in range(8)]
for p in l:
for i in range(8):
if used[i]: continue
if match(p,l3[i]):
print(l3[i][0],l3[i][1],l3[i][2])
used[i] = True
break
solved = True
break
if solved: break
if solved: break
if not solved: print("NO")
#if not poss(1,[l[0]]): print("NO")
``` | output | 1 | 33,757 | 23 | 67,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,758 | 23 | 67,516 |
Tags: brute force, geometry
Correct Solution:
```
from itertools import permutations as p
def razn(a, b):
return (a[0] - b[0], a[1] - b[1], a[2] - b[2])
def sp(a, b):
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
def su(a, b):
return (a[0] + b[0], a[1] + b[1], a[2] + b[2])
a = list(tuple(map(int, input().split())) for i in range(8))
cp = sorted(sorted(el) for el in a)
for p1 in p(a[0]):
for i in range(1, 8):
for j in range(i + 1, 8):
for l in range(j + 1, 8):
for p2 in p(a[i]):
for p3 in p(a[j]):
for p4 in p(a[l]):
s2 = razn(p2, p1)
s3 = razn(p3, p1)
s4 = razn(p4, p1)
le = sp(s2, s2)
if le and sp(s3, s3) == le and sp(s4, s4) == le and sp(s2, s3) == 0 and sp(s2, s4) == 0 and sp(s3, s4) == 0:
mass = [su(su(s3, s4), p1), su(su(s3, s2), p1), su(su(s2, s4), p1), p1, p2, p3, p4, su(su(su(s3, s4), p1), s2)]
if sorted(sorted(el) for el in mass) == cp:
print("YES")
for el in a:
tmp = sorted(el)
for kk in range(8):
if sorted(mass[kk]) == tmp:
print(mass[kk][0], mass[kk][1], mass[kk][2])
mass[kk] = ()
break
exit()
print("NO")
``` | output | 1 | 33,758 | 23 | 67,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO | instruction | 0 | 33,759 | 23 | 67,518 |
Tags: brute force, geometry
Correct Solution:
```
from itertools import permutations as p
d = lambda a, b: sum((i - j) ** 2 for i, j in zip(a, b))
f = lambda a, b: [i + j - k for i, j, k in zip(a, b, q)]
g = lambda t: sorted(sorted(q) for q in t)
v = [sorted(map(int, input().split())) for i in range(8)]
q = v.pop()
def yes(t, v):
print('YES')
d = {}
for q in t:
s = str(sorted(q))
d[s] = d.get(s, []) + [q]
for q in v:
i, j, k = d[str(q)].pop()
print(i, j, k)
exit()
u = g(v)
for a, b, c in p(v, 3):
for x in p(a):
s = 2 * d(q, x)
if s == 0: continue
for y in p(b):
if not 2 * d(q, y) == d(x, y) == s: continue
for z in p(c):
if not 2 * d(q, z) == d(x, z) == d(y, z) == s: continue
t = [x, y, z] + [f(x, y), f(x, z), f(y, z), f(f(x, y), z)]
if g(t) == u: yes(t + [q], v + [q])
print('NO')
# Made By Mostafa_Khaled
``` | output | 1 | 33,759 | 23 | 67,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO
Submitted Solution:
```
from itertools import permutations as p
d = lambda a, b: sum((i - j) ** 2 for i, j in zip(a, b))
f = lambda a, b: [i + j - k for i, j, k in zip(a, b, q)]
g = lambda t: sorted(sorted(q) for q in t)
v = [sorted(map(int, input().split())) for i in range(8)]
q = v.pop()
def yes(t, v):
print('YES')
d = [str(sorted(i)) for i in t]
for j in v:
i = d.index(str(j))
q = t.pop(i)
print(*q)
d.pop(i)
exit()
u = g(v)
for a, b, c in p(v, 3):
for x in p(a):
s = 2 * d(q, x)
if not s: continue
for y in p(b):
if not 2 * d(q, y) == d(x, y) == s: continue
for z in p(c):
if not 2 * d(q, z) == d(x, z) == d(y, z) == s: continue
t = [x, y, z] + [f(x, y), f(x, z), f(y, z), f(f(x, y), z)]
if g(t) == u: yes(t + [q], v + [q])
print('NO')
``` | instruction | 0 | 33,760 | 23 | 67,520 |
Yes | output | 1 | 33,760 | 23 | 67,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.
When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
Input
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
Output
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.
If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
Examples
Input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
Output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
Input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
Output
NO
Submitted Solution:
```
perm = [[0, 1, 2],
[0, 2, 1],
[1, 0, 2],
[1, 2, 0],
[2, 0, 1],
[2, 1, 0]]
coords = []
flag = False
cnt = 0
def check():
global cnt
cnt += 1
if cnt == 30000:
print('NO')
flag = True
return
global flag
lens = []
for i in range(8):
lens.append({})
alls = []
for i in range(8):
for j in range(8):
if i != j:
d = 0
for k in range(3):
d += (coords[i][k] - coords[j][k]) ** 2
if (d not in lens[i]):
lens[i][d] = 0
lens[i][d] += 1
lns = list(lens[i])
if len(lns) != 3:
return
lns.sort()
if not (lens[i][lns[0]] == 3 and lens[i][lns[1]] == 3 and lens[i][lns[2]] == 1):
return
if lns[0] * 3 != lns[2]:
return
if lns[0] * 2 != lns[1]:
return
alls.append(lns)
mflag = True
if len(alls) == 8:
for i in range(8):
for k in range(3):
if alls[i][k] != alls[0][k]:
mflag = False
break
if mflag:
coords.reverse()
print('YES')
flag = True
for i in range(8):
print(' '.join(map(str, coords[i])))
pass
def rec(n):
global flag
if flag:
return
if n == 8:
check()
else:
oldcor = coords[n][0], coords[n][1], coords[n][2]
for p in perm:
coords[n] = [oldcor[p[0]], oldcor[p[1]], oldcor[p[2]]]
pflag = True
for j in range(n):
if coords[n][0] == coords[j][0] and coords[n][1] == coords[j][1] and coords[n][2] == coords[j][2]:
pflag = False
if pflag:
rec(n + 1)
if flag:
return
coords[n] = [oldcor[0], oldcor[1], oldcor[2]]
for i in range(8):
coords.append(list(map(int, input().split())))
coords.reverse()
rec(0)
if not flag:
print('NO')
``` | instruction | 0 | 33,761 | 23 | 67,522 |
No | output | 1 | 33,761 | 23 | 67,523 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.