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
Provide a correct Python 3 solution for this coding contest problem. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO
instruction
0
86,455
23
172,910
"Correct Solution: ``` #凸包を求める def quickhull(l,r,s,k): if not s: return su = [] sd = [] a = (r[0]-l[0],r[1]-l[1]) for x,y in s: b = (x-l[0],y-l[1]) cro = cross(a,b) if cro > 0: su.append((x,y)) #上半分 elif cro < 0: sd.append((x,y)) #下半分 if su: c,d = direction(l,r,su[0]) p = su[0] for i in range(1,len(su)): c_,d_ = direction(l,r,su[i]) if c*d_ < c_*d: c,d = c_,d_ p = su[i] k.append(tuple(p)) #もっとも離れた点を凸包の頂点に追加 b = (l[0]-p[0],l[1]-p[1]) c = (p[0]-r[0],p[1]-r[1]) s1 = [] s2 = [] for x,y in su: b_ = (x-p[0],y-p[1]) c_ = (x-r[0],y-r[1]) cro_b,cro_c = cross(b,b_),cross(c,c_) if cro_b >= 0 and cro_c >= 0: #三角形内部判定 continue else: if cro_b < 0: s1.append((x,y)) elif cro_c < 0: s2.append((x,y)) quickhull(l,p,s1,k) #再帰 quickhull(p,r,s2,k) if sd: c,d = direction(l,r,sd[0]) p = sd[0] for i in range(1,len(sd)): c_,d_ = direction(l,r,sd[i]) if c*d_ < c_*d: c,d = c_,d_ p = sd[i] k.append(tuple(p)) #もっとも離れた点を凸包の頂点に追加 b = (l[0]-p[0],l[1]-p[1]) c = (p[0]-r[0],p[1]-r[1]) s1 = [] s2 = [] for x,y in sd: b_ = (x-p[0],y-p[1]) c_ = (x-r[0],y-r[1]) cro_b,cro_c = cross(b,b_),cross(c,c_) if cro_b <= 0 and cro_c <= 0: #三角形内部判定(ベクトルの向きにより上下で判定が異なることに注意) continue else: if cro_b > 0: s1.append((x,y)) elif cro_c > 0: s2.append((x,y)) quickhull(l,p,s1,k) #再帰 quickhull(p,r,s2,k) return k def cross(a,b): #外積 return a[0]*b[1]-a[1]*b[0] def direction(l,r,p): #点と直線の距離 a = r[1]-l[1] b = l[0]-r[0] return (a*(p[0]-l[0])+b*(p[1]-l[1]))**2, a**2+b**2 #分子の2乗,分母の2乗 while 1: try: t = [float(x) for x in input().split(",")] s = [] for i in range(len(t)//2): s.append((t[2*i],t[2*i+1])) s.sort() l = tuple(s.pop(0)) r = tuple(s.pop(-1)) k = quickhull(l,r,s,[l,r]) if len(k) < 4: print("NO") else: print("YES") except: quit() ```
output
1
86,455
23
172,911
Provide a correct Python 3 solution for this coding contest problem. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO
instruction
0
86,456
23
172,912
"Correct Solution: ``` from decimal import Decimal import sys for l in sys.stdin: xa,ya,xb,yb,xc,yc,xd,yd=list(map(Decimal,l.split(","))) a=xd-xb b=yd-yb c=xa-xb d=ya-yb e=xc-xb f=yc-yb try: s=(a*f-b*e)/(c*f-d*e) t=(-a*d+b*c)/(c*f-d*e) except: print("NO") if s>=0 and t>=0 and s+t>=1: print("YES") else: print("NO") ```
output
1
86,456
23
172,913
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` def cross(x, y): return (x.conjugate() * y).imag def is_convex(points): n = len(points) x = points[1] - points[0] y = points[2] - points[1] c0 = cross(x, y) for i in range(1, n): x = y y = points[(i+2)%n] - points[(i+1)%n] if c0 * cross(x, y) < 0: return False return True import sys for line in sys.stdin: li = list(map(float, line.split(','))) p = [] for i in range(0, len(li), 2): p.append(complex(li[i], li[i+1])) if is_convex(p): print('YES') else: print('NO') ```
instruction
0
86,457
23
172,914
Yes
output
1
86,457
23
172,915
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` import sys f = sys.stdin def take2(iterable): i = iter(iterable) while True: yield next(i), next(i) def cross(a, b): return a.real * b.imag - a.imag * b.real # 砂時計型の場合は考慮しない def is_convex(a, b, c, d): v1 = cross(a - b, b - c) v2 = cross(b - c, c - d) v3 = cross(c - d, d - a) v4 = cross(d - a, a - b) return 0 < v1 * v2 and 0 < v2 * v3 and 0 < v3 * v4 for line in f: a, b, c, d = [x + y *1j for x, y in take2(map(float, line.split(',')))] print('YES' if is_convex(a,b,c,d) else 'NO') ```
instruction
0
86,458
23
172,916
Yes
output
1
86,458
23
172,917
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` # AOJ 00035: Is it Convex? # Python3 2018.6.17 bal4u EPS = 0.0001 # a, b, はラインの同一側にあるか。 -1, 0, 1 def atSameSide(a, b, line): sa = (line[1].real-line[0].real)*(a.imag-line[0].imag) \ + (line[1].imag-line[0].imag)*(line[0].real-a.real); sb = (line[1].real-line[0].real)*(b.imag-line[0].imag) \ + (line[1].imag-line[0].imag)*(line[0].real-b.real); if -EPS <= sa and sa <= EPS: return 0 # a in line if -EPS <= sb and sb <= EPS: return 0 # b in line if sa*sb >= 0: return 1 # a,b at same side return -1; while True: try: p = list(map(float, input().split(','))) except: break p1 = complex(p[0], p[1]) p2 = complex(p[2], p[3]) p3 = complex(p[4], p[5]) p4 = complex(p[6], p[7]) if atSameSide(p2, p4, [p1, p3]) == -1 and \ atSameSide(p1, p3, [p2, p4]) == -1: print('YES') else: print('NO') ```
instruction
0
86,459
23
172,918
Yes
output
1
86,459
23
172,919
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` while True: try: data = list(map(float,input().split(","))) except EOFError: break vec1 = [data[2]-data[0],data[3]-data[1]] vec2 = [data[4]-data[0],data[5]-data[1]] vec3 = [data[6]-data[0],data[7]-data[1]] a = (vec2[0]*vec3[1] - vec2[1]*vec3[0]) / (vec1[0]*vec3[1] - vec1[1]*vec3[0]) b = (vec2[0]*vec1[1] - vec2[1]*vec1[0]) / (vec1[1]*vec3[0] - vec1[0]*vec3[1]) if (a < 0 or b < 0) or a+b < 1.0: print("NO") else: print("YES") ```
instruction
0
86,460
23
172,920
Yes
output
1
86,460
23
172,921
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` import fileinput for line in fileinput.input(): xa, ya, xb, yb, xc, yc, xd, yd = map(float, line.split(',')) x = ((yb * xd - yd * xb) * (xc - xa) - (ya * xc - yc * xa) * (xd - xb)) \ / ((yc - ya) * (xd - xb) - (yd - yb) * (xc - xa)) print('NO' if (x - xa) * (x - xc) > 0 or (x - xb) * (x - xd) > 0 else 'YES') ```
instruction
0
86,461
23
172,922
No
output
1
86,461
23
172,923
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` import sys for e in sys.stdin: e=list(map(float,e.split(',')));f=1 for i in range(0,8,2): s=(e[i]-e[(2+i)%8])*(e[(4+i)%8]-e[(2+i)%8])+(e[1+i]-e[(3+i)%8])*(e[(5+i)%8]-e[(3+i)%8]) if s:f*=s print(['YES','NO'][f<0]) ```
instruction
0
86,462
23
172,924
No
output
1
86,462
23
172,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` import math def get_data(): xa,ya,xb,yb,xc,yc,xd,yd = map(float,input().split(',')) return xa,ya,xb,yb,xc,yc,xd,yd def dist(x1,y1,x2,y2): d = ((x2-x1)**2 + (y2-y1)**2)**0.5 return d def lin(x1,y1,x2,y2): if x1 == x2: m = 10000000000 ac = dist(xa,ya,xc,yc) bd = dist(xb,yb,xd,yd) m1,n1 = lin(xb,yb,xd,yd) d1 = p_l(xa,ya,m1,n1) if ac < d1: print('NO') return 0 m2,n2 = lin(xb,yb,xd,yd) d2 = p_l(xc,yc,m2,n2) if ac < d2: print('NO') return 0 m3,n3 = lin(xa,ya,xc,yc) d3 = p_l(xb,yb,m3,n3) if bd < d3: print('NO') return 0 m4,n4 = lin(xa,ya,xc,yc) d4 = p_l(xd,yd,m4,n4) if bd < d4: print('NO') return 0 print('YES') return 0 while True: try: xa,ya,xb,yb,xc,yc,xd,yd = get_data() convex(xa,ya,xb,yb,xc,yc,xd,yd) except EOFError: break ```
instruction
0
86,463
23
172,926
No
output
1
86,463
23
172,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent. A quadrangle with a dent is a quadrangle as shown in Figure 1. <image> Input Given multiple datasets. The format of each dataset is as follows. $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ $ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers. 1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.) The number of datasets does not exceed 100. Output Print YES or NO on one line for each dataset. Example Input 0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0 0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0 Output YES NO Submitted Solution: ``` class Vector2: """ A simple 2D vector class. @Author:whitestone0811(Vir_MeL0) """ def __init__(self,x,y): self.x=x self.y=y def __add__(self,other): return Vector2(self.x+other.x,self.y+other.y) def __sub__(self,other): return Vector2(self.x-other.x,self.y-other.y) def __mul__(self,other): if isinstance(other, Vector2): return self.x*other.x+self.y*other.y else: return Vector2(self.x*other,self.y*other) def __rmul__(self,other): if not isinstance(other,Vector2): return Vector2(self.x*other,self.y*other) def abs(self): return (self.x**2+self.y**2)**0.5 def cos(self,other): return (self*other)/(self.abs()*other.abs()) def __str__(self): return "[{0},{1}]".format(self.x,self.y) def __neg__(self): return Vector2(-self.x,-self.y) # _in=input() while _in!='': cors=[float(cor)for cor in _in.split(',')] vAB=Vector2(cors[2]-cors[0],cors[3]-cors[1]) vBC=Vector2(cors[4]-cors[2],cors[5]-cors[3]) vCD=Vector2(cors[6]-cors[4],cors[7]-cors[5]) vDA=Vector2(cors[0]-cors[6],cors[1]-cors[7]) cnv_a=True if(vAB-vDA)*(vAB+vBC)>0 else False cnv_b=True if(vBC-vAB)*(vBC+vCD)>0 else False cnv_c=True if(vCD-vBC)*(vCD+vDA)>0 else False cnv_d=True if(vDA-vCD)*(vDA+vAB)>0 else False print("YES" if cnv_a and cnv_b and cnv_c and cnv_d else "NO") _in=input() ```
instruction
0
86,464
23
172,928
No
output
1
86,464
23
172,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` I = lambda: map(int, input().split()) n, q = I() A = [] for _ in range(q): x, y = I() A.append((n*(x-1)+y+1 + (n*n if (x+y)%2 else 0)) // 2) print(*A, sep='\n') ```
instruction
0
86,601
23
173,202
Yes
output
1
86,601
23
173,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` def R(): return map(int, input().split()) ans = [] n, q = R() d = (n*n+1)//2 for _ in range(q): x, y = R() i = ((x-1)*n+y-1)//2+1 if x % 2 != y % 2: i += d ans.append(str(i)) print("\n".join(ans)) ```
instruction
0
86,602
23
173,204
Yes
output
1
86,602
23
173,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` from functools import cmp_to_key from math import * import sys def main(): n,q = [int(i) for i in sys.stdin.readline().split(' ')] for i in range(q): x, y = [int(i) for i in sys.stdin.readline().split(' ')] tot = n*(x-1) + y tot = (tot+1)//2 if (x + y) % 2 == 1: tot += (n * n + 1) // 2 #ceiling division taken from Vovuh's answer print(tot) if __name__ == "__main__": main() ```
instruction
0
86,603
23
173,206
Yes
output
1
86,603
23
173,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` n,q=map(int,input().split()) a=[] for i in range(q): x,y=map(int,input().split()) k=(x-1)*n+y ans=(k+1)//2 if (x+y)%2!=0: ans+=(n**2+1)//2 a.append(ans) print(*a) ```
instruction
0
86,604
23
173,208
Yes
output
1
86,604
23
173,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Aug 22 10:31:45 2018 @author: saurabh panjiara """ import sys lst =sys.stdin.readlines() n,q=map(int, lst[0].split() ) for i in range(q): x , y=map(int,lst[i+1].split()) z=(x-1)*n z=z+y z=int((z+1)/2) if (x+y)%2 != 0: z=z+int((n*n+1)/2) sys.stdout.write(str(z) + '\n') ```
instruction
0
86,605
23
173,210
No
output
1
86,605
23
173,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` import math def get_odd(x, y, n): m = math.ceil(n * n / 2) temp = x % 2 if n % 2 == 0: return m + x * n / 2 + temp * (math.floor(y / 2) + 1) + (1 - temp) * ( math.floor(y + 1 / 2)) else: return m + math.floor(x / 2) * n + temp * math.floor(n / 2) + temp * (math.floor(y / 2) + 1) + (1 - temp) * ( math.floor(y + 1 / 2)) def get_even(x, y, n): temp = x % 2 if n % 2 == 0: return x * n / 2 + temp * (math.floor((y + 1) / 2)) + (1 - temp) * ( math.floor(y / 2) + 1) else: return math.floor(x / 2) * n + temp * math.ceil(n / 2) + temp * (math.floor((y + 1) / 2)) + (1 - temp) * ( math.floor(y / 2) + 1) def get_entry(x, y, n): if (x + y) % 2 == 0: # print('even') return get_even(x, y, n) else: # print('odd') return get_odd(x, y, n) inp = input() inp = inp.split() n = int(inp[0]) q = int(inp[1]) # print(' n ', n) # print(' q ', q) for i in range(0, q): inp = input() inp = inp.split() x = int(inp[0]) y = int(inp[1]) print(int(get_entry(x - 1, y - 1, n))) ```
instruction
0
86,606
23
173,212
No
output
1
86,606
23
173,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` import math def query(n, a, b): if (a+b)%2 == 0: temp = (a-1)*n + b if temp%2 == 0: return temp/2 else: return math.ceil(temp/2) else: temp = n**2 + n*(a-1) + b if temp%2 ==0: return temp/2 else: return math.ceil(temp/2) n, q = map(int, input().split()) ans = [] for i in range(q): a, b = map(int, input().split()) ans.append(query(n, a, b)) for a in ans: print(a) ```
instruction
0
86,607
23
173,214
No
output
1
86,607
23
173,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈x/y⌉ means division x by y rounded up. For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5. <image> You are given q queries. The i-th query is described as a pair x_i, y_i. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Input The first line contains two integers n and q (1 ≤ n ≤ 10^9, 1 ≤ q ≤ 10^5) — the size of the board and the number of queries. The next q lines contain two integers each. The i-th line contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n) — description of the i-th query. Output For each query from 1 to q print the answer to this query. The answer to the i-th query is the number written in the cell x_i, y_i (x_i is the row, y_i is the column). Rows and columns are numbered from 1 to n. Queries are numbered from 1 to q in order of the input. Examples Input 4 5 1 1 4 4 4 3 3 2 2 4 Output 1 8 16 13 4 Input 5 4 2 1 4 2 3 3 3 4 Output 16 9 7 20 Note Answers to the queries from examples are on the board in the picture from the problem statement. Submitted Solution: ``` from math import ceil def get_num(n, x, y, up_base): sum_odd = bool((x + y) % 2) n_odd = bool(n % 2) base = up_base if sum_odd else 1 prev_rows = (y - 1) // 2 * n if not y % 2: prev_rows += n // 2 if n_odd and (bool((y - 1) % 2) != sum_odd): prev_rows += 1 if bool(y % 2) == sum_odd: prev_cells = x // 2 - 1 else: prev_cells = x // 2 return base + prev_rows + prev_cells n, q = (int(num) for num in input().split()) up_base = ceil(n ** 2 / 2) + 1 responses = [] for _ in range(q): y, x = (int(num) for num in input().split()) responses.append(get_num(n, x, y, up_base)) for resp in responses: print(resp) ```
instruction
0
86,608
23
173,216
No
output
1
86,608
23
173,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools # import time,random,resource # sys.setrecursionlimit(10**6) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def IF(c, t, f): return t if c else f def YES(c): return IF(c, "YES", "NO") def Yes(c): return IF(c, "Yes", "No") def main(): t = 1#I() rr = [] for _ in range(t): n,m,k = LI() a = LI() if n == 1: rr.append(1) continue t = [] for i in range(1,n): t.append(a[i]-a[i-1] - 1) t.sort(reverse=True) r = a[-1] - a[0] + 1 - sum(t[:k-1]) rr.append(r) return JA(rr, "\n") print(main()) ```
instruction
0
86,641
23
173,282
Yes
output
1
86,641
23
173,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` n, m, k = map(int, input().split()) b = list(map(int, input().split())) d = [b[i + 1] - b[i] - 1 for i in range(n - 1)] d.sort() print(sum(d[:n - k]) + n) ```
instruction
0
86,642
23
173,284
Yes
output
1
86,642
23
173,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` from math import * n,l,k=map(int,input().split(" ")) a=list(map(int,input().split(" "))) diff=[] for i in range(1,n): diff.append(a[i]-a[i-1]) diff=sorted(diff) i=len(diff)-1 s=1 while(i>=0 and s<k): s+=1 i-=1 print(sum(diff[:i+1])+k) ```
instruction
0
86,643
23
173,286
Yes
output
1
86,643
23
173,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` n,m,k=map(int,input().split()) B=list(map(int,input().split())) if(k>=n): print(k) else: C=[] for i in range(len(B)-1): C.append(B[i+1]-B[i]) C=sorted(C) C=C[::-1] C=C[k-1:] X=k+sum(C) print(X) ```
instruction
0
86,644
23
173,288
Yes
output
1
86,644
23
173,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` from sys import stdin,stdout from itertools import combinations from collections import defaultdict def listIn(): return list((map(int,stdin.readline().strip().split()))) def stringListIn(): return([x for x in stdin.readline().split()]) def intIn(): return (int(stdin.readline())) def stringIn(): return (stdin.readline().strip()) if __name__=="__main__": n,m,k=listIn() b=listIn() if n==k: print(n) else: diff=[] for i in range(1,n): diff.append(b[i]-b[i-1]) a=sorted(diff) c=0 ans=sum(a[:-(k-1)]) print(ans+k) ```
instruction
0
86,645
23
173,290
No
output
1
86,645
23
173,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` n,m,k=map(int,input().split()) b=list(map(int,input().split())) c=[0]*n f=1 ans=0 y=0 for i in range(n): if(i%2==0): f+=1 c[i]=f for i in range(1,n-1): if(b[i+1]-b[i]>b[i]-b[i-1]): c[i] = c[i-1] for i in range(n-1): if(c[i]!=c[i+1]): ans+=b[i]-b[y]+1 y=i+1 print(ans+b[n-1]-b[y]+1) ```
instruction
0
86,646
23
173,292
No
output
1
86,646
23
173,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` n, m, k = map(int, input().split()) B = [int(a) for a in input().split()] A = [B[i+1]-B[i] for i in range(n-1)] A = sorted(A) print(min(sum(A[:n-k])+k,n)) ```
instruction
0
86,647
23
173,294
No
output
1
86,647
23
173,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length t placed at some position s will cover segments s, s+1, …, s+t-1. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most k continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers n, m and k (1 ≤ n ≤ 10^5, n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ m) — the positions of the broken segments. These integers are given in increasing order, that is, b_1 < b_2 < … < b_n. Output Print the minimum total length of the pieces. Examples Input 4 100 2 20 30 75 80 Output 17 Input 5 100 3 1 2 4 60 87 Output 6 Note In the first example, you can use a piece of length 11 to cover the broken segments 20 and 30, and another piece of length 6 to cover 75 and 80, for a total length of 17. In the second example, you can use a piece of length 4 to cover broken segments 1, 2 and 4, and two pieces of length 1 to cover broken segments 60 and 87. Submitted Solution: ``` #Greedy def Funcion(arreglo,n,m,k): suma = 0 separaciones = [] if n == k: return n if n == 2: return arreglo[1]-arreglo[0] for i in range(len(arreglo)-1): separaciones.append((arreglo[i+1]-arreglo[i])) separaciones_s = sorted(separaciones) i = 0 ya_k = 0 while i < k: if ya_k != 0 and i != 0: if k - ya_k == len(separaciones) - i: return suma + (k-ya_k) if separaciones.index(separaciones_s[i+1]) == separaciones.index(separaciones_s[i])-1 or separaciones.index(separaciones_s[i+1]) == separaciones.index(separaciones_s[i]) + 1: suma = suma + separaciones_s[i] else: suma = suma + separaciones_s[i] + 1 ya_k = ya_k + 1 i = i + 1 return suma ```
instruction
0
86,648
23
173,296
No
output
1
86,648
23
173,297
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,737
23
173,474
Tags: geometry Correct Solution: ``` n = int(input()) pts = set([tuple(map(int, input().split())) for i in range(n)]) centre = (sum([a for a,b in pts])/n, sum([b for a,b in pts])/n) ok = True for x,y in pts: if (int(x+(centre[0]-x)*2), int(y+(centre[1]-y)*2)) not in pts: ok = False break if ok: print("YES") else: print("NO") ```
output
1
86,737
23
173,475
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,738
23
173,476
Tags: geometry Correct Solution: ``` from sys import stdin, stdout def deg(p1, p2): if p1[0] == p2[0]: return 1e20 return (p1[1] - p2[1]) / (p1[0] - p2[0]) def dist2(p1, p2): return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) n = int(input()) a = [] for i in range(n): x, y = map(int, stdin.readline().split()) a.append((x, y)) if n % 2 == 1: print('no') exit() for i in range(n // 2): j = n-1 if i == 0 else i-1 ii = i + n // 2 jj = n-1 if ii == 0 else ii-1 if (deg(a[i], a[j]) != deg(a[ii], a[jj])) or (dist2(a[i], a[j]) != dist2(a[ii], a[jj])): print('no') exit() print('YES') ```
output
1
86,738
23
173,477
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,739
23
173,478
Tags: geometry Correct Solution: ``` """ Author: guiferviz Time: 2020-02-09 15:05:02 """ def normalize_pol(P): x_min, y_min, x_max, y_max = P[0][0], P[0][1], P[0][0], P[0][1] for x, y in P: x_min = min(x_min, x) x_max = max(x_max, x) y_min = min(y_min, y) y_max = max(y_max, y) P_norm = [] for x, y in P: p = ((x - x_min) / (x_max - x_min), (y - y_min) / (y_max - y_min)) P_norm.append(p) return P_norm def solve_tle(): n = int(input()) P = [] for i in range(n): x, y = map(int, input().split()) P.append((x,y)) pol = {} for x, y in P: for x2, y2 in P: tp = (x2-x, y2-y) count = pol.get(tp, 0) pol[tp] = count + 1 T = [] for (x, y), count in pol.items(): if count == 1: T.append((x,y)) # Test if P and T are similar. P = sorted(normalize_pol(P)) T = sorted(normalize_pol(T)) same = True for (xp, yp), (xt, yt) in zip(P, T): if xp != xt or yp != yt: same = False break if same: print("YES") else: print("NO") def solve(): n = int(input()) P = [] for i in range(n): x, y = map(int, input().split()) P.append((x,y)) if n % 2 != 0: print("NO") return h = n // 2 # half p = (P[0][0] + P[h][0], P[0][1] + P[h][1]) for i in range(1, h): pi = (P[i][0] + P[i + h][0], P[i][1] + P[i + h][1]) if p != pi: print("NO") return print("YES") def main(): solve() if __name__ == "__main__": main() ```
output
1
86,739
23
173,479
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,740
23
173,480
Tags: geometry Correct Solution: ``` import os,io import sys input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) shape=[] for _ in range(n): x,y=map(int,input().split()) shape.append([x,y]) if n%2==1: print('NO') sys.exit() for i in range(n): if shape[i][0]-shape[i-1][0]!=shape[(n//2+i-1)%n][0]-shape[(n//2+i)%n][0]: print('NO') sys.exit() if shape[i][1]-shape[i-1][1]!=shape[(n//2+i-1)%n][1]-shape[(n//2+i)%n][1]: print('NO') sys.exit() print('YES') ```
output
1
86,740
23
173,481
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,741
23
173,482
Tags: geometry Correct Solution: ``` n = int(input()) p = [] for i in range(n): p.append(list(map(int,input().split()))) if n%2==1: print("NO") else: ok = True for i in range(n//2): if p[0][0]+p[n//2][0]!=p[i][0]+p[i+n//2][0] or p[0][1]+p[n//2][1]!=p[i][1]+p[i+n//2][1]: ok = False print("NO") break if ok: print("YES") ```
output
1
86,741
23
173,483
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,742
23
173,484
Tags: geometry Correct Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() n = int(input()) xy = [] for _ in range(n): x, y = map(int, input().split()) xy.append((x, y)) if n%2: print('NO') exit(0) for i in range(n//2): xy0 = xy[i] xy1 = xy[i+1] xy2 = xy[n//2+i] xy3 = xy[(n//2+i+1)%n] if xy3[0]-xy2[0]!=xy0[0]-xy1[0]: print('NO') exit(0) if xy3[1]-xy2[1]!=xy0[1]-xy1[1]: print('NO') exit(0) print('YES') ```
output
1
86,742
23
173,485
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,743
23
173,486
Tags: geometry Correct Solution: ``` import sys def main(): n = int(sys.stdin.readline().split()[0]) a = [list(map(int, sys.stdin.readline().split())) for _ in range(n)] if n&1 == 1: print("NO") return m = n//2 for i in range(-1, m-1): if a[i+1][0]-a[i][0] != -a[i+1+m][0]+a[i+m][0] or a[i+1][1]-a[i][1] != -a[i+1+m][1]+a[i+m][1]: print("NO") return print("YES") return main() ```
output
1
86,743
23
173,487
Provide tags and a correct Python 3 solution for this coding contest problem. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image>
instruction
0
86,744
23
173,488
Tags: geometry Correct Solution: ``` n = int(input()) P = [list(map(int, input().split())) for i in range(n)] if n % 2 == 1: print('NO') else: dx, dy = P[0][0]-P[1][0], P[0][1]-P[1][1] for i in range(2, n): dx2, dy2 = P[i][0]-P[(i+1)%n][0], P[i][1]-P[(i+1)%n][1] if dx2 == -dx and dy2 == -dy: break r = 'YES' for j in range(n//2): dx, dy = P[j][0]-P[j+1][0], P[j][1]-P[j+1][1] dx2, dy2 = P[(i+j)%n][0]-P[(i+j+1)%n][0], P[(i+j)%n][1]-P[(i+j+1)%n][1] if dx != -dx2 or dy != -dy2: r = 'NO' break print(r) ```
output
1
86,744
23
173,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` import sys input = sys.stdin.readline N, = map(int, input().split()) if N%2: print("NO") else: E = [] bx, by = None, None for _ in range(N): x, y = map(int, input().split()) if bx != None: E.append(((x-bx), (y-by))) else: fx, fy = x, y bx, by = x, y E.append(((fx-bx), (fy-by))) for i in range(N//2): x, y = E[i] z, w = E[N//2+i] if not (x == -z and y == -w): print("No") break else: print("Yes") ```
instruction
0
86,745
23
173,490
Yes
output
1
86,745
23
173,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` import sys input = sys.stdin.readline n = int(input()) info = [list(map(int, input().split())) for i in range(n)] ox = 0 oy = 0 set_ = set() for i in range(n): x, y = info[i] set_.add((x, y)) ox += x oy += y ox = ox / n oy = oy / n for p in set_: x, y = p tmp1 = x - ox tmp2 = y - oy tmpx, tmpy = x - 2*tmp1, y - 2*tmp2 if (tmpx, tmpy) not in set_: print("NO") exit() print("YES") ```
instruction
0
86,746
23
173,492
Yes
output
1
86,746
23
173,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` from bisect import * from math import * n = int(input()) arr = [] for i in range(n): x, y = input().split() x = int(x)-1 y = int(y)-1 arr.append((x, y)) if n%2==1: print("NO") else: flag = True for i in range(0, n//2): if (arr[(i+1)%n][0]-arr[i%n][0], arr[(i+1)%n][1]-arr[i%n][1]) != (arr[(i+n//2)%n][0]-arr[(i+1+n//2)%n][0], arr[(i+n//2)%n][1]-arr[(i+1+n//2)%n][1]): flag = False break if flag == True: print("YES") else: print("NO") ```
instruction
0
86,747
23
173,494
Yes
output
1
86,747
23
173,495
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` from sys import stdin from os import getenv # if getenv('ONLINE_JUDGE'): def input(): return next(stdin)[:-1] def main(): n = int(input()) pp = [] for _ in range(n): pp.append(list(map(int, input().split()))) if n%2 != 0: print("NO") return for i in range(n//2): x1 = pp[i+1][0] - pp[i][0] y1 = pp[i+1][1] - pp[i][1] x2 = pp[(i+1+n//2) % n][0] - pp[i+n//2][0] y2 = pp[(i+1+n//2) % n][1] - pp[i+n//2][1] if x1 != -x2 or y1 != -y2: print("NO") return print("YES") if __name__ == "__main__": main() ```
instruction
0
86,748
23
173,496
Yes
output
1
86,748
23
173,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` from sys import stdin from collections import deque mod = 10**9 + 7 import sys # sys.setrecursionlimit(10**6) from queue import PriorityQueue # def rl(): # return [int(w) for w in stdin.readline().split()] from bisect import bisect_right from bisect import bisect_left from collections import defaultdict from math import sqrt,factorial,gcd,log2,inf,ceil # map(int,input().split()) # # l = list(map(int,input().split())) # from itertools import permutations import heapq # input = lambda: sys.stdin.readline().rstrip() input = lambda : sys.stdin.readline().rstrip() from sys import stdin, stdout from heapq import heapify, heappush, heappop from itertools import permutations n = int(input()) ba = [] if n%4!=0: print('NO') exit() for i in range(n): a,b = map(int,input().split()) ba.append([a,b]) slope = [] for i in range(1,n+1): a,b = ba[i%n] c,d = ba[(i-1)%n] try: slope.append((d-b)/(c-a)) except: slope.append(10**18) flag = 0 for i in range(len(slope)): if slope[i] == slope[(i+n//2)%n]: continue else: flag = 1 break if flag == 1: print('NO') else: print('YES') ```
instruction
0
86,749
23
173,498
No
output
1
86,749
23
173,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` from sys import stdin from collections import deque mod = 10**9 + 7 import sys # sys.setrecursionlimit(10**6) from queue import PriorityQueue # def rl(): # return [int(w) for w in stdin.readline().split()] from bisect import bisect_right from bisect import bisect_left from collections import defaultdict from math import sqrt,factorial,gcd,log2,inf,ceil # map(int,input().split()) # # l = list(map(int,input().split())) # from itertools import permutations import heapq # input = lambda: sys.stdin.readline().rstrip() input = lambda : sys.stdin.readline().rstrip() from sys import stdin, stdout from heapq import heapify, heappush, heappop from itertools import permutations n = int(input()) ba = [] # if n%4!=0: # print('NO') # exit() for i in range(n): a,b = map(int,input().split()) ba.append([a,b]) slope = [] for i in range(1,n+1): a,b = ba[i%n] c,d = ba[(i-1)%n] try: slope.append((d-b)/(c-a)) except: slope.append(10**18) flag = 0 for i in range(len(slope)): if slope[i] == slope[(i+n//2)%n]: continue else: flag = 1 break if flag == 1: print('NO') else: print('YES') ```
instruction
0
86,750
23
173,500
No
output
1
86,750
23
173,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` n=int(input()) for i in range(n): x,y=map(int,input().split()) if n%2==0: print("YES") else: print("NO") ```
instruction
0
86,751
23
173,502
No
output
1
86,751
23
173,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation: <image> Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored: <image> The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl). Input The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points. The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon. Output Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). Examples Input 4 1 0 4 1 3 4 0 3 Output YES Input 3 100 86 50 0 150 0 Output nO Input 8 0 0 1 0 2 1 3 3 4 6 3 6 2 5 1 3 Output YES Note The following image shows the first sample: both P and T are squares. The second sample was shown in the statements. <image> Submitted Solution: ``` from __future__ import division class Point: def __init__(self, x, y): self.x = x self.y = y def Left_index(points): ''' Finding the left most point ''' minn = 0 for i in range(1,len(points)): if points[i].x < points[minn].x: minn = i elif points[i].x == points[minn].x: if points[i].y > points[minn].y: minn = i return minn def orientation(p, q, r): ''' To find orientation of ordered triplet (p, q, r). The function returns following values 0 --> p, q and r are colinear 1 --> Clockwise 2 --> Counterclockwise ''' val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y) if val == 0: return 0 elif val > 0: return 1 else: return 2 def convexHull(points, n): # There must be at least 3 points if n < 3: return # Find the leftmost point l = Left_index(points) hull = [] ''' Start from leftmost point, keep moving counterclockwise until reach the start point again. This loop runs O(h) times where h is number of points in result or output. ''' p = l q = 0 while(True): if len(hull) >= 2: fp = points[hull[-2]] sp = points[hull[-1]] v_1 = sp.x - fp.x v_2 = sp.y - fp.y zp = points[p] w_1 = zp.x - sp.x w_2 = zp.y - sp.y if w_2*v_1 == v_2*w_1: hull.remove(hull[-1]) hull.append(p) else: hull.append(p) else: hull.append(p) # Add current point to result ''' Search for a point 'q' such that orientation(p, x, q) is counterclockwise for all points 'x'. The idea is to keep track of last visited most counterclock- wise point in q. If any point 'i' is more counterclock- wise than q, then update q. ''' q = (p + 1) % n for i in range(n): # If i is more counterclockwise # than current q, then update q if(orientation(points[p], points[i], points[q]) == 2): q = i ''' Now q is the most counterclockwise with respect to p Set p as q for next iteration, so that q is added to result 'hull' ''' p = q # While we don't come to first point if(p == l): # check to see if the second to last point and the # first point are collinear fp = points[hull[-2]] sp = points[l] zp = points[hull[-1]] v_1, v_2 = (fp.x - zp.x, fp.y - zp.y) w_1, w_2 = (zp.x - sp.x, zp.y - sp.y) if w_1*v_2 == w_2*v_1: hull.remove(hull[-1]) break # Print Result ''' for each in hull: print(points[each].x, points[each].y) ''' # Instead of printing we return the list out_list = [] for each in hull: out_list.append((points[each].x, points[each].y)) return out_list # number of points N = int(input()) # points in clockwise orientation pnts = [] for points in range(N): x, y = [int(x) for x in input().split()] pnts.append((x, y)) def translate(pnts, v): v_1, v_2 = v t_pnts = [] for points in range(len(pnts)): x, y = pnts[points] t_pnts.append((x + v_1, y + v_2)) return t_pnts def translate_p(pnt, v): x, y = pnt v_1, v_2 = v return (x + v_1, y + v_2) first_v = pnts[0] v_1, v_2 = first_v first_v = -v_1, -v_2 # move the polygon so that a single vertex is on the origin pnts = translate(pnts, first_v) # translate the polygon sides along the origin c_pnts = pnts T_pnts = [c_pnts] for pos in range(N): if pos < N - 1: fp = c_pnts[pos] sp = c_pnts[pos + 1] fp_x, fp_y = fp[0], fp[1] sp_x, sp_y = sp[0], sp[1] v = (fp_x - sp_x, fp_y - sp_y) c_pnts = translate(c_pnts, v) T_pnts.append(c_pnts) else: fp = c_pnts[pos] sp = c_pnts[0] fp_x, fp_y = fp[0], fp[1] sp_x, sp_y = sp[0], sp[1] v = (fp_x - sp_x, fp_y - sp_y) c_pnts = translate(c_pnts, v) T_pnts.append(c_pnts) T_pnts = sum(T_pnts, []) # traced out figure is new polygon # Can use Jarvis' Algorithm to find the convex hull of T_pnts for pos in range(len(T_pnts)): x, y = T_pnts[pos] T_pnts[pos] = Point(x, y) T_pnts = convexHull(T_pnts, len(T_pnts)) if len(T_pnts) == len(pnts): print ('YES') else: print ('NO') ```
instruction
0
86,752
23
173,504
No
output
1
86,752
23
173,505
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,067
23
174,134
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` __author__ = 'User' def f(arr, value, deep, vis): global flag if flag == True: return fl = False #print("Num") pos = (0, 0) for i in range(n): for j in range(n): #print(i, j, arr[i][j], end = " ") if arr[i][j] == 0: pos = (i, j) fl = True break if fl == True: break #print() #print(n, "N") #print(arr, "AAAAAA") #print(pos, vis) symbol = value[2] for y, x in value[:-1]: #print(y, x, "YX" + symbol) tarr = arr[:] y0, x0 = pos[0], pos[1] if y0 < n and x0 < n and arr[y0][x0] == 0: if x0 + x - 1 < n and y0 + y - 1 < n: tr = True for i in range(y0, y0 + y): for j in range(x0, x0 + x): if arr[i][j] != 0: tr = False break arr[i][j] = symbol if tr == False: break if tr: """print(tr) for i in range(n): print(*tarr[i]) print()""" if deep == 0: print(n) flag = True for i in range(n): print(*arr[i], sep = '') return for k in range(3): if vis[k] == 0: vis[k] = -1 #print(tarr, val[k], deep - 1, vis) f(arr, val[k], deep - 1, vis) """ for i in range(n): print(*arr[i]) print() """ tr = True for i in range(y0, y0 + y): for j in range(x0, x0 + x): if arr[i][j] == symbol: arr[i][j] = 0 else: tr = False break if tr == False: break x1, y1, x2, y2, x3, y3 = map(int, input().split()) val = [[(x1, y1), (y1, x1), "A"], [(x2, y2) , (y2, x2), "B"], [(x3, y3) , (y3, x3), "C"]] s = x1 * y1 + x2 * y2 + x3 * y3 flag = True mx = max(x1, x2, x3, y1, y2, y3) if round((s) ** (1/2)) == round((s) ** (1/2), 8): n = int(s ** 0.5) if n < mx: flag = False else: flag = False if flag == True: flag = False arr = [n * [0] for i in range(n)] for i in range(3): deep = 3 vis = [0] * 3 vis[i] = -1 #print(n, "N") f(arr, val[i], deep - 1, vis) if flag == False: print(-1) else: print(-1) ```
output
1
87,067
23
174,135
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,068
23
174,136
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` v=list(map(int,input().split())) def funk(a): if ((a[0]==a[2]+a[4])and(a[1]+a[3]==a[0])and(a[3]==a[5])): print(a[0]) for i in range(a[1]): print('A'*a[0]) for i in range(a[3]): print('B'*a[2]+'C'*a[4]) elif ((a[0]==a[2]==a[4])and(a[1]+a[3]+a[5]==a[0])): print(a[0]) for i in range(a[1]): print('A'*a[0]) for i in range(a[3]): print('B'*a[2]) for i in range(a[5]): print('C'*a[4]) elif ((a[0]+a[2]+a[4]==a[1])and(a[1]==a[3]==a[5])): print(a[1]) for i in range(a[1]): print('A'*a[0]+'B'*a[2]+'C'*a[4]) elif ((a[0]+a[2]==a[4])and(a[1]==a[3])and(a[1]+a[5]==a[4])): print(a[4]) for i in range(a[1]): print('A'*a[0]+'B'*a[2]) for i in range(a[5]): print('C'*a[4]) elif ((a[0]+a[2]==a[1])and(a[2]==a[4])and(a[3]+a[5]==a[1])): print(a[1]) for i in range(a[3]): print('A'*a[0]+'B'*a[2]) for i in range(a[5]): print('A'*a[0]+'C'*a[4]) elif ((a[0]+a[2]==a[3])and(a[0]==a[4])and(a[1]+a[5]==a[3])): print(a[3]) for i in range(a[1]): print('A'*a[0]+'B'*a[2]) for i in range(a[5]): print('C'*a[4]+'B'*a[2]) else: #~ print('-1') return 0 return 1 s=0 for i in range(2): v[0],v[1]=v[1],v[0] for i1 in range(2): v[2],v[3]=v[3],v[2] for i2 in range(2): v[4],v[5]=v[5],v[4] if s==0: s=funk(v) if s:break if s==0: print('-1') ```
output
1
87,068
23
174,137
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,069
23
174,138
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` x1, y1, x2, y2, x3, y3 = map(int, input().split()) x1, y1 = max(x1, y1), min(x1, y1) x2, y2 = max(x2, y2), min(x2, y2) x3, y3 = max(x3, y3), min(x3, y3) x1c, y1c, x2c, y2c, x3c, y3c = x1, y1, x2, y2, x3, y3 if x2 == max(x1, x2, x3) : x1, y1, x2, y2 = x2, y2, x1, y1 elif x3 == max(x1, x2, x3) : x1, y1, x3, y3 = x3, y3, x1, y1 if x1 == x1c and y1 == y1c and x2 == x2c and y2 == y2c : s1 = 'A' s2 = 'B' s3 = 'C' elif x1 == x1c and y1 == y1c and x2 == x3c and y2 == y3c : s1 = 'A' s2 = 'C' s3 = 'B' elif x1 == x2c and y1 == y2c and x2 == x1c and y2 == y1c : s1 = 'B' s2 = 'A' s3 = 'C' elif x1 == x2c and y1 == y2c and x2 == x3c and y2 == y3c : s1 = 'B' s2 = 'C' s3 = 'A' elif x1 == x3c and y1 == y3c and x2 == x1c and y2 == y1c : s1 = 'C' s2 = 'A' s3 = 'B' elif x1 == x3c and y1 == y3c and x2 == x2c and y2 == y2c : s1 = 'C' s2 = 'B' s3 = 'A' if x1 == x2 == x3 and y1 + y2 + y3 == x1 : print(x1) for i in range(x1) : for j in range(x1) : if i < y1 : print(s1, end = '') elif y1 <= i < y1 + y2 : print(s2, end = '') else : print(s3, end = '') print() elif x1 == y2 + x3 and x2 + y1 == y3 + y1 == x1 : print(x1) for i in range(x1) : for j in range(x1) : if i < y1 : print(s1, end = '') else : if j < y2 : print(s2, end = '') else : print(s3, end = '') print() elif x1 == x2 + y3 and y2 + y1 == x3 + y1 == x1 : print(x1) for i in range(x1) : for j in range(x1) : if i < y1 : print(s1, end = '') else : if j < x2 : print(s2, end = '') else : print(s3, end = '') print() elif x1 == x2 + x3 and y2 + y1 == y3 + y1 == x1 : print(x1) for i in range(x1) : for j in range(x1) : if i < y1 : print(s1, end = '') else : if j < x2 : print(s2, end = '') else : print(s3, end = '') print() elif x1 == y2 + y3 and x2 + y1 == x3 + y1 == x1 : print(x1) for i in range(x1) : for j in range(x1) : if i < y1 : print(s1, end = '') else : if j < y2 : print(s2, end = '') else : print(s3, end = '') print() else : print(-1) ```
output
1
87,069
23
174,139
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,070
23
174,140
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` from sys import * inp = lambda : stdin.readline() def main(): x1,y1,x2,y2,x3,y3 = map(int,inp().split()) m = max(x1,x2,x3,y1,y2,y3) l = [(x1,y1),(x2,y2),(x3,y3)] ans = [ ['C' for i in range(m)] for i in range(m)] bools = True if all([m in x for x in l]): if min(x1, y1) + min(x2, y2) + min(x3, y3) != m: bools = False else: for i in range(0,min(x1,y1)): ans[i] = ['A' for i in range(m)] for i in range(min(x1,y1),min(x1,y1)+min(x2,y2)): ans[i] = ['B' for i in range(m)] else: if x2 * y2 + x3 * y3 + x1 * y1 != m * m: bools = False elif m in l[0]: if not all([m-min(x1,y1) in i for i in [l[1],l[2]]]): bools = False else: for i in range(0,min(x1,y1)): ans[i] = ['A' for i in range(m)] if min(x2,y2) + min(x1,y1) == m: for i in range(min(x1, y1), m): ans[i] = ['B' for i in range(max(x2,y2))] + ['C' for i in range(m-max(x2,y2))] else: for i in range(min(x1, y1), m): ans[i] = ['B' for i in range(min(x2, y2))] + ['C' for i in range(m - min(x2, y2))] elif m in l[1]: if not all([m - min(x2, y2) in i for i in [l[0], l[2]]]): bools = False else: x1,x2=x2,x1 y1,y2=y2,y1 for i in range(0, min(x1, y1)): ans[i] = ['B' for i in range(m)] if min(x2, y2) + min(x1, y1) == m: for i in range(min(x1, y1), m): ans[i] = ['A' for i in range(max(x2, y2))] + ['C' for i in range(m - max(x2, y2))] else: for i in range(min(x1, y1), m): ans[i] = ['A' for i in range(min(x2, y2))] + ['C' for i in range(m - min(x2, y2))] elif m in l[2]: if not all([m - min(x3, y3) in i for i in [l[1], l[0]]]): bools = False else: x1, x3 = x3, x1 y1, y3 = y3, y2 for i in range(0, min(x1, y1)): ans[i] = ['C' for i in range(m)] if min(x2, y2) + min(x1, y1) == m: for i in range(min(x1, y1), m): ans[i] = ['B' for i in range(max(x2, y2))] + ['A' for i in range(m - max(x2, y2))] else: for i in range(min(x1, y1), m): ans[i] = ['B' for i in range(min(x2, y2))] + ['A' for i in range(m - min(x2, y2))] if bools: print(m) for i in ans: print("".join(map(str,i))) else: print(-1) if __name__ == "__main__": main() ```
output
1
87,070
23
174,141
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,071
23
174,142
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` #!/usr/bin/python3 from itertools import permutations def isqrt(x): l, r = 0, 10**100 while l < r - 1: mid = (l + r) // 2 if mid ** 2 > x: r = mid else: l = mid return l x1, y1, x2, y2, x3, y3 = map(int, input().split()) p = [(x1, y1, "A"), (x2, y2, "B"), (x3, y3, "C")] s = x1 * y1 + x2 * y2 + x3 * y3 x = isqrt(s) if x * x != s: print(-1) exit(0) for mask in range(1 << 3): q = [] for i in range(3): if (mask >> i) & 1: q.append((p[i][0], p[i][1], p[i][2])) else: q.append((p[i][1], p[i][0], p[i][2])) if q[0][0] == q[1][0] == q[2][0] == x: print(x) for i in range(q[0][1]): print("A" * x) for i in range(q[1][1]): print("B" * x) for i in range(q[2][1]): print("C" * x) exit(0) for r in permutations(q): t = list(r) if t[0][0] == x and t[0][1] + t[1][1] == x and t[0][1] + t[2][1] == x and t[1][0] + t[2][0] == x: print(x) for i in range(t[0][1]): print(t[0][2] * x) for i in range(x - t[0][1]): print(t[1][2] * t[1][0] + t[2][2] * t[2][0]) exit(0) print(-1) ```
output
1
87,071
23
174,143
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,072
23
174,144
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` inp = input().split() a = [int(inp[0]),int(inp[1])] b = [int(inp[2]),int(inp[3])] c = [int(inp[4]),int(inp[5])] a.sort() a.reverse() a.append("A") b.sort() b.reverse() b.append("B") c.sort() c.reverse() c.append("C") first = [a, b ,c] first.sort() first.reverse() second = [a, b, c] second.sort() second.reverse() third = [a, b, c] #print(first) #print(second) def swap(a): temp = a[0] a[0] = a[1] a[1] = temp def check_first(x): #print(x) fla = (x[0][0] == x[1][0] + x[2][0]) #print(x[0][0], "==", x[1][0], "+", x[2][0]) #print(fla) flb = (x[1][1] == x[2][1] == (x[0][0] - x[0][1])) #print(x[1][1], "==", x[2][1], "==", x[0][0] - x[0][1]) #print(flb) return fla and flb def check_second(x): if (x[0][0] == x[1][0]) and (x[0][1] + x[1][1] == x[2][0] == x[0][0]): return True else: return False flag = False ind = 0 res = -1 s = "" while (not flag): ind = 1 if check_first(first): break swap(first[1]) if check_first(first): break swap(first[2]) if check_first(first): break swap(first[1]) if check_first(first): break ind = 2 if check_second(second): break swap(second[2]) if check_second(second): break if (third[0][0] == third[1][0] == third[2][0]) and (third[0][0] == third[0][1] + third[1][1] + third[2][1]): ind = 3 break flag = True if flag: print(-1) elif ind == 1: print(first[0][0]) for i in range(first[0][1]): print(first[0][2] * first[0][0]) for i in range(first[1][1]): print(first[1][2]*first[1][0] + first[2][2] * first[2][0]) elif ind == 2: print(second[2][1]) for i in range(second[0][1]): print(second[0][2]*second[0][0] + second[2][2]*second[2][0]) for i in range(second[1][1]): print(second[1][2]*second[1][0] + second[2][2]*second[2][0]) elif ind == 3: print(third[0][0]) for i in range(third[0][1]): print(third[0][2]*third[0][0]) for i in range(third[1][1]): print(third[1][2]*third[0][0]) for i in range(third[2][1]): print(third[2][2]*third[0][0]) ```
output
1
87,072
23
174,145
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,073
23
174,146
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` import sys def get_sol(a, b, c, n, reverse): #1 if reverse[0]: a = (a[1], a[0], a[2]) if reverse[1]: b = (b[1], b[0], b[2]) if reverse[2]: c = (c[1], c[0], c[2]) ans = [] if a[0] == b[0] == c[0] == n: if a[1] + b[1] + c[1] == n: for i in range(a[1]): ans.append(a[2]*n) for i in range(b[1]): ans.append(b[2]*n) for i in range(c[1]): ans.append(c[2]*n) return True, ans if a[0] + c[0] == b[0] + c[0] == n and c[1] == n == a[1] + b[1]: for i in range(a[1]): ans.append(a[2]*a[0] + c[2] * c[0]) for i in range(b[1]): ans.append(b[2]*b[0] + c[2] * c[0]) return True, ans return False, ans def printans(ans, n): print(n) for line in ans: print(line) exit() #sys.stdin = open('input.txt') #sys.stdout = open('output.txt', 'w') x1, y1, x2, y2, x3, y3 = [int(i) for i in input().split()] total_area = x1*y1 + x2*y2 + x3*y3 n = 0 while n ** 2 < total_area: n += 1 if n ** 2 != total_area: print(-1) else: first = (x1, y1, 'A') second = (x2, y2, 'B') third = (x3, y3, 'C') pereb = ( (first, second, third), (first, third, second), (second, first, third), (second, third, first), (third, first, second), (third, second, first)) for rev1 in (False, True): for rev2 in (False, True): for rev3 in (False, True): for per in pereb: reverse = (rev1, rev2, rev3) is_ans, ans = get_sol(per[0], per[1], per[2], n, reverse) if is_ans: printans(ans, n) print(-1) ```
output
1
87,073
23
174,147
Provide tags and a correct Python 3 solution for this coding contest problem. Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard. Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules. Input The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. Output If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that: * the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company, * the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company, * the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement. Examples Input 5 1 2 5 5 2 Output 5 AAAAA BBBBB BBBBB CCCCC CCCCC Input 4 4 2 6 4 2 Output 6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
instruction
0
87,074
23
174,148
Tags: bitmasks, brute force, constructive algorithms, geometry, implementation, math Correct Solution: ``` a,b,c,d,e,f=map(int,input().split()) m=sorted([(max(a,b),min(a,b),"A"),(max(c,d),min(c,d),"B"),(max(e,f),min(e,f),"C")]) ma=m[-1][0] ma2=ma-m[-1][1] ans=[["A"]*ma for i in range(ma)] if a*b+c*d+e*f!=ma*ma: print(-1) elif m[0][0]*m[0][1]+m[1][0]*m[1][1]!=ma2*ma: print(-1) elif m[0][0]!=m[1][0]: if m[0][0]!=m[1][1] and m[0][1]!=m[1][1] : print(-1) else: for i in range(m[-1][1]): for j in range(ma): ans[i][j]=m[-1][2] for i in range(m[-1][1],ma): for j in range(m[0][0]+m[0][1]-ma2): ans[i][j]=m[0][2] for i in range(m[-1][1],ma): for j in range(m[0][0]+m[0][1]-ma2,ma): ans[i][j]=m[1][2] print(ma) for x in ans: print(''.join(x)) else: for i in range(m[-1][1]): for j in range(ma): ans[i][j]=m[-1][2] if m[0][0]==ma: for i in range(m[-1][1],m[-1][1]+m[0][1]): for j in range(ma): ans[i][j]=m[0][2] for i in range(m[-1][1]+m[0][1],ma): for j in range(ma): ans[i][j]=m[1][2] else: for i in range(m[-1][1],ma): for j in range(m[0][1]): ans[i][j]=m[0][2] for i in range(m[-1][1],ma): for j in range(m[0][1],ma): ans[i][j]=m[1][2] print(ma) for x in ans: print(''.join(x)) ```
output
1
87,074
23
174,149