message
stringlengths 2
45.8k
| message_type
stringclasses 2
values | message_id
int64 0
1
| conversation_id
int64 254
108k
| cluster
float64 3
3
| __index_level_0__
int64 508
217k
|
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
|
instruction
| 0
| 93,967
| 3
| 187,934
|
Tags: data structures, geometry, math
Correct Solution:
```
from collections import defaultdict
n=int(input())
dic,dicx,dicy=defaultdict(int),defaultdict(int),defaultdict(int)
ans=0
for _ in range(n):
x,y=input().split()
x,y=int(x),int(y)
ans += (dicx[x]+dicy[y]-dic[(x,y)])
dicx[x]+=1
dicy[y]+=1
dic[(x,y)]+=1
print(ans)
```
|
output
| 1
| 93,967
| 3
| 187,935
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
|
instruction
| 0
| 93,968
| 3
| 187,936
|
Tags: data structures, geometry, math
Correct Solution:
```
# link: https://codeforces.com/contest/651/problem/C
import heapq
import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from math import ceil
mod = 10 ** 9 + 7
# number of test cases
for _ in range(1):
n = int(input()) # number of watchmen
memo_x = {}
memo_y = {}
memo_xy = {}
pairs = 0
for i in range(n):
x,y = map(int, input().split())
if x not in memo_x: memo_x[x] = 1
else: memo_x[x] += 1
if y not in memo_y: memo_y[y] = 1
else: memo_y[y] += 1
if (x,y) not in memo_xy: memo_xy[(x,y)] = 1
else: memo_xy[(x,y)] += 1
for key, value in memo_x.items():
pairs += (value * (value-1)) // 2
for key, value in memo_y.items():
pairs += (value * (value-1)) // 2
for key, value in memo_xy.items():
pairs -= (value * (value-1)) // 2
print(pairs)
```
|
output
| 1
| 93,968
| 3
| 187,937
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
|
instruction
| 0
| 93,969
| 3
| 187,938
|
Tags: data structures, geometry, math
Correct Solution:
```
from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
# from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *
####################################---fast-input-output----#########################################
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = read(self._fd, max(fstat(self._fd).st_size, 8192))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = read(self._fd, max(fstat(self._fd).st_size, 8192))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
stdin, stdout = IOWrapper(stdin), IOWrapper(stdout)
graph, mod, szzz = {}, 10**9 + 7, lambda: sorted(zzz())
def getStr(): return input()
def getInt(): return int(input())
def listStr(): return list(input())
def getStrs(): return input().split()
def isInt(s): return '0' <= s[0] <= '9'
def input(): return stdin.readline().strip()
def zzz(): return [int(i) for i in input().split()]
def output(answer, end='\n'): stdout.write(str(answer) + end)
def lcd(xnum1, xnum2): return (xnum1 * xnum2 // gcd(xnum1, xnum2))
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
#################################################---Some Rule For Me To Follow---#################################
"""
--instants of Reading problem continuously try to understand them.
--If you Know some-one , Then you probably don't know him !
--Try & again try
"""
##################################################---START-CODING---###############################################
num = getInt()
X=[]
Y=[]
XY=[]
for _ in range(num):
x,y=zzz()
X.append(x)
Y.append(y)
XY.append((x,y))
new1= Counter(X)
new2= Counter(Y)
new3=Counter(XY)
ans = 0
for i in new1:
ans+=(new1[i]*(new1[i]-1))//2
for j in new2:
ans+=(new2[j]*(new2[j]-1))//2
for k in new3:
ans-=(new3[k]*(new3[k]-1))//2
print(ans)
```
|
output
| 1
| 93,969
| 3
| 187,939
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
import math
def nCr(n,r):
if n<r:
return 0
return math.factorial(n) // ((math.factorial(r) * math.factorial(n-r)))
n = int(input())
dict_x ={}
dict_y = {}
dict_x_y = {}
ans = 0
for i in range(n):
x,y = map(int,input().split())
ans += (dict_x.get(x,0)+dict_y.get(y,0) - dict_x_y.get((x,y),0))
dict_x[x] = dict_x.get(x,0)+1
dict_y[y] = dict_y.get(y,0)+1
dict_x_y[(x,y)] = dict_x_y.get((x,y),0)+1
print(ans)
# print(dict_x)
# print(dict_y)
# print(dict_x_y)
```
|
instruction
| 0
| 93,970
| 3
| 187,940
|
Yes
|
output
| 1
| 93,970
| 3
| 187,941
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
n=int(input())
x=[]
y=[]
res=0
for i in range(n):
m,k=(int(z) for z in input().split())
x+=[[m,k]]
y+=[[k,m]]
x.sort()
y.sort()
cur1=x[0][0]
cur2=x[0][1]
count1=1
count2=1
sum1=0
sum2=0
i=1
while i<n:
e=x[i][0]
f=x[i][1]
if e==cur1:
count1+=1
if f==cur2:
count2+=1
else:
cur2=f
sum2+=count2*(count2-1)//2
count2=1
else:
cur1=e
cur2=f
sum1+=count1*(count1-1)//2
count1=1
sum2+=count2*(count2-1)//2
count2=1
i+=1
i=1
sum1+=count1*(count1-1)//2
sum2+=count2*(count2-1)//2
count=1
sum3=0
cur1=y[0][0]
while i<n:
e=y[i][0]
if e==cur1:
count+=1
else:
cur1=e
sum3+=count*(count-1)//2
count=1
i+=1
sum3+=count*(count-1)//2
print(sum1-sum2+sum3)
```
|
instruction
| 0
| 93,971
| 3
| 187,942
|
Yes
|
output
| 1
| 93,971
| 3
| 187,943
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
#for deque append(),pop(),appendleft(),popleft(),count()
I=lambda:int(input())
S=lambda:input().strip()
n=I()
a=[]
b=[]
for i in range(0,n):
k=li()
a.append(k)
b.append(k[::-1])
a.sort()
b.sort()
temp=a[0][0]
c=1
s=0
for i in range(1,n):
if(a[i][0]==temp):
c+=1
else:
s=s+(c*(c-1))//2
c=1
temp=a[i][0]
s=s+(c*(c-1))//2
c=1
temp=b[0][0]
for i in range(1,n):
if(b[i][0]==temp):
c+=1
else:
s=s+(c*(c-1))//2
c=1
temp=b[i][0]
s=s+(c*(c-1))//2
temp=a[0][0]
temp1=a[0][1]
c=1
d=0
for i in range(1,n):
if(a[i][0]==temp and a[i][1]==temp1):
c+=1
else:
d=d+((c)*(c-1))//2
temp=a[i][0]
temp1=a[i][1]
c=1
d=d+((c)*(c-1))//2
print(s-d)
```
|
instruction
| 0
| 93,972
| 3
| 187,944
|
Yes
|
output
| 1
| 93,972
| 3
| 187,945
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
if __name__=='__main__':
n = int(input())
gx,gy,c= {},{},0
tup = {}
for i in range(n):
x,y= map(int,input().split(' '))
if x in gx and y not in gy:
c += gx[x]
gx[x]+=1
gy[y]=1
tup[(x,y)]=1
elif x not in gx and y in gy:
c += gy[y]
gy[y]+=1
gx[x]=1
tup[(x,y)]=1
elif x not in gx and y not in gy:
gx[x],gy[y],tup[(x,y)]=1,1,1
elif x in gx and y in gy:
if (x,y) in tup:
c+=gx[x]+gy[y]-tup[(x,y)] #common
tup[(x,y)]+=1
else:
c+=gx[x]+gy[y]
tup[(x,y)]=1
gx[x]+=1
gy[y]+=1
#print(gx,gy)
print(c)
```
|
instruction
| 0
| 93,973
| 3
| 187,946
|
Yes
|
output
| 1
| 93,973
| 3
| 187,947
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
n=int(input())
a=[]
for i in range(n):
x,y=map(int,input().split())
a.append([x,y])
c,d=0,0
p,q,r={},{},{}
for i in range(n):
c=a[i][0]
d=a[i][1]
if c in p:
p[c]+=1
else:
p[c]=1
if d in q:
q[d]+=1
else:
q[d]=1
if (c,d) in r:
r[(c,d)]+=1
else:
r[(c,d)]=1
count=0
for i in p.values():
count+=(i*(i-1))//2
for i in q.values():
count+=(i*(i-1))//2
for i in r.values():
count+=(i*(i-1))//2
print(count)
```
|
instruction
| 0
| 93,974
| 3
| 187,948
|
No
|
output
| 1
| 93,974
| 3
| 187,949
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
n = int(input())
dic ={}
X={}
Y={}
for _ in range(n):
tup = tuple(map(int,input().split()))
if tup in dic:
dic[tup]+=1
else:
dic[tup]=1
if tup[0] in X:
X[tup[0]]+=1
else:
X[tup[0]]=1
if tup[1] in Y:
Y[tup[1]]+=1
else:
Y[tup[1]]=1
final = 0
for i in X:
final+= ((X[i])*(X[i]-1))//2
for i in Y:
final+= ((Y[i])*(Y[i]-1))//2
for i in dic:
if dic[i]>1:
if X[i[0]]>dic[i] and Y[i[1]]>dic[i]:
final+= -(((dic[i])*(dic[i]-1))//2)
if n==1000:
for i in X:
if i!=4250:
print(i)
print(final)
```
|
instruction
| 0
| 93,975
| 3
| 187,950
|
No
|
output
| 1
| 93,975
| 3
| 187,951
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
n = int(input())
dic ={}
X={}
Y={}
for _ in range(n):
tup = tuple(map(int,input().split()))
if tup in dic:
dic[tup]+=1
else:
dic[tup]=1
if tup[0] in X:
X[tup[0]]+=1
else:
X[tup[0]]=1
if tup[1] in Y:
Y[tup[1]]+=1
else:
Y[tup[1]]=1
final = 0
for i in X:
final+= ((X[i])*(X[i]-1))//2
for i in Y:
final+= ((Y[i])*(Y[i]-1))//2
for i in dic:
if dic[i]>1:
if X[i[0]]>dic[i] and Y[i[1]]>dic[i]:
final+= -(((dic[i])*(dic[i]-1))//2)
if n==1000:
for i in dic:
if dic[i]>1:
print(i)
print(final)
```
|
instruction
| 0
| 93,976
| 3
| 187,952
|
No
|
output
| 1
| 93,976
| 3
| 187,953
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 β€ i < j β€ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 β€ n β€ 200 000) β the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| β€ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 8 10:55:25 2020
@author: Nada Adel
"""
import os
import sys
from atexit import register
from io import BytesIO
n = int(input())
line=''
x={}
y={}
pairs={}
for i in range(n):
line=input()
line=line.split()
if int(line[0]) not in x:
x[int(line[0])]=1
else:
x[int(line[0])]+=1
if int(line[1]) not in y:
y[int(line[1])]=1
else:
y[int(line[1])]+=1
if (int(line[0]),int(line[1])) not in pairs:
pairs[(int(line[0]),int(line[1]))]=1
else:
pairs[(int(line[0]),int(line[1]))]+=1
sumX=0
sumY=0
sumPairs=0
for key,value in x.items():
if value!=1:
sumX+=value*(value-1)/2.0
for key,value in y.items():
if value!=1:
sumY+=value*(value-1)/2.0
for key,value in pairs.items():
if value!=1:
sumPairs+=value*(value-1)/2.0
print(sumX+sumY-sumPairs)
```
|
instruction
| 0
| 93,977
| 3
| 187,954
|
No
|
output
| 1
| 93,977
| 3
| 187,955
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
class Solution():
def __init__(self):
test = int(input())
for i in range(0, test):
n = int(input())
a = [input() for i in range(0, n)]
print(self.solve(n, a))
def solve(self, n, a):
q = [None for i in range(0, 60 * 60)]
used = [[False for i in range(0, n)] for j in range(0, n)]
l = r = 0
p = [(0, -1), (-1, 0)]
for i in range(0, n):
if a[i][n - 1] == '1':
q[r] = (i, n - 1)
r += 1
used[i][n - 1] = True
if a[n - 1][i] == '1' and i < n - 1:
q[r] = (n - 1, i)
r += 1
used[n - 1][i] = True
while l < r:
u = q[l]
l += 1
for i in p:
v = (u[0] + i[0], u[1] + i[1])
if min(v[0], v[1]) >= 0 and max(v[0], v[1]) < n and not used[v[0]][v[1]] and a[v[0]][v[1]] == '1':
q[r] = v
r += 1
used[v[0]][v[1]] = True
for i in range(0, n):
for j in range(0, n):
if a[i][j] == '1' and not used[i][j]:
return "NO"
return "YES"
Solution()
```
|
instruction
| 0
| 94,561
| 3
| 189,122
|
Yes
|
output
| 1
| 94,561
| 3
| 189,123
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
T = int(input())
def fn_check(arr, n):
for i in range(n):
for j in range(n):
if (arr[i][j] == '1'):
if (i!=n-1 and j!=n-1):
if (arr[i+1][j] =='0' and arr[i][j+1]=='0'):
return "NO"
return "YES"
for t in range(T):
n = int(input())
arr = []
for i in range(n):
l = list(input())
arr.append(l)
print(fn_check(arr, n))
```
|
instruction
| 0
| 94,562
| 3
| 189,124
|
Yes
|
output
| 1
| 94,562
| 3
| 189,125
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
#!/usr/bin/env python3
# coding: utf-8
import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
def solve(matrix, n):
for i in range(n-1):
for j in range(n-1):
if matrix[i][j] == '1' and matrix[i+1][j] == '0' and matrix[i][j+1] == '0':
return 'No'
return 'Yes'
def main():
t = inp()
for _ in range(t):
n = inp()
matrix = [insr() for _ in range(n)]
# print(matrix)
ans = solve(matrix, n)
print(ans)
if __name__ == "__main__":
main()
```
|
instruction
| 0
| 94,563
| 3
| 189,126
|
Yes
|
output
| 1
| 94,563
| 3
| 189,127
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
def solve(A,n):
for i in range(n-1):
for j in range(n-1):
if(A[i][j]=='1'):
if(A[i][j+1]!='1' and A[i+1][j]!='1'):
print("NO")
return
print("YES")
t=int(input())
for _ in range(t):
n=int(input())
A=[]
for i in range(n):
A.append(input())
if (n == 1):
print("YES")
continue
solve(A,n)
```
|
instruction
| 0
| 94,564
| 3
| 189,128
|
Yes
|
output
| 1
| 94,564
| 3
| 189,129
|
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
mod=10**9+7
def ni():
return int(raw_input())
def li():
return map(int,raw_input().strip())
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
pre=[[0 for i in range(51)] for j in range(51)]
suf=[[0 for i in range(51)] for j in range(51)]
for t in range(input()):
n=ni()
mat=[]
for i in range(n):
mat.append(list(reversed(li())))
mat=list(reversed(mat))
f=0
for i in range(n):
for j in range(n):
if mat[i][j]:
if not ( (i!=0 and mat[i-1][j]) or (j!=0 and mat[i][j-1])):
if i!=0 and j!=0:
f=1
break
if f:
break
if f:
pr('NO\n')
else:
pr('YES\n')
```
|
instruction
| 0
| 94,565
| 3
| 189,130
|
Yes
|
output
| 1
| 94,565
| 3
| 189,131
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
#------------------------------what is this I don't know....just makes my mess faster--------------------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#----------------------------------Real game starts here--------------------------------------
'''
___________________THIS IS AESTROIX CODE________________________
KARMANYA GUPTA
'''
#_______________________________________________________________#
def fact(x):
if x == 0:
return 1
else:
return x * fact(x-1)
def lower_bound(li, num): #return 0 if all are greater or equal to
answer = -1
start = 0
end = len(li)-1
while(start <= end):
middle = (end+start)//2
if li[middle] >= num:
answer = middle
end = middle - 1
else:
start = middle + 1
return answer #index where x is not less than num
def upper_bound(li, num): #return n-1 if all are small or equal
answer = -1
start = 0
end = len(li)-1
while(start <= end):
middle = (end+start)//2
if li[middle] <= num:
answer = middle
start = middle + 1
else:
end = middle - 1
return answer #index where x is not greater than num
def abs(x):
return x if x >=0 else -x
def binary_search(li, val, lb, ub):
ans = 0
while(lb <= ub):
mid = (lb+ub)//2
#print(mid, li[mid])
if li[mid] > val:
ub = mid-1
elif val > li[mid]:
lb = mid + 1
else:
ans = 1
break
return ans
#_______________________________________________________________#
from math import *
for _ in range(int(input())):
n = int(input())
if n==1:
print("YES")
continue
mat = []
for i in range(n):
string = input()
li = []
for j in range(n):
li.append(int(string[j]))
mat.append(li)
flag = 1
for i in range(n-1):
for j in range(n-1):
if mat[i][j] == 1:
if mat[i+1][j] == 0 and mat[i][j+1] == 0:
flag = 0
break
"""for j in range(n-1):
if mat[n-1][j] == 1 and mat[n-1][j+1] == 0:
print("there.......")
flag = 0
break
for i in range(n-1):
if mat[i][n-1] == 1 and mat[i+1][n-1] == 0:
print("thence.....")
flag = 0
break"""
print("YNEOS"[flag==0::2])
```
|
instruction
| 0
| 94,566
| 3
| 189,132
|
No
|
output
| 1
| 94,566
| 3
| 189,133
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
l.append(input())
# print(l)
flag = 0
for i in range(n):
for j in range(n):
if i==n-1:
if l[i][j]=='1' and j<n-1:
if l[i][j+1] == '0':
flag = 1
break
else:
if l[i][j]=='1' and j<n-1:
if l[i+1][j] == '0' and l[i][j+1] == '0':
flag = 1
break
if flag == 1:
break
if flag==1:
print('NO')
else:
print('YES')
```
|
instruction
| 0
| 94,567
| 3
| 189,134
|
No
|
output
| 1
| 94,567
| 3
| 189,135
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations,permutations
# input = sys.stdin.readline
flush = lambda : sys.stdout.flush
comb = lambda x , y : (factorial(x) // factorial(y)) // factorial(x - y)
#inputs
# ip = lambda : input().rstrip()
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
```
|
instruction
| 0
| 94,568
| 3
| 189,136
|
No
|
output
| 1
| 94,568
| 3
| 189,137
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2n cannons were placed.
<image> Initial polygon for n=4.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally:
* if a cannon stands in the row i, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell (i, 1) and ends in some cell (i, j);
* if a cannon stands in the column j, above the first row, and shoots with a 1, then the 1 starts its flight from the cell (1, j) and ends in some cell (i, j).
For example, consider the following sequence of shots:
<image>
1. Shoot the cannon in the row 2. 2. Shoot the cannon in the row 2. 3. Shoot the cannon in column 3.
You have a report from the military training on your desk. This report is a square matrix with side length n consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
Input
The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
Each test case starts with a line containing an integer n (1 β€ n β€ 50) β the size of the polygon.
This is followed by n lines of length n, consisting of 0 and 1 β the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed 10^5.
Output
For each test case print:
* YES if there is a sequence of shots leading to a given matrix;
* NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
Example
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
Note
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell (1, 1) flying out of any cannon would continue its flight further.
Submitted Solution:
```
def find_training():
one = []
edge = []
inside = []
n = int(input())
for i in range(n):
row = input()
row = list(row)
row = list(map(int, row))
for idx,val in enumerate(row):
if val == 1:
one.append([i,idx])
if idx == n-1:
edge.append([i,idx])
else:
inside.append([i,idx])
result = 'YES'
for element in inside:
if [element[0]+1, element[1]] in one or [element[0], element[1]+1] in one:
result = 'YES'
else:
result = 'NO'
break
return result
t = int(input())
output = []
for i in range(t):
output.append(find_training())
for i in output:
print(i)
```
|
instruction
| 0
| 94,569
| 3
| 189,138
|
No
|
output
| 1
| 94,569
| 3
| 189,139
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.
Help Bender to solve this difficult task.
Input
The first line contains two positive integers n and m (4 β€ n β€ 500, 2 β€ m β€ 500, n is even) β the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers β the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.
Output
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers β i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.
If there are multiple solutions, print any of them.
Examples
Input
4 2
0 0
0 2
2 2
2 0
4 4
Output
YES
1 -1 2 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
3 2 3
Output
YES
1 -1 2 -1 3 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
2 2 3
Output
NO
Submitted Solution:
```
n,m = map(int,input().split())
s = []
for i in range(n):
a = map(int,input().split())
a = list(a)
s.append(a)
s_chet = []
for i in range(1,n-1,2): #ΠΡΠΎΡ
ΠΎΠ΄ ΠΏΠΎ ΡΠ΅ΡΠ½ΡΠΌ Π³Π²ΠΎΠ·Π΄ΡΠΌ
q = abs((s[i][0]-s[i-1][0])+(s[i][1]-s[i-1][1])) + abs((s[i][0]-s[i+1][0])+(s[i][1]-s[i+1][1]))
s_chet.append(q)
q1 = abs((s[-1][0]-s[-2][0])+(s[-1][1]-s[-2][1])) + abs((s[-1][0]-s[0][0])+(s[-1][1]-s[0][1]))
s_chet.append(q1)
s_ch = s_chet.copy()
s_nechet = []
for i in range(2,n-1,2): #ΠΡΠΎΡ
ΠΎΠ΄ ΠΏΠΎ Π½Π΅ΡΠ΅ΡΠ½ΡΠΌ Π³Π²ΠΎΠ·Π΄ΡΠΌ
qq = abs((s[i][0]-s[i-1][0])+(s[i][1]-s[i-1][1])) + abs((s[i][0]-s[i+1][0])+(s[i][1]-s[i+1][1]))
s_nechet.append(qq)
qq1 = abs((s[-1][0]-s[0][0])+(s[-1][1]-s[0][1])) + abs((s[1][0]-s[0][0])+(s[1][1]-s[0][1]))
s_nechet.append(qq1)
s_n = s_nechet.copy()
ss = map(int,input().split())
ss = list(ss)
ss1 = ss.copy()
ss2 = ss.copy()
for i in s_chet:
if i in ss1:
s_ch.remove(i)
ss1.remove(i)
if len(s_ch) == 0:
print('YES')
sss = []
for i in range(m):
sss.append(-1)
sss.append(i+1)
print(" ".join(map(str,sss)))
else:
for i in s_nechet:
if i in ss2:
s_n.remove(i)
ss2.remove(i)
if len(s_n) == 0:
print('YES')
sss = []
for i in range(m):
sss.append(i+1)
sss.append(-1)
print(" ".join(map(str,sss)))
else:
print('NO')
```
|
instruction
| 0
| 94,691
| 3
| 189,382
|
No
|
output
| 1
| 94,691
| 3
| 189,383
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.
Help Bender to solve this difficult task.
Input
The first line contains two positive integers n and m (4 β€ n β€ 500, 2 β€ m β€ 500, n is even) β the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers β the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.
Output
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers β i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.
If there are multiple solutions, print any of them.
Examples
Input
4 2
0 0
0 2
2 2
2 0
4 4
Output
YES
1 -1 2 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
3 2 3
Output
YES
1 -1 2 -1 3 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
2 2 3
Output
NO
Submitted Solution:
```
n,m = map(int,input().split())
x = 0
y = 0
sx = []
sy = []
for i in range(n):
A = map(int,input().split())
A = list(A)
if A[0] in sx:
sx = sx
else:
sx.append(A[0])
if A[1] in sy:
sy = sy
else:
sy.append(A[1])
q = 2 * sx[-1] + 2 * sy[-1]
ss = map(int,input().split())
ss = list(ss)
if sum(ss) >= q:
print('YES')
ss = []
for i in range(1,m+1):
ss.append(i)
ss.append(-1)
print(" ".join(map(str,ss)))
else:
print('NO')
```
|
instruction
| 0
| 94,692
| 3
| 189,384
|
No
|
output
| 1
| 94,692
| 3
| 189,385
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.
Help Bender to solve this difficult task.
Input
The first line contains two positive integers n and m (4 β€ n β€ 500, 2 β€ m β€ 500, n is even) β the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers β the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.
Output
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers β i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.
If there are multiple solutions, print any of them.
Examples
Input
4 2
0 0
0 2
2 2
2 0
4 4
Output
YES
1 -1 2 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
3 2 3
Output
YES
1 -1 2 -1 3 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
2 2 3
Output
NO
Submitted Solution:
```
import sys
n, m = map(int, input().split())
points = [tuple(map(int, input().split())) for i in range(n)]
segments = []
x, y = points[-1]
for a, b in points:
if x == a:
segments.append(abs(y - b))
else:
segments.append(abs(x - a))
x, y = a, b
rods = list(map(int, input().split()))
rod_indices = {}
for index, rod in enumerate(rods):
rod_indices.setdefault(rod, []).append(index+1)
for offset in range(2):
target_indices = rod_indices.copy()
assignment = [-1 for i in range(n)]
for i in range(offset, n, 2):
target = segments[(i-1)%n] + segments[i]
if target not in target_indices or target_indices[target] == []:
assignment = None
break
assignment[i] = target_indices[target].pop()
if assignment != None:
print('YES')
print(' '.join(map(str, assignment)))
sys.exit()
print('NO')
```
|
instruction
| 0
| 94,693
| 3
| 189,386
|
No
|
output
| 1
| 94,693
| 3
| 189,387
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.
Help Bender to solve this difficult task.
Input
The first line contains two positive integers n and m (4 β€ n β€ 500, 2 β€ m β€ 500, n is even) β the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers β the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.
Output
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers β i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.
If there are multiple solutions, print any of them.
Examples
Input
4 2
0 0
0 2
2 2
2 0
4 4
Output
YES
1 -1 2 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
3 2 3
Output
YES
1 -1 2 -1 3 -1
Input
6 3
0 0
1 0
1 1
2 1
2 2
0 2
2 2 3
Output
NO
Submitted Solution:
```
n,m = map(int,input().split())
s = []
for i in range(n):
a = map(int,input().split())
a = list(a)
s.append(a)
s_chet = []
for i in range(1,n-1,2): #ΠΡΠΎΡ
ΠΎΠ΄ ΠΏΠΎ ΡΠ΅ΡΠ½ΡΠΌ Π³Π²ΠΎΠ·Π΄ΡΠΌ
q = abs(sum(s[i])-sum(s[i-1])) + abs(sum(s[i])-sum(s[i+1]))
s_chet.append(q)
q1 = abs(sum(s[-1])-sum(s[-2])) + abs(sum(s[-1])-sum(s[0]))
s_chet.append(q1)
s_ch = s_chet.copy()
s_nechet = []
for i in range(2,n-1,2): #ΠΡΠΎΡ
ΠΎΠ΄ ΠΏΠΎ Π½Π΅ΡΠ΅ΡΠ½ΡΠΌ Π³Π²ΠΎΠ·Π΄ΡΠΌ
qq = abs(sum(s[i])-sum(s[i-1])) + abs(sum(s[i])-sum(s[i+1]))
s_nechet.append(qq)
qq1 = abs(sum(s[-1])-sum(s[0])) + abs(sum(s[1])-sum(s[0]))
s_nechet.append(qq1)
s_n = s_nechet.copy()
ss = map(int,input().split())
ss = list(ss)
ss1 = ss.copy()
ss2 = ss.copy()
for i in s_chet:
if i in ss1:
s_ch.remove(i)
ss1.remove(i)
if len(s_ch) == 0:
print('YES')
sss = []
for i in range(m):
sss.append(-1)
sss.append(i+1)
print(" ".join(map(str,sss)))
else:
for i in s_nechet:
if i in ss2:
s_n.remove(i)
ss2.remove(i)
if len(s_n) == 0:
print('YES')
sss = []
for i in range(m):
sss.append(i+1)
sss.append(-1)
print(" ".join(map(str,sss)))
else:
print('NO')
```
|
instruction
| 0
| 94,694
| 3
| 189,388
|
No
|
output
| 1
| 94,694
| 3
| 189,389
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
No Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. Thatβs why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to fire, soldiers are marching on the main square... And the air forces general Mr. Generalov is in trouble again. This year a lot of sky-scrapers have been built which makes it difficult for the airplanes to fly above the city. It was decided that the planes should fly strictly from south to north. Moreover, there must be no sky scraper on a planeβs route, otherwise the anniversary will become a tragedy. The Ministry of Building gave the data on n sky scrapers (the rest of the buildings are rather small and will not be a problem to the planes). When looking at the city from south to north as a geometrical plane, the i-th building is a rectangle of height hi. Its westernmost point has the x-coordinate of li and the easternmost β of ri. The terrain of the area is plain so that all the buildings stand on one level. Your task as the Ministry of Defenceβs head programmer is to find an enveloping polyline using the data on the sky-scrapers. The polylineβs properties are as follows:
* If you look at the city from south to north as a plane, then any part of any building will be inside or on the boarder of the area that the polyline encloses together with the land surface.
* The polyline starts and ends on the land level, i.e. at the height equal to 0.
* The segments of the polyline are parallel to the coordinate axes, i.e. they can only be vertical or horizontal.
* The polylineβs vertices should have integer coordinates.
* If you look at the city from south to north the polyline (together with the land surface) must enclose the minimum possible area.
* The polyline must have the smallest length among all the polylines, enclosing the minimum possible area with the land.
* The consecutive segments of the polyline must be perpendicular.
<image> Picture to the second sample test (the enveloping polyline is marked on the right).
Input
The first input line contains integer n (1 β€ n β€ 100000). Then follow n lines, each containing three integers hi, li, ri (1 β€ hi β€ 109, - 109 β€ li < ri β€ 109).
Output
In the first line output integer m β amount of vertices of the enveloping polyline. The next m lines should contain 2 integers each β the position and the height of the polylineβs vertex. Output the coordinates of each vertex in the order of traversing the polyline from west to east. Remember that the first and the last vertices of the polyline should have the height of 0.
Examples
Input
2
3 0 2
4 1 3
Output
6
0 0
0 3
1 3
1 4
3 4
3 0
Input
5
3 -3 0
2 -1 1
4 2 4
2 3 7
3 6 8
Output
14
-3 0
-3 3
0 3
0 2
1 2
1 0
2 0
2 4
4 4
4 2
6 2
6 3
8 3
8 0
Submitted Solution:
```
import sys
from array import array # noqa: F401
from collections import defaultdict
from heapq import heappop, heappush
def input():
with open('input.txt') as fp:
return fp.readlines()
def output(ans: str):
with open('output.txt', mode='w') as fp:
fp.write(ans)
'''
def input():
return [line.decode('utf-8') for line in sys.stdin.buffer.readlines()]
def output(ans):
print(ans)
'''
s = input()
n = int(s[0])
dd = defaultdict(list)
pos_set = set()
pos_a, hi_a = [0] * n, [0] * n
for i, (h, l, r) in enumerate(map(int, line.split()) for line in s[1:]):
hi_a[i] = -h
pos_a[i] = r
dd[l].append(i)
pos_set.add(l)
pos_set.add(r)
hi_pos = defaultdict(int)
hi_pos[0] = 10**9 + 100
hq = [0]
ans = []
hi = 0
for pos in sorted(pos_set):
while hq and hi_pos[hq[0]] <= pos:
heappop(hq)
if pos in dd:
for i in dd[pos]:
heappush(hq, hi_a[i])
hi_pos[hi_a[i]] = max(hi_pos[hi_a[i]], pos_a[i])
if hi != hq[0]:
ans.append(f'{pos} {-hi}')
ans.append(f'{pos} {-hq[0]}')
hi = hq[0]
output(str(len(ans)) + '\n' + '\n'.join(ans))
```
|
instruction
| 0
| 94,727
| 3
| 189,454
|
No
|
output
| 1
| 94,727
| 3
| 189,455
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
No Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. Thatβs why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to fire, soldiers are marching on the main square... And the air forces general Mr. Generalov is in trouble again. This year a lot of sky-scrapers have been built which makes it difficult for the airplanes to fly above the city. It was decided that the planes should fly strictly from south to north. Moreover, there must be no sky scraper on a planeβs route, otherwise the anniversary will become a tragedy. The Ministry of Building gave the data on n sky scrapers (the rest of the buildings are rather small and will not be a problem to the planes). When looking at the city from south to north as a geometrical plane, the i-th building is a rectangle of height hi. Its westernmost point has the x-coordinate of li and the easternmost β of ri. The terrain of the area is plain so that all the buildings stand on one level. Your task as the Ministry of Defenceβs head programmer is to find an enveloping polyline using the data on the sky-scrapers. The polylineβs properties are as follows:
* If you look at the city from south to north as a plane, then any part of any building will be inside or on the boarder of the area that the polyline encloses together with the land surface.
* The polyline starts and ends on the land level, i.e. at the height equal to 0.
* The segments of the polyline are parallel to the coordinate axes, i.e. they can only be vertical or horizontal.
* The polylineβs vertices should have integer coordinates.
* If you look at the city from south to north the polyline (together with the land surface) must enclose the minimum possible area.
* The polyline must have the smallest length among all the polylines, enclosing the minimum possible area with the land.
* The consecutive segments of the polyline must be perpendicular.
<image> Picture to the second sample test (the enveloping polyline is marked on the right).
Input
The first input line contains integer n (1 β€ n β€ 100000). Then follow n lines, each containing three integers hi, li, ri (1 β€ hi β€ 109, - 109 β€ li < ri β€ 109).
Output
In the first line output integer m β amount of vertices of the enveloping polyline. The next m lines should contain 2 integers each β the position and the height of the polylineβs vertex. Output the coordinates of each vertex in the order of traversing the polyline from west to east. Remember that the first and the last vertices of the polyline should have the height of 0.
Examples
Input
2
3 0 2
4 1 3
Output
6
0 0
0 3
1 3
1 4
3 4
3 0
Input
5
3 -3 0
2 -1 1
4 2 4
2 3 7
3 6 8
Output
14
-3 0
-3 3
0 3
0 2
1 2
1 0
2 0
2 4
4 4
4 2
6 2
6 3
8 3
8 0
Submitted Solution:
```
import sys
from array import array # noqa: F401
from collections import defaultdict
from heapq import heappop, heappush
def input():
with open('input.txt') as fp:
return fp.readlines()
def output(ans: str):
with open('output.txt', mode='w') as fp:
fp.write(ans)
'''
def input():
return [line.decode('utf-8') for line in sys.stdin.buffer.readlines()]
def output(ans):
print(ans)
'''
s = input()
n = int(s[0])
dd = defaultdict(list)
pos_set = set()
pos_a, hi_a = [0] * n, [0] * n
for i, (h, l, r) in enumerate(map(int, line.split()) for line in s[1:]):
hi_a[i] = -h
pos_a[i] = r
dd[l].append(i)
pos_set.add(l)
pos_set.add(r)
hi_pos = defaultdict(lambda: -10**9 - 100)
hi_pos[0] = 10**9 + 100
hq = [0]
ans = []
hi = 0
for pos in sorted(pos_set):
while hq and hi_pos[hq[0]] <= pos:
heappop(hq)
if pos in dd:
for i in dd[pos]:
heappush(hq, hi_a[i])
hi_pos[hi_a[i]] = max(hi_pos[hi_a[i]], pos_a[i])
if hi != hq[0]:
ans.append(f'{pos} {-hi}\n{pos} {-hq[0]}')
hi = hq[0]
output(str(len(ans)) + '\n' + '\n'.join(ans))
```
|
instruction
| 0
| 94,728
| 3
| 189,456
|
No
|
output
| 1
| 94,728
| 3
| 189,457
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,734
| 3
| 189,468
|
Tags: implementation, math
Correct Solution:
```
import math
a, d = map(float, input().split())
n = int(input())
for p in (math.fmod(i * d, 4 * a) for i in range(1, n + 1)):
if p <= a:
x, y = p, 0
elif p <= 2 * a:
x, y = a, p - a
elif p <= 3 * a:
x, y = 3 * a - p, a
else:
x, y = 0, 4 * a - p
print("{:.10f} {:.10f}".format(x, y))
```
|
output
| 1
| 94,734
| 3
| 189,469
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,735
| 3
| 189,470
|
Tags: implementation, math
Correct Solution:
```
a, d = map(float, input().split())
n = int(input())
t = 0
for i in range(n):
t = (t+d) % (4*a)
if t < a:
print(t, 0)
continue
if t < 2 * a:
print(a, t-a)
continue
if t < 3 * a:
print(3*a-t, a)
continue
if t < 4 * a:
print(0, 4*a-t)
```
|
output
| 1
| 94,735
| 3
| 189,471
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,736
| 3
| 189,472
|
Tags: implementation, math
Correct Solution:
```
from math import floor
a, d = map(float, input().split())
n = int(input())
res = []
for i in range(n):
rec = i*d + d
tra = floor(rec/a) % 4
seg = rec - floor(rec/a)*a
# print("D>",rec, tra, seg)
if tra == 0:
res.append("%.8f %.8f" % (seg, 0.0))
elif tra == 1:
res.append("%.8f %.8f" % (a, seg))
elif tra == 2:
res.append("%.8f %.8f" % (a-seg, a))
elif tra == 3:
res.append("%.8f %.8f" % (0.0, a-seg))
print("\n".join(res))
```
|
output
| 1
| 94,736
| 3
| 189,473
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,737
| 3
| 189,474
|
Tags: implementation, math
Correct Solution:
```
def main():
a, d = map(float, input().split())
ai, di = (int(_ * 1e4 + .1) for _ in (a, d))
a2, a3, a4 = (ai * _ for _ in (2, 3, 4))
n, sa = int(input()), "%.10f" % a
for t in range(di, n * di + 5001, di):
t %= a4
if t <= a2:
if t <= ai:
print("%.10f 0.0000000000" % (t * 1e-4))
else:
print(sa, "%.10f" % ((t - ai) * 1e-4))
else:
if t <= a3:
print("%.10f" % ((-t) % ai * 1e-4), sa)
else:
print("0.0000000000 %.10f" % ((- t) % ai * 1e-4))
if __name__ == '__main__':
main()
```
|
output
| 1
| 94,737
| 3
| 189,475
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,738
| 3
| 189,476
|
Tags: implementation, math
Correct Solution:
```
[a, d], n, tmp = map(float, input().split()), int(input()), 0
for i in range(n):
tmp = (tmp + d) % (4 * a)
if tmp <= a:
print(tmp, 0)
elif tmp <= 2 * a:
print(a, tmp - a)
elif tmp <= 3 * a:
print(3 * a - tmp, a)
else:
print(0, 4 * a - tmp)
```
|
output
| 1
| 94,738
| 3
| 189,477
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,739
| 3
| 189,478
|
Tags: implementation, math
Correct Solution:
```
a,b = [float(x) for x in input().split()]
n = int(input())
for i in range(1,n+1):
rem = (i*b)%(4*a)
print(*[(rem,0),(a,rem-a),(3*a-rem,a),(0,4*a-rem)][int(rem//a)])
```
|
output
| 1
| 94,739
| 3
| 189,479
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,740
| 3
| 189,480
|
Tags: implementation, math
Correct Solution:
```
a,d = [float(i) for i in input().split()]
n = int(input())
d%=4*a
start = 0
seg = 0
for i in range(n):
start += d
lengths = int(start/a)
start = start%a
seg = (seg+lengths)%4
if seg==0:
print(start, 0)
elif seg==1:
print(a, start)
elif seg==2:
print(a-start, a)
else:
print(0, a-start)
```
|
output
| 1
| 94,740
| 3
| 189,481
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
|
instruction
| 0
| 94,741
| 3
| 189,482
|
Tags: implementation, math
Correct Solution:
```
from decimal import Decimal
a, d=map(Decimal, input().split())
n=int(input())
tot=Decimal(0.0)
x=Decimal(); y=Decimal()
for i in range(n):
tot+=d
tot%=4*a
if tot<a: x=tot; y=0.0
elif tot<2*a: x=a; y=tot-a
elif tot<3*a: x=3*a-tot; y=a
else: x=0.0; y=4*a-tot
print(x, end=' '); print(y)
```
|
output
| 1
| 94,741
| 3
| 189,483
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
def setPoint(point, a):
p = point
x = 0
y = 0
if p <= a:
x = p
y = 0
elif p <= a*2:
x = a
y = p - a
elif p <= a*3:
x = a*3 - p
y = a
else:
x = 0
y = a*4 - p
x = int(x*100000)/100000
y = int(y*100000)/100000
return str(x) + ' ' + str(y)
a, d = map(float, input().split())
n = int(input())
curP = 0
for l in range(0, n):
curP += d
curP = curP % (a*4)
print(setPoint(curP, a))
```
|
instruction
| 0
| 94,742
| 3
| 189,484
|
Yes
|
output
| 1
| 94,742
| 3
| 189,485
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
a, d = map(float, input().split())
n = int(input())
def coordinates(s):
if s <= a:
return (s, 0)
elif s <= 2*a:
return (a, s-a)
elif s <= 3*a:
return (3*a - s, a)
else:
return (0, 4*a - s)
for i in range(1, n+1):
print("%f %f" % coordinates(i*d % (4*a)))
```
|
instruction
| 0
| 94,743
| 3
| 189,486
|
Yes
|
output
| 1
| 94,743
| 3
| 189,487
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
a,d=map(float,input().split())
n=int(input())
for i in range(1,n+1):
s=(d*i)%(4*a)
if s<=a:
print(s,0)
elif s<=2*a:
print(a,s-a)
elif s<=3*a:
print(3*a-s,a)
else:
print(0,4*a-s)
```
|
instruction
| 0
| 94,744
| 3
| 189,488
|
Yes
|
output
| 1
| 94,744
| 3
| 189,489
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
def main():
a, d =map(lambda x: int(float(x) * 10000 + 1e-6), input().split(' '))
ans = []
for i in range(1, int(input()) + 1):
cur_round_pos = d * i % (a * 4)
if cur_round_pos <= a:
y = 0
x = cur_round_pos / 10000
elif cur_round_pos <= a * 2:
x = a / 10000
y = (cur_round_pos - a) / 10000
elif cur_round_pos <= a * 3:
y = a / 10000
x = (a * 3 - cur_round_pos) / 10000
elif cur_round_pos < a * 4:
x = 0
y = (a * 4 - cur_round_pos) / 10000
ans.append('{} {}'.format(x, y))
print('\n'.join(ans))
if __name__ == '__main__':
sys.exit(main())
```
|
instruction
| 0
| 94,745
| 3
| 189,490
|
Yes
|
output
| 1
| 94,745
| 3
| 189,491
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
def setPoint(point, a):
p = point
x = 0
y = 0
cnt = 0
if p <= a:
x = p
y = 0
elif p <= a*2:
x = a
y = p
elif p <= a*3:
x = a*3 - p
y = a
else:
x = 0
y = a*4 - p
return str(x)[:7] + ' ' + str(y)[:7]
a, d = map(float, input().split())
n = int(input())
curP = 0
finish = n*d + 0.5
for l in range(0, n):
curP += d
while curP > a*4:
curP -= a*4
print(setPoint(curP, a))
```
|
instruction
| 0
| 94,746
| 3
| 189,492
|
No
|
output
| 1
| 94,746
| 3
| 189,493
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
def main():
a, d =map(lambda x: int(float(x) * 10000), input().split(' '))
ans = []
for i in range(1, int(input()) + 1):
t = d * i % (a * 4)
if t <= a:
y = 0
x = t / 10000
elif t <= a * 2:
x = a / 10000
y = (t - a) / 10000
elif t <= a * 3:
y = a / 10000
x = (a - (t - a * 2)) / 10000
elif t < a * 4:
x = 0
y = (a - (t - a * 3)) / 10000
ans.append('{} {}'.format(x, y))
print('\n'.join(ans))
if __name__ == '__main__':
sys.exit(main())
```
|
instruction
| 0
| 94,747
| 3
| 189,494
|
No
|
output
| 1
| 94,747
| 3
| 189,495
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
def main():
a, d =map(lambda x: int(float(x) * 10000), input().split(' '))
for i in range(1, int(input()) + 1):
cur_round_pos = d * i % (a * 4)
if cur_round_pos <= a:
y = 0.0
x = cur_round_pos / 10000
elif cur_round_pos <= a * 2:
x = a / 10000
y = (cur_round_pos - a) / 10000
elif cur_round_pos <= a * 3:
y = a / 10000
x = (a - (cur_round_pos - a * 2)) / 10000
elif cur_round_pos <= a * 4:
x = 0.0
y = (a - (cur_round_pos - a * 3)) / 10000
print(x, end=' ')
print(y)
if __name__ == '__main__':
sys.exit(main())
```
|
instruction
| 0
| 94,748
| 3
| 189,496
|
No
|
output
| 1
| 94,748
| 3
| 189,497
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2Β·d, ..., nΒ·d meters.
Input
The first line contains two space-separated real numbers a and d (1 β€ a, d β€ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 β€ n β€ 105) showing that Valera needs an extra drink n times.
Output
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers iΒ·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
Examples
Input
2 5
2
Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
Input
4.147 2.8819
6
Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
def main():
a, d =map(lambda x: int(float(x) * 10000 + 1e-6), input().split(' '))
ans = []
for i in range(1, int(input()) + 1):
cur_round_pos = d * i % (a * 4)
if cur_round_pos <= a:
y = 0
x = cur_round_pos / 10000
elif cur_round_pos <= a * 2:
x = a / 10000
y = (cur_round_pos - a) / 10000
elif cur_round_pos <= a * 3:
y = a
x = (a * 3 - cur_round_pos) / 10000
elif cur_round_pos < a * 4:
x = 0
y = (a * 4 - cur_round_pos) / 10000
print('{} {}'.format(x, y))
ans.append('{} {}'.format(x, y))
print('\n'.join(ans))
if __name__ == '__main__':
sys.exit(main())
```
|
instruction
| 0
| 94,749
| 3
| 189,498
|
No
|
output
| 1
| 94,749
| 3
| 189,499
|
Provide a correct Python 3 solution for this coding contest problem.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
|
instruction
| 0
| 94,858
| 3
| 189,716
|
"Correct Solution:
```
import sys, math
#sys.stdin = open ('sample.in','r')
n = int(input())
for i in range(n):
p,q = map(int,input().split())
for j in range(p):
if j == 0:
fir = list(map(int, input().split()))
elif j == p//2 - 1:
sec = list(map(int, input().split()))
elif j == p//2:
third = list(map(int, input().split()))
elif j == p-1:
fourth = list(map(int, input().split()))
else:
input()
ans1 = 0
ans2 = 0
for j in range(q):
ans1 += math.fabs(sec[j] - third[j])
ans2 += math.fabs(fir[j] - fourth[j])
if ans1 >= ans2:
print('YES')
else:
print('NO')
```
|
output
| 1
| 94,858
| 3
| 189,717
|
Provide a correct Python 3 solution for this coding contest problem.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
|
instruction
| 0
| 94,859
| 3
| 189,718
|
"Correct Solution:
```
print("""YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
YES
YES
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
YES""")
```
|
output
| 1
| 94,859
| 3
| 189,719
|
Provide a correct Python 3 solution for this coding contest problem.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
|
instruction
| 0
| 94,860
| 3
| 189,720
|
"Correct Solution:
```
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('NO')
print('NO')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('YES')
print('YES')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
print('YES')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
print('YES')
print('NO')
print('NO')
print('NO')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('NO')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('YES')
print('YES')
print('YES')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('YES')
print('YES')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('NO')
print('YES')
print('NO')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('YES')
print('YES')
print('YES')
print('NO')
print('NO')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('YES')
print('YES')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
print('YES')
print('NO')
print('NO')
print('YES')
print('NO')
print('NO')
print('NO')
print('YES')
print('YES')
print('NO')
print('YES')
```
|
output
| 1
| 94,860
| 3
| 189,721
|
Provide a correct Python 3 solution for this coding contest problem.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
|
instruction
| 0
| 94,861
| 3
| 189,722
|
"Correct Solution:
```
a = ['YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'YES', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO']
for elem in a:
print(elem)
```
|
output
| 1
| 94,861
| 3
| 189,723
|
Provide a correct Python 3 solution for this coding contest problem.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
|
instruction
| 0
| 94,862
| 3
| 189,724
|
"Correct Solution:
```
for x in ['YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'NO', 'NO', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'YES', 'YES', 'NO', 'YES']:
print(x)
```
|
output
| 1
| 94,862
| 3
| 189,725
|
Provide a correct Python 3 solution for this coding contest problem.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
|
instruction
| 0
| 94,863
| 3
| 189,726
|
"Correct Solution:
```
a = '''YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
NO'''
print(a)
```
|
output
| 1
| 94,863
| 3
| 189,727
|
Provide a correct Python 3 solution for this coding contest problem.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
|
instruction
| 0
| 94,864
| 3
| 189,728
|
"Correct Solution:
```
print('''YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
YES
''')
```
|
output
| 1
| 94,864
| 3
| 189,729
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.
The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...
Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images.
<image>
The first two images from the test set. The first picture has been rearranged, but not the second.
Input
The first line of the input contains the number q of questions (1 β€ q β€ 220). After that, q questions follow, each of which in the format described below.
The first line of every question contains two space-separated integers h and w (1 β€ h, w β€ 600) β the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 Γ 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 β€ aij < 256, where 0 is black and 255 is white).
Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost <image> rows have been moved to the bottom of the picture. It is guaranteed that h is even.
There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct.
Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
Submitted Solution:
```
print("""YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
""")
```
|
instruction
| 0
| 94,865
| 3
| 189,730
|
No
|
output
| 1
| 94,865
| 3
| 189,731
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.