message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
Can Gerald cope with the task?
Input
The first line contains integers x1 и y1 — the coordinates of the vector A ( - 108 ≤ x1, y1 ≤ 108). The second and the third line contain in the similar manner vectors B and C (their coordinates are integers; their absolute value does not exceed 108).
Output
Print "YES" (without the quotes) if it is possible to get vector B using the given operations. Otherwise print "NO" (without the quotes).
Examples
Input
0 0
1 1
0 1
Output
YES
Input
0 0
1 1
1 1
Output
YES
Input
0 0
1 1
2 2
Output
NO
Submitted Solution:
```
def amob(a,b):
if b==0:return 1
return a%b==0
ax,ay=map(int,input().split())
bx,by=map(int,input().split())
cx,cy=map(int,input().split())
#
for x,y in[(ax,ay),(ay,-ax),(-ax,-ay),(-ay,ax)]:
nx=bx-x
ny=by-y
if(amob(nx,cx) or amob(nx,cy))and (amob(ny,cx)or amob(ny,cy)):exit(print('YES'))
print('NO')
#3,0 -> 0,3 -> -3,0 -> 0,-3
``` | instruction | 0 | 57,158 | 23 | 114,316 |
No | output | 1 | 57,158 | 23 | 114,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
Can Gerald cope with the task?
Input
The first line contains integers x1 и y1 — the coordinates of the vector A ( - 108 ≤ x1, y1 ≤ 108). The second and the third line contain in the similar manner vectors B and C (their coordinates are integers; their absolute value does not exceed 108).
Output
Print "YES" (without the quotes) if it is possible to get vector B using the given operations. Otherwise print "NO" (without the quotes).
Examples
Input
0 0
1 1
0 1
Output
YES
Input
0 0
1 1
1 1
Output
YES
Input
0 0
1 1
2 2
Output
NO
Submitted Solution:
```
def amob(a,b):
if a<0 and b>0 or a>0 and b<0:return 0
if b==0:return 0
return a%b==0
ax,ay=map(int,input().split())
bx,by=map(int,input().split())
cx,cy=map(int,input().split())
#
for x,y in[(ax,ay),(ay,-ax),(-ax,-ay),(-ay,ax)]:
nx=bx-x
ny=by-y
if(amob(nx,cx) or amob(nx,cy))and (amob(ny,cx)or amob(ny,cy)):exit(print('YES'))
print('NO')
#3,0 -> 0,3 -> -3,0 -> 0,-3
``` | instruction | 0 | 57,159 | 23 | 114,318 |
No | output | 1 | 57,159 | 23 | 114,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,709 | 23 | 115,418 |
Tags: geometry, math
Correct Solution:
```
from fractions import Fraction
xa, ya, xb, yb, xc, yc = map(int, input().split())
if xa * (yb - yc) + xb * (yc - ya) + xc * (ya - yb) == 0:
print('NO')
elif (xa - xb)**2 + (ya - yb)**2 == (xb - xc)**2 + (yb - yc)**2:
print('YES')
else:
print('NO')
``` | output | 1 | 57,709 | 23 | 115,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,710 | 23 | 115,420 |
Tags: geometry, math
Correct Solution:
```
from math import sqrt
ax,ay,bx,by,cx,cy = [int(i) for i in input().split()]
if (ax-bx)**2+(ay-by)**2 != (bx-cx)**2+(by-cy)**2:
print("No")
elif abs((ax-bx)*(bx-cx)+((ay-by)*(by-cy)))**2== ((ax-bx)**2+(ay-by)**2)* ((bx-cx)**2+(by-cy)**2):
print("No")
else:
print("Yes")
``` | output | 1 | 57,710 | 23 | 115,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,711 | 23 | 115,422 |
Tags: geometry, math
Correct Solution:
```
a = [int(i) for i in input().split()]
t1 = (a[0] - a[2]) ** 2 + (a[1] - a[3]) ** 2
t2 = (a[4] - a[2]) ** 2 + (a[5] - a[3]) ** 2
t3 = (a[4] - a[0]) ** 2 + (a[5] - a[1]) ** 2
if t1 == t2 and t1 * 4 != t3:
print("YES")
else:
print("NO")
``` | output | 1 | 57,711 | 23 | 115,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,712 | 23 | 115,424 |
Tags: geometry, math
Correct Solution:
```
# http://codeforces.com/contest/851/problem/B
get=lambda:list(map(int,input().split()))
l=get()
a1,b1,a2,b2,a3,b3=l
if l==[0, 0, 1000000000 ,1, 1000000000 ,-999999999]:
print("No")
exit()
a=complex(a1,b1)
b=complex(a2,b2)
c=complex(a3,b3)
try:
x=(a*c-b*b)/(a+c-2*b)
except:
x=0
#print(x)
if abs(abs(a-x)-abs(b-x))<10**-6 and abs(abs(b-x)-abs(c-x))<10**-6 and abs(abs(a-x)-abs(c-x))<10**-6 :
print("Yes")
else:
print("No")
``` | output | 1 | 57,712 | 23 | 115,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,713 | 23 | 115,426 |
Tags: geometry, math
Correct Solution:
```
def main():
ax, ay, bx, by, cx, cy = map(int, input().split())
AB = (ax-bx)*(ax-bx)+(ay-by)*(ay-by)
BC = (bx-cx)*(bx-cx)+(by-cy)*(by-cy)
if AB == BC and not (bx-ax == cx-bx and by-ay == cy-by):
print("Yes")
else:
print("No")
main()
``` | output | 1 | 57,713 | 23 | 115,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,714 | 23 | 115,428 |
Tags: geometry, math
Correct Solution:
```
import sys
import math
ax, ay, bx, by, cx, cy = [int(x) for x in sys.stdin.readline().strip().split(" ")]
def dist(ax, ay, bx, by):
return (bx - ax) ** 2 + (by - ay) ** 2
def slope(ax, ay, bx, by):
if(bx - ax == 0):
return float("inf")
return ((by - ay + 0.0) / (bx - ax))
def collinear(ax, ay, bx, by, cx, cy):
if(slope(ax, ay, bx, by) == slope(bx, by, cx, cy)):
return True
else:
return False
if(dist(ax, ay, bx, by) == dist(bx, by, cx, cy) and not collinear(ax, ay, bx, by, cx, cy)):
print("yes")
else:
print("no")
``` | output | 1 | 57,714 | 23 | 115,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,715 | 23 | 115,430 |
Tags: geometry, math
Correct Solution:
```
ax,ay,bx,by,cx,cy = list(map(int,input().split()))
ax -= bx
ay -= by
cx -= bx
cy -= by
num = 0
qwe = 0
if (ax**2 + ay**2) == (cx**2 + cy**2) :
num = 1
if (ax*cy - ay*cx) == 0:
qwe = 1
if num and not qwe:
print("YES")
else:
print("NO")
``` | output | 1 | 57,715 | 23 | 115,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | instruction | 0 | 57,716 | 23 | 115,432 |
Tags: geometry, math
Correct Solution:
```
ax,ay,bx,by,cx,cy = [int(i) for i in input().split(" ")]
def distance(ax,ay,bx,by):
return (ax-bx)**2+(ay-by)**2
def same_line(ax,ay,bx,by,cx,cy):
#if (ay-by)/(ax-bx) == (by-cy)/(bx-cx): ERROR!!
if (by-ay)*(cx-bx) == (cy-by)*(bx-ax):
return True
if same_line(ax,ay,bx,by,cx,cy):
print("No")
else:
if distance(ax,ay,bx,by) == distance(cx,cy,bx,by):
print("Yes")
else:
print("No")
``` | output | 1 | 57,716 | 23 | 115,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
import math
import sys
import decimal
decimal.getcontext().prec = 100
ax, ay, bx, by, cx, cy = list(map(decimal.Decimal, input().split()))
absq = (ax - bx) ** decimal.Decimal(2) + (ay - by) ** decimal.Decimal(2)
bcsq = (bx - cx) ** decimal.Decimal(2) + (by - cy) ** decimal.Decimal(2)
acsq = (ax - cx) ** decimal.Decimal(2) + (ay - cy) ** decimal.Decimal(2)
on_one_line = False
# print(absq, bcsq, acsq)
lengths = sorted([absq ** decimal.Decimal(.5), bcsq ** decimal.Decimal(.5), acsq ** decimal.Decimal(.5)])
# print(lengths)
if lengths[0] + lengths[1] - lengths[2] < sys.float_info.epsilon:# 0.0000000000000000000000000000000000001:
on_one_line = True
if absq == bcsq and not on_one_line:
print("Yes")
else:
print("No")
``` | instruction | 0 | 57,717 | 23 | 115,434 |
Yes | output | 1 | 57,717 | 23 | 115,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
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")
#-------------------game starts now-----------------------------------------------------
def gx(a,b,c,d,e,f):
if (a-c)*(b-f)==((a-e)*(b-d)):
return 1
else:
return 0
a,b,c,d,e,f=map(int,input().split())
if (a-c)*(a-c)+(b-d)*(b-d)==(c-e)*(c-e)+(d-f)*(d-f) and (not gx(a,b,c,d,e,f)):
print('Yes')
else:
print('No')
``` | instruction | 0 | 57,718 | 23 | 115,436 |
Yes | output | 1 | 57,718 | 23 | 115,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
x1,y1,x2,y2,x3,y3 = map(int,input().split())
if(abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))>0):
if(((x2-x1)**2+(y2-y1)**2) == ((x3-x2)**2+(y3-y2)**2)):
print("Yes")
else:
print("No")
else:
print("No")
``` | instruction | 0 | 57,719 | 23 | 115,438 |
Yes | output | 1 | 57,719 | 23 | 115,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
[ax, ay, bx, by, cx, cy] = list(map(int, input().split()))
if (by-ay)*(cx-bx) == (cy-by)*(bx-ax):
print("No")
else:
if ((cy-by)**2 + (cx-bx)**2) == ((by-ay)**2+(bx-ax)**2):
print("Yes")
else:
print("No")
``` | instruction | 0 | 57,720 | 23 | 115,440 |
Yes | output | 1 | 57,720 | 23 | 115,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
ax,ay,bx,by,cx,cy = map(int,input().split())
if (ax-bx)*(ax-bx) + (ay-by)*(ay-by) == (bx-cx)*(bx-cx) + (by-cy)*(by-cy):
if (ax==bx and bx==cx):
print("NO")
elif ax==bx or bx==cx:
print("YES")
elif (by-ay)/(bx-ax)*(cy-by)/(cx-bx)>0 and abs((by-ay)/(bx-ax)-(cy-by)/(cx-bx))<10**13:
print("NO")
else:
print("YES")
else:
print("NO")
``` | instruction | 0 | 57,721 | 23 | 115,442 |
No | output | 1 | 57,721 | 23 | 115,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
ax,ay,bx,by,cx,cy=map(float,input().split())
ab=((ax-bx)**2+(ay-by)**2)**0.5
bc=((bx-cx)**2+(by-cy)**2)**0.5
ca=((cx-ax)**2+(cy-by)**2)**0.5
if ab==bc and ab+bc>ca:
A1=2*ax+2*cx
B1=2*ay+2*cy
C1=ax**2+ay**2-cx**2-cy**2
A2=2*bx+2*cx
B2=2*by+2*cy
C2=bx**2+by**2-cx**2-cy**2
A3=2*ax+2*bx
B3=2*ay+2*by
C3=ax**2+ay**2-bx**2-by**2
h1=(B1*C2-B2*C1)/(A1*B2-A2*B1)
k1=(C1*A2-C2*A1)/(A1*B2-A2*B1)
h2=(B2*C3-B3*C2)/(A2*B3-A3*B2)
k2=(C2*A3-C3*A2)/(A2*B3-A3*B2)
if h1==h2 and k1==k2:
print("Yes")
else:
print("No")
else:
print("No")
``` | instruction | 0 | 57,722 | 23 | 115,444 |
No | output | 1 | 57,722 | 23 | 115,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
ax,ay,bx,by,cx,cy=map(float,input().split())
ab=((ax-bx)**2+(ay-by)**2)**0.5
bc=((bx-cx)**2+(by-cy)**2)**0.5
ca=((cx-ax)**2+(cy-ay)**2)**0.5
if ab==bc!=ca:
print("Yes")
else:
print("No")
``` | instruction | 0 | 57,723 | 23 | 115,446 |
No | output | 1 | 57,723 | 23 | 115,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution.
Submitted Solution:
```
a,b,c,d,e,f=map(int,input().split())
l1=(a-c)**2+(b-d)**2
l2=(e-c)**2+(f-d)**2
if (l2 == l1 ):
if (a-c) == (c-e):
print("No")
else:
print("yes")
else:
print("No")
``` | instruction | 0 | 57,724 | 23 | 115,448 |
No | output | 1 | 57,724 | 23 | 115,449 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,954 | 23 | 115,908 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def det(a,b):
return a[0]*b[1]-a[1]*b[0]
def minus(a,b):
return (a[0]-b[0],a[1]-b[1])
def convex_hull(ps):
n = len(ps)
ps.sort()
k = 0
qs = [0]*(n+2)
for i in range(n):
while k > 1 and det(minus(qs[k-1], qs[k-2]), minus(ps[i], qs[k-1])) < 0:
k -= 1
qs[k] = ps[i]
k += 1
t = k
for i in range(n-1)[::-1]:
while k > t and det(minus(qs[k-1], qs[k-2]), minus(ps[i], qs[k-1])) < 0:
k -= 1
qs[k] = ps[i]
k += 1
qs = qs[:min(n,k-1)]
return qs
n = I()
ps = LIR(n)
qs = convex_hull(ps)
if len(qs) == n:
print(1)
else:
print(0)
return
#Solve
if __name__ == "__main__":
solve()
``` | output | 1 | 57,954 | 23 | 115,909 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,955 | 23 | 115,910 |
"Correct Solution:
```
import math
class Point():
def __init__(self, x=None, y=None):
self.x = x
self.y = y
class Vector():
def __init__(self, x, y):
self.x = x
self.y = y
def inner_product(self, vec):
return self.x*vec.x + self.y*vec.y
def outer_product(self, vec):
return self.x*vec.y - self.y*vec.x
def norm(self):
return math.sqrt(self.x**2 + self.y**2)
n = int(input())
points = []
for i in range(n):
x, y = list(map(int, input().split(' ')))
points.append(Point(x, y))
points.extend(points[0:2])
is_convex = True
for i in range(1, n+1):
a, b, c = points[i-1:i+2]
vec1, vec2 = Vector(a.x - b.x, a.y - b.y), Vector(c.x - b.x, c.y - b.y)
theta = math.degrees(math.atan2(vec2.outer_product(vec1), vec2.inner_product(vec1)))
if theta < 0:
is_convex = False
break
if is_convex:
print(1)
else:
print(0)
``` | output | 1 | 57,955 | 23 | 115,911 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,956 | 23 | 115,912 |
"Correct Solution:
```
n = int(input())
vec = []
for i in range(n):
vec += [list(map(int, input().split()))]
vec += [vec[0]]
vec += [vec[1]]
Sum = 0
def cross(a, b):
return a[0]*b[1]-a[1]*b[0]
def ab(a, b):
c = (b[0]-a[0],b[1]-a[1])
return c
def check(a, b, c):
if cross(ab(a, b),ab(a, c)) >= 0:
return 1
else:
return 0
for a, b, c in zip(vec[0:-2],vec[1:-1],vec[2:]):
cnt = check(a,b,c)
if cnt == 0:
break
print(cnt)
``` | output | 1 | 57,956 | 23 | 115,913 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,957 | 23 | 115,914 |
"Correct Solution:
```
import cmath
import math
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
PI = cmath.pi
TAU = cmath.pi * 2
EPS = 1e-8
class Point:
"""
2次元空間上の点
"""
# 反時計回り側にある
CCW_COUNTER_CLOCKWISE = 1
# 時計回り側にある
CCW_CLOCKWISE = -1
# 線分の後ろにある
CCW_ONLINE_BACK = 2
# 線分の前にある
CCW_ONLINE_FRONT = -2
# 線分上にある
CCW_ON_SEGMENT = 0
def __init__(self, c: complex):
self.c = c
@property
def x(self):
return self.c.real
@property
def y(self):
return self.c.imag
@staticmethod
def from_rect(x: float, y: float):
return Point(complex(x, y))
@staticmethod
def from_polar(r: float, phi: float):
return Point(cmath.rect(r, phi))
def __add__(self, p):
"""
:param Point p:
"""
return Point(self.c + p.c)
def __iadd__(self, p):
"""
:param Point p:
"""
self.c += p.c
return self
def __sub__(self, p):
"""
:param Point p:
"""
return Point(self.c - p.c)
def __isub__(self, p):
"""
:param Point p:
"""
self.c -= p.c
return self
def __mul__(self, f: float):
return Point(self.c * f)
def __imul__(self, f: float):
self.c *= f
return self
def __truediv__(self, f: float):
return Point(self.c / f)
def __itruediv__(self, f: float):
self.c /= f
return self
def __repr__(self):
return "({}, {})".format(round(self.x, 10), round(self.y, 10))
def __neg__(self):
return Point(-self.c)
def __eq__(self, p):
return abs(self.c - p.c) < EPS
def __abs__(self):
return abs(self.c)
@staticmethod
def ccw(a, b, c):
"""
線分 ab に対する c の位置
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja
:param Point a:
:param Point b:
:param Point c:
"""
b = b - a
c = c - a
det = b.det(c)
if det > EPS:
return Point.CCW_COUNTER_CLOCKWISE
if det < -EPS:
return Point.CCW_CLOCKWISE
if b.dot(c) < -EPS:
return Point.CCW_ONLINE_BACK
if c.norm() - b.norm() > EPS:
return Point.CCW_ONLINE_FRONT
return Point.CCW_ON_SEGMENT
def dot(self, p):
"""
内積
:param Point p:
:rtype: float
"""
return self.x * p.x + self.y * p.y
def det(self, p):
"""
外積
:param Point p:
:rtype: float
"""
return self.x * p.y - self.y * p.x
def dist(self, p):
"""
距離
:param Point p:
:rtype: float
"""
return abs(self.c - p.c)
def norm(self):
"""
原点からの距離
:rtype: float
"""
return abs(self.c)
def phase(self):
"""
原点からの角度
:rtype: float
"""
return cmath.phase(self.c)
def angle(self, p, q):
"""
p に向かってる状態から q まで反時計回りに回転するときの角度
:param Point p:
:param Point q:
:rtype: float
"""
return (cmath.phase(q.c - self.c) - cmath.phase(p.c - self.c)) % TAU
def area(self, p, q):
"""
p, q となす三角形の面積
:param Point p:
:param Point q:
:rtype: float
"""
return abs((p - self).det(q - self) / 2)
def projection_point(self, p, q, allow_outer=False):
"""
線分 pq を通る直線上に垂線をおろしたときの足の座標
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A&lang=ja
:param Point p:
:param Point q:
:param allow_outer: 答えが線分の間になくても OK
:rtype: Point|None
"""
diff_q = q - p
# 答えの p からの距離
r = (self - p).dot(diff_q) / abs(diff_q)
# 線分の角度
phase = diff_q.phase()
ret = Point.from_polar(r, phase) + p
if allow_outer or (p - ret).dot(q - ret) < EPS:
return ret
return None
def reflection_point(self, p, q):
"""
直線 pq を挟んで反対にある点
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B&lang=ja
:param Point p:
:param Point q:
:rtype: Point
"""
# 距離
r = abs(self - p)
# pq と p-self の角度
angle = p.angle(q, self)
# 直線を挟んで角度を反対にする
angle = (q - p).phase() - angle
return Point.from_polar(r, angle) + p
def on_segment(self, p, q, allow_side=True):
"""
点が線分 pq の上に乗っているか
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja
:param Point p:
:param Point q:
:param allow_side: 端っこでギリギリ触れているのを許容するか
:rtype: bool
"""
if not allow_side and (self == p or self == q):
return False
# 外積がゼロ: 面積がゼロ == 一直線
# 内積がマイナス: p - self - q の順に並んでる
return abs((p - self).det(q - self)) < EPS and (p - self).dot(q - self) < EPS
class Line:
"""
2次元空間上の直線
"""
def __init__(self, a: float, b: float, c: float):
"""
直線 ax + by + c = 0
"""
self.a = a
self.b = b
self.c = c
@staticmethod
def from_gradient(grad: float, intercept: float):
"""
直線 y = ax + b
:param grad: 傾き
:param intercept: 切片
:return:
"""
return Line(grad, -1, intercept)
@staticmethod
def from_segment(p1, p2):
"""
:param Point p1:
:param Point p2:
"""
a = p2.y - p1.y
b = p1.x - p2.x
c = p2.y * (p2.x - p1.x) - p2.x * (p2.y - p1.y)
return Line(a, b, c)
@property
def gradient(self):
"""
傾き
"""
return INF if self.b == 0 else -self.a / self.b
@property
def intercept(self):
"""
切片
"""
return INF if self.b == 0 else -self.c / self.b
def is_parallel_to(self, l):
"""
平行かどうか
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=ja
:param Line l:
"""
# 法線ベクトル同士の外積がゼロ
return abs(Point.from_rect(self.a, self.b).det(Point.from_rect(l.a, l.b))) < EPS
def is_orthogonal_to(self, l):
"""
直行しているかどうか
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=ja
:param Line l:
"""
# 法線ベクトル同士の内積がゼロ
return abs(Point.from_rect(self.a, self.b).dot(Point.from_rect(l.a, l.b))) < EPS
def intersection_point(self, l):
"""
交差する点
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_B&lang=ja
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_C&lang=ja
FIXME: 誤差が気になる。EPS <= 1e-9 だと CGL_2_B ダメだった。
:param l:
:rtype: Point|None
"""
a1, b1, c1 = self.a, self.b, self.c
a2, b2, c2 = l.a, l.b, l.c
det = a1 * b2 - a2 * b1
if abs(det) < EPS:
# 並行
return None
x = (b1 * c2 - b2 * c1) / det
y = (a2 * c1 - a1 * c2) / det
return Point.from_rect(x, y)
class Segment:
"""
2次元空間上の線分
"""
def __init__(self, p1, p2):
"""
:param Point p1:
:param Point p2:
"""
self.p1 = p1
self.p2 = p2
def norm(self):
"""
線分の長さ
"""
return abs(self.p1 - self.p2)
def intersects_with(self, s, allow_side=True):
"""
交差するかどうか
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_B&lang=ja
:param Segment s:
:param allow_side: 端っこでギリギリ触れているのを許容するか
"""
l1 = Line.from_segment(self.p1, self.p2)
l2 = Line.from_segment(s.p1, s.p2)
if l1.is_parallel_to(l2):
# 並行なら線分の端点がもう片方の線分の上にあるかどうか
return (s.p1.on_segment(self.p1, self.p2, allow_side) or
s.p2.on_segment(self.p1, self.p2, allow_side) or
self.p1.on_segment(s.p1, s.p2, allow_side) or
self.p2.on_segment(s.p1, s.p2, allow_side))
else:
# 直線同士の交点が線分の上にあるかどうか
p = l1.intersection_point(l2)
return p.on_segment(self.p1, self.p2, allow_side) and p.on_segment(s.p1, s.p2, allow_side)
def closest_point(self, p):
"""
線分上の、p に最も近い点
:param Point p:
"""
# p からおろした垂線までの距離
d = (p - self.p1).dot(self.p2 - self.p1) / self.norm()
# p1 より前
if d < EPS:
return self.p1
# p2 より後
if -EPS < d - self.norm():
return self.p2
# 線分上
return Point.from_polar(d, (self.p2 - self.p1).phase()) + self.p1
def dist(self, p):
"""
他の点との最短距離
:param Point p:
"""
return abs(p - self.closest_point(p))
def dist_segment(self, s):
"""
他の線分との最短距離
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D&lang=ja
:param Segment s:
"""
if self.intersects_with(s):
return 0.0
return min(
self.dist(s.p1),
self.dist(s.p2),
s.dist(self.p1),
s.dist(self.p2),
)
class Polygon:
"""
2次元空間上の多角形
"""
def __init__(self, points):
"""
:param list of Point points:
"""
self.points = points
def iter2(self):
"""
隣り合う2点を順に返すイテレータ
:rtype: typing.Iterator[(Point, Point)]
"""
return zip(self.points, self.points[1:] + self.points[:1])
def iter3(self):
"""
隣り合う3点を順に返すイテレータ
:rtype: typing.Iterator[(Point, Point, Point)]
"""
return zip(self.points,
self.points[1:] + self.points[:1],
self.points[2:] + self.points[:2])
def area(self):
"""
面積
Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A&lang=ja
"""
# 外積の和 / 2
dets = []
for p, q in self.iter2():
dets.append(p.det(q))
return abs(math.fsum(dets)) / 2
def is_convex(self, allow_straight=False, allow_collapsed=False):
"""
凸包かどうか
:param allow_straight: 3点がまっすぐ並んでるのを許容するかどうか
:param allow_collapsed: 面積がゼロの場合を許容するか
"""
ccw = []
for a, b, c in self.iter3():
ccw.append(Point.ccw(a, b, c))
ccw = set(ccw)
if len(ccw) == 1:
if ccw == {Point.CCW_CLOCKWISE}:
return True
if ccw == {Point.CCW_COUNTER_CLOCKWISE}:
return True
if allow_straight and len(ccw) == 2:
if ccw == {Point.CCW_ONLINE_FRONT, Point.CCW_CLOCKWISE}:
return True
if ccw == {Point.CCW_ONLINE_FRONT, Point.CCW_COUNTER_CLOCKWISE}:
return True
if allow_collapsed and len(ccw) == 3:
return ccw == {Point.CCW_ONLINE_FRONT, Point.CCW_ONLINE_BACK, Point.CCW_ON_SEGMENT}
return False
Q = int(sys.stdin.buffer.readline())
XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]
points = []
for x, y in XY:
points.append(Point(complex(x, y)))
polygon = Polygon(points)
print(int(polygon.is_convex(allow_straight=True, allow_collapsed=True)))
``` | output | 1 | 57,957 | 23 | 115,915 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,958 | 23 | 115,916 |
"Correct Solution:
```
n=int(input())
p=[complex(*map(int,input().split())) for _ in range(n)]
e=[b-a for a,b in zip(p,p[1:]+[p[0]])]
p=e[0]
for i in range(1,n,):
now=e[-i]
if now.real*p.imag-p.real*now.imag<-1e-6:print(0);break
p=now
else: print(1)
``` | output | 1 | 57,958 | 23 | 115,917 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,959 | 23 | 115,918 |
"Correct Solution:
```
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())
###########################
# 幾何
###########################
def sgn(a):
if a < -eps: return -1
if a > eps: return 1
return 0
class Point:
def __init__(self,x,y):
self.x = x
self.y = y
pass
def tolist(self):
return [self.x,self.y]
def __add__(self,p):
return Point(self.x+p.x, self.y+p.y)
def __iadd__(self,p):
return self + p
def __sub__(self,p):
return Point(self.x - p.x, self.y - p.y)
def __isub__(self,p):
return self - p
def __truediv__(self,n):
return Point(self.x/n, self.y/n)
def __itruediv__(self,n):
return self / n
def __mul__(self,n):
return Point(self.x*n, self.y*n)
def __imul__(self,n):
return self * n
def __lt__(self,other):
tmp = sgn(self.x - other.x)
if tmp != 0:
return tmp < 0
else:
return sgn(self.y - other.y) < 0
def __eq__(self,other):
return sgn(self.x - other.x) == 0 and sgn(self.y - other.y) == 0
def abs(self):
return math.sqrt(self.x**2+self.y**2)
def dot(self,p):
return self.x * p.x + self.y*p.y
def det(self,p):
return self.x * p.y - self.y*p.x
def arg(self,p):
return math.atan2(y,x)
# 点の進行方向 a -> b -> c
def iSP(a,b,c):
tmp = sgn((b-a).det(c-a))
if tmp > 0: return 1 # 左に曲がる場合
elif tmp < 0: return -1 # 右に曲がる場合
else: # まっすぐ
if sgn((b-a).dot(c-a)) < 0: return -2 # c-a-b の順
if sgn((a-b).dot(c-b)) < 0: return 2 # a-b-c の順
return 0 # a-c-bの順
# ab,cd の直線交差
def isToleranceLine(a,b,c,d):
if sgn((b-a).det(c-d)) != 0: return 1 # 交差する
else:
if sgn((b-a).det(c-a)) != 0: return 0 # 平行
else: return -1 # 同一直線
# ab,cd の線分交差 重複,端点での交差もTrue
def isToleranceSegline(a,b,c,d):
return sgn(iSP(a,b,c)*iSP(a,b,d))<=0 and sgn(iSP(c,d,a)*iSP(c,d,b)) <= 0
# 直線ab と 直線cd の交点 (存在する前提)
def Intersection(a,b,c,d):
tmp1 = (b-a)*((c-a).det(d-c))
tmp2 = (b-a).det(d-c)
return a+(tmp1/tmp2)
# 直線ab と 点c の距離
def DistanceLineToPoint(a,b,c):
return abs(((c-a).det(b-a))/((b-a).abs()))
# 線分ab と 点c の距離
def DistanceSeglineToPoint(a,b,c):
if sgn((b-a).dot(c-a)) < 0: # <cab が鈍角
return (c-a).abs()
if sgn((a-b).dot(c-b)) < 0: # <cba が鈍角
return (c-b).abs()
return DistanceLineToPoint(a,b,c)
# 直線ab への 点c からの垂線の足
def Vfoot(a,b,c):
d = c + Point((b-a).y,-(b-a).x)
return Intersection(a,b,c,d)
# 多角形の面積
def PolygonArea(Plist):
#Plist = ConvexHull(Plist)
L = len(Plist)
S = 0
for i in range(L):
tmpS = (Plist[i-1].det(Plist[i]))/2
S += tmpS
return S
# 多角形の重心
def PolygonG(Plist):
Plist = ConvexHull(Plist)
L = len(Plist)
S = 0
G = Point(0,0)
for i in range(L):
tmpS = (Plist[i-1].det(Plist[i]))/2
S += tmpS
G += (Plist[i-1]+Plist[i])/3*tmpS
return G/S
# 凸法
def ConvexHull(Plist):
Plist.sort()
L = len(Plist)
qu = deque([])
quL = 0
for p in Plist:
while quL >= 2 and iSP(qu[quL-2],qu[quL-1],p) == 1:
qu.pop()
quL -= 1
qu.append(p)
quL += 1
qd = deque([])
qdL = 0
for p in Plist:
while qdL >= 2 and iSP(qd[qdL-2],qd[qdL-1],p) == -1:
qd.pop()
qdL -= 1
qd.append(p)
qdL += 1
qd.pop()
qu.popleft()
hidari = list(qd) + list(reversed(qu)) # 左端開始,左回りPlist
return hidari
N = int(input())
Plyst = [Point(*inpl()) for _ in range(N)]
Plyst2 = ConvexHull(Plyst)
L1 = [tuple(p.tolist()) for p in Plyst]
L2 = [tuple(p.tolist()) for p in Plyst2]
if len(list(set(L1))) != len(list(set(L2))):
print(0)
else:
print(1)
``` | output | 1 | 57,959 | 23 | 115,919 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,960 | 23 | 115,920 |
"Correct Solution:
```
def cross(ux, uy, vx, vy):
return ux*vy - uy*vx
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
points.append(points[0])
points.append(points[1])
is_convex = True
for i in range(n):
x1, y1 = points[i]
x2, y2 = points[i + 1]
x3, y3 = points[i + 2]
if cross(x2 - x1, y2 - y1, x3 - x1, y3 - y1) < 0:
is_convex = False
break
print(1 if is_convex else 0)
``` | output | 1 | 57,960 | 23 | 115,921 |
Provide a correct Python 3 solution for this coding contest problem.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0 | instruction | 0 | 57,961 | 23 | 115,922 |
"Correct Solution:
```
#!/usr/bin/env python3
# CGL_3_B: Polygon - Is-Convex
def run():
n = int(input())
ps = []
for _ in range(n):
x, y = [int(i) for i in input().split()]
ps.append((x, y))
if convex(ps):
print(1)
else:
print(0)
def dot(v1, v2):
x1, y1 = v1
x2, y2 = v2
return x1 * x2 + y1 * y2
def orthogonal(v):
x, y = v
return -y, x
def convex(ps0):
p0, *ps1 = ps0
ps1.append(p0)
p1, *ps2 = ps1
ps2.append(p1)
ret = []
for pa, pb, pc in zip(ps0, ps1, ps2):
xa, ya = pa
xb, yb = pb
xc, yc = pc
v1 = (xb - xa, yb - ya)
v2 = (xc - xb, yc - yb)
ret.append(dot(orthogonal(v1), v2))
return all([d >= 0 for d in ret]) or all([d <= 0 for d in ret])
if __name__ == '__main__':
run()
``` | output | 1 | 57,961 | 23 | 115,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0
Submitted Solution:
```
def cross(a,b):
return a.real*b.imag-a.imag*b.real
n=int(input())
A=[]
for _ in range(n):
x,y=map(int,input().split())
A.append(x+y*1j)
flag=0
for i in range(n-1):
for j in range(i+1,n):
if cross(A[i]-A[i-1],A[j]-A[i-1])<0 or cross(A[i+1]-A[i],A[j]-A[i])<0:
print("0")
flag=1
break
if(flag==1):
break
if(flag==0):
print("1")
``` | instruction | 0 | 57,962 | 23 | 115,924 |
Yes | output | 1 | 57,962 | 23 | 115,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0
Submitted Solution:
```
# Aizu Problem CGL_3_B: Is-Convex
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input3.txt", "rt")
def is_convex(P):
# check whether polygon P is convex or not
# see: https://stackoverflow.com/questions/471962/how-do-determine-if-a-polygon-is-complex-convex-nonconvex
N = len(P)
prods = []
for k in range(N):
x0, y0 = P[k]
x1, y1 = P[(k + 1) % N]
x2, y2 = P[(k + 2) % N]
dx1 = x1 - x0
dy1 = y1 - y0
dx2 = x2 - x1
dy2 = y2 - y1
cross = dx1 * dy2 - dy1 * dx2
prods.append(cross)
prods = sorted(prods)
return prods[0] * prods[-1] >= 0
N = int(input())
P = [[int(_) for _ in input().split()] for __ in range(N)]
print(1 if is_convex(P) else 0)
``` | instruction | 0 | 57,963 | 23 | 115,926 |
Yes | output | 1 | 57,963 | 23 | 115,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0
Submitted Solution:
```
def vc(p,q):
return[p[0]-q[0],p[1]-q[1]]
def cross(u,v):
return(u[0]*v[1]-u[1]*v[0])
n = int(input())
v = []
for _ in range(n):
x0,y0 = map(int,input().split())
v.append([x0,y0])
flag = True
for i in range(n-2):
e_i = vc(v[i+1],v[i])
e_nxt = vc(v[i+2],v[i+1])
if cross(e_i,e_nxt)<0:
flag = False
e_i = vc(v[-1],v[-2])
e_nxt = vc(v[0],v[-1])
if cross(e_i,e_nxt)<0:
flag = False
e_i = vc(v[0],v[-1])
e_nxt = vc(v[1],v[0])
if cross(e_i,e_nxt)<0:
flag = False
if flag:
print(1)
else:
print(0)
``` | instruction | 0 | 57,964 | 23 | 115,928 |
Yes | output | 1 | 57,964 | 23 | 115,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0
Submitted Solution:
```
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
edges = [p1 - p0 for p0, p1 in zip(points, points[1:] + [points[0]])]
prev = edges[0]
while edges:
edge = edges.pop()
if edge.real * prev.imag - prev.real * edge.imag < -1e-6:
print(0)
break
prev = edge
else:
print(1)
``` | instruction | 0 | 57,965 | 23 | 115,930 |
Yes | output | 1 | 57,965 | 23 | 115,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0
Submitted Solution:
```
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
edges = [p1 - p0 for p0, p1 in zip(points, points[1:] + [points[0]])]
prev = edges[0]
while edges:
edge = edges.pop()
if edge.real * prev.imag - prev.real * edge.imag < 1e-6:
print(0)
break
prev = edge
else:
print(1)
``` | instruction | 0 | 57,966 | 23 | 115,932 |
No | output | 1 | 57,966 | 23 | 115,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0
Submitted Solution:
```
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dif(a,b):return [x-y for x,y in zip(a,b)]
x = range(int(input()))
t = 1
P,Q = [],[]
for _ in x:P+=[[int(i) for i in input().split()]]
for i in x:Q+=[dif(P[i],P[i-1])]
for i in x:if cross(Q[i-1],Q[i]) < 0: t *= False
print(t)
``` | instruction | 0 | 57,967 | 23 | 115,934 |
No | output | 1 | 57,967 | 23 | 115,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
Constraints
* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.
Input
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
Output
Print "1" or "0" in a line.
Examples
Input
4
0 0
3 1
2 3
0 3
Output
1
Input
5
0 0
2 0
1 1
2 2
0 2
Output
0
Submitted Solution:
```
# Aizu Problem CGL_3_B: Is-Convex
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def is_convex(P):
# check whether polygon P is convex or not
# see: https://stackoverflow.com/questions/471962/how-do-determine-if-a-polygon-is-complex-convex-nonconvex
N = len(P)
prods = []
for k in range(N):
x0, y0 = P[k]
x1, y1 = P[(k + 1) % N]
x2, y2 = P[(k + 2) % N]
dx1 = x1 - x0
dy1 = y1 - y0
dx2 = x2 - x1
dy2 = y2 - y1
cross = dx1 * dy2 - dy1 * dx2
prods.append(cross)
prods = sorted(prods)
return prods[0] * prods[-1] > 0
N = int(input())
P = [[int(_) for _ in input().split()] for __ in range(N)]
print(1 if is_convex(P) else 0)
``` | instruction | 0 | 57,968 | 23 | 115,936 |
No | output | 1 | 57,968 | 23 | 115,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2). | instruction | 0 | 57,983 | 23 | 115,966 |
Tags: bitmasks, brute force, combinatorics, math, number theory
Correct Solution:
```
from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3, 1, 2, 2, 2, 1] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1
for i, s in enumerate(l):
a, b, c = map(int, s.split())
k = gcd(b, c)
ab = d[gcd(a, b)]
ac = d[gcd(a, c)]
bc = d[k]
abc = d[gcd(a, k)]
asz = d[a] - ab - ac + abc
bsz = d[b] - bc - ab + abc
csz = d[c] - ac - bc + abc
absz = ab - abc
bcsz = bc - abc
acsz = ac - abc
abcsz = abc
l[i] = (asz * bsz * csz +
(absz * (asz + bsz) * csz) +
(bcsz * (bsz + csz) * asz) +
(acsz * (asz + csz) * bsz) +
(abcsz * (asz * bsz + asz * csz + bsz * csz)) +
(abcsz * (absz + bcsz + acsz) * (asz + bsz + csz)) +
((asz + bsz + csz + absz + bcsz + acsz) * (abcsz * (abcsz + 1) // 2)) +
(absz * bcsz * acsz) +
((absz * (absz + 1) * d[c]) +
(bcsz * (bcsz + 1) * d[a]) +
(acsz * (acsz + 1) * d[b])) // 2 +
((asz + bsz + csz + abcsz) * (absz * acsz + absz * bcsz + bcsz * acsz)) +
(abcsz + (abcsz * (abcsz - 1)) + (abcsz * (abcsz - 1) * (abcsz - 2) // 6)))
print('\n'.join(map(str, l)))
if __name__ == '__main__':
main()
``` | output | 1 | 57,983 | 23 | 115,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2). | instruction | 0 | 57,984 | 23 | 115,968 |
Tags: bitmasks, brute force, combinatorics, math, number theory
Correct Solution:
```
from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3., 1., 2., 2., 2., 1.] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1.
for i, s in enumerate(l):
a, b, c = map(int, s.split())
k = gcd(b, c)
ab = d[gcd(a, b)]
ac = d[gcd(a, c)]
bc = d[k]
abc = d[gcd(a, k)]
asz = d[a] - ab - ac + abc
bsz = d[b] - bc - ab + abc
csz = d[c] - ac - bc + abc
absz = ab - abc
bcsz = bc - abc
acsz = ac - abc
l[i] = '%d' % (asz * bsz * csz +
(absz * (asz + bsz) * csz) +
(bcsz * (bsz + csz) * asz) +
(acsz * (asz + csz) * bsz) +
(abc * (asz * bsz + asz * csz + bsz * csz)) +
(abc * (absz + bcsz + acsz) * (asz + bsz + csz)) +
((asz + bsz + csz + absz + bcsz + acsz) * (abc * (abc + 1) * .5)) +
(absz * bcsz * acsz) +
((absz * (absz + 1.) * d[c]) +
(bcsz * (bcsz + 1.) * d[a]) +
(acsz * (acsz + 1.) * d[b])) * .5 +
((asz + bsz + csz + abc) * (absz * acsz + absz * bcsz + bcsz * acsz)) +
(abc + (abc * (abc - 1.)) + (abc * (abc - 1.) * (abc - 2.) / 6.)))
print('\n'.join(map(str, l)))
if __name__ == '__main__':
main()
# Made By Mostafa_Khaled
``` | output | 1 | 57,984 | 23 | 115,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2). | instruction | 0 | 57,985 | 23 | 115,970 |
Tags: bitmasks, brute force, combinatorics, math, number theory
Correct Solution:
```
from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3., 1., 2., 2., 2., 1.] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1.
for i, s in enumerate(l):
a, b, c = map(int, s.split())
k = gcd(b, c)
ab = d[gcd(a, b)]
ac = d[gcd(a, c)]
bc = d[k]
abc = d[gcd(a, k)]
asz = d[a] - ab - ac + abc
bsz = d[b] - bc - ab + abc
csz = d[c] - ac - bc + abc
absz = ab - abc
bcsz = bc - abc
acsz = ac - abc
l[i] = '%d' % (asz * bsz * csz +
(absz * (asz + bsz) * csz) +
(bcsz * (bsz + csz) * asz) +
(acsz * (asz + csz) * bsz) +
(abc * (asz * bsz + asz * csz + bsz * csz)) +
(abc * (absz + bcsz + acsz) * (asz + bsz + csz)) +
((asz + bsz + csz + absz + bcsz + acsz) * (abc * (abc + 1) * .5)) +
(absz * bcsz * acsz) +
((absz * (absz + 1.) * d[c]) +
(bcsz * (bcsz + 1.) * d[a]) +
(acsz * (acsz + 1.) * d[b])) * .5 +
((asz + bsz + csz + abc) * (absz * acsz + absz * bcsz + bcsz * acsz)) +
(abc + (abc * (abc - 1.)) + (abc * (abc - 1.) * (abc - 2.) / 6.)))
print('\n'.join(map(str, l)))
if __name__ == '__main__':
main()
``` | output | 1 | 57,985 | 23 | 115,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2). | instruction | 0 | 57,986 | 23 | 115,972 |
Tags: bitmasks, brute force, combinatorics, math, number theory
Correct Solution:
```
from math import gcd
N = 100001
d = [0 for i in range(N)]
for i in range(1, N):
for j in range(i, N, i):
d[j] += 1
n = int(input())
for _ in range(n):
a, b, c = map(int, input().split())
A, B, C = d[a], d[b], d[c]
AB, BC, CA = d[gcd(a, b)], d[gcd(b, c)], d[gcd(c, a)]
ABC = d[gcd(gcd(a, b), c)]
print(A * B * C - AB * BC * CA + ABC * (AB * BC + BC * CA + CA * AB)
- A * BC * (BC - 1) // 2 - B * CA * (CA - 1) // 2 - C * AB * (AB - 1) // 2
- ABC * (ABC + 1) * (AB + BC + CA) // 2 + ABC * (ABC + 1) * (ABC + 2) // 6)
``` | output | 1 | 57,986 | 23 | 115,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2). | instruction | 0 | 57,987 | 23 | 115,974 |
Tags: bitmasks, brute force, combinatorics, math, number theory
Correct Solution:
```
N=100001
fac=[0 for i in range(N)]
for i in range(1,N):
for j in range(i,N,i):
fac[j]+=1
def gcd(a,b):
if a<b:
a,b=b,a
while b>0:
a,b=b,a%b
return a
def ctt(A,B,C):
la=fac[A]
lb=fac[B]
lc=fac[C]
ab=gcd(A,B)
ac=gcd(A,C)
bc=gcd(B,C)
abc=gcd(ab,C)
dupabc=fac[abc]
dupac=fac[ac]-dupabc
dupbc=fac[bc]-dupabc
dupab=fac[ab]-dupabc
lax=la-dupabc-dupab-dupac
lbx=lb-dupabc-dupab-dupbc
lcx=lc-dupabc-dupac-dupbc
ctx=lax*lbx*lcx
ctx+=lax*lbx*(lc-lcx)
ctx+=lax*lcx*(lb-lbx)
ctx+=lcx*lbx*(la-lax)
ctx+=lax*((lb-lbx)*(lc-lcx)-(dupabc+dupbc)*(dupabc+dupbc-1)/2)
ctx+=lbx*((la-lax)*(lc-lcx)-(dupabc+dupac)*(dupabc+dupac-1)/2)
ctx+=lcx*((la-lax)*(lb-lbx)-(dupabc+dupab)*(dupabc+dupab-1)/2)
ctx+=dupab*dupac*dupbc
ctx+=dupab*dupac*(dupab+dupac+2)/2
ctx+=dupab*dupbc*(dupab+dupbc+2)/2
ctx+=dupbc*dupac*(dupbc+dupac+2)/2
ctx+=dupabc*(dupab*dupac+dupab*dupbc+dupbc*dupac)
ctx+=dupabc*(dupab*(dupab+1)+(dupbc+1)*dupbc+(dupac+1)*dupac)/2
ctx+=(dupabc+1)*dupabc*(dupab+dupac+dupbc)/2
ctx+=(dupabc*dupabc+dupabc*(dupabc-1)*(dupabc-2)/6)
return int(ctx)
n=int(input())
for _ in range(n):
a,b,c = map(int,input().split())
print(ctt(a,b,c))
exit()
``` | output | 1 | 57,987 | 23 | 115,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2).
Submitted Solution:
```
import math
from itertools import combinations
# Get all combinations of [1, 1, 3]
# and length 2
def num(n):
n1 = int(math.sqrt(n))
j=1
count=0
while(j<=n1):
if(n%j==0 and j*j!=n):
count+=2
elif(n%j==0 and j*j==n):
count+=1
j+=1
return count
def comb(com):
for k in range(1,100000+1):
com[k][0]=1
com[k][1]=k
for k in range(1,100000+1):
if(k>=2):
com[k][2] = com[k-1][2] + com[k-1][1]
com[k][3] = com[k-1][3] + com[k-1][2]
test = int(input())
i=1
com = []
for k in range(1,100000+2):
com.append([])
for k in range(0,100000+1):
for l in range(4):
com[k].append(0)
comb(com)
while(i<=test):
s = input().split()
ans = []
sample=[]
check=0
counter=1
dim = list(map(int,s))
for d in dim:
ans.append(num(d))
if(ans[0]==ans[1] and ans[0]==ans[2]):
check=1
elif(ans[0]==ans[1] or ans[0]==ans[2] or ans[1]==ans[2]):
check=2
else:
check=3
# print("check" + str(check))
# print("ans"+str(ans[0]))
# print("ans1" + str(ans[1]))
if(check==1 and ans[0]==1):
print(1)
elif(check==1 and ans[0]==2):
print(ans[0]+ans[0]*(ans[0]-1))
elif(check==1):
a=com[ans[0]][3]
# print("a" + str(a))
print(ans[0]+ans[0]*(ans[0]-1) + a)
if(check==2):
if(ans[0]==ans[1]):
print(ans[0]*ans[2])
elif(ans[0]==ans[2]):
print(ans[0]*ans[1])
else:
print(ans[0]*ans[1])
elif(check==3):
print(ans[0]*ans[1]*ans[2])
i+=1
``` | instruction | 0 | 57,988 | 23 | 115,976 |
No | output | 1 | 57,988 | 23 | 115,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2).
Submitted Solution:
```
N=100001
fac=[0 for i in range(N)]
for i in range(1,N):
for j in range(i,N,i):
fac[j]+=1
def gcd(a,b):
if a<b:
a,b=b,a
while b>0:
a,b=b,a%b
return a
def ctt(A,B,C):
la=fac[A]
lb=fac[B]
lc=fac[C]
ab=gcd(A,B)
ac=gcd(A,C)
bc=gcd(B,C)
abc=gcd(ab,C)
dupabc=fac[abc]
dupac=fac[ac]-dupabc
dupbc=fac[bc]-dupabc
dupab=fac[ab]-dupabc
lax=la-dupabc-dupab-dupac
lbx=lb-dupabc-dupab-dupbc
lcx=lc-dupabc-dupac-dupbc
ctx=lax*lbx*lcx
ctx+=lax*lbx*(lc-lcx)
ctx+=lax*lcx*(lb-lbx)
ctx+=lcx*lbx*(la-lax)
ctx+=lax*((lb-lbx)*(lc-lcx)-(dupabc+dupbc)*(dupabc+dupbc-1)/2)
ctx+=lbx*((la-lax)*(lc-lcx)-(dupabc+dupac)*(dupabc+dupac-1)/2)
ctx+=lcx*((la-lax)*(lb-lbx)-(dupabc+dupab)*(dupabc+dupab-1)/2)
ctx+=dupab*dupac*dupbc
ctx+=dupab*dupac*(dupab+dupac+2)/2
ctx+=dupab*dupbc*(dupab+dupbc+2)/2
ctx+=dupbc*dupac*(dupbc+dupac+2)/2
ctx+=dupabc*(dupab*dupac+dupab*dupbc+dupbc*dupac)
ctx+=dupabc*(dupab*(dupab+1)+(dupbc+1)*dupbc+(dupac+1)*dupac)/2
ctx+=(dupabc+1)*dupabc*(dupab+dupac+dupbc)/2
ctx+=(dupabc*dupabc+dupabc*(dupabc-1)*(dupabc-2)/6)
return ctx
n=int(input())
for _ in range(n):
a,b,c = map(int, input().split())
print(ctt(a,b,c))
exit()
``` | instruction | 0 | 57,989 | 23 | 115,978 |
No | output | 1 | 57,989 | 23 | 115,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2).
Submitted Solution:
```
from math import sqrt
def get_factors(x):
i = 1
res = []
while i <= int(sqrt(x)):
if x%i == 0:
res.append(i)
if i != x//i:
res.append(x//i)
i += 1
return res
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
t = int(input())
for _ in range(t):
A, B, C = map(int, input().split(' '))
#print(A, B, C)
a1, b1, c1 = map(get_factors, [A, B, C])
#print(a1, b1, c1)
a2, b2, c2 = map(get_factors, [gcd(B, C), gcd(C, A), gcd(A, B)])
#print(a2, b2, c2)
d = get_factors(gcd(A, gcd(B, C)))
#print(d)
ans = len(a1)*len(b1)*len(c1) - len(a1)*len(a2)*(len(a2)-1)/2 - len(b1)*len(b2)*(len(b2)-1)/2 - len(c1)*len(c2)*(len(c2)-1)/2
if len(d) >= 2:
ans += len(d)*(len(d)-1)
if len(d) >= 3:
ans += 4*len(d)*(len(d)-1)*(len(d)-2)/6
print(int(ans))
``` | instruction | 0 | 57,990 | 23 | 115,980 |
No | output | 1 | 57,990 | 23 | 115,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.
Output
For each test case, print the number of different groups of three points that satisfy all given conditions.
Example
Input
4
1 1 1
1 6 1
2 2 2
100 100 100
Output
1
4
4
165
Note
In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).
In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).
In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2).
Submitted Solution:
```
import sys
import os
div = dict()
def prepare():
global div
div = dict()
for i in range(1, 100001):
div[i] = [1]
for i in range(2, 100001):
k = i
while k <= 100000:
div[k].append(i)
k += i
def mergeSort(xx, yy, zz):
result = []
x1 = 0
y1 = 0
z1 = 0
while x1 < len(xx) or y1 < len(yy) or z1 < len(zz):
if x1 < len(xx) and y1 < len(yy) and z1 < len(zz) and xx[x1][0] == yy[y1][0] and xx[x1][0] == zz[z1][0]:
result.append((xx[x1][0], 3))
x1 += 1
y1 += 1
z1 += 1
elif x1 < len(xx) and y1 < len(yy) and xx[x1][0] == yy[y1][0]:
result.append((xx[x1][0], 1))
x1 += 1
y1 += 1
elif x1 < len(xx) and z1 < len(zz) and xx[x1][0] == zz[z1][0]:
result.append((xx[x1][0], 2))
x1 += 1
z1 += 1
elif y1 < len(yy) and z1 < len(zz) and yy[y1][0] == zz[z1][0]:
result.append((yy[y1][0], 3))
y1 += 1
z1 += 1
elif x1 < len(xx) and (y1 >= len(yy) or xx[x1][0] < yy[y1][0]) and (z1 >= len(zz) or xx[x1][0] < zz[z1][0]):
result.append((xx[x1][0], 0))
x1 += 1
elif y1 < len(yy) and (x1 >= len(xx) or yy[y1][0] < xx[x1][0]) and (z1 >= len(zz) or yy[y1][0] < zz[z1][0]):
result.append((yy[y1][0], 1))
y1 += 1
elif z1 < len(zz) and (x1 >= len(xx) or zz[z1][0] < xx[x1][0]) and (y1 >= len(yy) or zz[z1][0] < yy[y1][0]):
result.append((zz[z1][0], 2))
z1 += 1
return result
def c2(x):
if x <= 1:
return 0
return x * (x - 1) // 2
def paveTheParallelepiped(x, y, z):
global div
result = 0
xx = list(zip(div[x], [0] * len(div[x])))
yy = list(zip(div[y], [1] * len(div[y])))
zz = list(zip(div[z], [2] * len(div[z])))
merged = mergeSort(xx, yy, zz)
count = []
for i in range(5):
count.append([0] * (len(merged) + 1))
for i in range(1, len(merged) + 1):
for j in range(5):
count[j][i] = count[j][i - 1] + (1 if merged[i - 1][1] == j else 0)
result = 0
xind = 0
for i in range(len(merged)):
if xind >= len(xx):
break
if merged[i][0] != xx[xind][0]:
continue
else:
xind += 1
a0 = count[0][len(merged)] - count[0][i]
a1 = count[1][len(merged)] - count[1][i]
a2 = count[2][len(merged)] - count[2][i]
a3 = count[3][len(merged)] - count[3][i]
result += c2(a0 + a1 + a2 + a3) - c2(a0) - c2(a1) - c2(a2) - a0 * a1 - a0 * a2 + a3
return result
def main():
prepare()
n = int(input())
for i in range(n):
x, y, z = (int(x) for x in input().split())
print(paveTheParallelepiped(x, y, z))
if __name__ == '__main__':
main()
``` | instruction | 0 | 57,991 | 23 | 115,982 |
No | output | 1 | 57,991 | 23 | 115,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
For example, the following matrices are palindromic:
<image>
The following matrices are not palindromic because they change after the order of rows is reversed:
<image>
The following matrices are not palindromic because they change after the order of columns is reversed:
<image>
You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
Input
The first line contains one integer n (1 ≤ n ≤ 20).
The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.
Output
If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.
If it's impossible to construct any matrix, then print "NO".
You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
Examples
Input
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
Output
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
Input
3
1 1 1 1 1 3 3 3 3
Output
YES
1 3 1
3 1 3
1 3 1
Input
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
Output
NO
Input
1
10
Output
YES
10
Note
Note that there exist multiple answers for the first two examples.
Submitted Solution:
```
from collections import Counter
import math
n = int(input())
a = [ int(x) for x in input().split()]
def unfold_matrix(mat,odd=False):
if(not odd):
for row in mat:
row += list(reversed(row))
mat += list(reversed(mat))
else:
for row in mat:
row += list(reversed(row[:-1]))
mat += list(reversed(mat[:-1]))
freq = Counter(a)
keys= freq.keys()
if(n%2==0):
keys4=[]
for key in keys:
while(freq[key]>=4 ):
keys4.append(key)
freq[key]-=4
if(freq[key]>0):
print('No')
exit()
size=n//2
mat = [ keys4[size*i:size*(i+1)] for i in range(size)]
unfold_matrix(mat)
else:
keys4=[]
keys2=[]
keys1=[]
count4=0
count2=0
mx4 = ((n-1)//2)**2
mx2 = n-1
for key in keys:
while(freq[key]>=4 and count4<mx4):
keys4.append(key)
freq[key]-=4
count4+=1
while(freq[key]>=2 and count2<mx2):
keys2.append(key)
freq[key]-=2
count2+=1
if(freq[key]==1):
keys1.append(key)
elif(freq[key]>1):
print('No')
exit()
if(len(keys2)!=n-1):
print('No')
exit()
if(len(keys1)!=1):
print('No')
exit()
#print(keys2)
size=n//2
mat = [ keys4[size*i:size*(i+1)]+[keys2[i]] for i in range(size)]
#print(mat)
mat += [keys2[size:] + keys1]
unfold_matrix(mat,True)
print('Yes')
for row in mat:
for elem in row:
print(elem,end=' ')
print()
``` | instruction | 0 | 58,064 | 23 | 116,128 |
Yes | output | 1 | 58,064 | 23 | 116,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
For example, the following matrices are palindromic:
<image>
The following matrices are not palindromic because they change after the order of rows is reversed:
<image>
The following matrices are not palindromic because they change after the order of columns is reversed:
<image>
You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
Input
The first line contains one integer n (1 ≤ n ≤ 20).
The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.
Output
If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.
If it's impossible to construct any matrix, then print "NO".
You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
Examples
Input
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
Output
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
Input
3
1 1 1 1 1 3 3 3 3
Output
YES
1 3 1
3 1 3
1 3 1
Input
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
Output
NO
Input
1
10
Output
YES
10
Note
Note that there exist multiple answers for the first two examples.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(RL())
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//gcd(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
# ------------------------------
# f = open('./input.txt')
# sys.stdin = f
def main():
n = N()
arr = RLL()
ct = Counter(arr)
res = [[0]*n for _ in range(n)]
index = 0
le = n//2
def put(value):
nonlocal index
px, py = index//le, index%le
res[px][py] = value
res[px][n-py-1] = value
res[n-px-1][py] = value
res[n-px-1][n-py-1] = value
index+=1
center = 0
sd_index_v = 0
sd_index_h = 0
for k, v in ct.items():
for _ in range(v//4):
if index==le**2:
tag = 2
while tag>0:
if sd_index_v < le:
res[sd_index_v][le] = k
res[n - 1 - sd_index_v][le] = k
sd_index_v += 1
else:
res[le][sd_index_h] = k
res[le][n - 1 - sd_index_h] = k
sd_index_h += 1
tag-=1
else:
put(k)
if v%2==1:
if n%2==0:
print('NO')
break
center+=1
res[le][le] = k
if v%4>=2:
if n%2==0:
print('NO')
break
if sd_index_v<le:
res[sd_index_v][le] = k
res[n-1-sd_index_v][le] = k
sd_index_v+=1
else:
res[le][sd_index_h] = k
res[le][n-1-sd_index_h] = k
sd_index_h+=1
if center>1 or sd_index_h>le:
print('NO')
break
else:
print('YES')
for i in res:
print(*i)
if __name__ == "__main__":
main()
``` | instruction | 0 | 58,065 | 23 | 116,130 |
Yes | output | 1 | 58,065 | 23 | 116,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
For example, the following matrices are palindromic:
<image>
The following matrices are not palindromic because they change after the order of rows is reversed:
<image>
The following matrices are not palindromic because they change after the order of columns is reversed:
<image>
You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
Input
The first line contains one integer n (1 ≤ n ≤ 20).
The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.
Output
If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.
If it's impossible to construct any matrix, then print "NO".
You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
Examples
Input
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
Output
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
Input
3
1 1 1 1 1 3 3 3 3
Output
YES
1 3 1
3 1 3
1 3 1
Input
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
Output
NO
Input
1
10
Output
YES
10
Note
Note that there exist multiple answers for the first two examples.
Submitted Solution:
```
n = int(input())
num = [0 for j in range(1000)]
a = [int(j) for j in input().split()]
var = 0
arr = [[0 for j in range(n)] for j in range(n)]
count = 0
t = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
for i in range(n*n):
num[a[i]-1] += 1
if n%2 == 0:
i = 0
for x in num:
if x%4 != 0:
var = 1
break
if var == 1:
print("NO")
else:
print("YES")
for x in range(n//2):
for y in range(n//2):
if num[i] == 0:
while num[i] == 0:
i += 1
arr[x][y] = i+1
arr[n-x-1][y] = i+1
arr[x][n-y-1] = i+1
arr[n-x-1][n-y-1] = i+1
num[i] -= 4
# print(num)
for x in arr:
print(*x)
else:
for x in num:
if x%4 == 0:
count4 += 1
elif x%4 == 2:
count2 += 1
elif x%4 == 1:
count1 += 1
elif x%4 == 3:
count2 += 1
count1 += 1
if count2 > 2*(n//2) or count1 > 1:
print("NO")
else:
print("YES")
i = 0
for x in range(n//2):
for y in range(n//2):
if num[i] < 4:
while num[i] < 4:
i += 1
arr[x][y] = i+1
arr[n-x-1][y] = i+1
arr[x][n-y-1] = i+1
arr[n-x-1][n-y-1] = i+1
num[i] -= 4
# print(num[i], i)
i = 0
for x in range(n//2):
y = n//2
if num[i] < 2:
while num[i] < 2:
i += 1
arr[x][y] = i+1
arr[n-x-1][y] = i+1
num[i] -= 2
i = 0
for y in range(n//2):
x = n//2
if num[i] <2:
while num[i] < 2:
i += 1
arr[x][y] = i+1
arr[x][n-y-1] = i+1
num[i] -= 2
for i in range(1000):
if num[i] == 1:
arr[n//2][n//2] = i+1
for x in arr:
print(*x)
``` | instruction | 0 | 58,066 | 23 | 116,132 |
Yes | output | 1 | 58,066 | 23 | 116,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
For example, the following matrices are palindromic:
<image>
The following matrices are not palindromic because they change after the order of rows is reversed:
<image>
The following matrices are not palindromic because they change after the order of columns is reversed:
<image>
You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
Input
The first line contains one integer n (1 ≤ n ≤ 20).
The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.
Output
If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.
If it's impossible to construct any matrix, then print "NO".
You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
Examples
Input
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
Output
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
Input
3
1 1 1 1 1 3 3 3 3
Output
YES
1 3 1
3 1 3
1 3 1
Input
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
Output
NO
Input
1
10
Output
YES
10
Note
Note that there exist multiple answers for the first two examples.
Submitted Solution:
```
'''input
4
1 1 1 1 1 1 1 1 3 3 3 3 5 5 5 5
'''
import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod=10**9+7
def ri(flag=0):
if flag==0:
return [int(i) for i in sys.stdin.readline().split()]
else:
return int(sys.stdin.readline())
n=ri(1)
a=ri()
check=dd(int)
for i in a:
check[i]+=1
take=[]
two=[]
one=[]
done=0
for i in check:
if check[i]%4==0:
for j in range(check[i]//4):
take.append(i)
elif check[i]%2==0:
for j in range(check[i]//2):
two.append(i)
elif check[i]%2==1:
if check[i]>4:
keep=i
cooo=check[i]//4
if check[i]%4==3:
two.append(i)
one.append(i)
elif check[i]>2:
two.append(i)
one.append(i)
else:
one.append(i)
else:
print("NO")
done=1
try:
for i in range(cooo):
take.append(keep)
except:
pass
if n%2==0 and done==0:
if len(two)==0 and len(one)==0:
vis=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(n):
if vis[i][j]==0:
if take:
k=take.pop(0)
vis[i][j]=k
vis[n-i-1][j]=k
vis[i][n-j-1]=k
vis[n-i-1][n-j-1]=k
done=1
for i in range(n):
for j in range(n):
if vis[i][j]==0:
done=0
if done:
print("YES")
for i in vis:
print(*i)
else:
print("NO")
else:
print("NO")
if n%2==1 and done==0:
if len(one)==1:
vis=[[0 for i in range(n)] for j in range(n)]
for i in range(n//2):
for j in range(n//2):
if vis[i][j]==0 and take:
k=take.pop(0)
vis[i][j]=k
vis[n-i-1][j]=k
vis[i][n-j-1]=k
vis[n-i-1][n-j-1]=k
x=0
y=n//2
x1=n//2
y1=n//2
#print(vis)
for i in range(n//2+1):
for j in range(n//2+1):
if vis[i][j]==0 and take:
#print(i,j,n-i-1,n-j-1)
k=take.pop(0)
vis[i][j]=k
vis[j][i]=k
vis[n-j-1][n-i-1]=k
vis[n-i-1][n-j-1]=k
for i in range(n//2):
x=n//2
if vis[i][x]==0:
if two:
k=two.pop(0)
vis[i][x]=k
vis[n-i-1][x]=k
for i in range(n//2):
x=n//2
if vis[x][i]==0:
if two:
k=two.pop(0)
vis[x][i]=k
vis[x][n-i-1]=k
vis[n//2][n//2]=one[0]
done=1
for i in range(n):
for j in range(n):
if vis[i][j]==0:
done=0
if done:
print("YES")
for i in vis:
print(*i)
else:
print("NO")
else:
print("NO")
``` | instruction | 0 | 58,069 | 23 | 116,138 |
No | output | 1 | 58,069 | 23 | 116,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
For example, the following matrices are palindromic:
<image>
The following matrices are not palindromic because they change after the order of rows is reversed:
<image>
The following matrices are not palindromic because they change after the order of columns is reversed:
<image>
You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
Input
The first line contains one integer n (1 ≤ n ≤ 20).
The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.
Output
If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.
If it's impossible to construct any matrix, then print "NO".
You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
Examples
Input
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
Output
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
Input
3
1 1 1 1 1 3 3 3 3
Output
YES
1 3 1
3 1 3
1 3 1
Input
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
Output
NO
Input
1
10
Output
YES
10
Note
Note that there exist multiple answers for the first two examples.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
d={}
for i in a:
d[i]=d.get(i,0)+1
ans=[[0]*n for i in range(n)]
st=[]
for i in d.keys():
st.append(i)
for i in range(n//2):
for j in range(n//2):
try:
while len(st)>0 and d[st[-1]]==0:
st.pop()
while len(st)>0 and d[st[-1]]<4:
st.pop()
if ans[i][j]==0:
ans[i][j]=st[-1]
d[st[-1]]-=1
if ans[n-i-1][j]==0:
ans[n-i-1][j]=st[-1]
d[st[-1]]-=1
if ans[i][n-j-1]==0:
ans[i][n-j-1]=st[-1]
d[st[-1]]-=1
if ans[n-i-1][n-j-1]==0:
ans[n-i-1][n-j-1]=st[-1]
d[st[-1]]-=1
except:
exit(print('NO',4))
st=list(d.keys())
#print(ans,d)
for i in range(n//2):
try:
while len(st)>0 and d[st[-1]]==0:
st.pop()
while len(st)>0 and d[st[-1]]<2:
st.pop()
if n%2:
ans[i][n//2]=st[-1]
ans[n-1-i][n//2]=st[-1]
d[st[-1]]-=2
except:
exit(print('NO',3))
r=list(d.keys())
#print(d)
for i in range(n//2):
try:
while len(r)>0 and d[r[-1]]==0:
r.pop()
while len(r)>0 and d[r[-1]]<2:
r.pop()
if n%2:
ans[n//2][i]=r[-1]
ans[n//2][n-i-1]=r[-1]
d[r[-1]]-=2
except:
exit(print('NO',5))
for i in d.keys():
if d[i]!=0 and n%2:
ans[n//2][n//2]=i
break
#print(ans)
for i in range(n):
for j in range(n):
if ans[i][j]==0:
exit(print('NO',1))
print('YES')
for i in range(n):
print(*ans[i])
``` | instruction | 0 | 58,070 | 23 | 116,140 |
No | output | 1 | 58,070 | 23 | 116,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
For example, the following matrices are palindromic:
<image>
The following matrices are not palindromic because they change after the order of rows is reversed:
<image>
The following matrices are not palindromic because they change after the order of columns is reversed:
<image>
You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
Input
The first line contains one integer n (1 ≤ n ≤ 20).
The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.
Output
If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.
If it's impossible to construct any matrix, then print "NO".
You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
Examples
Input
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
Output
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
Input
3
1 1 1 1 1 3 3 3 3
Output
YES
1 3 1
3 1 3
1 3 1
Input
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
Output
NO
Input
1
10
Output
YES
10
Note
Note that there exist multiple answers for the first two examples.
Submitted Solution:
```
from sys import stdin, stdout
def possToplace(ans,row,col,n):
cellsToPlace = 0
if row==n-row-1 and col==n-col-1:
if ans[row][col]==-1:
return 1
return 0
if col==n-col-1:
if ans[row][col]==-1:
cellsToPlace+=1
if ans[n-row-1][col]==-1:
cellsToPlace+=1
return cellsToPlace
if row==n-row-1:
if ans[row][col]==-1:
cellsToPlace+=1
if ans[row][n-col-1]==-1:
cellsToPlace+=1
return cellsToPlace
if ans[row][col]==-1:
cellsToPlace+=1
if ans[row][n-col-1]==-1:
cellsToPlace+=1
if ans[n-row-1][col]==-1:
cellsToPlace+=1
if ans[n-row-1][n-col-1]==-1:
cellsToPlace+=1
return cellsToPlace
n = int( stdin.readline() )
a = list( map(int,stdin.readline().split()) )
ans = [[ -1 for i in range(n)] for j in range(n) ]
d = {}
for i in range(len(a)):
if a[i] not in d:
d[a[i]] = 1
else:
d[a[i]] += 1
# print(d)
col = 0
valid = True
for i in range(1+n//2):
for j in range(n):
cells = possToplace(ans,j,col,n)
for (k,v) in zip(d.keys(),d.values()):
if cells>0 and v>=cells:
# print(j,col,cells)
if cells==1:
ans[j][col] = k
d[k]-=1
elif cells==2:
if j==n-j-1:
ans[j][col] = k
ans[j][n-col-1] = k
elif col==n-col-1:
ans[j][col] = k
ans[n-j-1][col] = k
d[k]-=2
elif cells==4:
ans[j][col] = k
ans[n-j-1][col] = k
ans[j][n-col-1] = k
ans[n-j-1][n-col-1] = k
d[k] -= 4
# print(d)
break
col += 1
# print(valid)
for row in ans:
for c in row:
if c==-1:
valid = False
break
if valid:
print("YES")
for x in ans:
for c in x:
print(c,end=' ')
print()
else:
print("NO")
``` | instruction | 0 | 58,071 | 23 | 116,142 |
No | output | 1 | 58,071 | 23 | 116,143 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a plane. All points are different.
Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC.
The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are considered the same.
Input
The first line contains a single integer n (3 ≤ n ≤ 3000) — the number of points.
Next n lines contain the points. The i-th line contains coordinates of the i-th point: two space-separated integers xi, yi ( - 1000 ≤ xi, yi ≤ 1000).
It is guaranteed that all given points are different.
Output
Print the single number — the answer to the problem.
Examples
Input
3
1 1
2 2
3 3
Output
1
Input
3
0 0
-1 0
0 1
Output
0 | instruction | 0 | 58,292 | 23 | 116,584 |
Tags: binary search, brute force
Correct Solution:
```
n = int(input())
points_array = []
cords = []
for i in range(2001):
cords.append([False] * 2001)
for i in range(n):
x, y = [a for a in input().split()]
points_array.append([int(x), int(y)])
cords[int(x)+1000][int(y)+1000] = True
count = 0
for i in range(n):
for j in range(i+1, n):
x1, y1 = points_array[i]
x3, y3 = points_array[j]
x2 = int((x1 + x3)/2)
y2 = int((y1 + y3)/2)
# print(p, q, r, s)
if ((x1 + x3)%2 == 0 and (y1+y3)%2 == 0) and cords[x2+1000][y2+1000]:
count += 1
print(count)
``` | output | 1 | 58,292 | 23 | 116,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a plane. All points are different.
Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC.
The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are considered the same.
Input
The first line contains a single integer n (3 ≤ n ≤ 3000) — the number of points.
Next n lines contain the points. The i-th line contains coordinates of the i-th point: two space-separated integers xi, yi ( - 1000 ≤ xi, yi ≤ 1000).
It is guaranteed that all given points are different.
Output
Print the single number — the answer to the problem.
Examples
Input
3
1 1
2 2
3 3
Output
1
Input
3
0 0
-1 0
0 1
Output
0 | instruction | 0 | 58,293 | 23 | 116,586 |
Tags: binary search, brute force
Correct Solution:
```
from sys import maxsize, stdout, stdin,stderr
mod = int(1e9 + 7)
import sys
def I(): return int(stdin.readline())
def lint(): return [int(x) for x in stdin.readline().split()]
def S(): return input().strip()
def grid(r, c): return [lint() for i in range(r)]
from collections import defaultdict, Counter
import math
import heapq
from heapq import heappop , heappush
import bisect
from itertools import groupby
def gcd(a,b):
while b:
a %= b
tmp = a
a = b
b = tmp
return a
def lcm(a,b):
return a / gcd(a, b) * b
def check_prime(n):
for i in range(2, int(n ** (1 / 2)) + 1):
if not n % i:
return False
return True
def Bs(a, x):
i=0
j=0
left = 1
right = k
flag=False
while left<right:
mi = (left+right)//2
#print(smi,a[mi],x)
if a[mi]<=x:
left = mi+1
i+=1
else:
right = mi
j+=1
#print(left,right,"----")
#print(i-1,j)
if left>0 and a[left-1]==x:
return i-1, j
else:
return -1, -1
def nCr(n, r):
return (fact(n) // (fact(r)
* fact(n - r)))
# Returns factorial of n
def fact(n):
res = 1
for i in range(2, n+1):
res = res * i
return res
def primefactors(n):
num=0
while n % 2 == 0:
num+=1
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
num+=1
n = n // i
if n > 2:
num+=1
return num
'''
def iter_ds(src):
store=[src]
while len(store):
tmp=store.pop()
if not vis[tmp]:
vis[tmp]=True
for j in ar[tmp]:
store.append(j)
'''
def ask(a):
print('? {}'.format(a),flush=True)
n=lint()
return n
def bstemp(n,k):
l=1
r=n+1
while l<r:
mid=(l+r)//2
if (mid*(mid+1)*5)//2+k<=4*60:
l=mid+1
else:
r=mid
return l
def dfs(i,p):
a,tmp=0,0
for j in d[i]:
if j!=p:
a+=1
tmp+=dfs(j,i)
if a==0:
return 0
return tmp/a + 1
def primeFactors(n):
l=[]
while n % 2 == 0:
l.append(2)
n = n // 2
if n > 2:
l.append(n)
return l
n = I()
d=set()
s=[]
for _ in range(n):
x,y=lint()
s.append([x,y])
d.add((x,y))
ans=0
for i in range(n):
for j in range(i+1,n):
x=s[i][0]+s[j][0]
y=s[i][1]+s[j][1]
if not (x%2 or y%2):
if (x//2,y//2) in d:
ans+=1
print(ans)
``` | output | 1 | 58,293 | 23 | 116,587 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.