message
stringlengths
2
45.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
254
108k
cluster
float64
3
3
__index_level_0__
int64
508
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
instruction
0
106,414
3
212,828
Tags: math Correct Solution: ``` sa=int(input()) mod=10**9+7 if sa==0: print(1) else: print((pow(2, 2*sa-1, mod)+pow(2, sa-1, mod))%mod) ```
output
1
106,414
3
212,829
Provide tags and a correct Python 3 solution for this coding contest problem. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
instruction
0
106,415
3
212,830
Tags: math Correct Solution: ``` n,m=int(input()),1000000007 n=pow(2,n,m) print((((n%m)*((n+1)%m))//2)%m) ```
output
1
106,415
3
212,831
Provide tags and a correct Python 3 solution for this coding contest problem. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
instruction
0
106,416
3
212,832
Tags: math Correct Solution: ``` def cal_pow(a, b): if b == 0: return 1 res = cal_pow(a, b // 2) res = res * res % 1000000007 if b % 2 == 1: res = (res * a) % 1000000007 return res n = int(input()) res = cal_pow(2, n) print(((res * (res + 1) // 2)) % 1000000007) ```
output
1
106,416
3
212,833
Provide tags and a correct Python 3 solution for this coding contest problem. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
instruction
0
106,417
3
212,834
Tags: math Correct Solution: ``` n = pow(2, int(input()), int(1e9 + 7)) print(((n + 1) // 2 * n + (n // 2, 0)[n % 2]) % int(1e9 + 7)) ```
output
1
106,417
3
212,835
Provide tags and a correct Python 3 solution for this coding contest problem. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
instruction
0
106,418
3
212,836
Tags: math Correct Solution: ``` import math MOD = 1000000007 def mod_inverse(b,m): g = math.gcd(b, m) if (g != 1): return -1 else: return pow(b, m - 2, m) def div_mod(a,b,m): a = a % m inv = mod_inverse(b,m) if(inv == -1): return None else: return (inv*a) % m def sum_mod(a, b): return (a + b) % MOD def fast_power(base, power): result = 1 while power > 0: if power % 2 == 1: result = (result * base) % MOD power = power // 2 base = (base * base) % MOD return result years = int(input()) fst = fast_power(4, years) snd = fast_power(2, years) sum_num = sum_mod(fst, snd) out = div_mod(sum_num, 2, MOD) print(out) ```
output
1
106,418
3
212,837
Provide tags and a correct Python 3 solution for this coding contest problem. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
instruction
0
106,419
3
212,838
Tags: math Correct Solution: ``` def fstexp(x,y): if (y<=1): return x**y%1000000007 if (y%2==1): return ((((fstexp(x,y//2)%1000000007)**2)%1000000007)*(x%1000000007))%1000000007 return (((fstexp(x,y//2)%1000000007)**2)%1000000007) x=int(input()) x=fstexp(2,x) x=x%1000000007 print(int((((x**2)+x)//2)%1000000007)) ```
output
1
106,419
3
212,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` n = int(input()) res = pow(2, n, 1000000007) print((res+1)*res//2 % 1000000007) ```
instruction
0
106,420
3
212,840
Yes
output
1
106,420
3
212,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` n=int(input()) mod=1000000007 if n==0: print(1) else: print ((pow(2,n-1,mod))*(pow(2,n,mod)+1)%mod) ```
instruction
0
106,421
3
212,842
Yes
output
1
106,421
3
212,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` n = int(input()) if n == 0: print(1) else: print(((2 * pow(4, n - 1, 1000000007)) + pow(2, n - 1, 1000000007)) % 1000000007) ```
instruction
0
106,422
3
212,844
Yes
output
1
106,422
3
212,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` n = int(input()) x = pow(2, n-1, 1000000007) y = (pow(2, n, 1000000007) + 1) % 1000000007 a = (x * y) % 1000000007 print(a) ```
instruction
0
106,423
3
212,846
Yes
output
1
106,423
3
212,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` mod = 1000000007 n = int(input()) h = pow(2, n, mod) print(((h) * (h + 1) % mod)//2) ```
instruction
0
106,424
3
212,848
No
output
1
106,424
3
212,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` n=int(input()) print(n*(2*n+1)) ```
instruction
0
106,425
3
212,850
No
output
1
106,425
3
212,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` MOD = 1000000007 def divide_mod(a, b): return int((a / b) % MOD) def fast_power(base, power): """ Returns the result of a^b i.e. a**b We assume that a >= 1 and b >= 0 Remember two things! - Divide power by 2 and multiply base to itself (if the power is even) - Decrement power by 1 to make it even and then follow the first step """ result = 1 while power > 0: # If power is odd if power % 2 == 1: result = (result * base) % MOD # Divide the power by 2 power = power // 2 # Multiply base to itself base = (base * base) % MOD return result years = int(input()) fst = fast_power(4, years) snd = fast_power(2, years) out = divide_mod((fst + snd), 2) # for _ in range(years): # up_partial = up # down_partial = down # up = up_partial * 3 - up_partial # down = down_partial * 3 - down_partial # down += up_partial # up += down_partial # print(up, down) print(out) ```
instruction
0
106,426
3
212,852
No
output
1
106,426
3
212,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. <image> Help the dwarfs find out how many triangle plants that point "upwards" will be in n years. Input The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). Examples Input 1 Output 3 Input 2 Output 10 Note The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. Submitted Solution: ``` def pow(x,y): if y == 0: return 1 elif y % 2 == 0: return ((pow(x, y // 2) ** 2)) % (10 ** 9 + 7) else: return (pow(x, y - 1) * x) % (10 ** 9 + 7) n = int(input()) print(((pow(2,n)+pow(4,n)) // 2) % (10 ** 9 + 7)) ```
instruction
0
106,427
3
212,854
No
output
1
106,427
3
212,855
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,574
3
213,148
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` n,x,y = map(int, input().split()) a = [] for i in range(n): x1, y1, = map(int, input().split()) a.append((x1,y1)) d = set() for p, q in a: x2, y2 = p-x, q-y found = False for x1, y1 in d: if x1*y2 == x2*y1: found = True break if not found: d.add((x2,y2)) print(len(d)) ```
output
1
106,574
3
213,149
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,575
3
213,150
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` def calc_slope(p1, p2): dy = p2[1] - p1[1] dx = p2[0] - p1[0] if dx == 0: return "vertical" #if dy > 0: # return "+y" #else: # return "-y" #if dy == 0: # if dx > 0: # return "+x" # else: # return "-x" return dy / dx #slope = dy / dx #if slope < 0: # slope *= -1 #return slope def calc_shots(origin, st): slopes = {} vertical = 0 for s in st: slope = calc_slope(origin, s) #dy = s[1] - origin[1] #dx = s[0] - origin[0] #if dx == 0: # vertical = 1 #else: # slope = abs(dy/dx) # slopes[slope] = True if slope in slopes.keys(): slopes[slope] += 1 else: slopes[slope] = 1 #print("slopes: " + str(slopes)) return len(slopes.keys())# + vertical def main(): num_st, o_x, o_y = input().strip().split(' ') num_st, o_x, o_y = int(num_st), int(o_x), int(o_y) origin = (o_x, o_y) st = [] for s in range(num_st): x, y = input().strip().split(' ') x, y = int(x), int(y) if not (x == origin[0] and y == origin[1]): st.append((x, y)) num_shots = calc_shots(origin, st) print(str(num_shots)) main() ```
output
1
106,575
3
213,151
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,576
3
213,152
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` n, x1, y1 = [int(s) for s in input().split()] slope = {} shoot=0 for i in range(n): x2,y2=[int(s) for s in input().split()] if(x2-x1)==0: m="a" else: m = (y2-y1)/(x2-x1) if m not in slope: shoot+=1 slope[m] = 0 print(shoot) ```
output
1
106,576
3
213,153
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,577
3
213,154
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` from math import * n,gx,gy = map(int,input().split()) pts = [tuple(map(int,input().split())) for _ in range(n)] vis = [1]*n def ccw(g,p,q): return (p[0]-g[0])*(q[1]-g[1])-(p[1]-g[1])*(q[0]-g[0]) for i in range(n): if vis[i]: for j in range(i+1,n): if vis[j] and not ccw((gx,gy),pts[i],pts[j]): vis[j] = 0 print(sum(vis)) # C:\Users\Usuario\HOME2\Programacion\ACM ```
output
1
106,577
3
213,155
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,578
3
213,156
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` read = lambda : list(map(int, input().split())) params = read() n, x, y = params[0], params[1], params[2] slopes = set() for i in range(n): point = read() diffx = (point[0] - x) diffy = (point[1] - y) if diffx == 0: slope = "inf" elif diffy == 0: slope = "0" else: slope = str(diffy / diffx) slopes.add(slope) print(len(slopes)) ```
output
1
106,578
3
213,157
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,579
3
213,158
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` a,b,c=map(int,input().split()) l=set() for __ in range(a): x,y=map(int,input().split()) if b-x==0: z=100001 else: z=(c-y)/(b-x) l.add(z) print(len(l)) ```
output
1
106,579
3
213,159
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,580
3
213,160
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` n,x,y=map(int,input().split()) d={} for i in range(n): a,b=map(int,input().split()) if y-b==0: d['i']=0 else: d[(x-a)/(y-b)]=0 print(len(d.keys())) ```
output
1
106,580
3
213,161
Provide tags and a correct Python 3 solution for this coding contest problem. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image>
instruction
0
106,581
3
213,162
Tags: brute force, data structures, geometry, implementation, math Correct Solution: ``` n,x0,y0=map(int,input().split()) d={} for i in range(n): x,y=map(int,input().split()) d[(x,y)]=1 ans=0 for i in d: if d[i]==1: x1=i[0] y1=i[1] if y0-y1==0: m1=float('inf') else: m1=(x0-x1)/(y0-y1) for j in d: x2=j[0] y2=j[1] if y0-y2==0: m2=float('inf') else: m2=(x0-x2)/(y0-y2) if m2==m1: d[j]=0 ans+=1 print(ans) ```
output
1
106,581
3
213,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) ilelec = lambda: map(int1,input().split()) alelec = lambda: list(map(int1, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) n,x,y = ilele() G = defaultdict(list) for i in range(n): a,b = ilele() c = a - x d = b - y if d == 0: G['inf'] = 1 else: G[c/d] = 1 print(len(G)) ```
instruction
0
106,582
3
213,164
Yes
output
1
106,582
3
213,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` n,x,y=map(int,input().split()) s=set() f=0 for i in range(n): x1,y1=map(int,input().split()) if x1!=x: m=(y1-y)/(x1-x) s.add(m) else: f=1 if f==0: print(len(s)) else: print(len(s)+1) ```
instruction
0
106,583
3
213,166
Yes
output
1
106,583
3
213,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` from collections import defaultdict n, x1, y1 = map(int, input().split()) cnt = 0 points = [] # O(n) for _ in range(n): x, y = map(int, input().split()) points.append((x, y)) for i in range(n): x2, y2 = points[i] if x2 == x1 and y2 == y1: continue cnt += 1 for j in range(n): if i == j: continue x3, y3 = points[j] if (x2 - x1) * (y3 - y1) == (x3 - x1) * (y2 - y1): points[j] = (x1, y1) points[i] = (x1, y1) print(cnt) ```
instruction
0
106,584
3
213,168
Yes
output
1
106,584
3
213,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` n, x0, y0 = map(int, input().split()) arr = [] for _ in range(n): x, y = map(int, input().split()) s = (y-y0) / (x-x0) if x != x0 else "Inf" if not s in arr: arr.append(s) print(len(arr)) ```
instruction
0
106,585
3
213,170
Yes
output
1
106,585
3
213,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` n,x0,y0=list(map(int,input().split())) b=[] for i in range(n): x,y=map(int,input().split()) if (x-x0)!=0: t1=(y-y0)/(x-x0) elif (y-y0)==0: t1=y else: t1=x if t1<0: t1=t1*(-1) if t1 not in b: b.append(t1) print(len(b)) ```
instruction
0
106,586
3
213,172
No
output
1
106,586
3
213,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return [str(x) for x in stdin.readline().split()] from sys import stdin arr = [0] * 4 n, x0, y0 = arr_inp(1) for i in range(n): x, y = arr_inp(1) if x == x0: arr[0] += 1 elif y == y0: arr[1] += 1 elif abs(x - y) == abs(x0 - y0): arr[2] += 1 else: arr[3] += 1 arr.sort(reverse=True) print(len(list(filter(lambda x: x, arr)))) ```
instruction
0
106,587
3
213,174
No
output
1
106,587
3
213,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` n,x,y=map(int,input().split()) s=set() for i in range(n): a,b=map(int,input().split()) if b-y!=0: s.add((a-x)/(b-y)) else: float("INF") print(len(s)) ```
instruction
0
106,588
3
213,176
No
output
1
106,588
3
213,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Examples Input 4 0 0 1 1 2 2 2 0 -1 -1 Output 2 Input 2 1 2 1 1 1 0 Output 1 Note Explanation to the first and second samples from the statement, respectively: <image> Submitted Solution: ``` import math from decimal import * if __name__ == '__main__': getcontext().prec = 28 n, x, y = map(int, input().split()) troopers = set() for _ in range(n): tx, ty = map(int, input().split()) if tx == x and ty == y: continue troopers.add((tx, ty)) if not troopers: print(1) exit(0) unit_vecs = set() for t in troopers: u_x = Decimal(t[0] - x) u_y = Decimal(t[1] - y) vec_len = (Decimal(int(u_x)) ** 2 + Decimal(int(u_y)) ** 2).sqrt() u_x /= vec_len u_y /= vec_len unit_vecs.add((u_x, u_y)) dups = 0 for a, b in unit_vecs: if (-a, -b) in unit_vecs: dups += 1 print(len(unit_vecs) - dups // 2) ```
instruction
0
106,589
3
213,178
No
output
1
106,589
3
213,179
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,897
3
213,794
"Correct Solution: ``` import math temp=input().split() N=int(temp[0]) L=int(temp[1]) T=int(temp[2]) XW=[[int(j) for j in input().split()] for i in range(N)] count=0 for i in range(N): if XW[i][1]==1: XW[i][0]+=T else: XW[i][0]-=T count+=math.floor(XW[i][0]/L) # # if XW[0][1]==1: # for i in range(1,N): # if XW[i][0]<XW[0][0]: # count+=int((XW[0][0]-XW[i][0])/L)+1 # else: # for i in range(1,N): # if XW[i][0]>XW[0][0]: # count+=int((XW[i][0]-XW[0][0])/L)+1 #print(count) #print(len()) newX=[] for i in range(N): newX.append(XW[i][0]%L) newX.sort() #print(newX) for i in range(N): print(newX[(i+count)%N]%L) ```
output
1
106,897
3
213,795
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,898
3
213,796
"Correct Solution: ``` import math temp=input().split() N=int(temp[0]) L=int(temp[1]) T=int(temp[2]) XW=[[int(j) for j in input().split()] for i in range(N)] count=0 for i in range(N): if XW[i][1]==1: XW[i][0]+=T else: XW[i][0]-=T count+=math.floor(XW[i][0]/L) newX=[] for i in range(N): newX.append(XW[i][0]%L) newX.sort() #print(newX) for i in range(N): print(newX[(i+count)%N]%L) ```
output
1
106,898
3
213,797
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,899
3
213,798
"Correct Solution: ``` # C N, L, T = map(int, input().split()) X = list() W = list() positions = list() for _ in range(N): x, w = map(int, input().split()) X.append(x) W.append(w) if w == 1: positions.append((x + T) % L) else: positions.append((x - T) % L) # find which is the position cnt_conf = 0 if W[0] == 1: for i in range(N): if W[i] != W[0]: cnt_conf += (2*T - (X[i] - X[0])) // L + 1 n0 = cnt_conf % N p0 = (X[0] + T) % L else: for i in range(N): if W[i] != W[0]: cnt_conf += (2*T - (X[0] + L - X[i])) // L + 1 n0 = -cnt_conf % N p0 = (X[0] - T) % L positions.sort() # find index if W[0] == 1: num = max([n for n in range(N) if positions[n]==p0]) else: num = min([n for n in range(N) if positions[n]==p0]) for i in range(N): print(positions[(num - n0 + i) % N]) ```
output
1
106,899
3
213,799
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,900
3
213,800
"Correct Solution: ``` import bisect n, l, t = map(int, input().split()) plots = [] plots_after = [] for i in range(n): x, w = map(int, input().split()) plots.append((x, w, i)) if w == 1: plots_after.append((x+t) % l) else: plots_after.append((x-t) % l) x0, w0, _ = plots[0] if w0 == 1: cnt = 0 for i in range(1, n): xi, wi, _ = plots[i] if wi == 2: cnt += max(0, (2 * t - (xi - x0)) // l + 1) cnt %= n plots_after.sort() x_after = (x0 + t) % l idx = bisect.bisect_right(plots_after, x_after)-1 for i in range(n): print(plots_after[(i-cnt+idx) % n]) else: cnt = 0 for i in range(1, n): xi, wi, _ = plots[i] if wi == 1: cnt -= max(0, (2 * t - (l - xi + x0)) // l + 1) cnt %= n plots_after.sort() x_after = (x0 - t) % l idx = bisect.bisect_left(plots_after, x_after) for i in range(n): print(plots_after[(i-cnt+idx) % n]) ```
output
1
106,900
3
213,801
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,901
3
213,802
"Correct Solution: ``` import sys def input(): return sys.stdin.readline() def inpl(): return [int(i) for i in input().split()] N, L, T = inpl() Ant = [] ctr = 0 for _ in range(N): X, W = inpl() Ant.append((X + T*(3-2*W))%L) ctr += (X + T*(3-2*W))//L Ant.sort() ctr %= N ans = Ant[ctr:] + Ant[:ctr] for i in ans: print(i) ```
output
1
106,901
3
213,803
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,902
3
213,804
"Correct Solution: ``` from collections import deque n, l, t = map(int, input().split()) ants = [list(map(int, input().split())) for i in range(n)] # print(ants) ants_t = [] count = 0 for ant in ants: ant_t = ant if ant[1] == 1: c, ant_t[0] = divmod(t + ant[0], l) # count += c else: c, ant_t[0] = divmod(-t + ant[0], l) # count -= c ants_t.append(ant_t) count += c # print(ants_t, count) ants_d = deque(sorted(ants_t)) # print(ants_d) # if ants_d[0][1] == 1: # ants_d.rotate(count) # else: # ants_d.rotate(-count) ants_d.rotate(-count) # print(ants_d) for ant in ants_d: print( (ant[0]) % l ) ```
output
1
106,902
3
213,805
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,903
3
213,806
"Correct Solution: ``` import sys input = sys.stdin.readline n, l, t = map(int, input().split()) XW = [list(map(int, input().split())) for _ in range(n)] L = [] cnt = 0 for i, xw in enumerate(XW): x, w = xw L.append((x+t*(3-2*w))%l) cnt += (x+t*(3-2*w))//l L.sort() for i in range(cnt, cnt+n): print(L[i%n]) ```
output
1
106,903
3
213,807
Provide a correct Python 3 solution for this coding contest problem. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1
instruction
0
106,904
3
213,808
"Correct Solution: ``` import sys input = sys.stdin.buffer.readline N, L, T= map(int,input().split()) X = [] W = [] for i in range(N): x,w = map(int,input().split()) X.append(2*x) W.append(2*(1-w)+1) pos = [((x+2*T*w) % (2*L))//2 for x,w in zip(X,W)] meet = 0 for i in range(1,N): if W[0] != W[i]: if W[0] == 1: R = 2*T - (X[i] - X[0])//2 else: R = 2*T - (2*L - (X[i] - X[0]))//2 if R >= 0: meet += 1 + R//L M = (meet * W[0]) % N aM_pos = pos[0] pos.sort() aM_idx = pos.index(aM_pos) if pos.count(aM_pos) == 2 and W[0] == 1: aM_idx += 1 a0_idx = (aM_idx-M) % N ans = pos[a0_idx:]+pos[:a0_idx] for ant in ans: print(ant) ```
output
1
106,904
3
213,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` N, L, T = map(int, input().split()) X = [0] * N W = [0] * N for i in range(N): X[i], W[i] = map(int, input().split()) res = [0] * N c = 0 for i in range(N): if W[i] == 1: res[i] = (X[i] + T) % L c += (X[i] + T) // L else: res[i] = (X[i] - T) % L c += (X[i] - T) // L res = sorted(res) c = c % N res = res[c:] + res[:c] print(*[ans for ans in res], sep='\n') ```
instruction
0
106,905
3
213,810
Yes
output
1
106,905
3
213,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` n, l, t = map(int,input().split()) c = [] s = 0 for i in range(n): x, w = map(int,input().split()) if w == 1: c.append((x+t)%l) s += (x+t)//l else: # w == 2 c.append((x-t)%l) s += (x-t)//l c.sort() s %= n c = c[s:] + c[:s] print(*[i for i in c], sep='\n') ```
instruction
0
106,906
3
213,812
Yes
output
1
106,906
3
213,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` N, L, T = map(int, input().split()) gap = 0 X = [0] * N for i in range(N): x, w = map(int, input().split()) x += ((w + 1) % 3 - 1) * T gap += x // L gap %= N X[i] = x % L X.sort() for i in range(N): print(X[(i+gap) % N]) ```
instruction
0
106,907
3
213,814
Yes
output
1
106,907
3
213,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` from bisect import bisect n, l, t = map(int, input().split()) ants = [list(map(int, input().split())) for _ in range(n)] bnts = [] diff = [] for i in range(n): x, w = ants[i][0], 3 - 2*ants[i][1] bnts.append((x + t*w) % l) if i == 0: zero = bnts[-1] if ants[i][1] != ants[0][1]: if ants[0][1] == 1: diff.append(x - ants[0][0]) else: diff.append(l - (x - ants[0][0])) bnts.sort() num = 0 quo, mod = t//l, t%l num += quo * len(diff) * 2 diff.sort() diff += [d+l for d in diff] num += bisect(diff, mod*2) num %= n for i in range(n): if bnts[i] == zero: if ants[0][1] == 1: true_zero = (i-num) % n else: if i < n-1: if bnts[i+1] == zero: num -= 1 true_zero = (i+num) % n ans = bnts[true_zero:] + bnts[:true_zero] print(*ans, sep="\n") ```
instruction
0
106,908
3
213,816
Yes
output
1
106,908
3
213,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, L, T = map(int, input().split()) T %= L X = [] W = [] for _ in range(N): x, w = map(int, input().split()) X.append(x) W.append(w) if N == 1: if W[0] == 1: print((X[0] + T)%L) else: print((X[0] - T)%L) exit() Y = [] for i in range(N): if W[i] == 1: Y.append(((X[i] + T)%L, 1)) else: Y.append(((X[i] - T)%L, 2)) Y.sort(key=lambda p: p[0]) if W[0] == 1: y0 = (X[0] + T)%L for i in range(N): if Y[i][0] == y0: i0 = i break S = 0 i = i0 idx = 0 while True: i = (i+1)%N S += (Y[i][0] - Y[i-1][0])%L if S > T*2: break if W[i] == 2: idx = (idx+1)%N ans = [0] * N for i in range(N): ans[(idx+i)%N] = Y[(i0+i)%N][0] else: y0 = (X[0] - T) % L for i in range(N-1, -1, -1): if Y[i][0] == y0: i0 = i break S = 0 i = i0 idx = 0 while True: i = (i - 1) % N S += (Y[i][0] - Y[(i+1)%N][0])%L if S > T * 2: break if W[i] == 1: idx = (idx - 1)%N ans = [0] * N for i in range(N): ans[(idx + i) % N] = Y[(i0+i)%N][0] for a in ans: print(a) if __name__ == '__main__': main() ```
instruction
0
106,909
3
213,818
No
output
1
106,909
3
213,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` import numpy as np import sys N, L, T = map(int, input().split()) I = np.array(sys.stdin.read().split(), np.int64) X = I[::2] W = I[1::2] W[np.where(W==2)] = -1 P = (X + T*W) % L #1の蟻の場所を調べるために、なんか1がすれ違うかを考える #1の蟻と反対向きに動く蟻は停止させて、1の蟻の速度を2にして考える。 cond = 1 if W[0] == -1: W *= -1 X = (L-X)%L cond = 0 lap, over = divmod(2*T,L) anti_aunt_ind = np.where(W == -1) anti_aunt = X[anti_aunt_ind] encount = lap*len(anti_aunt) + np.searchsorted(anti_aunt, over, side = 'left') if cond: no = 1 + (encount%N) else: no = (N - (encount-1))%N ans = np.concatenate([P[N-no+1:],P[:N-no+1]]) for a in ans: print(a) ```
instruction
0
106,910
3
213,820
No
output
1
106,910
3
213,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` # AGC C Ants on a Circle f=lambda:map(int,input().split()) N,L,T=f() X,W=[],[] for _ in [0]*N: x,w=f() X.append(x) W.append(w) if W[0]==2: X[0]+=L col=0 for j in range(N): if W[j]==W[0]: continue else: if W[0]>0: if 2*T-(X[j]-X[0])>=0: col+=1+(2*T-(X[j]-X[0]))//L else: col+=0 else: col-=max((2*T-X[j]+X[0])//L,0) col=col%N X2=[(X[i]+(3-2*W[i])*(T-0.01)) % L for i in range(N)] ant0=(X2[0],col) X2.sort() x=X2.index(ant0[0]) for i in range(x-col-N,x-col): print(round(X2[i])) ```
instruction
0
106,911
3
213,822
No
output
1
106,911
3
213,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i. The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction. For each ant, find its position after T seconds. Constraints * All input values are integers. * 1 \leq N \leq 10^5 * 1 \leq L \leq 10^9 * 1 \leq T \leq 10^9 * 0 \leq X_1 < X_2 < ... < X_N \leq L - 1 * 1 \leq W_i \leq 2 Input The input is given from Standard Input in the following format: N L T X_1 W_1 X_2 W_2 : X_N W_N Output Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive. Examples Input 3 8 3 0 1 3 2 6 1 Output 1 3 0 Input 4 20 9 7 2 9 1 12 1 18 1 Output 7 18 18 1 Submitted Solution: ``` # アリ1からNまでの前後関係は不変。つまり、アリ1からNまでの順番は保たれる。 # アリの最終座標の昇順リストを用意して、アリ1からNに対応させればよい。 n,l,t=map(int,input().split()) x=[] w=[] ans=[] crash=0 for i in range(n): xx,ww=map(int,input().split()) x.append(xx); w.append(ww) if w[i]==1: anss=(x[i]+t)%l else: anss=(x[i]-t+l)%l ans.append(anss) if i!=0 and w[i] != w[0]: if w[0] == 1: crash += (t-((x[i]-x[0])/2)) // (l/2) + 1 else: crash += (t-(l-(x[i]-x[0]))/2) // (l/2) + 1 # あり1の現在のゼッケン番号num0 if w[0]==1: num0 =int(crash)%n else: num0 =int(-crash)%n # あり1の現在地点に対応する昇順リストの番号num nowplace = ans[0] ans.sort() num = ans.index(nowplace) if w[0]==1 and ans.count(nowplace)==2: num += 1 # 2つ該当する場合の処理 # numがnum0の位置であるように調整したい gap = num0-num for i in range(n): i = (i+gap)%n print(ans[i]) print(ans) ```
instruction
0
106,912
3
213,824
No
output
1
106,912
3
213,825
Provide tags and a correct Python 3 solution for this coding contest problem. After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n power sources, and the second one has m power sources. A power source can be described as a point (x_i, y_i) on a 2-D plane. All points in each engine are different. You can manipulate each engine separately. There are two operations that you can do with each engine. You can do each operation as many times as you want. 1. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i+a, y_i+b), a and b can be any real numbers. In other words, all power sources will be shifted. 2. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i cos θ - y_i sin θ, x_i sin θ + y_i cos θ), θ can be any real number. In other words, all power sources will be rotated. The engines work as follows: after the two engines are powered, their power sources are being combined (here power sources of different engines may coincide). If two power sources A(x_a, y_a) and B(x_b, y_b) exist, then for all real number k that 0 < k < 1, a new power source will be created C_k(kx_a+(1-k)x_b,ky_a+(1-k)y_b). Then, this procedure will be repeated again with all new and old power sources. After that, the "power field" from all power sources will be generated (can be considered as an infinite set of all power sources occurred). A supersonic rocket is "safe" if and only if after you manipulate the engines, destroying any power source and then power the engine, the power field generated won't be changed (comparing to the situation where no power source erased). Two power fields are considered the same if and only if any power source in one field belongs to the other one as well. Given a supersonic rocket, check whether it is safe or not. Input The first line contains two integers n, m (3 ≤ n, m ≤ 10^5) — the number of power sources in each engine. Each of the next n lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the first engine. Each of the next m lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the second engine. It is guaranteed that there are no two or more power sources that are located in the same point in each engine. Output Print "YES" if the supersonic rocket is safe, otherwise "NO". You can print each letter in an arbitrary case (upper or lower). Examples Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 1 1 Output YES Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 0 0 Output NO Note The first sample: <image> Those near pairs of blue and orange points actually coincide. First, manipulate the first engine: use the second operation with θ = π (to rotate all power sources 180 degrees). The power sources in the first engine become (0, 0), (0, -2), and (-2, 0). <image> Second, manipulate the second engine: use the first operation with a = b = -2. The power sources in the second engine become (-2, 0), (0, 0), (0, -2), and (-1, -1). <image> You can examine that destroying any point, the power field formed by the two engines are always the solid triangle (0, 0), (-2, 0), (0, -2). In the second sample, no matter how you manipulate the engines, there always exists a power source in the second engine that power field will shrink if you destroy it.
instruction
0
107,026
3
214,052
Tags: geometry, hashing, strings Correct Solution: ``` import sys # > 0 anti-clock, < 0 clockwise, == 0 same line def orientation(p1, p2, p3): return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) def dot(p1, p2, p3, p4): return (p2[0]-p1[0])*(p4[0]-p3[0]) + (p2[1]-p1[1])*(p4[1]-p3[1]) def theta(p1, p2): dx = p2[0] - p1[0] dy = p2[1] - p1[1] if abs(dx) < 0.1 and abs(dy) < 0.1: t = 0 else: t = dy/(abs(dx) + abs(dy)) if abs(t) < 0.1 ** 10: t = 0 if dx < 0: t = 2 - t elif dy < 0: t = 4 + t return t*90 def dist_sq(p1, p2): return (p1[0] - p2[0])*(p1[0] - p2[0]) + (p1[1] - p2[1])*(p1[1] - p2[1]) def chull(points): # let 0 element to be smallest, reorder elements pi = [x for x in range(len(points))] min_y = points[0][1] min_x = points[0][0] min_ind = 0 for i in range(len(points)): if points[i][1] < min_y or points[i][1] == min_y and points[i][0] < min_x: min_y = points[i][1] min_x = points[i][0] min_ind = i pi[0] = min_ind pi[min_ind] = 0 th = [theta(points[pi[0]], points[x]) for x in range(len(points))] pi.sort(key=lambda x: th[x]) # process equals unique = [pi[0], pi[1]] for i in range(2, len(pi)): if th[pi[i]] != th[unique[-1]]: unique.append(pi[i]) else: if dist_sq(points[pi[0]], points[unique[-1]]) < dist_sq(points[pi[0]], points[pi[i]]): unique[-1] = pi[i] # put max pi = unique stack = [] for i in range(min(len(pi), 3)): stack.append(points[pi[i]]) if len(stack) < 3: return stack for i in range(3, len(pi)): while len(stack) >= 2: o = orientation(stack[-2], stack[-1], points[pi[i]]) if o > 0: stack.append(points[pi[i]]) break elif o < 0: stack.pop() else: # == if dist_sq(stack[-2], stack[-1]) < dist_sq(stack[-2], points[pi[i]]): stack.pop() else: break # skip i-th point return stack def z_func(s): slen, l, r = len(s), 0, 0 z = [0]*slen z[0] = slen for i in range(1, slen): if i <= r: z[i] = min(r-i+1, z[i-l]) while i+z[i] < slen and s[z[i]] == s[i+z[i]]: z[i] += 1 if i+z[i]-1 > r: l, r = i, i+z[i]-1 return z n,m = map(int, sys.stdin.readline().strip().split()) a = [] for _ in range(n): x,y = map(int, sys.stdin.readline().strip().split()) a.append((x, y)) b = [] for _ in range(m): x, y = map(int, sys.stdin.readline().strip().split()) b.append((x, y)) ah = chull(a) bh = chull(b) if len(ah) == len(bh): if len(ah) == 2: if dist_sq(ah[0], ah[1]) == dist_sq(bh[0], bh[1]): print('YES') else: print('NO') else: da = [] for i in range(len(ah)): dot_a = dot(ah[i-2], ah[i-1], ah[i-1], ah[i]) da.append((dist_sq(ah[i], ah[i-1]), dot_a)) db = [] for i in range(len(bh)): dot_b = dot(bh[i - 2], bh[i - 1], bh[i - 1], bh[i]) db.append((dist_sq(bh[i], bh[i-1]), dot_b)) l = r = 0 daab = [] daab.extend(db) daab.append(-1) daab.extend(da) daab.extend(da) zab = z_func(daab) found = False for i in range(len(db)+1, len(daab)-len(db)+1): if zab[i] == len(db): found = True break if found: print('YES') else: print('NO') else: print('NO') ```
output
1
107,026
3
214,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n power sources, and the second one has m power sources. A power source can be described as a point (x_i, y_i) on a 2-D plane. All points in each engine are different. You can manipulate each engine separately. There are two operations that you can do with each engine. You can do each operation as many times as you want. 1. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i+a, y_i+b), a and b can be any real numbers. In other words, all power sources will be shifted. 2. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i cos θ - y_i sin θ, x_i sin θ + y_i cos θ), θ can be any real number. In other words, all power sources will be rotated. The engines work as follows: after the two engines are powered, their power sources are being combined (here power sources of different engines may coincide). If two power sources A(x_a, y_a) and B(x_b, y_b) exist, then for all real number k that 0 < k < 1, a new power source will be created C_k(kx_a+(1-k)x_b,ky_a+(1-k)y_b). Then, this procedure will be repeated again with all new and old power sources. After that, the "power field" from all power sources will be generated (can be considered as an infinite set of all power sources occurred). A supersonic rocket is "safe" if and only if after you manipulate the engines, destroying any power source and then power the engine, the power field generated won't be changed (comparing to the situation where no power source erased). Two power fields are considered the same if and only if any power source in one field belongs to the other one as well. Given a supersonic rocket, check whether it is safe or not. Input The first line contains two integers n, m (3 ≤ n, m ≤ 10^5) — the number of power sources in each engine. Each of the next n lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the first engine. Each of the next m lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the second engine. It is guaranteed that there are no two or more power sources that are located in the same point in each engine. Output Print "YES" if the supersonic rocket is safe, otherwise "NO". You can print each letter in an arbitrary case (upper or lower). Examples Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 1 1 Output YES Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 0 0 Output NO Note The first sample: <image> Those near pairs of blue and orange points actually coincide. First, manipulate the first engine: use the second operation with θ = π (to rotate all power sources 180 degrees). The power sources in the first engine become (0, 0), (0, -2), and (-2, 0). <image> Second, manipulate the second engine: use the first operation with a = b = -2. The power sources in the second engine become (-2, 0), (0, 0), (0, -2), and (-1, -1). <image> You can examine that destroying any point, the power field formed by the two engines are always the solid triangle (0, 0), (-2, 0), (0, -2). In the second sample, no matter how you manipulate the engines, there always exists a power source in the second engine that power field will shrink if you destroy it. Submitted Solution: ``` import sys # > 0 anti-clock, < 0 clockwise, == 0 same line def orientation(p1, p2, p3): return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) def theta(p1, p2): dx = p2[0] - p1[0] dy = p2[1] - p1[1] if abs(dx) < 0.1**10 and abs(dy) < 0.1**10: t = 0 else: t = dy/(abs(dx) + abs(dy)) if dx < 0: t = 2 - t elif dy < 0: t = 4 + t return t*90 def dist_sq(p1, p2): return (p1[0] - p2[0])*(p1[0] - p2[0]) + (p1[1] - p2[1])*(p1[1] - p2[1]) def chull(points): # let 0 element to be smallest, reorder elements pi = [x for x in range(len(points))] min_y = points[0][1] min_ind = 0 for i in range(len(points)): if points[i][1] < min_y: min_y = points[i][1] min_ind = i pi[0] = min_ind pi[min_ind] = 0 th = [theta(points[pi[0]], points[x]) for x in range(len(points))] pi.sort(key=lambda x: th[x]) # process equals unique = [pi[0], pi[1]] for i in range(2, len(pi)): if th[pi[i]] != th[unique[-1]]: unique.append(pi[i]) else: if dist_sq(points[pi[0]], points[unique[-1]]) < dist_sq(points[pi[0]], points[pi[i]]): unique[-1] = pi[i] # put max pi = unique stack = [] for i in range(min(len(pi), 3)): stack.append(points[pi[i]]) if len(stack) < 3: return stack for i in range(3, len(pi)): while len(stack) >= 2: o = orientation(stack[-2], stack[-1], points[pi[i]]) if o > 0: stack.append(points[pi[i]]) break elif o < 0: stack.pop() else: # == if dist_sq(stack[-2], stack[-1]) < dist_sq(stack[-2], points[pi[i]]): stack.pop() else: break # skip i-th point return stack def z_func(s): slen, l, r = len(s), 0, 0 z = [0]*slen z[0] = slen for i in range(1, slen): if i <= r: z[i] = min(r-i+1, z[i-l]) while i+z[i] < slen and s[z[i]] == s[i+z[i]]: z[i] += 1 if i+z[i]-1 > r: l, r = i, i+z[i]-1 return z n,m = map(int, sys.stdin.readline().strip().split()) a = [] for _ in range(n): x,y = map(int, sys.stdin.readline().strip().split()) a.append((x, y)) b = [] for _ in range(m): x, y = map(int, sys.stdin.readline().strip().split()) b.append((x, y)) ah = chull(a) bh = chull(b) if len(ah) == len(bh): if len(ah) == 2: if dist_sq(ah[0], ah[1]) == dist_sq(bh[0], bh[1]): print('YES') else: print('NO') else: da = [] for i in range(len(ah)): da.append((dist_sq(ah[i], ah[i-1]), orientation(ah[i-2], ah[i-1], ah[i]))) db = [] for i in range(len(bh)): db.append((dist_sq(bh[i], bh[i - 1]), orientation(bh[i - 2], bh[i - 1], bh[i]))) l = r = 0 dab = [] dab.extend(da) dab.append(-1111) dab.extend(db) zab = z_func(dab) dba = [] dba.extend(db) dba.append(-1111) dba.extend(da) zba = z_func(dba) found = False for i in range(len(da)+1, len(dba)): if zab[i] == len(dba)-i: rem = len(da) - zab[i] if rem == 0 or zba[-rem] == rem: found = True if found: print('YES') else: print('NO') else: print('NO') ```
instruction
0
107,027
3
214,054
No
output
1
107,027
3
214,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n power sources, and the second one has m power sources. A power source can be described as a point (x_i, y_i) on a 2-D plane. All points in each engine are different. You can manipulate each engine separately. There are two operations that you can do with each engine. You can do each operation as many times as you want. 1. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i+a, y_i+b), a and b can be any real numbers. In other words, all power sources will be shifted. 2. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i cos θ - y_i sin θ, x_i sin θ + y_i cos θ), θ can be any real number. In other words, all power sources will be rotated. The engines work as follows: after the two engines are powered, their power sources are being combined (here power sources of different engines may coincide). If two power sources A(x_a, y_a) and B(x_b, y_b) exist, then for all real number k that 0 < k < 1, a new power source will be created C_k(kx_a+(1-k)x_b,ky_a+(1-k)y_b). Then, this procedure will be repeated again with all new and old power sources. After that, the "power field" from all power sources will be generated (can be considered as an infinite set of all power sources occurred). A supersonic rocket is "safe" if and only if after you manipulate the engines, destroying any power source and then power the engine, the power field generated won't be changed (comparing to the situation where no power source erased). Two power fields are considered the same if and only if any power source in one field belongs to the other one as well. Given a supersonic rocket, check whether it is safe or not. Input The first line contains two integers n, m (3 ≤ n, m ≤ 10^5) — the number of power sources in each engine. Each of the next n lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the first engine. Each of the next m lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the second engine. It is guaranteed that there are no two or more power sources that are located in the same point in each engine. Output Print "YES" if the supersonic rocket is safe, otherwise "NO". You can print each letter in an arbitrary case (upper or lower). Examples Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 1 1 Output YES Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 0 0 Output NO Note The first sample: <image> Those near pairs of blue and orange points actually coincide. First, manipulate the first engine: use the second operation with θ = π (to rotate all power sources 180 degrees). The power sources in the first engine become (0, 0), (0, -2), and (-2, 0). <image> Second, manipulate the second engine: use the first operation with a = b = -2. The power sources in the second engine become (-2, 0), (0, 0), (0, -2), and (-1, -1). <image> You can examine that destroying any point, the power field formed by the two engines are always the solid triangle (0, 0), (-2, 0), (0, -2). In the second sample, no matter how you manipulate the engines, there always exists a power source in the second engine that power field will shrink if you destroy it. Submitted Solution: ``` import sys # > 0 anti-clock, < 0 clockwise, == 0 same line def orientation(p1, p2, p3): return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) def theta(p1, p2): dx = p2[0] - p1[0] dy = p2[1] - p1[1] if abs(dx) < 0.1**5 and abs(dy) < 0.1**5: t = 0 else: t = dy/(abs(dx) + abs(dy)) if dx < 0: t = 2 - t elif dy < 0: t = 4 + t return t*90 def dist_sq(p1, p2): return (p1[0] - p2[0])*(p1[0] - p2[0]) + (p1[1] - p2[1])*(p1[1] - p2[1]) def chull(points): # let 0 element to be smallest, reorder elements pi = [x for x in range(len(points))] min_y = points[0][1] min_ind = 0 for i in range(len(points)): if points[i][1] < min_y: min_y = points[i][1] min_ind = i pi[0] = min_ind pi[min_ind] = 0 th = [theta(points[pi[0]], points[x]) for x in range(len(points))] pi.sort(key=lambda x: th[x]) # process equals unique = [pi[0], pi[1]] for i in range(2, len(pi)): if th[pi[i]] != th[unique[-1]]: unique.append(pi[i]) else: if dist_sq(points[pi[0]], points[unique[-1]]) < dist_sq(points[pi[0]], points[pi[i]]): unique[-1] = pi[i] # put max pi = unique stack = [] for i in range(min(len(pi), 3)): stack.append(points[pi[i]]) if len(stack) < 3: return stack for i in range(3, len(pi)): while len(stack) >= 2: o = orientation(stack[-2], stack[-1], points[pi[i]]) if o > 0: stack.append(points[pi[i]]) break elif o < 0: stack.pop() else: # == if dist_sq(stack[-2], stack[-1]) < dist_sq(stack[-2], points[pi[i]]): stack.pop() else: break # skip i-th point return stack def z_func(s): out = [] if not s: return out i, slen = 1, len(s) out.append(slen) while i < slen: left, right = 0, i while right < slen and s[left] == s[right]: left += 1 right += 1 out.append(left) i += 1 return out n,m = map(int, sys.stdin.readline().strip().split()) a = [] for _ in range(n): x,y = map(int, sys.stdin.readline().strip().split()) a.append((x, y)) b = [] for _ in range(m): x, y = map(int, sys.stdin.readline().strip().split()) b.append((x, y)) ah = chull(a) bh = chull(b) if len(ah) == len(bh): da = [dist_sq(ah[-1], ah[0])] for i in range(1, len(ah)): da.append(dist_sq(ah[i], ah[i-1])) db = [dist_sq(bh[-1], bh[0])] for i in range(1, len(bh)): db.append(dist_sq(bh[i], bh[i-1])) l = r = 0 dab = [] dab.extend(da) dab.append(-1) dab.extend(db) zab = z_func(dab) dba = [] dba.extend(db) dba.append(-1) dba.extend(da) zba = z_func(dba) found = False for i in range(len(da)+1, len(dba)): if zab[i] == len(dba)-i: rem = len(da) - zab[i] if rem == 0 or zba[-rem] == rem: found = True if found: print('YES') else: print('NO') else: print('NO') ```
instruction
0
107,028
3
214,056
No
output
1
107,028
3
214,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n power sources, and the second one has m power sources. A power source can be described as a point (x_i, y_i) on a 2-D plane. All points in each engine are different. You can manipulate each engine separately. There are two operations that you can do with each engine. You can do each operation as many times as you want. 1. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i+a, y_i+b), a and b can be any real numbers. In other words, all power sources will be shifted. 2. For every power source as a whole in that engine: (x_i, y_i) becomes (x_i cos θ - y_i sin θ, x_i sin θ + y_i cos θ), θ can be any real number. In other words, all power sources will be rotated. The engines work as follows: after the two engines are powered, their power sources are being combined (here power sources of different engines may coincide). If two power sources A(x_a, y_a) and B(x_b, y_b) exist, then for all real number k that 0 < k < 1, a new power source will be created C_k(kx_a+(1-k)x_b,ky_a+(1-k)y_b). Then, this procedure will be repeated again with all new and old power sources. After that, the "power field" from all power sources will be generated (can be considered as an infinite set of all power sources occurred). A supersonic rocket is "safe" if and only if after you manipulate the engines, destroying any power source and then power the engine, the power field generated won't be changed (comparing to the situation where no power source erased). Two power fields are considered the same if and only if any power source in one field belongs to the other one as well. Given a supersonic rocket, check whether it is safe or not. Input The first line contains two integers n, m (3 ≤ n, m ≤ 10^5) — the number of power sources in each engine. Each of the next n lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the first engine. Each of the next m lines contains two integers x_i and y_i (0≤ x_i, y_i≤ 10^8) — the coordinates of the i-th power source in the second engine. It is guaranteed that there are no two or more power sources that are located in the same point in each engine. Output Print "YES" if the supersonic rocket is safe, otherwise "NO". You can print each letter in an arbitrary case (upper or lower). Examples Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 1 1 Output YES Input 3 4 0 0 0 2 2 0 0 2 2 2 2 0 0 0 Output NO Note The first sample: <image> Those near pairs of blue and orange points actually coincide. First, manipulate the first engine: use the second operation with θ = π (to rotate all power sources 180 degrees). The power sources in the first engine become (0, 0), (0, -2), and (-2, 0). <image> Second, manipulate the second engine: use the first operation with a = b = -2. The power sources in the second engine become (-2, 0), (0, 0), (0, -2), and (-1, -1). <image> You can examine that destroying any point, the power field formed by the two engines are always the solid triangle (0, 0), (-2, 0), (0, -2). In the second sample, no matter how you manipulate the engines, there always exists a power source in the second engine that power field will shrink if you destroy it. Submitted Solution: ``` import sys # > 0 anti-clock, < 0 clockwise, == 0 same line def orientation(p1, p2, p3): return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) def theta(p1, p2): dx = p2[0] - p1[0] dy = p2[1] - p1[1] if abs(dx) < 0.1**5 and abs(dy) < 0.1**5: t = 0 else: t = dy/(abs(dx) + abs(dy)) if dx < 0: t = 2 - t elif dy < 0: t = 4 + t return t*90 def dist_sq(p1, p2): return (p1[0] - p2[0])*(p1[0] - p2[0]) + (p1[1] - p2[1])*(p1[1] - p2[1]) def chull(points): # let 0 element to be smallest, reorder elements pi = [x for x in range(len(points))] min_y = points[0][1] min_ind = 0 for i in range(len(points)): if points[i][1] < min_y: min_y = points[i][1] min_ind = i pi[0] = min_ind pi[min_ind] = 0 th = [theta(points[pi[0]], points[x]) for x in range(len(points))] pi.sort(key=lambda x: th[x]) # process equals unique = [pi[0], pi[1]] for i in range(2, len(pi)): if th[pi[i]] != th[unique[-1]]: unique.append(pi[i]) else: if dist_sq(points[pi[0]], points[unique[-1]]) < dist_sq(points[pi[0]], points[pi[i]]): unique[-1] = pi[i] # put max pi = unique stack = [] for i in range(min(len(pi), 3)): stack.append(points[pi[i]]) if len(stack) < 3: return stack for i in range(3, len(pi)): while len(stack) >= 2: o = orientation(stack[-2], stack[-1], points[pi[i]]) if o > 0: stack.append(points[pi[i]]) break elif o < 0: stack.pop() else: # == if dist_sq(stack[-2], stack[-1]) < dist_sq(stack[-2], points[pi[i]]): stack.pop() else: break # skip i-th point return stack def z_func(s): out = [] if not s: return out i, slen = 1, len(s) out.append(slen) while i < slen: left, right = 0, i while right < slen and s[left] == s[right]: left += 1 right += 1 out.append(left) i += 1 return out n,m = map(int, sys.stdin.readline().strip().split()) a = [] for _ in range(n): x,y = map(int, sys.stdin.readline().strip().split()) a.append((x, y)) b = [] for _ in range(m): x, y = map(int, sys.stdin.readline().strip().split()) b.append((x, y)) ah = chull(a) bh = chull(b) if len(ah) == len(bh): if len(ah) == 2: if dist_sq(ah[0], ah[1]) == dist_sq(bh[0], bh[1]): print('YES') else: print('NO') else: da = [] for i in range(len(ah)): da.append((dist_sq(ah[i], ah[i-1]), orientation(ah[i-2], ah[i-1], ah[i]))) db = [] for i in range(len(bh)): db.append((dist_sq(bh[i], bh[i - 1]), orientation(bh[i - 2], bh[i - 1], bh[i]))) l = r = 0 dab = [] dab.extend(da) dab.append(-1) dab.extend(db) zab = z_func(dab) dba = [] dba.extend(db) dba.append(-1) dba.extend(da) zba = z_func(dba) found = False for i in range(len(da)+1, len(dba)): if zab[i] == len(dba)-i: rem = len(da) - zab[i] if rem == 0 or zba[-rem] == rem: found = True if found: print('YES') else: print('NO') else: print('NO') ```
instruction
0
107,029
3
214,058
No
output
1
107,029
3
214,059