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. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455
instruction
0
27,290
23
54,580
"Correct Solution: ``` import math while True: x = int(input().strip()) h = int(input().strip()) if x==0 and h==0: break d = math.sqrt((x/2.0)**2 + h**2) s = x * d / 2.0 * 4 + x**2 print(s) ```
output
1
27,290
23
54,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` for x in iter(input,'0'): x=int(x) print(x*x+2*x*((x/2)**2+int(input())**2)**.5) ```
instruction
0
27,291
23
54,582
Yes
output
1
27,291
23
54,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` from math import sqrt while True: x, h = int(input()), int(input()) if x==h==0: break sh = sqrt((x/2)**2 + h**2) print((x*x) + sum([sh*x*0.5 for _ in range(4)])) ```
instruction
0
27,292
23
54,584
Yes
output
1
27,292
23
54,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` for x in iter(input,'0'):x=int(x);print(x*x+2*x*((x/2)**2+int(input())**2)**.5) ```
instruction
0
27,293
23
54,586
Yes
output
1
27,293
23
54,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` import math while True: a=int(input()) b=int(input()) if a==0: break s=a*a+2*a*(math.sqrt(b*b+(a/2)*(a/2))) print(s) ```
instruction
0
27,294
23
54,588
Yes
output
1
27,294
23
54,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` import math x = int(input()) h = int(input()) if x == h == 0: S = (x ** 2) + 4(x * (math.sqrt((1 / 2) ** 2 + h ** 2 ))) print(S) ```
instruction
0
27,295
23
54,590
No
output
1
27,295
23
54,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` import math x = int(input()) h = int(input()) if x == h == 0: break S = (x ** 2) + 4(x * (math.sqrt(((1 / 2) * x) ** 2 + h ** 2 ))) print(S) ```
instruction
0
27,296
23
54,592
No
output
1
27,296
23
54,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` import math while True: x = float(input()) if x == 0: break h = float(input()) l = math.sqrt(0.025*x**2 + h**2) s = x**2 + 2*x*l print(s) ```
instruction
0
27,297
23
54,594
No
output
1
27,297
23
54,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100. Input Given multiple datasets. Each dataset is given in the following format: x h When both x and h are 0, it indicates the end of input. Output Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less. Example Input 6 4 7 9 0 0 Output 96.000000 184.192455 Submitted Solution: ``` import math while True: x = int(input()) h = int(input()) if x == h == 0: break S = (x ** 2) + 4(x * (math.sqrt((1 / 2) ** 2 + h ** 2 ))) print(S) ```
instruction
0
27,298
23
54,596
No
output
1
27,298
23
54,597
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,353
23
54,706
"Correct Solution: ``` p=[complex(*map(int,input().split())) for _ in range(int(input()))] s,pre=0,p[0] while p: now=p.pop() s+=now.real*pre.imag-now.imag*pre.real pre=now print(abs(s)/2) ```
output
1
27,353
23
54,707
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,354
23
54,708
"Correct Solution: ``` n = int(input()) P =[] s = 0 for _ in range(n):P += [[int(i) for i in input().split()]] for j in range(n-1):s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0] s += P[-1][0]*P[0][1] - P[-1][1]*P[0][0] print(s*0.5) ```
output
1
27,354
23
54,709
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,355
23
54,710
"Correct Solution: ``` n = int(input()) P =[] s = 0 for i in range(n):P.append([int(i) for i in input().split()]) P.append(P[0]) for i in range(n): a = P[i][0] ; b = P[i][1]; c = P[i+1][0] ; d = P[i+1][1] s += a * d - b * c print(abs(s)*0.5) ```
output
1
27,355
23
54,711
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,356
23
54,712
"Correct Solution: ``` n = int(input()) P =[] s = 0 for i in range(n):P.append([int(i) for i in input().split()]) P.append(P[0]) for i in range(n):s += (P[i][0]*P[i+1][1] - P[i][1]*P[i+1][0]) print(abs(s)*0.5) ```
output
1
27,356
23
54,713
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,357
23
54,714
"Correct Solution: ``` def get_area(ps): """頂点集合psから成る多角形の面積を求める。""" n = len(ps) ans = 0 for i in range(n): p1 = ps[i] p2 = ps[i - 1] ans += (p1[0] * p2[1] - p2[0] * p1[1]) / 2 return abs(ans) n = int(input()) ps = [list(map(int, input().split())) for i in range(n)] print(get_area(ps)) ```
output
1
27,357
23
54,715
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,358
23
54,716
"Correct Solution: ``` def norm(c): a = abs(c) return a*a def dot_product(a,b): return (a.conjugate()*b).real def cross_product(a,b): return (a.conjugate()*b).imag def projection(p,b): return b*dot_product(p,b)/norm(b) P = [] N = int(input()) for i in range(N): x,y = map(float,input().split(' ')) P.append(complex(x,y)) total = 0.0 for i in range(1,N-1): a,b,c = P[0],P[i],P[i+1] S = cross_product(b-a,c-a)/2 total += S print("%.1f" % (abs(total))) ```
output
1
27,358
23
54,717
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,359
23
54,718
"Correct Solution: ``` n = int(input()) P =[] s = 0 for _ in range(n):P.append(list(map(int,input().split()))) P.append(P[0]) for j in range(n):s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0] print(s*0.5) ```
output
1
27,359
23
54,719
Provide a correct Python 3 solution for this coding contest problem. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5
instruction
0
27,360
23
54,720
"Correct Solution: ``` x=range(int(input()),0,-1) P=[] for _ in x:P+=[[int(i) for i in input().split()]] P+=[P[0]] for j in x:_+=P[j-1][0]*P[j][1]-P[j-1][1]*P[j][0] print(_*0.5-0.5) ```
output
1
27,360
23
54,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` def cross(a,b):return a[0]*b[1] - a[1]*b[0] n = int(input()) P =[] s = 0 for i in range(n):P.append([int(i) for i in input().split()]) P.append(P[0]) for i in range(n):s += cross(P[i],P[i+1]) print(abs(s)*0.5) ```
instruction
0
27,361
23
54,722
Yes
output
1
27,361
23
54,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` def cross(a,b):return a[0]*b[1] - a[1]*b[0] n = int(input()) P =[] s = 0 for i in range(n):P.append([int(i) for i in input().split()]) P = P*2 for i in range(n):s += cross(P[i],P[i+1]) print(abs(s)/2) ```
instruction
0
27,362
23
54,724
Yes
output
1
27,362
23
54,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` #!/usr/bin/env python3 import cmath def outer_product(v1, v2): return v1.real * v2.imag - v1.imag * v2.real def area_polygon(n, points): s = sum(outer_product(points[i], points[(i + 1) % n]) for i in range(n)) / 2.0 return s def main(): n = int(input()) ps = [complex(*map(float, input().split())) for _ in range(n)] s = area_polygon(n, ps) print("{:.1f}".format(s)) if __name__ == '__main__': main() ```
instruction
0
27,363
23
54,726
Yes
output
1
27,363
23
54,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` from sys import stdin readline = stdin.readline def dot(a, b): return a.real * b.real + a.imag * b.imag def cross(a, b): return a.real * b.imag - a.imag * b.real def triangle(a, b, c): v1, v2 = b - a, c - a s = abs(v1) ** 2 * abs(v2) ** 2 - dot(v1, v2) ** 2 return s ** 0.5 * 0.5 def polygon(p): return 0.5 * sum(cross(p[i - 1], p[i]) for i in range(len(p))) n = int(readline()) p = [map(int, readline().split()) for _ in range(n)] p = [x + y * 1j for x, y in p] print('{:.1f}'.format(polygon(p))) ```
instruction
0
27,364
23
54,728
Yes
output
1
27,364
23
54,729
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` import math def vec(s,e): return (e[0]-s[0], e[1]-s[1]) def dot(p,q): return p[0]*p[1] + q[0]*q[1] def is_obtuse(p,q,r): b = vec(q,r) a = vec(q,p) c = (-b[1],b[0]) bc = dot(a,b) pc = dot(c,b) return math.atan2(pc,bc) < 0 def dist(p,q): return ((p[0]-q[0])**2 + (p[1]-q[1])**2)**0.5 def area(p,q,r): a = dist(p,q) b = dist(q,r) c = dist(r,p) z = (a+b+c)/2 return (z*(z-a)*(z-b)*(z-c))**0.5 n = int(input()) v = [] for _ in range(n): v.append([float(x) for x in input().split()]) sub_area = 0 v_ignore = [0 for _ in range(n)] for i in range(n-2): if is_obtuse(v[i],v[i+1],v[i+2]): sub_list += area(v[i],v[i+1],v[i+2]) v_ignore[i+1] = 1 else: pass v_cover = [] for i,x in enumerate(v_ignore): if x == 0: v_cover.append(v[i]) cover_area = 0 for i in range(1,len(v_cover)-1): cover_area += area(v_cover[0],v_cover[i],v_cover[i+1]) print(round(cover_area - sub_area,1)) ```
instruction
0
27,365
23
54,730
No
output
1
27,365
23
54,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` import math def vec(s,e): return (e[0]-s[0], e[1]-s[1]) def dot(p,q): return p[0]*p[1] + q[0]*q[1] def is_obtuse(p,q,r): b = vec(q,r) a = vec(q,p) c = (-b[1],b[0]) bc = dot(a,b) pc = dot(c,b) return math.atan2(pc,bc) < 0 def dist(p,q): return ((p[0]-q[0])**2 + (p[1]-q[1])**2)**0.5 def area(p,q,r): a = dist(p,q) b = dist(q,r) c = dist(r,p) z = (a+b+c)/2 return (z*(z-a)*(z-b)*(z-c))**0.5 n = int(input()) v = [] for _ in range(n): v.append([int(x) for x in input().split()]) sub_area = 0 v_ignore = [0 for _ in range(n)] for i in range(n-2): if is_obtuse(v[i],v[i+1],v[i+2]): sub_list += area(v[i],v[i+1],v[i+2]) v_ignore[i+1] = 1 else: pass v_cover = [] for i,x in enumerate(v_ignore): if x == 0: v_cover.append(v[i]) cover_area = 0 for i in range(1,len(v_cover)-1): cover_area += area(v_cover[0],v_cover[i],v_cover[i+1]) print(round(cover_area - sub_area,1)) ```
instruction
0
27,366
23
54,732
No
output
1
27,366
23
54,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` x=range(int(input())) f=lambda a,b,c,d : a*d - b*c P=[] for _ in x:P+=[[int(i) for i in input().split()]] _=0 P+=[P[0]] for j in x:_+=f(P[j][0],P[j][1],,P[j+1][0]P[j+1][1]) print(_*0.5) ```
instruction
0
27,367
23
54,734
No
output
1
27,367
23
54,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given polygon g, computes the area of the polygon. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon. Note that the polygon is not necessarily convex. Constraints * 3 ≤ n ≤ 100 * -10000 ≤ xi, yi ≤ 10000 * No point will occur more than once. * Two sides can intersect only at a common endpoint. Input The input consists of coordinates of the points p1,..., pn in the following format: n x1 y1 x2 y2 : xn yn The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Output Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. Examples Input 3 0 0 2 2 -1 1 Output 2.0 Input 4 0 0 1 1 1 2 0 2 Output 1.5 Submitted Solution: ``` import math class Vector(): def __init__(self, x, y): self.x = x self.y = y def inner_product(self, vec): return self.x*vec.x + self.y*vec.y def outer_product(self, vec): return self.x*vec.y - self.y*vec.x def norm(self): return math.sqrt(self.x**2 + self.y**2) n = int(input()) points = [] for i in range(n): x, y = list(map(int, input().split(' '))) points.append(Vector(x, y)) points.append(points[0]) area = 0 for i in range(n-1): a, b = points[i], points[i+1] if (a.x == 0 and a.y == 0) or (b.x == 0 and b.y == 0): continue theta = math.atan2(a.outer_product(b), a.inner_product(b)) if theta > 0: area += abs(a.outer_product(b))/2 elif theta < 0: area -= abs(a.outer_product(b))/2 print(area) ```
instruction
0
27,368
23
54,736
No
output
1
27,368
23
54,737
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,511
23
55,022
Tags: greedy Correct Solution: ``` import functools from math import inf class event: def __init__(self, x, type, index): self.x = x self.type = type self.i = index def custom_sort(a, b): # if a.i == b.i: # if a.type == "s" and b.type == "e": # return -1 # if a.type == "e" and b.type == "s": # return 1 if a.x < b.x: return - 1 if a.x > b.x: return 1 if a.type == "e" and b.type == "s": return 1 if a.type == "s" and b.type == "e": return -1 return 0 if __name__ == "__main__": line = input().split(" ") n, k = int(line[0]), int(line[1]) events = [] original_events = [] for i in range(n): line = input().split(" ") s = int(line[0]) e = int(line[1]) events.append(event(s, "s", i)) events.append(event(e, "e", i)) original_events.append([s, e]) events.sort(key=functools.cmp_to_key(custom_sort)) active = {} ans = [] cnt = 0 for curr in events: # print(curr.x, curr.type, curr.i, cnt) if curr.type == "s": cnt += 1 active[curr.i] = 1 if cnt > k: # print("over:", curr.i, cnt) to_remove = 0 rightmost = -inf for i in active.keys(): if original_events[i][1] > rightmost: rightmost = original_events[i][1] to_remove = i ans.append(str(to_remove + 1)) del active[to_remove] cnt -= 1 else: if curr.i in active.keys(): cnt -= 1 del active[curr.i] print(len(ans)) print(" ".join(ans)) ```
output
1
27,511
23
55,023
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,512
23
55,024
Tags: greedy Correct Solution: ``` ''' template author-: Pyduper ''' # MAX = pow(10, 5) # stdin = open("testdata.txt", "r") # ip = stdin # def input(): # return ip.readline().strip() N = 250 n, k = map(int, input().split()) segs = [[0, 0] for _ in range(n)] cnt = [0]*N ans = [0]*n for i in range(n): segs[i][0], segs[i][1] = map(int, input().split()) cnt[segs[i][0]] += 1 cnt[segs[i][1]+1] -= 1 for i in range(N-1): cnt[i+1] += cnt[i] for i in range(N-1): while cnt[i] > k: pos = -1 for p in range(n): if not ans[p] and segs[p][0] <= i <= segs[p][1] and (pos == -1 or segs[p][1] > segs[pos][1]): pos = p assert pos != -1 for j in range(segs[pos][0], segs[pos][1]+1): cnt[j] -= 1 ans[pos] = 1 print(ans.count(1)) for i in range(n): if ans[i]: print(i+1, end=" ") print() ```
output
1
27,512
23
55,025
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,513
23
55,026
Tags: greedy Correct Solution: ``` n,m=map(int,input().split()) a=[[] for i in range(201)] for i in range(n): b,c=map(int,input().split()) a[b].append([c,i+1]) l=0 d=0 stack=[] count=0 for i in range(1,201): a[i].sort() l=len(a[i]) if(l>m): d=l-m for j in range(d): stack.append(a[i][-1][1]) a[i].pop(-1) count+=1 while(len(a[i])>0 and a[i][0][0]==i): a[i].pop(0) if(len(a[i])>0): a[i+1]=a[i+1]+a[i] print(count) for i in range(count): print(stack[i],end=' ') ```
output
1
27,513
23
55,027
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,514
23
55,028
Tags: greedy Correct Solution: ``` from heapq import * def main(): n, k = map(int, input().split()) E = [] opent = {} for i in range(n): l, r = map(int, input().split()) E.append([l, 1, i]) E.append([r, -1, i]) opent[i] = r E.sort(key=lambda x: (x[0], -x[1])) now_r = [] heapify(now_r) cnt_delet = 0 ans = [] deleted = set() for x, t, i in E: if t == 1: heappush(now_r, -(opent[i] * 10 ** 6 + i)) else: if i not in deleted: cnt_delet += 1 if len(now_r) - cnt_delet > k: for _ in range(len(now_r) - cnt_delet - k): nm = heappop(now_r) ind = (-nm) % 10 ** 6 ans.append(ind + 1) deleted.add(ind) print(len(ans)) print(' '.join(list(map(str, ans)))) main() ```
output
1
27,514
23
55,029
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,515
23
55,030
Tags: greedy Correct Solution: ``` n, k = map(int, input().split()) i = [] all_offenders = [] for q in range(n): i.append((tuple(map(int, input().split())),q)) i.sort(key=lambda x: x[0][1]) for t in range(200): count = 0 offenders = [] for pos in range(len(i)): if i[pos][0][0] <= t <= i[pos][0][1]: count += 1 if count > k: offenders.append(pos) all_offenders.append(i[pos][1]+1) offenders.reverse() for y in offenders: i.pop(y) print(len(all_offenders)) print(*all_offenders) ```
output
1
27,515
23
55,031
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,516
23
55,032
Tags: greedy Correct Solution: ``` # -*- coding: utf-8 -*- import sys line_count = 0 segments = [] for line in sys.stdin.readlines(): inputs = line.split() if line_count == 0: n = int(inputs[0]) k = int(inputs[1]) else: l = int(inputs[0]) r = int(inputs[1]) segments.append((l, r)) if line_count == n: break line_count += 1 removed = [False for i in range(n)] remove_count = 0 removed_list = [] for i in range(1, 201): max_i = 0 covering = [] for j in range(n): if removed[j]: continue l, r = segments[j] if l <= i and i <= r: covering.append((r, j)) to_remove = len(covering) - k if to_remove > 0: covering.sort() for _ in range(to_remove): _, j = covering.pop() # print(i, j, segments[j]) removed[j] = True removed_list.append(j) print(len(removed_list)) for j in removed_list: print(j + 1, end = " ") ```
output
1
27,516
23
55,033
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,517
23
55,034
Tags: greedy Correct Solution: ``` import heapq def main(): n,k=readIntArr() lr=[] for i in range(n): l,r=readIntArr() lr.append([l,r,i+1]) lr.sort(key=lambda x:x[0]) # store [r,idx] of segments # maxHeapRs=[] # minHeapRs=[] # removedIdxes=set() ans=[] cnts=0 # for l,r,i in lr: # while len(minHeapRs)>0 and minHeapRs[0][0]<l: # leftestRIdx=minHeapRs[0][0] # heapq.heappop(minHeapRs) # if leftestRIdx not in removedIdxes: # not removed previously # removedIdxes.add(leftestRIdx) # cnts-=1 # heapq.heappush(minHeapRs,[r,i]) # heapq.heappush(maxHeapRs,[-r,i]) # cnts+=1 # while cnts>k: # get rid of segment with rightest r # rightestRIdx=maxHeapRs[0][1] # heapq.heappop(maxHeapRs) # if rightestRIdx not in removedIdxes: # removedIdxes.add(rightestRIdx) # ans.append(rightestRIdx) # cnts-=1 def getMinR(storedRandI): # return minR and corresponding i and idx n=len(storedRandI) minR,ii=storedRandI[0] idx=0 for j in range(1,n): if storedRandI[j][0]<minR: minR,ii=storedRandI[j] idx=j return [minR,ii,idx] def getMaxR(storedRandI): # return maxR and corresponding i and idx n=len(storedRandI) maxR,ii=storedRandI[0] idx=0 for j in range(1,n): if storedRandI[j][0]>maxR: maxR,ii=storedRandI[j] idx=j return [maxR,ii,idx] storedRandI=[] # [r,i] ans=[] cnts=0 for l,r,i in lr: while storedRandI and getMinR(storedRandI)[0]<l: minR,ii,idx=getMinR(storedRandI) storedRandI.pop(idx) cnts-=1 storedRandI.append([r,i]) cnts+=1 while cnts>k: # print('cnts:{} l:{} r:{}'.format(cnts,l,r)) maxR,ii,idx=getMaxR(storedRandI) storedRandI.pop(idx) cnts-=1 ans.append(ii) # print('l:{} r:{} storedRAndI:{}'.format(l,r,storedRandI)) print(len(ans)) oneLineArrayPrint(ans) return import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) # input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] # def readFloatArr(): # return [float(x) for x in input().split()] def makeArr(defaultVal,dimensionArr): # eg. makeArr(0,[n,m]) dv=defaultVal;da=dimensionArr if len(da)==1:return [dv for _ in range(da[0])] else:return [makeArr(dv,da[1:]) for _ in range(da[0])] def queryInteractive(x,y): print('? {} {}'.format(x,y)) sys.stdout.flush() return int(input()) def answerInteractive(ans): print('! {}'.format(ans)) sys.stdout.flush() inf=float('inf') MOD=10**9+7 # MOD=998244353 for _abc in range(1): main() ```
output
1
27,517
23
55,035
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6
instruction
0
27,518
23
55,036
Tags: greedy Correct Solution: ``` import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify, nlargest from copy import deepcopy mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split())) def inps(): return sys.stdin.readline() def inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x]) def err(x): print(x); exit() #####segfunc##### def segfunc(x,y): return x+y ################# class LazySegTree_RAQ: """ init(init_val, ide_ele): 配列init_valで初期化 O(N) add(l, r, x): 区間[l, r)にxを加算 O(logN) query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN) """ def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.lazy = [0] * 2 * self.num for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def gindex(self, l, r): l += self.num r += self.num lm = l >> (l & -l).bit_length() rm = r >> (r & -r).bit_length() while r > l: if l <= lm: yield l if r <= rm: yield r r >>= 1 l >>= 1 while l: yield l l >>= 1 def propagates(self, *ids): for i in reversed(ids): v = self.lazy[i] if v==0: continue self.lazy[i] = 0 self.lazy[2 * i] += v self.lazy[2 * i + 1] += v self.tree[2 * i] += v self.tree[2 * i + 1] += v def add(self, l, r, x): *ids, = self.gindex(l, r) l += self.num r += self.num while l < r: if l & 1: self.lazy[l] += x self.tree[l] += x l += 1 if r & 1: self.lazy[r - 1] += x self.tree[r - 1] += x r >>= 1 l >>= 1 for i in ids: self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) + self.lazy[i] def query(self, l, r): *ids, = self.gindex(l, r) self.propagates(*ids) res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res n,k = inpl() segs = [] for i in range(n): l,r = inpl() segs.append((l,r,i+1)) segs.sort(key=lambda x:x[1]) # segs.sort(key=lambda x:abs(x[0]-x[1])) # print(segs) st = LazySegTree_RAQ([0]*200010,max,-1) res = [] for l,r,i in segs: if st.query(l,r+1)<k: st.add(l,r+1,1) else: res.append(i) print(len(res)) print(*res) ```
output
1
27,518
23
55,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10**8) mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=2**51, func=lambda a, b: a & b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n,k=map(int,input().split()) l=[0]*(2*10**5+2) ma=0 rt=[] for i in range(n): a,b=map(int,input().split()) rt.append((a,b,i+1)) ma=max(b,ma) l[a]+=1 l[b+1]-=1 s1=SegmentTree(l) rt.sort() t=0 g=[] heapq.heapify(g) ans=[] for i in range(1,ma+1): cou=s1.query(0,i) while (t<n and rt[t][0] <= i): heapq.heappush(g, (-rt[t][1], rt[t][0],rt[t][2])) t+=1 if t==n: break if cou>k: c=cou-k for i in range(c): r,l1,ind=heapq.heappop(g) ans.append(ind) r*=-1 l[l1]-=1 l[r+1]+=1 s1.__setitem__(l1,l[l1]) s1.__setitem__(r+1,l[r+1]) print(len(ans)) print(*ans) ```
instruction
0
27,519
23
55,038
Yes
output
1
27,519
23
55,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` import heapq n,k=map(int,input().split()) st=[] L=[0]*(200005) for i in range(0,n): l,r=map(int,input().split()) st.append((r,l,i+1)) L[l]+=1 L[r+1]-=1 pre=[0] for i in range(1,len(L)): pre.append(pre[-1]+L[i]) st2=sorted(st) st2=st2[::-1] dp=[] for i in range(0,200005): h=[] dp.append(h) for i in range(0,len(st2)): dp[st2[i][1]].append(i+1) dp[st2[i][0]+1].append(-i-1) #print(st2) #print('pre',pre[25:31]) tot=0 ans=[] pos=[0]*(200005) yaad=[0]*(n+2) q=[] heapq.heapify(q) c=0 for i in range(1,200002): #print(i,q) c=c+pos[i] for j in range(0,len(dp[i])): if(dp[i][j]>0): yaad[dp[i][j]]+=1 heapq.heappush(q,dp[i][j]) else: yaad[-dp[i][j]]-=1 #print(i,q,c) if(pre[i]-c>k): c2=0 while(pre[i]-c>k): tt=heapq.heappop(q) if(yaad[tt]>0): tot+=1 ans.append(st2[tt-1][2]) pos[st2[tt-1][0]+1]-=1 c2+=1 pre[i]-=1 c+=c2 if(len(ans)>0): ans=sorted(ans) print(tot) print(*ans) ```
instruction
0
27,520
23
55,040
Yes
output
1
27,520
23
55,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` [n, k] = list( map( int, input().split(' '))) arr = [] for index in range( n ): inp = list( map( int, input().split(' '))) inp.append( index + 1 ) arr.append( inp ) arr.sort( key=lambda x: x[0] ) pres = [] m = 0 rem = [] for segment in arr: pres = list( filter( lambda x: x[1]>= segment[0], pres ) ) pres.append( segment ) while( len( pres ) > k ): maxi = max( pres, key=lambda x: x[1]) pres.remove( maxi ) m+=1 rem.append( maxi[2] ) print( m ) print( *rem ) ```
instruction
0
27,521
23
55,042
Yes
output
1
27,521
23
55,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` from sys import stdin import heapq n,k = [int(x) for x in stdin.readline().split()] segs = [] axis = [0 for x in range(200)] for seg in range(n): l,r = [int(x) for x in stdin.readline().split()] l -= 1 segs.append((l,r,seg+1)) segs.sort() q = [] dummy = [] for l,r,ind in segs: heapq.heappush(q,(-r,l,ind)) chill = True for x in range(l,r): axis[x] += 1 if axis[x] > k: chill = False if not chill: rR, rL, rInd = heapq.heappop(q) rR *= -1 dummy.append(rInd) for x in range(rL,rR): axis[x] -= 1 print(len(dummy)) print(' '.join([str(x) for x in dummy])) ```
instruction
0
27,522
23
55,044
Yes
output
1
27,522
23
55,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` n, k = map(int, input().split()) l = [0] * n r = [0] * n events = [(0, 0)] * 2 * n for i in range(n): l[i], r[i] = map(int, input().split()) events[2 * i] = (l[i], 0, i) events[2 * i + 1] = (r[i], 1, i) events.sort() print(events) import heapq as h s = [] ans = [] for e in events: x, t, id = e if t == 0: h.heappush(s, (-r[id], l[id], id)) else: temp = [] while s: x = h.heappop(s) if x == (-r[id], l[id], id): break temp.append(x) for x in temp: h.heappush(s, x) while len(s) > k: x = h.heappop(s) ans.append(x[2]) print(len(ans)) print(*[x + 1 for x in ans]) ```
instruction
0
27,523
23
55,046
No
output
1
27,523
23
55,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` import sys input = sys.stdin.readline from collections import defaultdict n, k = map(int, input().split()) covered = [0] * 201 d = defaultdict(list) d2 = defaultdict(list) for i in range(n): li, ri = map(int, input().split()) for j in range(li, ri+1): covered[j] += 1 d[j].append(i) d2[i].append(j) flag = [-1] * (201) for i in range(201): if covered[i] <= k: flag[i] = 1 ans = 0 ans_l = [] already_removed = [-1] * 200 while -1 in flag: count = [0] * 200 for i, vl in d.items(): if flag[i] == 1: continue for v in vl: if already_removed[v] == 1: continue count[v] += 1 count = list(enumerate(count)) count.sort(key=lambda k: k[1], reverse=True) remove_seg = count[0][0] already_removed[remove_seg] = 1 ans_l.append(remove_seg+1) for x in d2[remove_seg]: covered[x] -= 1 if covered[x] <= k: flag[x] = 1 ans += 1 print(ans) print(*ans_l) ```
instruction
0
27,524
23
55,048
No
output
1
27,524
23
55,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` a = [0 for i in range(201)] n, y = map(int, input().split()) b = [list(map(int, input().split())) for i in range(n)] for i in range(n): b[i].append(i+1) c = [] flag = 0 b.sort(key=lambda x: x[0]-x[1]) j = 0 while j < len(b): for i in range(b[j][0],b[j][1]+1): if b[j][0] <= i <= b[j][1]: a[i] += 1 if a[i] > y: flag = 1 if flag == 1: c.append(b[j][2]) k = b[j][0] while k <= b[j][1]: a[k] -= 1 k += 1 b.__delitem__(j) flag = 0 j += 1 c.sort() print(len(c)) print(' '.join(map(str, c))) ```
instruction
0
27,525
23
55,050
No
output
1
27,525
23
55,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` from sys import stdin, stdout import bisect def getremovesegments(list, k): res = [] list.sort(key=lambda x:x[1]) blist = [] for item in list: ri = bisect.bisect_left(blist, item[0]) #print(blist) #print(ri) #print(item[0]) cnt = len(blist) - ri if cnt < k: blist.append((item[1])) else: res.append(item[2]) return res if __name__ == '__main__': nk = list(map(int, stdin.readline().strip().split())) n = nk[0] k = nk[1] seglist = [] for i in range(n): lr = list(map(int, stdin.readline().strip().split())) lr.append(i+1) seglist.append(lr) res = getremovesegments(seglist, k) stdout.write(str(len(res)) + '\n') stdout.write(' '.join(str(x) for x in res)) ```
instruction
0
27,526
23
55,052
No
output
1
27,526
23
55,053
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): for i in arr: stdout.write(str(i)+' ') stdout.write('\n') range = xrange # not for python 3.0+ # main code n,k1=in_arr() dp=[[0 for i in range(201)] for j in range(n)] ans=defaultdict(list) for i in range(n): l,r=in_arr() for j in range(l,r+1): dp[i][j]=1 dp[i][0]=1 ans[i].append(i) ans_mx=1 pos=0 for i in range(n): mx=0 val=-1 for j in range(i-1,-1,-1): f=0 for k in range(1,201): if dp[i][k]+dp[j][k]>k1: #print 'a',i,j,k,dp[i][k],dp[j][k] f=1 break if not f: if dp[j][0]>mx: mx=dp[j][0] val=j if val<0: continue for k in range(1,201): dp[i][k]+=dp[val][k] #print i,mx,val dp[i][0]=mx+1 ans[i]=ans[val]+[i] if dp[i][0]>ans_mx: ans_mx=dp[i][0] pos=i print n-ans_mx d=Counter(ans[pos]) for i in range(n): if not d[i]: pr(str(i+1)+' ') pr('\n') ```
instruction
0
27,527
23
55,054
No
output
1
27,527
23
55,055
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad if it is covered by strictly more than k segments. Your task is to remove the minimum number of segments so that there are no bad points at all. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered. The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment. Output In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points. In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them. Examples Input 7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9 Output 3 1 4 7 Input 5 1 29 30 30 30 29 29 28 30 30 30 Output 3 1 2 4 Input 6 1 2 3 3 3 2 3 2 2 2 3 2 3 Output 4 1 3 5 6 Submitted Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): for i in arr: stdout.write(str(i)+' ') stdout.write('\n') range = xrange # not for python 3.0+ # main code n,k=in_arr() arr=[0]*(201) l=[] for i in range(n): l1,r1=in_arr() l.append((l1,r1)) for j in range(l1,r1+1): arr[j]+=1 ans=[] vis=Counter() while 1: val=-1 mx=0 for i in range(n): c=0 if vis[i]: continue for j in range(l[i][0],l[i][1]+1): if arr[j]>k: c+=1 if mx<c: mx=c val=i if mx: vis[val]=1 for i in range(l[val][0],l[val][1]+1): arr[i]-=1 ans.append(val+1) else: break pr_num( len(ans)) pr_arr(ans) ```
instruction
0
27,528
23
55,056
No
output
1
27,528
23
55,057
Provide tags and a correct Python 2 solution for this coding contest problem. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him. Input The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value. Output Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 0 0 0 1 -1 2 1 2 Output 12.566370614359172464 Input 4 1 -1 0 0 1 2 2 0 1 1 Output 21.991148575128551812 Note In the first sample snow will be removed from that area: <image>
instruction
0
27,892
23
55,784
Tags: binary search, geometry, ternary search Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations from bisect import bisect raw_input = stdin.readline pr = stdout.write import math def in_num(): return int(raw_input()) def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total integer input def inp(): # this function returns whole input of # space/line seperated integers # Use Ctrl+D to flush stdin. return map(int,stdin.read().split()) range = xrange # not for python 3.0+ def get_par(x1,y1,x2,y2): if x1==x2: return 1,0,-x1 elif y1==y2: return 0,1,-y1 else: return y2-y1,x1-x2,(y1*(x2-x1))-(x1*(y2-y1)) def get_dis1(x1,y1,x2,y2): return ((x1-x2)**2)+((y1-y2)**2) def get_dis2(x1,y1,x2,y2,x3,y3): a,b,c=get_par(x2,y2,x3,y3) #print a,b,c a1=-b b1=a c1=-(a1*x1+b1*y1) #print (a1*x2+b1*y2+c1)*(a1*x3+b1*y3+c1) if (a1*x2+b1*y2+c1)*(a1*x3+b1*y3+c1)<=0: return ((((a*x1)+(b*y1)+c)**2)/float(a**2+b**2)) else: return 10**18 n,x,y=in_arr() l=[] for i in range(n): l.append(tuple(in_arr())) l.append(l[0]) mx=0 mn=10**18 for i in range(n): mx=max(mx,get_dis1(x,y,l[i][0],l[i][1])) mn=min(mn,get_dis1(x,y,l[i][0],l[i][1])) for i in range(n): mn=min(mn,get_dis2(x,y,l[i][0],l[i][1],l[i+1][0],l[i+1][1])) print math.pi*(mx-mn) ```
output
1
27,892
23
55,785
Provide tags and a correct Python 3 solution for this coding contest problem. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him. Input The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value. Output Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 0 0 0 1 -1 2 1 2 Output 12.566370614359172464 Input 4 1 -1 0 0 1 2 2 0 1 1 Output 21.991148575128551812 Note In the first sample snow will be removed from that area: <image>
instruction
0
27,893
23
55,786
Tags: binary search, geometry, ternary search Correct Solution: ``` import math def main(): (n, xp, yp) = (int(x) for x in input().split()) polygon = [None] * n for i in range(n): (xi, yi) = (int(x) for x in input().split()) polygon[i] = (xi, yi) print(solver((xp, yp), polygon)) def solver(P, polygon): n = len(polygon) (xp, yp) = P distances = [distance(xp, yp, x, y) for (x, y) in polygon] maxDist = max(distances) minDist = min(distances) for i in range(n): p = perpenPoint(polygon[i%n], polygon[(i+1)%n], P) if p != None: dist = distance(xp, yp, p[0], p[1]) if dist < minDist: minDist = dist area = math.pi * (maxDist**2 - minDist**2) return area # ax + by = c def toLine(point1, point2): (x1, y1) = point1 (x2, y2) = point2 if x1 == x2: if y1 == y2: assert(False) else: return (1, 0, x1) else: a = (y2 - y1) / (x1 - x2) c = a * x1 + y1 return (a, 1, c) # perpendicular point from point to the line segment: point1 to point3 def perpenPoint(point1, point2, point): line = toLine(point1, point2) (a, b, c) = line # perpendicular line if a == 0: (ap, bp) = (b, a) else: (ap, bp) = (-b / a, 1) (x, y) = point cp = ap * x + bp * y (xi, yi) = intersection(line, (ap, bp, cp)) (x1, y1) = point1 (x2, y2) = point2 if min(x1, x2) <= xi and xi <= max(x1, x2) and \ min(y1, y2) <= yi and yi <= max(y1, y2): return (xi, yi) else: return None def intersection(line1, line2): (a1, b1, c1) = line1 (a2, b2, c2) = line2 if b1 == 0 and a2 == 0: return (c1, c2) elif a1 == 0 and b2 == 0: return (c2, c1) else: x = (b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1) y = (c1 - a1 * x) / b1 return (x, y) def almostEqual(x, y): return abs(x - y) < 10**-16 def distance(x1, y1, x2, y2): leg1 = abs(x1 - x2) leg2 = abs(y1 - y2) return (leg1**2 + leg2**2)**0.5 main() #print(perpenPoint((-1, 0), (0, 1), (1.1, 0))) #print(perpenPoint((-2, 0), (-2, 1), (0, 0))) #print(perpenPoint((-1, 1), (2, 1), (0, 0))) #print(perpenPoint((-1, 0), (1, 1), (0, 0))) #print(12.56637061435 / math.pi) #print(solver((0, 0), [(0, 1), (-1, 2), (1, 2)])) #print(solver((1, -1), [(0, 0), (1, 2), (2, 0), (1, 1)])) ```
output
1
27,893
23
55,787
Provide tags and a correct Python 3 solution for this coding contest problem. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him. Input The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value. Output Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 0 0 0 1 -1 2 1 2 Output 12.566370614359172464 Input 4 1 -1 0 0 1 2 2 0 1 1 Output 21.991148575128551812 Note In the first sample snow will be removed from that area: <image>
instruction
0
27,894
23
55,788
Tags: binary search, geometry, ternary search Correct Solution: ``` from math import hypot, pi, copysign def main(): n, a, b = map(int, input().split()) l, res = [], [] for _ in range(n): x0, y0 = map(int, input().split()) l.append((x0 - a, y0 - b)) x0, y0 = l[-1] for x1, y1 in l: res.append(hypot(x1, y1)) dx, dy = x1 - x0, y1 - y0 if copysign(1., x0 * dx + y0 * dy) != copysign(1., x1 * dx + y1 * dy): res.append(abs(x0 * y1 - x1 * y0) / hypot(dx, dy)) x0, y0 = x1, y1 print((max(res) ** 2 - min(res) ** 2) * pi) if __name__ == '__main__': main() ```
output
1
27,894
23
55,789
Provide tags and a correct Python 3 solution for this coding contest problem. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him. Input The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value. Output Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 0 0 0 1 -1 2 1 2 Output 12.566370614359172464 Input 4 1 -1 0 0 1 2 2 0 1 1 Output 21.991148575128551812 Note In the first sample snow will be removed from that area: <image>
instruction
0
27,895
23
55,790
Tags: binary search, geometry, ternary search Correct Solution: ``` def dot_product(v1, v2): return v1.x * v2.x + v1.y * v2.y class vector: def __init__(self, x, y): self.x = x self.y = y def length(self): return (self.x ** 2 + self.y ** 2) ** 0.5 def cross_product(self, v): return self.x * v.y - self.y * v.x class line: def __init__(self, a, b): self.a = a self.b = b def distance(self, p): return abs(vector(p.x - self.a.x, p.y - self.a.y).cross_product(vector(p.x - self.b.x, p.y - self.b.y)) / vector(self.a.x - self.b.x, self.a.y - self.b.y).length()) class ray: def __init__(self, a, b): self.a = a self.b = b def distance(self, p): if dot_product(vector(self.b.x - self.a.x, self.b.y - self.a.y), vector(p.x - self.a.x, p.y - self.a.y)) >= 0: return line(self.a, self.b).distance(p) return vector(self.a.x - p.x, self.a.y - p.y).length() class segment: def __init__(self, a, b): self.a = a self.b = b def min_distance(self, p): if dot_product(vector(self.b.x - self.a.x, self.b.y - self.a.y), vector(p.x - self.a.x, p.y - self.a.y)) >= 0: return ray(self.b, self.a).distance(p) return vector(self.a.x - p.x, self.a.y - p.y).length() def max_distance(self, p): return max(vector(self.a.x - p.x, self.a.y - p.y).length(), vector(self.b.x - p.x, self.b.y - p.y).length()) n, x, y = map(int, input().split()) p = vector(x, y) min_r = 2000000 max_r = 0 a = [[] for i in range(n + 1)] for i in range(n): a[i] = list(map(int, input().split())) a[i] = vector(a[i][0], a[i][1]) a[n] = a[0] for i in range(n): s = segment(a[i], a[i + 1]) min_r = min(min_r, s.min_distance(p)) max_r = max(max_r, s.max_distance(p)) pi = 3.141592653589 print(pi * max_r ** 2 - pi * min_r ** 2) ```
output
1
27,895
23
55,791
Provide tags and a correct Python 3 solution for this coding contest problem. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him. Input The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value. Output Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 0 0 0 1 -1 2 1 2 Output 12.566370614359172464 Input 4 1 -1 0 0 1 2 2 0 1 1 Output 21.991148575128551812 Note In the first sample snow will be removed from that area: <image>
instruction
0
27,896
23
55,792
Tags: binary search, geometry, ternary search Correct Solution: ``` def main(): n, a, b = map(int, input().split()) l, res = [], [] for _ in range(n): u, v = input().split() l.append((int(u) - a, int(v) - b)) x0, y0 = l[-1] for x1, y1 in l: res.append(x1 * x1 + y1 * y1) dx, dy = x1 - x0, y1 - y0 if (x0 * dx + y0 * dy) * (x1 * dx + y1 * dy) < 0: x0 = x0 * y1 - x1 * y0 res.append(x0 * x0 / (dx * dx + dy * dy)) x0, y0 = x1, y1 print((max(res) - min(res)) * 3.141592653589793) if __name__ == '__main__': main() ```
output
1
27,896
23
55,793
Provide tags and a correct Python 3 solution for this coding contest problem. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him. Input The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value. Output Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 0 0 0 1 -1 2 1 2 Output 12.566370614359172464 Input 4 1 -1 0 0 1 2 2 0 1 1 Output 21.991148575128551812 Note In the first sample snow will be removed from that area: <image>
instruction
0
27,897
23
55,794
Tags: binary search, geometry, ternary search Correct Solution: ``` import math def dot(v1, v2): return v1[0]*v2[0] + v1[1]*v2[1] def cross(v1, v2): return v1[0]*v2[1] - v1[1]*v2[0] def mag(x,y): return math.sqrt(x**2 + y**2) def main(): PI = 3.141592653589793 mags = [] n, x0, y0 = map(int, input().split()) x, y = x0, y0 for i in range(n): x_, y_ = map(int, input().split()) x_, y_ = x_ - x0, y_ - y0 if i == 0: x1, y1 = x_ , y_ x, y = x_, y_ mags.append(mag(x_,y_)) if dot([x,y],[x-x_, y-y_])*dot([x_,y_],[x_-x,y_-y]) > 0: mags.append(abs(cross([x,y],[x_-x,y_-y])) / mag(x-x_,y-y_)) x, y = x_, y_ if dot([x,y],[x-x1,y-y1])*dot([x1,y1],[x1-x,y1-y]) > 0: mags.append(abs(cross([x,y],[x1-x,y1-y])) / mag(x-x1,y-y1)) print((max(mags)**2 - min(mags)**2) * PI) if __name__ == '__main__': main() ```
output
1
27,897
23
55,795
Provide tags and a correct Python 3 solution for this coding contest problem. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him. Input The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value. Output Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 0 0 0 1 -1 2 1 2 Output 12.566370614359172464 Input 4 1 -1 0 0 1 2 2 0 1 1 Output 21.991148575128551812 Note In the first sample snow will be removed from that area: <image>
instruction
0
27,898
23
55,796
Tags: binary search, geometry, ternary search Correct Solution: ``` __author__ = 'vboldovs' #A613 import math GLOBAL_INNER_PRODUCT_LIMIT = math.pow(10,-3) class point: def __init__(self,x,y): self.x = x self.y = y class line: def __init__(self,start_point, end_point): self.x = end_point.x - start_point.x self.y = end_point.y - start_point.y def distance(p1,p2): return math.sqrt(math.pow(p1.x-p2.x,2)+math.pow(p1.y-p2.y,2)) def product(line1,line2): return line1.x*line2.x+line1.y*line2.y m = input().split() n = int(m[0]) center = point(int(m[1]), int(m[2])) points = [] for _i in range(n): temp = input().split() points.append(point(int(temp[0]),int(temp[1]))) max_r = distance(center,points[0]) min_r = max_r for p in points: d = distance(p,center) max_r = max(max_r,d) min_r = min(min_r,d) for i in range(n): s_point = points[i] try: e_point = points[i+1] except IndexError: e_point = points[0] curr_line = line(s_point,e_point) prod_s = product(curr_line,line(s_point,center)) prod_e = product(curr_line,line(e_point,center)) if prod_s*prod_e>0: continue alpha = prod_s/abs(prod_e-prod_s) p_point = point((1-alpha)*s_point.x+alpha*e_point.x,(1-alpha)*s_point.y+alpha*e_point.y) min_r = min(min_r, distance(p_point,center)) #alpha = 0.5 #while True: # test_point = point((1-alpha)*s_point.x+alpha*e_point.x,(1-alpha)*s_point.y+alpha*e_point.y) # prod = product(line(test_point,center),curr_line) # # if abs(prod) <= GLOBAL_INNER_PRODUCT_LIMIT: # min_r = min(min_r,distance(test_point,center)) # break # if prod > GLOBAL_INNER_PRODUCT_LIMIT: # alpha+=alpha/2 # else: # alpha-=alpha/2 print(math.pi*math.pow(max_r,2)-math.pi*math.pow(min_r,2)) ```
output
1
27,898
23
55,797