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
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below. Category | Age --- | --- Under 10 years old | 0 ~ 9 Teens | 10 ~ 19 20s | 20 ~ 29 30s | 30 ~ 39 40s | 40 ~ 49 50s | 50 ~ 59 Over 60 years old | 60 ~ Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n a1 a2 :: an The first line gives the number of visitors n (1 ≀ n ≀ 1000000), and the following n lines give the age of the i-th visitor ai (0 ≀ ai ≀ 120). Output The number of people is output in the following format for each data set. Line 1: Number of people under 10 Line 2: Number of teens Line 3: Number of people in their 20s Line 4: Number of people in their 30s Line 5: Number of people in their 40s Line 6: Number of people in their 50s Line 7: Number of people over 60 Example Input 8 71 34 65 11 41 39 6 5 4 67 81 78 65 0 Output 2 1 0 2 1 0 2 0 0 0 0 0 0 4 Submitted Solution: ``` while True: n =int(input()) if n==0: break a0=a1=a2=a3=a4=a5=a6=0 for i in range(n): a=int(input()) if a<10: a0+=1 elif a<20: a1+=1 elif a<30: a2+=1 elif a<40: a3+=1 elif a<50: a4+=1 elif a<60: a5+=1 else: a6+=1 print(a0) print(a1) print(a2) print(a3) print(a4) print(a5) print(a6) ```
instruction
0
63,044
3
126,088
Yes
output
1
63,044
3
126,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below. Category | Age --- | --- Under 10 years old | 0 ~ 9 Teens | 10 ~ 19 20s | 20 ~ 29 30s | 30 ~ 39 40s | 40 ~ 49 50s | 50 ~ 59 Over 60 years old | 60 ~ Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n a1 a2 :: an The first line gives the number of visitors n (1 ≀ n ≀ 1000000), and the following n lines give the age of the i-th visitor ai (0 ≀ ai ≀ 120). Output The number of people is output in the following format for each data set. Line 1: Number of people under 10 Line 2: Number of teens Line 3: Number of people in their 20s Line 4: Number of people in their 30s Line 5: Number of people in their 40s Line 6: Number of people in their 50s Line 7: Number of people over 60 Example Input 8 71 34 65 11 41 39 6 5 4 67 81 78 65 0 Output 2 1 0 2 1 0 2 0 0 0 0 0 0 4 Submitted Solution: ``` while True: n = int(input()) ans = [0 for _ in range(7)] for _ in range(n): age = int(input()) if age < 10: ans[0] += 1 elif age < 20: ans[1] += 1 elif age < 30: ans[2] += 1 elif age < 40: ans[3] += 1 elif age < 50: ans[4] += 1 elif age < 60: ans[5] += 1 else: ans[6] += 1 for a in ans: print(a) ```
instruction
0
63,045
3
126,090
No
output
1
63,045
3
126,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below. Category | Age --- | --- Under 10 years old | 0 ~ 9 Teens | 10 ~ 19 20s | 20 ~ 29 30s | 30 ~ 39 40s | 40 ~ 49 50s | 50 ~ 59 Over 60 years old | 60 ~ Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n a1 a2 :: an The first line gives the number of visitors n (1 ≀ n ≀ 1000000), and the following n lines give the age of the i-th visitor ai (0 ≀ ai ≀ 120). Output The number of people is output in the following format for each data set. Line 1: Number of people under 10 Line 2: Number of teens Line 3: Number of people in their 20s Line 4: Number of people in their 30s Line 5: Number of people in their 40s Line 6: Number of people in their 50s Line 7: Number of people over 60 Example Input 8 71 34 65 11 41 39 6 5 4 67 81 78 65 0 Output 2 1 0 2 1 0 2 0 0 0 0 0 0 4 Submitted Solution: ``` n=int(input()) x=[0 for i in range(7)] while True: if n==0: break for i in range(n): a=int(input()) if 0<=a<10: x[0]+=1 elif 10<=a<20: x[1]+=1 elif 20<=a<30: x[2]+=1 elif 30<=a<40: x[3]+=1 elif 40<=a<50: x[4]+=1 elif 50<=a<60: x[5]+=1 else: x[6]+=1 for i in range(7): if x[i]==0: print(0) else: print(x[i]) ```
instruction
0
63,046
3
126,092
No
output
1
63,046
3
126,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below. Category | Age --- | --- Under 10 years old | 0 ~ 9 Teens | 10 ~ 19 20s | 20 ~ 29 30s | 30 ~ 39 40s | 40 ~ 49 50s | 50 ~ 59 Over 60 years old | 60 ~ Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n a1 a2 :: an The first line gives the number of visitors n (1 ≀ n ≀ 1000000), and the following n lines give the age of the i-th visitor ai (0 ≀ ai ≀ 120). Output The number of people is output in the following format for each data set. Line 1: Number of people under 10 Line 2: Number of teens Line 3: Number of people in their 20s Line 4: Number of people in their 30s Line 5: Number of people in their 40s Line 6: Number of people in their 50s Line 7: Number of people over 60 Example Input 8 71 34 65 11 41 39 6 5 4 67 81 78 65 0 Output 2 1 0 2 1 0 2 0 0 0 0 0 0 4 Submitted Solution: ``` n=int(input()) x=[0 for i in range(7)] while True: if n==0: break for i in range(n): a=int(input()) if 0<=a<10: x[0]+=1 elif 10<=a<20: x[1]+=1 elif 20<=a<30: x[2]+=1 elif 30<=a<40: x[3]+=1 elif 40<=a<50: x[4]+=1 elif 50<=a<60: x[5]+=1 else: x[6]+=1 for i in range(7): if x[i]==0: print(0) else: print('{}'.format(x[i])) ```
instruction
0
63,047
3
126,094
No
output
1
63,047
3
126,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below. Category | Age --- | --- Under 10 years old | 0 ~ 9 Teens | 10 ~ 19 20s | 20 ~ 29 30s | 30 ~ 39 40s | 40 ~ 49 50s | 50 ~ 59 Over 60 years old | 60 ~ Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n a1 a2 :: an The first line gives the number of visitors n (1 ≀ n ≀ 1000000), and the following n lines give the age of the i-th visitor ai (0 ≀ ai ≀ 120). Output The number of people is output in the following format for each data set. Line 1: Number of people under 10 Line 2: Number of teens Line 3: Number of people in their 20s Line 4: Number of people in their 30s Line 5: Number of people in their 40s Line 6: Number of people in their 50s Line 7: Number of people over 60 Example Input 8 71 34 65 11 41 39 6 5 4 67 81 78 65 0 Output 2 1 0 2 1 0 2 0 0 0 0 0 0 4 Submitted Solution: ``` n=int(input()) x=[0 for i in range(7)] for i in range(n): a=int(input()) if 0<=a<10: x[0]+=1 elif 10<=a<20: x[1]+=1 elif 20<=a<30: x[2]+=1 elif 30<=a<40: x[3]+=1 elif 40<=a<50: x[4]+=1 elif 50<=a<60: x[5]+=1 else: x[6]+=1 for i in range(7): if x[i]==0: print(0) else: print('{}'.format(x[i])) ```
instruction
0
63,048
3
126,096
No
output
1
63,048
3
126,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem statement There is a town with a size of H in the north-south direction and W in the east-west direction. In the town, square plots with a side length of 1 are maintained without gaps, and one house is built in each plot. A typhoon broke out over a section of the town, causing damage and then changing to an extratropical cyclone over a section. No damage is done after the change. As shown in the figure below, a typhoon is a square with a height of 3 and a width of 3, and the square with a star is called the center. The typhoon moves to the vicinity of 8 in units of sections. In other words, the center of the typhoon moves with the whole so that it moves to the section that shares the sides or vertices (including the current section). However, the typhoon does not protrude outside the town, and the center of the typhoon is the 0th and H-1st sections from the north and the 0th and W-1st sections from the west, as shown in the shaded area in the figure below. Move so that it does not pass. <image> Once a typhoon hits the sky, the degree of damage to the house changes as follows. > No damage β†’ Partially damaged β†’ Half destroyed β†’ Completely destroyed β†’ No trace Fortunately, however, there seems to be no house that has become a trace pear. Since the damage situation of each house is given, find the point where the typhoon occurred and the point where it changed to an extratropical cyclone. However, if the generated section is s_ith from the north, s_jth from the west, and the section changed to an extratropical cyclone is t_ith from the north and t_jth from the west, the two points are 10000 t_i + t_j ≀ 10000 s_i + s_j. Determined to meet. input H \ W D_ {11} \… \ D_ {1W} D_ {21} \… \ D_ {2W} ... D_ {H1} \… \ D_ {HW} D_ {ij} is an integer that expresses the degree of damage to the i-th house from the north and the j-th house from the west as follows. * 0: No damage * 1: Partially damaged * 2: Half destroyed * 3: Completely destroyed Constraint * An integer * Input is given only if the answer is uniquely determined * 3 ≀ H, W ≀ 500 * 0 ≀ D_ {ij} ≀ 3 output Output the answer in one line as follows. s_i \ s_j \ t_i \ t_j sample Sample input 1 7 5 0 0 0 0 0 0 1 1 1 0 0 2 2 2 0 0 3 3 3 0 0 2 2 2 0 0 1 1 1 0 0 0 0 0 0 Sample output 1 4 2 2 2 Sample input 2 6 6 0 0 0 1 1 1 0 0 0 2 2 2 0 0 1 3 3 2 1 2 3 3 2 1 1 2 3 2 1 0 1 2 2 1 0 0 Sample output 2 4 1 1 4 Sample input 3 4 4 2 2 2 0 2 2 2 0 2 2 2 0 0 0 0 0 Sample output 3 1 1 1 1 Example Input 7 5 0 0 0 0 0 0 1 1 1 0 0 2 2 2 0 0 3 3 3 0 0 2 2 2 0 0 1 1 1 0 0 0 0 0 0 Output 4 2 2 2 Submitted Solution: ``` import copy H,W = map(int, input().split()) f = [list(map(int, input().split())) for i in range(H)] path = [] s = [] t = [] b_flag = False r_flag = False def search(f, path): y, x = path.pop() for i in range(-1, 2): for j in range(-1, 2): f[y+i][x+j] -= 1 if f[y+i][x+j] == -1: return for l in f: if (l.count(0) != W): break else: print(str(y)+" "+str(x)) exit() for i in range(4): ny = y+[0, -1, -1, 0][i] nx = x+[0, 0, 1, 1][i] if (ny > 0 and nx < W-1 and f[ny][nx] != 0): path += [[ny, nx]] search(copy.deepcopy(f), path) else: return for y in range(H-1, -1, -1): for x in range(W): if (f[y][x] != 0): path += [[y-1, x+1]] b_flag = True break if (b_flag): break s = map(str, path[0]) print(" ".join(s), end=" ") search(f, path) ```
instruction
0
63,112
3
126,224
No
output
1
63,112
3
126,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values p_i β€” the index of the router to which the i-th router was connected after being purchased (p_i < i). There are n routers in Boogle in total now. Print the sequence of routers on the path from the first to the n-th router. Input The first line contains integer number n (2 ≀ n ≀ 200000) β€” the number of the routers. The following line contains n-1 integers p_2, p_3, ..., p_n (1 ≀ p_i < i), where p_i is equal to index of the router to which the i-th was connected after purchase. Output Print the path from the 1-st to the n-th router. It starts with 1 and ends with n. All the elements in the path should be distinct. Examples Input 8 1 1 2 2 3 2 5 Output 1 2 5 8 Input 6 1 2 3 4 5 Output 1 2 3 4 5 6 Input 7 1 1 2 3 4 3 Output 1 3 7 Submitted Solution: ``` n = int(input()) p = list(map(lambda x: int(x), input().split())) path = [n] t = n while t != 1: t = p[t - 2] path.append(t) print(path[len(path) - 1], end='', sep='') for i in range(len(path) - 2, -1, -1): print(' ', path[i], end='', sep='') ```
instruction
0
63,174
3
126,348
Yes
output
1
63,174
3
126,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values p_i β€” the index of the router to which the i-th router was connected after being purchased (p_i < i). There are n routers in Boogle in total now. Print the sequence of routers on the path from the first to the n-th router. Input The first line contains integer number n (2 ≀ n ≀ 200000) β€” the number of the routers. The following line contains n-1 integers p_2, p_3, ..., p_n (1 ≀ p_i < i), where p_i is equal to index of the router to which the i-th was connected after purchase. Output Print the path from the 1-st to the n-th router. It starts with 1 and ends with n. All the elements in the path should be distinct. Examples Input 8 1 1 2 2 3 2 5 Output 1 2 5 8 Input 6 1 2 3 4 5 Output 1 2 3 4 5 6 Input 7 1 1 2 3 4 3 Output 1 3 7 Submitted Solution: ``` Answer, N, Sequence = [], int(input()), list(map(int, input().split())) Answer.append(N) Index = N - 2 while Sequence[Index] != 1: Answer.append(Sequence[Index]) Index = Sequence[Index] - 2 print(1, *Answer[::-1]) # Hope the best for Ravens # Never give up ```
instruction
0
63,175
3
126,350
Yes
output
1
63,175
3
126,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values p_i β€” the index of the router to which the i-th router was connected after being purchased (p_i < i). There are n routers in Boogle in total now. Print the sequence of routers on the path from the first to the n-th router. Input The first line contains integer number n (2 ≀ n ≀ 200000) β€” the number of the routers. The following line contains n-1 integers p_2, p_3, ..., p_n (1 ≀ p_i < i), where p_i is equal to index of the router to which the i-th was connected after purchase. Output Print the path from the 1-st to the n-th router. It starts with 1 and ends with n. All the elements in the path should be distinct. Examples Input 8 1 1 2 2 3 2 5 Output 1 2 5 8 Input 6 1 2 3 4 5 Output 1 2 3 4 5 6 Input 7 1 1 2 3 4 3 Output 1 3 7 Submitted Solution: ``` n = int(input()) l = list(map(int, input().split())) ans = [] ptr = l[-1] ans.append(n) while True: ans.append(ptr) if ans[-1] == 1: break ptr = l[ptr-2] ans.reverse() print(ans) ```
instruction
0
63,177
3
126,354
No
output
1
63,177
3
126,355
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values p_i β€” the index of the router to which the i-th router was connected after being purchased (p_i < i). There are n routers in Boogle in total now. Print the sequence of routers on the path from the first to the n-th router. Input The first line contains integer number n (2 ≀ n ≀ 200000) β€” the number of the routers. The following line contains n-1 integers p_2, p_3, ..., p_n (1 ≀ p_i < i), where p_i is equal to index of the router to which the i-th was connected after purchase. Output Print the path from the 1-st to the n-th router. It starts with 1 and ends with n. All the elements in the path should be distinct. Examples Input 8 1 1 2 2 3 2 5 Output 1 2 5 8 Input 6 1 2 3 4 5 Output 1 2 3 4 5 6 Input 7 1 1 2 3 4 3 Output 1 3 7 Submitted Solution: ``` class Node: my_nodes = [] def __init__(self, index, p_index = None): if p_index: self.parent = Node.my_nodes[p_index-1] else: self.parent = None self.index = index Node.my_nodes.append(self) def find_trace(self,lst): if(self.parent): lst.insert(0,self.index) return ( self.parent.find_trace(lst) ) else: lst.insert(0,1) return lst def add(index, p_index): me = Node(index, p_index) return me hh = Node(1) size = int(input()) lst = list(map(int, input().strip().split())) i = 2 for t in lst: hh = add(i, t) i += 1 mm = hh.find_trace([]) mm = list(set(mm)) for m in mm: print(m, end = ' ') ```
instruction
0
63,179
3
126,358
No
output
1
63,179
3
126,359
Provide tags and a correct Python 3 solution for this coding contest problem. There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one detachment to another he should first choose one of four directions of movement (up, right, left or down) and then start moving with the constant speed of one unit interval in a second until he comes to a detachment. After he reaches an arbitrary detachment, he can repeat the same process. Each t seconds an orbital strike covers the whole surface, so at that moment Brimstone should be in a point where some detachment is located. He can stay with any detachment as long as needed. Brimstone is a good commander, that's why he can create at most one detachment and place it in any empty point with integer coordinates he wants before his trip. Keep in mind that Brimstone will need to visit this detachment, too. Help Brimstone and find such minimal t that it is possible to check each detachment. If there is no such t report about it. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of detachments. In each of the next n lines there is a pair of integers x_i, y_i (|x_i|, |y_i| ≀ 10^9) β€” the coordinates of i-th detachment. It is guaranteed that all points are different. Output Output such minimal integer t that it is possible to check all the detachments adding at most one new detachment. If there is no such t, print -1. Examples Input 4 100 0 0 100 -100 0 0 -100 Output 100 Input 7 0 2 1 0 -3 0 0 -2 -1 -1 -1 -3 -2 -3 Output -1 Input 5 0 0 0 -1 3 0 -2 0 -2 1 Output 2 Input 5 0 0 2 0 0 -1 -2 0 -2 1 Output 2 Note In the first test it is possible to place a detachment in (0, 0), so that it is possible to check all the detachments for t = 100. It can be proven that it is impossible to check all detachments for t < 100; thus the answer is 100. In the second test, there is no such t that it is possible to check all detachments, even with adding at most one new detachment, so the answer is -1. In the third test, it is possible to place a detachment in (1, 0), so that Brimstone can check all the detachments for t = 2. It can be proven that it is the minimal such t. In the fourth test, there is no need to add any detachments, because the answer will not get better (t = 2). It can be proven that it is the minimal such t.
instruction
0
63,330
3
126,660
Tags: binary search, data structures, dfs and similar, dsu, graphs, implementation Correct Solution: ``` # import numpy as npy import functools import math n=int(input()) x=[0 for i in range(n+2)] y=[0 for i in range(n+2)] adj=[[] for i in range(n+2)] idx=[] idy=[] for i in range(n): x[i],y[i]=map(int,input().split()) idx.append(i) idy.append(i) def cmpx(a,b): if x[a]!=x[b]: if x[a]<x[b]: return -1 else: return 1 if y[a]!=y[b]: if y[a]<y[b]: return -1 else: return 1 return 0 def cmpy(a,b): if y[a]!=y[b]: if y[a]<y[b]: return -1 else: return 1 if x[a]!=x[b]: if x[a]<x[b]: return -1 else: return 1 return 0 idx=sorted(idx,key=functools.cmp_to_key(cmpx)) idy=sorted(idy,key=functools.cmp_to_key(cmpy)) # print(idx) # print(idy) def disx(a,b): if x[a]!=x[b]: return 1e18 return y[b]-y[a] def disy(a,b): if y[a]!=y[b]: return 1e18 return x[b]-x[a] l=0 r=2000000000 ans=-1 while l<=r: # print(l,r) mid=(l+r)//2 for i in range(n): adj[i]=[] for i in range(n-1): if disx(idx[i],idx[i+1])<=mid: adj[idx[i]].append(idx[i+1]) adj[idx[i+1]].append(idx[i]) # print(idx[i],idx[i+1]) if disy(idy[i],idy[i+1])<=mid: adj[idy[i]].append(idy[i+1]) adj[idy[i+1]].append(idy[i]) # print(idy[i],idy[i+1]) col=[0 for i in range(n)] cur=0 def dfs(x): col[x]=cur for i in range(len(adj[x])): if col[adj[x][i]]==0: dfs(adj[x][i]) for i in range(n): if col[i]==0: cur=cur+1 dfs(i) ok=0 if cur>4: ok=0 if cur==1: ok=1 if cur==2: for i in range(n): for j in range(i+1,n): if (col[i]!=col[j]): d1=abs(x[i]-x[j]) d2=abs(y[i]-y[j]) if d1==0 or d2==0: if d1+d2<=2*mid: ok=1 if d1<=mid and d2<=mid: ok=1 if cur==3: for i in range(n-1): px=idx[i] py=idx[i+1] if x[px]==x[py] and col[px]!=col[py]: for j in range(n): if col[px]!=col[j] and col[py]!=col[j]: d1=abs(y[px]-y[j]) d2=abs(y[py]-y[j]) d3=abs(x[px]-x[j]) if d1<=mid and d2<=mid and d3<=mid: ok=1 for i in range(n-1): px=idy[i] py=idy[i+1] if y[px]==y[py] and col[px]!=col[py]: for j in range(n): if col[px]!=col[j] and col[py]!=col[j]: d1=abs(x[px]-x[j]) d2=abs(x[py]-x[j]) d3=abs(y[px]-y[j]) if d1<=mid and d2<=mid and d3<=mid: ok=1 if cur==4: for i in range(n-1): px=idx[i] py=idx[i+1] if x[px]==x[py] and col[px]!=col[py]: for j in range(n-1): pz=idy[j] pw=idy[j+1] if y[pz]==y[pw] and col[pz]!=col[pw]: if col[pz]!=col[px] and col[pz]!=col[py]: if col[pw]!=col[px] and col[pw]!=col[py]: d1=abs(y[px]-y[pz]) d2=abs(y[py]-y[pz]) d3=abs(x[pz]-x[px]) d4=abs(x[pw]-x[px]) if d1<=mid and d2<=mid and d3<=mid and d4<=mid: ok=1 if ok: ans=mid r=mid-1 else: l=mid+1 print(ans) ```
output
1
63,330
3
126,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one detachment to another he should first choose one of four directions of movement (up, right, left or down) and then start moving with the constant speed of one unit interval in a second until he comes to a detachment. After he reaches an arbitrary detachment, he can repeat the same process. Each t seconds an orbital strike covers the whole surface, so at that moment Brimstone should be in a point where some detachment is located. He can stay with any detachment as long as needed. Brimstone is a good commander, that's why he can create at most one detachment and place it in any empty point with integer coordinates he wants before his trip. Keep in mind that Brimstone will need to visit this detachment, too. Help Brimstone and find such minimal t that it is possible to check each detachment. If there is no such t report about it. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of detachments. In each of the next n lines there is a pair of integers x_i, y_i (|x_i|, |y_i| ≀ 10^9) β€” the coordinates of i-th detachment. It is guaranteed that all points are different. Output Output such minimal integer t that it is possible to check all the detachments adding at most one new detachment. If there is no such t, print -1. Examples Input 4 100 0 0 100 -100 0 0 -100 Output 100 Input 7 0 2 1 0 -3 0 0 -2 -1 -1 -1 -3 -2 -3 Output -1 Input 5 0 0 0 -1 3 0 -2 0 -2 1 Output 2 Input 5 0 0 2 0 0 -1 -2 0 -2 1 Output 2 Note In the first test it is possible to place a detachment in (0, 0), so that it is possible to check all the detachments for t = 100. It can be proven that it is impossible to check all detachments for t < 100; thus the answer is 100. In the second test, there is no such t that it is possible to check all detachments, even with adding at most one new detachment, so the answer is -1. In the third test, it is possible to place a detachment in (1, 0), so that Brimstone can check all the detachments for t = 2. It can be proven that it is the minimal such t. In the fourth test, there is no need to add any detachments, because the answer will not get better (t = 2). It can be proven that it is the minimal such t. Submitted Solution: ``` # import numpy as npy import functools import math n=int(input()) x=[0 for i in range(n+2)] y=[0 for i in range(n+2)] adj=[[] for i in range(n+2)] idx=[] idy=[] for i in range(n): x[i],y[i]=map(int,input().split()) idx.append(i) idy.append(i) def cmpx(a,b): if x[a]!=x[b]: if x[a]<x[b]: return -1 else: return 1 if y[a]!=y[b]: if y[a]<y[b]: return -1 else: return 1 return 0 def cmpy(a,b): if y[a]!=y[b]: if y[a]<y[b]: return -1 else: return 1 if x[a]!=x[b]: if x[a]<x[b]: return -1 else: return 1 return 0 idx=sorted(idx,key=functools.cmp_to_key(cmpx)) idy=sorted(idy,key=functools.cmp_to_key(cmpy)) print(idx) print(idy) def disx(a,b): if x[a]!=x[b]: return 1e18 return y[b]-y[a] def disy(a,b): if y[a]!=y[b]: return 1e18 return x[b]-x[a] l=0 r=2000000000 ans=-1 while l<=r: # print(l,r) mid=(l+r)//2 for i in range(n): adj[i]=[] for i in range(n-1): if disx(idx[i],idx[i+1])<=mid: adj[idx[i]].append(idx[i+1]) adj[idx[i+1]].append(idx[i]) # print(idx[i],idx[i+1]) if disy(idy[i],idy[i+1])<=mid: adj[idy[i]].append(idy[i+1]) adj[idy[i+1]].append(idy[i]) # print(idy[i],idy[i+1]) col=[0 for i in range(n)] cur=0 def dfs(x): col[x]=cur for i in range(len(adj[x])): if col[adj[x][i]]==0: dfs(adj[x][i]) for i in range(n): if col[i]==0: cur=cur+1 dfs(i) ok=0 if cur>4: ok=0 if cur==1: ok=1 if cur==2: for i in range(n): for j in range(i+1,n): if (col[i]!=col[j]): d1=abs(x[i]-x[j]) d2=abs(y[i]-y[j]) if d1==0 or d2==0: if d1+d2<=2*mid: ok=1 if d1<=mid or d2<=mid: ok=1 if cur==3: for i in range(n-1): px=idx[i] py=idx[i+1] if x[px]==x[py] and col[px]!=col[py]: for j in range(n): if col[px]!=col[j] and col[py]!=col[j]: d1=abs(y[px]-y[j]) d2=abs(y[py]-y[j]) d3=abs(x[px]-x[j]) if d1<=mid and d2<=mid and d3<=mid: ok=1 for i in range(n-1): px=idy[i] py=idy[i+1] if y[px]==y[py] and col[px]!=col[py]: for j in range(n): if col[px]!=col[j] and col[py]!=col[j]: d1=abs(x[px]-x[j]) d2=abs(x[py]-x[j]) d3=abs(y[px]-y[j]) if d1<=mid and d2<=mid and d3<=mid: ok=1 if cur==4: for i in range(n-1): px=idx[i] py=idx[i+1] if x[px]==x[py] and col[px]!=col[py]: for j in range(n-1): pz=idy[j] pw=idy[j+1] if y[pz]==y[pw] and col[pz]!=col[pw]: if col[pz]!=col[px] and col[pz]!=col[py]: if col[pw]!=col[px] and col[pw]!=col[py]: d1=abs(y[px]-x[pz]) d2=abs(y[py]-x[pz]) d3=abs(x[pz]-y[px]) d4=abs(x[pw]-y[px]) if d1<=mid and d2<=mid and d3<=mid and d4<=mid: ok=1 if ok: ans=mid r=mid-1 else: l=mid+1 print(ans) ```
instruction
0
63,331
3
126,662
No
output
1
63,331
3
126,663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one detachment to another he should first choose one of four directions of movement (up, right, left or down) and then start moving with the constant speed of one unit interval in a second until he comes to a detachment. After he reaches an arbitrary detachment, he can repeat the same process. Each t seconds an orbital strike covers the whole surface, so at that moment Brimstone should be in a point where some detachment is located. He can stay with any detachment as long as needed. Brimstone is a good commander, that's why he can create at most one detachment and place it in any empty point with integer coordinates he wants before his trip. Keep in mind that Brimstone will need to visit this detachment, too. Help Brimstone and find such minimal t that it is possible to check each detachment. If there is no such t report about it. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of detachments. In each of the next n lines there is a pair of integers x_i, y_i (|x_i|, |y_i| ≀ 10^9) β€” the coordinates of i-th detachment. It is guaranteed that all points are different. Output Output such minimal integer t that it is possible to check all the detachments adding at most one new detachment. If there is no such t, print -1. Examples Input 4 100 0 0 100 -100 0 0 -100 Output 100 Input 7 0 2 1 0 -3 0 0 -2 -1 -1 -1 -3 -2 -3 Output -1 Input 5 0 0 0 -1 3 0 -2 0 -2 1 Output 2 Input 5 0 0 2 0 0 -1 -2 0 -2 1 Output 2 Note In the first test it is possible to place a detachment in (0, 0), so that it is possible to check all the detachments for t = 100. It can be proven that it is impossible to check all detachments for t < 100; thus the answer is 100. In the second test, there is no such t that it is possible to check all detachments, even with adding at most one new detachment, so the answer is -1. In the third test, it is possible to place a detachment in (1, 0), so that Brimstone can check all the detachments for t = 2. It can be proven that it is the minimal such t. In the fourth test, there is no need to add any detachments, because the answer will not get better (t = 2). It can be proven that it is the minimal such t. Submitted Solution: ``` # import numpy as npy import functools import math n=int(input()) x=[0 for i in range(n+2)] y=[0 for i in range(n+2)] adj=[[] for i in range(n+2)] idx=[] idy=[] for i in range(n): x[i],y[i]=map(int,input().split()) idx.append(i) idy.append(i) def cmpx(a,b): if x[a]!=x[b]: if x[a]<x[b]: return -1 else: return 1 if y[a]!=y[b]: if y[a]<y[b]: return -1 else: return 1 return 0 def cmpy(a,b): if y[a]!=y[b]: if y[a]<y[b]: return -1 else: return 1 if x[a]!=x[b]: if x[a]<x[b]: return -1 else: return 1 return 0 idx=sorted(idx,key=functools.cmp_to_key(cmpx)) idy=sorted(idy,key=functools.cmp_to_key(cmpy)) # print(idx) # print(idy) def disx(a,b): if x[a]!=x[b]: return 1e18 return y[b]-y[a] def disy(a,b): if y[a]!=y[b]: return 1e18 return x[b]-x[a] l=0 r=2000000000 ans=-1 while l<=r: # print(l,r) mid=(l+r)//2 for i in range(n): adj[i]=[] for i in range(n-1): if disx(idx[i],idx[i+1])<=mid: adj[idx[i]].append(idx[i+1]) adj[idx[i+1]].append(idx[i]) # print(idx[i],idx[i+1]) if disy(idy[i],idy[i+1])<=mid: adj[idy[i]].append(idy[i+1]) adj[idy[i+1]].append(idy[i]) # print(idy[i],idy[i+1]) col=[0 for i in range(n)] cur=0 def dfs(x): col[x]=cur for i in range(len(adj[x])): if col[adj[x][i]]==0: dfs(adj[x][i]) for i in range(n): if col[i]==0: cur=cur+1 dfs(i) ok=0 if cur>4: ok=0 if cur==1: ok=1 if cur==2: for i in range(n): for j in range(i+1,n): if (col[i]!=col[j]): d1=abs(x[i]-x[j]) d2=abs(y[i]-y[j]) if d1==0 or d2==0: if d1+d2<=2*mid: ok=1 if d1<=mid or d2<=mid: ok=1 if cur==3: for i in range(n-1): px=idx[i] py=idx[i+1] if x[px]==x[py] and col[px]!=col[py]: for j in range(n): if col[px]!=col[j] and col[py]!=col[j]: d1=abs(y[px]-y[j]) d2=abs(y[py]-y[j]) d3=abs(x[px]-x[j]) if d1<=mid and d2<=mid and d3<=mid: ok=1 for i in range(n-1): px=idy[i] py=idy[i+1] if y[px]==y[py] and col[px]!=col[py]: for j in range(n): if col[px]!=col[j] and col[py]!=col[j]: d1=abs(x[px]-x[j]) d2=abs(x[py]-x[j]) d3=abs(y[px]-y[j]) if d1<=mid and d2<=mid and d3<=mid: ok=1 if cur==4: for i in range(n-1): px=idx[i] py=idx[i+1] if x[px]==x[py] and col[px]!=col[py]: for j in range(n-1): pz=idy[j] pw=idy[j+1] if y[pz]==y[pw] and col[pz]!=col[pw]: if col[pz]!=col[px] and col[pz]!=col[py]: if col[pw]!=col[px] and col[pw]!=col[py]: d1=abs(y[px]-y[pz]) d2=abs(y[py]-y[pz]) d3=abs(x[pz]-x[px]) d4=abs(x[pw]-x[px]) if d1<=mid and d2<=mid and d3<=mid and d4<=mid: ok=1 if ok: ans=mid r=mid-1 else: l=mid+1 print(ans) # why??? ```
instruction
0
63,332
3
126,664
No
output
1
63,332
3
126,665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one detachment to another he should first choose one of four directions of movement (up, right, left or down) and then start moving with the constant speed of one unit interval in a second until he comes to a detachment. After he reaches an arbitrary detachment, he can repeat the same process. Each t seconds an orbital strike covers the whole surface, so at that moment Brimstone should be in a point where some detachment is located. He can stay with any detachment as long as needed. Brimstone is a good commander, that's why he can create at most one detachment and place it in any empty point with integer coordinates he wants before his trip. Keep in mind that Brimstone will need to visit this detachment, too. Help Brimstone and find such minimal t that it is possible to check each detachment. If there is no such t report about it. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of detachments. In each of the next n lines there is a pair of integers x_i, y_i (|x_i|, |y_i| ≀ 10^9) β€” the coordinates of i-th detachment. It is guaranteed that all points are different. Output Output such minimal integer t that it is possible to check all the detachments adding at most one new detachment. If there is no such t, print -1. Examples Input 4 100 0 0 100 -100 0 0 -100 Output 100 Input 7 0 2 1 0 -3 0 0 -2 -1 -1 -1 -3 -2 -3 Output -1 Input 5 0 0 0 -1 3 0 -2 0 -2 1 Output 2 Input 5 0 0 2 0 0 -1 -2 0 -2 1 Output 2 Note In the first test it is possible to place a detachment in (0, 0), so that it is possible to check all the detachments for t = 100. It can be proven that it is impossible to check all detachments for t < 100; thus the answer is 100. In the second test, there is no such t that it is possible to check all detachments, even with adding at most one new detachment, so the answer is -1. In the third test, it is possible to place a detachment in (1, 0), so that Brimstone can check all the detachments for t = 2. It can be proven that it is the minimal such t. In the fourth test, there is no need to add any detachments, because the answer will not get better (t = 2). It can be proven that it is the minimal such t. Submitted Solution: ``` import itertools import copy import math import sys from collections import defaultdict def stdinWrapper(): data = '''2 1000000000 1000000000 -1000000000 -1000000000 ''' for line in data.split('\n'): yield line if '--debug' not in sys.argv: def stdinWrapper(): while True: yield input() inputs = stdinWrapper() def inputWrapper(): return next(inputs) def getType(_type): return _type(inputWrapper()) def getArray(_type): return [_type(x) for x in inputWrapper().split()] ''' Solution ''' def is_prime(num): if num == 1 or num == 2: return True div = 2 while True: if num % div == 0: return False if div * div > num: break div += 1 return True R,L,D,U = range(4) def solve(coords): def dist(x1, y1, x2, y2): if x1 == x2 or y1 == y2: return ((x2-x1), (y2-y1)) def append_point(graph, coords, id1, x1, y1, id2, x2, y2): graph[id1] graph[id2] dst = dist(x1, y1, x2, y2) if dst is not None: # print((x1,y1), (x2,y2), dst) if dst[0] > 0: if graph[id1][R] is None or dist(x1, y1, *coords[graph[id1][R]])[0] > dst[0]: if graph[id1][R] is not None: graph[graph[id1][R]][L] = id2 graph[id2][R] = graph[id1][R] graph[id1][R] = id2 graph[id2][L] = id1 if dst[0] < 0: if graph[id1][L] is None or dist(x1, y1, *coords[graph[id1][L]])[0] < dst[0]: if graph[id1][L] is not None: graph[graph[id1][L]][R] = id2 graph[id2][L] = graph[id1][L] graph[id1][L] = id2 graph[id2][R] = id1 if dst[1] > 0: if graph[id1][U] is None or dist(x1, y1, *coords[graph[id1][U]])[1] > dst[1]: if graph[id1][U] is not None: graph[graph[id1][U]][D] = id2 graph[id2][U] = graph[id1][U] graph[id1][U] = id2 graph[id2][D] = id1 if dst[1] < 0: if graph[id1][D] is None or dist(x1, y1, *coords[graph[id1][D]])[1] < dst[1]: if graph[id1][D] is not None: graph[graph[id1][D]][U] = id2 graph[id2][D] = graph[id1][D] graph[id1][D] = id2 graph[id2][U] = id1 # print('\t graph', dict(graph)) def make_graph(coords): graph = defaultdict(lambda: [None, None, None, None]) for a in range(len(coords)-1): x1, y1 = coords[a] for b in range(a+1, len(coords)): x2, y2 =coords[b] append_point(graph, coords, a, x1, y1, b, x2, y2) return dict(graph) def dfs(graph, v, component, visited): if v in visited: return visited.add(v) component.append(v) for n in graph[v]: if n is not None: dfs(graph, n, component, visited) components = [] visited = set() graph = make_graph(coords) for v in graph: if v in visited: continue new_component = [] dfs(graph, v, new_component, visited) components.append(new_component) if len(components) > 2: return -1 def get_edge_infos(graph, coords): edges = {} visited = set() def dfs(graph, v, visited, edges): if v in visited: return visited.add(v) for n in graph[v]: if n is not None: dst = dist(*coords[v], *coords[n]) edges[tuple(sorted([v,n]))] = abs(dst[0]) + abs(dst[1]) dfs(graph, n, visited, edges) dfs(graph, v, visited, edges) return edges if len(components) == 1: edges = get_edge_infos(graph, coords) edge_lengths = list(edges.values()) _max = max(edge_lengths) if edge_lengths.count(_max) == 1: return (_max+1)//2 return _max checked = set() _min_max_edge = float('inf') for a in components[0]: x1, y1 = coords[a] for b in components[1]: x2, y2 = coords[b] candidates = [(x1,y2), (x2, y1)] for x3, y3 in candidates: if (x3,y3) in checked: continue checked.add((x3,y3)) new_coords = [x for x in coords] + [(x3,y3)] new_graph = make_graph(new_coords) _max_edge = max(list(get_edge_infos(new_graph, new_coords).values())) _min_max_edge = min(_min_max_edge, _max_edge) return _min_max_edge n = getType(int) coords = [tuple(getArray(int)) for _ in range(n)] print(solve(coords)) ```
instruction
0
63,333
3
126,666
No
output
1
63,333
3
126,667
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xaΒ·ybΒ·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≀ x, y, z; x + y + z ≀ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≀ S ≀ 103) β€” the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≀ a, b, c ≀ 103) β€” the numbers that describe the metric of mushroom scientists. Output Print three real numbers β€” the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
63,418
3
126,836
Tags: math, ternary search Correct Solution: ``` sa=int(input()) a, b, c=map(int, input().split(' ')) if a==0 and b==0 and c==0: print(0, 0, 0) else: x=(a*sa/(a+b+c)) y=(b*sa/(a+b+c)) z=(c*sa/(a+b+c)) print(x, y, z) ```
output
1
63,418
3
126,837
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xaΒ·ybΒ·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≀ x, y, z; x + y + z ≀ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≀ S ≀ 103) β€” the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≀ a, b, c ≀ 103) β€” the numbers that describe the metric of mushroom scientists. Output Print three real numbers β€” the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
63,419
3
126,838
Tags: math, ternary search Correct Solution: ``` S = int(input()) v = [int(x) for x in input().strip().split()] print(*[S * v[i] / sum(v) for i in range(3)] if sum(v) != 0 else "000") ```
output
1
63,419
3
126,839
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xaΒ·ybΒ·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≀ x, y, z; x + y + z ≀ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≀ S ≀ 103) β€” the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≀ a, b, c ≀ 103) β€” the numbers that describe the metric of mushroom scientists. Output Print three real numbers β€” the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
63,420
3
126,840
Tags: math, ternary search Correct Solution: ``` S = int(input()) v = [int(x) for x in input().strip().split()] zeroes = v.count(0) total = sum(v) ans = [] if zeroes == 0: ans = [S * v[i] / total for i in range(3)] elif zeroes == 1: for i in range(3): if v[i] == 0: total -= v[i] for i in range(3): if v[i] != 0: ans.append(S * v[i] / total) else: ans.append(0) else: # 2 or more for i in range(3): if v[i] == 0: ans.append(0) else: ans.append(S) print(*ans) ```
output
1
63,420
3
126,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots. Constraints * 1 \leq N \leq 100 * 1 \leq K \leq 100 * 0 < x_i < K * All input values are integers. Inputs Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N Outputs Print the minimum possible total distance covered by robots. Examples Input 1 10 2 Output 4 Input 2 9 3 6 Output 12 Input 5 20 11 12 9 17 12 Output 74 Submitted Solution: ``` N = int(input()) K = int(input()) A = list(map(int, input().split())) ans = 0 for a in A: ans += 2*min(a, K-a) print(ans) ```
instruction
0
63,856
3
127,712
Yes
output
1
63,856
3
127,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots. Constraints * 1 \leq N \leq 100 * 1 \leq K \leq 100 * 0 < x_i < K * All input values are integers. Inputs Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N Outputs Print the minimum possible total distance covered by robots. Examples Input 1 10 2 Output 4 Input 2 9 3 6 Output 12 Input 5 20 11 12 9 17 12 Output 74 Submitted Solution: ``` n=int(input()) k=int(input()) x=list(map(int,input().split())) ans=0 for xx in x: ans+=min(xx,abs(k-xx))*2 print(ans) ```
instruction
0
63,859
3
127,718
Yes
output
1
63,859
3
127,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots. Constraints * 1 \leq N \leq 100 * 1 \leq K \leq 100 * 0 < x_i < K * All input values are integers. Inputs Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N Outputs Print the minimum possible total distance covered by robots. Examples Input 1 10 2 Output 4 Input 2 9 3 6 Output 12 Input 5 20 11 12 9 17 12 Output 74 Submitted Solution: ``` n=int(input()) k=int(input()) a=0 for i in range(n): x=int(input()) a+=min(x,abs(k-x)) print(a*2) ```
instruction
0
63,862
3
127,724
No
output
1
63,862
3
127,725
Provide a correct Python 3 solution for this coding contest problem. Evil organizations that attempt to conquer the world are everywhere, regardless of age, east or west fiction, non-fiction, but what on earth did they try to conquer the world? I suddenly thought about that because I was also planning to conquer the world. The only reason I want to conquer the world is to show the world that I am the best in the field of robotics in the world. I'm not interested in the world after the conquest, and I don't mind giving it to dogs everywhere. I regret to say that there are researchers who are considered to be better than me. The person has an idea. Whoever it is, Dr. Synchronous R in my school days. I admit his achievements, but I don't think he was better than that of mine. However, he was well received by the professors because he was saying something sloppy, such as using robots for peace. Although I missed the president, I'm actually much better. A simple example of its excellence is the combat robot prepared for this world domination. Combat robots have their own weapons according to their characteristics, and the weapons are contained in chips, but this chip has strong compatibility. It's not just compatible with the developers' own other combat robots (that's already achieved by none other than Dr. R). The great thing about my chip is that it's also compatible with Dr. R's housework robot. The housework robot is a one-off model not for sale, so I developed a compatible chip without knowing the robot's design. I have to say that it is a divine work. Some people call this spec a wasteful spec for the enemy, but it's a silly idea. I'm developing a combat robot to show my excellence. It's not just about winning. Let's return to the world domination plan. I built n combat robots, each with one different weapon chip installed. He intends to use it to seize the world's major facilities, but Dr. R will send in a robot to help with his housework to thwart the plan. The domestic help robot challenges my combat robot with its own weapon, but each battle takes a unit of time, and as a result of the battle, one of the robots is defeated and destroyed. If my robot is destroyed as a result of a battle, the robot's weapon chips will be stolen by the opponent. The weapon chip of one of my robots is the weakness of one of my other robots, and every my robot has only one weakness of the weapon chip. For each of my robots, I can estimate the probability of defeat if the opponent has the weakness weapon of that robot and the probability of defeat if they do not. If the opponent's housework robot is destroyed as a result of the battle, Dr. R will send the same housework robot through the spare body transfer system. At this time, the weapon chips already obtained by the opponent's robot are not lost. Dr. R uses the spare body transfer system indefinitely, but I can repair my combat robot in the meantime, so the probability of defeat described above does not change no matter how many times I fight. Also, the spare body transfer system can only be used where the housework robot was destroyed when it was destroyed, so the housework robot cannot challenge another of my combat robots immediately after being defeated. It's only a matter of time before all n combat robots are destroyed, as Dr. R has unlimited spare body transfer systems. So, behind the scenes of fighting combat robots, I will work on developing more robots that can destroy the entire spare body transfer system. But how much time do I have left? How long would it take for Dr. R's robot to take the fastest strategy to destroy my n robots? You have to calculate it first. By the way, I would like to confirm how many such robots are defeated. Input The input consists of multiple cases. Each case is given in the following format. n p0 id0 w0 p1 id1 w1 .. .. .. p1 idn-1 wn-1 pi represents the probability that the i-th combat robot will be defeated when the opponent does not have a weak weapon. idi represents a combat robot that has a weapon that is the weakness of the i-th combat robot. wi represents the probability that the i-th combat robot will be defeated when the opponent has a weak weapon. The end of the input is given by n = 0. Each value meets the following conditions 2 ≀ n ≀ 100 pi and wi are represented by numbers with three decimal places. 0.001 ≀ pi <wi ≀ 1.000 idi! = i The number of test cases does not exceed 500. Output Output the expected value of the time until the n combat robots are destroyed and the remainder of dividing the number of combinations of the destruction order by 1000000007 with a blank. The expected value has an error of up to 1e-9 from the answer prepared by the judge. Example Input 4 0.200 3 0.500 0.100 0 0.400 0.900 1 1.000 0.400 2 0.600 2 0.600 1 0.800 0.500 0 1.000 9 0.200 7 0.600 0.400 0 0.500 0.700 8 1.000 0.100 4 0.400 0.200 2 0.600 0.100 6 0.400 0.100 5 0.400 0.600 3 0.900 0.500 1 0.900 9 0.300 8 0.900 0.700 3 0.800 0.300 0 0.900 0.700 6 0.800 0.200 5 0.700 0.200 2 0.700 0.700 4 0.800 0.700 1 0.800 0.300 7 0.900 0 Output 7.27777777778 1 2.66666666667 1 23.98412698413 72 11.36904761905 4
instruction
0
63,943
3
127,886
"Correct Solution: ``` E = 10 ** -9 MOD = 100000007 fact_result = {} while True: n = int(input()) if n == 0: break plst = [] wlst = [] diff = [] to = [None for _ in range(n)] for i in range(n): p, Id, w = input().split() to[i] = int(Id) plst.append(float(p)) wlst.append(float(w)) diff.append(1 / float(w) - 1 / float(p)) def elapsed_time(group): ret = 0 ret += 1 / plst[group[0]] for g in group[1:]: ret += 1 / wlst[g] return ret def init_comb(group): d = diff[group[0]] ret = 0 for g in group: if abs(diff[g] - d) < E: ret += 1 return ret def fact(n): if n == 0: return 1 if n in fact_result: return fact_result[n] fact_result[n] = n * fact(n - 1) return fact_result[n] used = [False] * n time = 0 comb = fact(n) group_cnt = 0 for i in range(n): if used[i]: continue group_cnt += 1 group = [i] used[i] = True nex = to[i] while not used[nex]: group.append(nex) used[nex] = True nex = to[nex] group.sort(key=lambda x:-diff[x]) time += elapsed_time(group) comb //= fact(len(group)) comb *= init_comb(group) print(time, comb % MOD) ```
output
1
63,943
3
127,887
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,185
3
128,370
Tags: geometry, hashing, number theory Correct Solution: ``` from sys import stdin, stdout from collections import defaultdict import math def main(): t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) rec = defaultdict(int) cnt= 0 for _ in range(n): x,y,u,v = list(map(int, stdin.readline().split())) X,Y = (u-x),(v-y) if X == 0: Y = 1 if Y > 0 else -1 elif Y == 0: X = 1 if X > 0 else -1 else: gcd = math.gcd(X,Y) X = int(X / gcd) Y = int(Y / gcd) rec[(X,Y)] += 1 cnt += rec[(-X,-Y)] stdout.write(str(cnt) + "\n") main() ```
output
1
64,185
3
128,371
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,186
3
128,372
Tags: geometry, hashing, number theory Correct Solution: ``` import sys LI=lambda:list(map(int, sys.stdin.readline().split())) MI=lambda:map(int, sys.stdin.readline().split()) SI=lambda:sys.stdin.readline().strip('\n') II=lambda:int(sys.stdin.readline()) # sys.stdin=open('input.txt') # sys.stdout=open('output.txt', 'w') from math import gcd for _ in range(II()): ln=set() cnt={} for __ in range(II()): x, y, u, v=MI() x, y=u-x, v-y v=gcd(x, y) x, y=x//v, y//v ln.add((x, y)) cnt[(x, y)]=cnt.get((x, y), 0)+1 ans=0 for x, y in ln: if (-x, -y) in ln: ans+=cnt[(x, y)]*cnt[(-x, -y)] print(ans//2) ```
output
1
64,186
3
128,373
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,187
3
128,374
Tags: geometry, hashing, number theory Correct Solution: ``` import sys,os,io from collections import defaultdict from math import gcd input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline for _ in range (int(input())): n = int(input()) vect = defaultdict(lambda : 0) for i in range (n): x,y,u,v = [int(i) for i in input().split()] vv = [u-x, v-y] if vv[0]==0: vv = [0, vv[1]//abs(vv[1])] elif vv[1]==0: vv = [vv[0]//abs(vv[0]), 0] else: g = gcd(vv[0], vv[1]) vv = [vv[0]//g, vv[1]//g] vv = tuple(vv) vect[vv]+=1 ans = 0 for i in vect: a = (-i[0], -i[1]) if a in vect: ans += vect[i]*vect[a] print(ans//2) ```
output
1
64,187
3
128,375
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,188
3
128,376
Tags: geometry, hashing, number theory Correct Solution: ``` import math from sys import stdin tt = int(stdin.readline()) for loop in range(tt): n = int(stdin.readline()) dic = {} ans = 0 for i in range(n): x,y,u,v = map(int,stdin.readline().split()) u -= x v -= y g = abs(math.gcd(u,v)) u //= g v //= g if (-1*u,-1*v) in dic: ans += dic[(-1*u,-1*v)] if (u,v) not in dic: dic[(u,v)] = 0 dic[(u,v)] += 1 print (ans) ```
output
1
64,188
3
128,377
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,189
3
128,378
Tags: geometry, hashing, number theory Correct Solution: ``` import sys LI=lambda:list(map(int, sys.stdin.readline().split())) MI=lambda:map(int, sys.stdin.readline().split()) SI=lambda:sys.stdin.readline().strip('\n') II=lambda:int(sys.stdin.readline()) # sys.stdin=open('input.txt') # sys.stdout=open('output.txt', 'w') from math import gcd for _ in range(II()): cnt={} for __ in range(II()): x, y, u, v=MI() x, y=u-x, v-y v=gcd(x, y) x, y=x//v, y//v cnt[(x, y)]=cnt.get((x, y), 0)+1 ans=0 for x, y in cnt: try: ans+=cnt[(x, y)]*cnt[(-x, -y)] except: pass print(ans//2) ```
output
1
64,189
3
128,379
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,190
3
128,380
Tags: geometry, hashing, number theory Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import defaultdict, deque, Counter from math import sqrt, pi, ceil, log, inf, gcd, floor from itertools import combinations, permutations from bisect import * from fractions import Fraction from heapq import * from random import randint def main(): for _ in range(int(input())): n=int(input()) b=Counter() for i in range(n): x,y,u,v=map(int,input().split()) z=gcd(v-y,u-x) p=(v-y)//z q=(u-x)//z if not p: q=q/abs(q) if not q: p=p/abs(p) b[(p,q)]+=1 ans=0 c=set() for i in b: if i not in c: z=b[i] y=b[(-i[0],-i[1])] ans+=y*z if y: c.add((-i[0],-i[1])) print(ans) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
output
1
64,190
3
128,381
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,191
3
128,382
Tags: geometry, hashing, number theory Correct Solution: ``` import sys, math input = sys.stdin.readline from collections import Counter for _ in range(int(input())): n = int(input()) A = [list(map(int, input().split())) for _ in range(n)] cnt = Counter() ans = 0 for a, b, c, d in A: x = c - a y = d - b g = math.gcd(x, y) x //= g y //= g ans += cnt[-x, -y] cnt[x, y] += 1 print(ans) ```
output
1
64,191
3
128,383
Provide tags and a correct Python 3 solution for this coding contest problem. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9
instruction
0
64,192
3
128,384
Tags: geometry, hashing, number theory Correct Solution: ``` import sys input = sys.stdin.readline # sys.setrecursionlimit(10**9) from sys import stdin, stdout from collections import defaultdict, Counter M = 10**9+7 from fractions import Fraction def main(): for _ in range(int(input())): dp = defaultdict(int) dn = defaultdict(int) zp,zn, ip, ine = 0,0,0,0 n = int(input()) for j in range(n): x,y,u,v = [int(j) for j in input().split()] if x==u: if v-y>0: ip+=1 else: ine+=1 elif y==v: if u-x>0: zp+=1 else: zn+=1 else: a = Fraction((v - y),(u - x)) if v-y>0: dp[a]+=1 else: dn[a]+=1 ans = ip*ine + zp*zn for i in dp: ans+=dp[i]*dn[i] print(ans) if __name__== '__main__': main() ```
output
1
64,192
3
128,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` import collections, math t = int(input()) for _ in range(t): n = int(input()) cnt = collections.defaultdict(int) for _ in range(n): x, y, u, v = map(int, input().split()) du, dv = u - x, v - y g = math.gcd(du, dv) cnt[(du // g, dv // g)] += 1 ans = 0 for du, dv in tuple(cnt.keys()): ans += cnt[(du, dv)] * cnt[(-du, -dv)] cnt[(du, dv)] = 0 cnt[(-du, -dv)] = 0 print(ans) ```
instruction
0
64,193
3
128,386
Yes
output
1
64,193
3
128,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` # Enter your code here. Read input from STDIN. Print output to STDOUT# =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import * from math import ceil, floor from copy import * from collections import deque, defaultdict from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)] from itertools import permutations as permutate from bisect import bisect_left as bl from operator import * # If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect # If the element is already present in the list, # the right most position where element has to be inserted is returned # ============================================================================================== # fast I/O region BUFSIZE = 8192 from sys import stderr class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") # =============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### ########################### # Sorted list class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(iterable) self._len = _len = len(values) self._load = _load self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)] self._list_lens = [len(_list) for _list in _lists] self._mins = [_list[0] for _list in _lists] self._fen_tree = [] self._rebuild = True def _fen_build(self): """Build a fenwick tree instance.""" self._fen_tree[:] = self._list_lens _fen_tree = self._fen_tree for i in range(len(_fen_tree)): if i | i + 1 < len(_fen_tree): _fen_tree[i | i + 1] += _fen_tree[i] self._rebuild = False def _fen_update(self, index, value): """Update `fen_tree[index] += value`.""" if not self._rebuild: _fen_tree = self._fen_tree while index < len(_fen_tree): _fen_tree[index] += value index |= index + 1 def _fen_query(self, end): """Return `sum(_fen_tree[:end])`.""" if self._rebuild: self._fen_build() _fen_tree = self._fen_tree x = 0 while end: x += _fen_tree[end - 1] end &= end - 1 return x def _fen_findkth(self, k): """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`).""" _list_lens = self._list_lens if k < _list_lens[0]: return 0, k if k >= self._len - _list_lens[-1]: return len(_list_lens) - 1, k + _list_lens[-1] - self._len if self._rebuild: self._fen_build() _fen_tree = self._fen_tree idx = -1 for d in reversed(range(len(_fen_tree).bit_length())): right_idx = idx + (1 << d) if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]: idx = right_idx k -= _fen_tree[idx] return idx + 1, k def _delete(self, pos, idx): """Delete value at the given `(pos, idx)`.""" _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len -= 1 self._fen_update(pos, -1) del _lists[pos][idx] _list_lens[pos] -= 1 if _list_lens[pos]: _mins[pos] = _lists[pos][0] else: del _lists[pos] del _list_lens[pos] del _mins[pos] self._rebuild = True def _loc_left(self, value): """Return an index pair that corresponds to the first position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins lo, pos = -1, len(_lists) - 1 while lo + 1 < pos: mi = (lo + pos) >> 1 if value <= _mins[mi]: pos = mi else: lo = mi if pos and value <= _lists[pos - 1][-1]: pos -= 1 _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value <= _list[mi]: idx = mi else: lo = mi return pos, idx def _loc_right(self, value): """Return an index pair that corresponds to the last position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins pos, hi = 0, len(_lists) while pos + 1 < hi: mi = (pos + hi) >> 1 if value < _mins[mi]: hi = mi else: pos = mi _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value < _list[mi]: idx = mi else: lo = mi return pos, idx def add(self, value): """Add `value` to sorted list.""" _load = self._load _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len += 1 if _lists: pos, idx = self._loc_right(value) self._fen_update(pos, 1) _list = _lists[pos] _list.insert(idx, value) _list_lens[pos] += 1 _mins[pos] = _list[0] if _load + _load < len(_list): _lists.insert(pos + 1, _list[_load:]) _list_lens.insert(pos + 1, len(_list) - _load) _mins.insert(pos + 1, _list[_load]) _list_lens[pos] = _load del _list[_load:] self._rebuild = True else: _lists.append([value]) _mins.append(value) _list_lens.append(1) self._rebuild = True def discard(self, value): """Remove `value` from sorted list if it is a member.""" _lists = self._lists if _lists: pos, idx = self._loc_right(value) if idx and _lists[pos][idx - 1] == value: self._delete(pos, idx - 1) def remove(self, value): """Remove `value` from sorted list; `value` must be a member.""" _len = self._len self.discard(value) if _len == self._len: raise ValueError('{0!r} not in list'.format(value)) def pop(self, index=-1): """Remove and return value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) value = self._lists[pos][idx] self._delete(pos, idx) return value def bisect_left(self, value): """Return the first index to insert `value` in the sorted list.""" pos, idx = self._loc_left(value) return self._fen_query(pos) + idx def bisect_right(self, value): """Return the last index to insert `value` in the sorted list.""" pos, idx = self._loc_right(value) return self._fen_query(pos) + idx def count(self, value): """Return number of occurrences of `value` in the sorted list.""" return self.bisect_right(value) - self.bisect_left(value) def __len__(self): """Return the size of the sorted list.""" return self._len def __getitem__(self, index): """Lookup value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) return self._lists[pos][idx] def __delitem__(self, index): """Remove value at `index` from sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) self._delete(pos, idx) def __contains__(self, value): """Return true if `value` is an element of the sorted list.""" _lists = self._lists if _lists: pos, idx = self._loc_left(value) return idx < len(_lists[pos]) and _lists[pos][idx] == value return False def __iter__(self): """Return an iterator over the sorted list.""" return (value for _list in self._lists for value in _list) def __reversed__(self): """Return a reverse iterator over the sorted list.""" return (value for _list in reversed(self._lists) for value in reversed(_list)) def __repr__(self): """Return string representation of sorted list.""" return 'SortedList({0})'.format(list(self)) # =============================================================================================== # some shortcuts mod = 1000000007 def testcase(t): for p in range(t): solve() def pow(x, y, p): res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0): return 0 while (y > 0): if ((y & 1) == 1): # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res from functools import reduce def factors(n): return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))) def gcd(a, b): if a == b: return a while b > 0: a, b = b, a % b return a # discrete binary search # minimise: # def search(): # l = 0 # r = 10 ** 15 # # for i in range(200): # if isvalid(l): # return l # if l == r: # return l # m = (l + r) // 2 # if isvalid(m) and not isvalid(m - 1): # return m # if isvalid(m): # r = m + 1 # else: # l = m # return m # maximise: # def search(): # l = 0 # r = 10 ** 15 # # for i in range(200): # # print(l,r) # if isvalid(r): # return r # if l == r: # return l # m = (l + r) // 2 # if isvalid(m) and not isvalid(m + 1): # return m # if isvalid(m): # l = m # else: # r = m - 1 # return m ##############Find sum of product of subsets of size k in a array # ar=[0,1,2,3] # k=3 # n=len(ar)-1 # dp=[0]*(n+1) # dp[0]=1 # for pos in range(1,n+1): # dp[pos]=0 # l=max(1,k+pos-n-1) # for j in range(min(pos,k),l-1,-1): # dp[j]=dp[j]+ar[pos]*dp[j-1] # print(dp[k]) def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10] return list(accumulate(ar)) def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4] return list(accumulate(ar[::-1]))[::-1] def N(): return int(inp()) def YES(): print("YES") def NO(): print("NO") def Yes(): print("Yes") def No(): print("No") # ========================================================================================= from collections import defaultdict def numberOfSetBits(i): i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 class MergeFind: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n self.num_sets = n # self.lista = [[_] for _ in range(n)] def find(self, a): to_update = [] while a != self.parent[a]: to_update.append(a) a = self.parent[a] for b in to_update: self.parent[b] = a return self.parent[a] def merge(self, a, b): a = self.find(a) b = self.find(b) if a == b: return if self.size[a] < self.size[b]: a, b = b, a self.num_sets -= 1 self.parent[b] = a self.size[a] += self.size[b] # self.lista[a] += self.lista[b] # self.lista[b] = [] def set_size(self, a): return self.size[self.find(a)] def __len__(self): return self.num_sets def lcm(a, b): return abs((a // gcd(a, b)) * b) # # to find factorial and ncr # tot = 200005 # mod = 10**9 + 7 # fac = [1, 1] # finv = [1, 1] # inv = [0, 1] # # for i in range(2, tot + 1): # fac.append((fac[-1] * i) % mod) # inv.append(mod - (inv[mod % i] * (mod // i) % mod)) # finv.append(finv[-1] * inv[-1] % mod) def comb(n, r): if n < r: return 0 else: return fac[n] * (finv[r] * finv[n - r] % mod) % mod def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input def out(var): sys.stdout.write(str(var)) # for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) def fsep(): return map(float, inp().split()) def nextline(): out("\n") # as stdout.write always print sring. def arr1d(n, v): return [v] * n def arr2d(n, m, v): return [[v] * m for _ in range(n)] def arr3d(n, m, p, v): return [[[v] * p for _ in range(m)] for i in range(n)] def solve(): n=N() d=defaultdict(int) for _ in range(n): x1,y1,u1,v1=sep() U=(u1-x1) V=(v1-y1) aU=abs(U) aV=abs(V) g=gcd(aU,aV) U//=g V//=g d[(U,V)]+=1 # print(d) ans=0 KEYS=list(d.keys()) for i in KEYS: a,b=i am,bm=-a,-b ans+=(d[(a,b)]*d[(am,bm)]) print(ans//2) #solve() testcase(int(inp())) # 5 # 3 6 # 5 10 # 4 3 # 2 1 # 1 3 ```
instruction
0
64,194
3
128,388
Yes
output
1
64,194
3
128,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): def __init__(self, file): self.newlines = 0 self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline() # -------------------------------------------------------------------- def RL(): return map(int, sys.stdin.readline().split()) def RLL(): return list(map(int, sys.stdin.readline().split())) def N(): return int(input()) def S(): return input().strip() def print_list(l): print(' '.join(map(str, l))) # sys.setrecursionlimit(100000) # import random # from functools import reduce # from functools import lru_cache # from heapq import * # from collections import deque as dq from math import * # import bisect as bs # from collections import Counter from collections import defaultdict as dc for _ in range(N()): dic = dc(int) for _ in range(N()): x, y, u, v = RL() dx, dy = u - x, v - y if dx == 0: dic[(0, 1 if dy > 0 else -1)] += 1 elif dy == 0: dic[(1 if dx > 0 else -1, 0)] += 1 else: t = gcd(dx, dy) dic[(dx // t, dy // t)] += 1 print(sum(dic[(x, y)] * dic[(-x, -y)] for (x, y) in dic if (-x, -y) in dic) >> 1) ```
instruction
0
64,195
3
128,390
Yes
output
1
64,195
3
128,391
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- from math import gcd as GCD;from collections import Counter for j in range(int(input())): n=int(input());ans=0;count=Counter() for s in range(n): a,b,c,d=map(int,input().split()) x=c-a;y=d-b;gcd=GCD(x,y) x//=gcd;y//=gcd ans+=count[-x,-y];count[x,y]+=1 print(ans) ```
instruction
0
64,196
3
128,392
Yes
output
1
64,196
3
128,393
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` import math for _ in range(int(input())): n=int(input()) xyuv=[] for i in range(n): xyuv.append(list(map(int, input().split()))) dangle={} for i in xyuv: deltaY=(i[3]-i[1]) deltaX=(i[2]-i[0]) angleInDegrees = math.atan2(deltaY, deltaX) #* 180 / math.pi if angleInDegrees in dangle: dangle[angleInDegrees]+=1 else: dangle[angleInDegrees]=1 ans=0 vis={} for i in dangle.keys(): if -math.pi+i in dangle.keys() : #print(i-180) ans+=dangle[i]*dangle[-math.pi+i] #print(dangle) print(ans) ```
instruction
0
64,197
3
128,394
No
output
1
64,197
3
128,395
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` import math import sys class Read: @staticmethod def string(): return input() @staticmethod def int(): return int(input()) @staticmethod def list(sep=' '): return input().split(sep) @staticmethod def list_int(sep=' '): return list(map(int, input().split(sep))) def solve(): n = Read.int() a = {} b = {} for i in range(n): x, y, u, v = Read.list_int() k1 = abs(x - u) k2 = abs(y - v) t = '0.0' if k2 == 0 else k1 / k2; t = str(t) if (x > u and y >= v) or (x < u and y <= v): t += '_' use_a = 1 if y > v: use_a = 1 elif v < y: use_a = 0 else: use_a = 1 if x > u else 0 if use_a == 1: if t in a: a[t] += 1 else: a[t] = 1 else: if t in b: b[t] += 1 else: b[t] = 1 res = 0 # print(a) # print(b) # print(0 / 2) for k, t in a.items(): if k in b: res += t * b[k] print(res) # query_count = 1 query_count = Read.int() while query_count: query_count -= 1 solve() ```
instruction
0
64,198
3
128,396
No
output
1
64,198
3
128,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` import sys, math input = sys.stdin.readline from collections import Counter for _ in range(int(input())): n = int(input()) A = [list(map(int, input().split())) for _ in range(n)] cnt = Counter() ans = 0 for x, y, u, v in A: deg = math.atan2(v - y, u - x) / math.pi * 180 if deg < 0: deg += 360 ans += cnt[(deg + 180) % 360] cnt[deg] += 1 print(ans) ```
instruction
0
64,199
3
128,398
No
output
1
64,199
3
128,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i). At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn. It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time. Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment). Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≀ 10^9; x_i β‰  u_i or y_i β‰  v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case. The sum of n over all test cases does not exceed 10^5. Output For each test case, print one integer β€” the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment. Example Input 3 2 0 0 0 1 1 0 2 0 3 0 0 1 1 1 1 0 0 1 0 2 0 6 0 0 0 1 1 0 1 2 2 0 2 3 3 0 3 -5 4 0 4 -5 5 0 5 -5 Output 0 1 9 Submitted Solution: ``` import math import sys class Read: @staticmethod def string(): return input() @staticmethod def int(): return int(input()) @staticmethod def list(sep=' '): return input().split(sep) @staticmethod def list_int(sep=' '): return list(map(int, input().split(sep))) def solve(): n = Read.int() a = {} b = {} for i in range(n): x, y, u, v = Read.list_int() k1 = abs(x - u) k2 = abs(y - v) t = 'inf' if k2 == 0 else k1 / k2; t = str(t) if (x > u and y > v) or (x < u and y < v): t += '_' use_a = 1 if y > v: use_a = 1 elif v < y: use_a = 0 else: use_a = 1 if x > u else 0 if use_a == 1: if t in a: a[t] += 1 else: a[t] = 1 else: if t in b: b[t] += 1 else: b[t] = 1 res = 0 # print(a) # print(b) for k, t in a.items(): if k in b: res += t * b[k] print(res) # query_count = 1 query_count = Read.int() while query_count: query_count -= 1 solve() ```
instruction
0
64,200
3
128,400
No
output
1
64,200
3
128,401
Provide tags and a correct Python 3 solution for this coding contest problem. Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request. Also, there are now villages with as few as a single inhabitant, meaning that <image>. Can you help Heidi find out whether a village follows a Poisson or a uniform distribution? Input Same as for the easy and medium versions. But remember that now 1 ≀ P ≀ 1000 and that the marmots may provide positive as well as negative integers. Output Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution.
instruction
0
64,499
3
128,998
Tags: math, probabilities Correct Solution: ``` def sampleVariance(V): X = sum(V) / len(V) S = 0.0 for x in V: S += (X-x)**2 S /= (len(V)-1) return (X, S) #That awkward moment when you realized that variance is sigma^2 but you just took the stat course this semester for i in range(int(input())): V = list(map(int, input().split())) X, S = sampleVariance(V) print("{}".format("uniform" if max(V) < 1.9*(S**0.5) else "poisson")) ```
output
1
64,499
3
128,999
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request. Also, there are now villages with as few as a single inhabitant, meaning that <image>. Can you help Heidi find out whether a village follows a Poisson or a uniform distribution? Input Same as for the easy and medium versions. But remember that now 1 ≀ P ≀ 1000 and that the marmots may provide positive as well as negative integers. Output Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution. Submitted Solution: ``` def sampleVariance(V): X = sum(V) / len(V) S = 0.0 for x in V: S += (X-x)**2 S /= (len(V)-1) return (X, S) #That awkward moment when you realized that variance is sigma^2 but you just took the stat course this semester for i in range(int(input())): V = list(map(int, input().split())) X, S = sampleVariance(V) print("{}".format("uniform" if max(V) <= 2*(S**0.5) else "poisson")) ```
instruction
0
64,501
3
129,002
No
output
1
64,501
3
129,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request. Also, there are now villages with as few as a single inhabitant, meaning that <image>. Can you help Heidi find out whether a village follows a Poisson or a uniform distribution? Input Same as for the easy and medium versions. But remember that now 1 ≀ P ≀ 1000 and that the marmots may provide positive as well as negative integers. Output Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution. Submitted Solution: ``` v = int(input()) eps = 170 def ans(a): a.sort() if len(a) % 2 == 0: med = a[len(a)//2] else: med = (a[len(a)//2] + a[len(a)//2 - 1]) // 2 l = med - med // 2 r = med + med // 2 c1 = c2 = 0 for i in a: if i >= l and i <= r: c1 += 1 else: c2 += 1 if abs(c1 - c2) <= eps: return "uniform" else: return "poisson" for i in range(v): cur = [int(i) for i in input().split()] print(ans(cur)) ```
instruction
0
64,502
3
129,004
No
output
1
64,502
3
129,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request. Also, there are now villages with as few as a single inhabitant, meaning that <image>. Can you help Heidi find out whether a village follows a Poisson or a uniform distribution? Input Same as for the easy and medium versions. But remember that now 1 ≀ P ≀ 1000 and that the marmots may provide positive as well as negative integers. Output Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution. Submitted Solution: ``` for i in range(int(input())): a=list(map(int,input().split())) mx=max(list(map(abs,a))) std=(sum(list(map(lambda x:x*x,a)))/len(a))**0.5 print(mx, std) print('poisson'if mx/std>2 else'uniform') ```
instruction
0
64,503
3
129,006
No
output
1
64,503
3
129,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request. Also, there are now villages with as few as a single inhabitant, meaning that <image>. Can you help Heidi find out whether a village follows a Poisson or a uniform distribution? Input Same as for the easy and medium versions. But remember that now 1 ≀ P ≀ 1000 and that the marmots may provide positive as well as negative integers. Output Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution. Submitted Solution: ``` for i in range(int(input())): a=list(map(int,input().split())) mx=max(list(map(abs,a))) var=sum(list(map(lambda x:x*x,a))) print('poisson'if mx/(var**0.5)<2 else'uniform') ```
instruction
0
64,504
3
129,008
No
output
1
64,504
3
129,009
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,690
3
129,380
"Correct Solution: ``` n=int(input()) x=list(map(int,input().split())) m=10**9+7 c=1 a=1 for i in range(n-1):c=min((x[i]+3)//2,c+1);a=a*c%m print(a%m) ```
output
1
64,690
3
129,381
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,691
3
129,382
"Correct Solution: ``` N = int(input()) X = list(map(int, input().split())) MOD = 10**9 + 7 cnt = 1 j = 1 n_to_remove = 0 runner = 1 for i,x in enumerate(X): j = i+1 - n_to_remove if runner > x: n_to_remove += 1 runner = x-1 runner += 2 cnt = (cnt*j)%MOD print(cnt) ```
output
1
64,691
3
129,383
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,692
3
129,384
"Correct Solution: ``` import sys from math import factorial def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): N = int(input()) X = [int(i) for i in input().split()] MOD = 10**9 + 7 ans = 1 stack = 0 for x in X: stack += 1 if x < 2*(stack - 1) + 1: ans *= stack ans %= MOD stack -= 1 ans *= (factorial(stack) % MOD) ans %= MOD print(ans) if __name__ == '__main__': solve() ```
output
1
64,692
3
129,385
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,693
3
129,386
"Correct Solution: ``` N = int(input()) A = list(map(int, input().split())) MOD = 10**9 + 7 class Combination: def __init__(self, size, mod=10**9 + 7): self.size = size + 2 self.mod = mod self.fact = [1, 1] + [0] * size self.factInv = [1, 1] + [0] * size self.inv = [0, 1] + [0] * size for i in range(2, self.size): self.fact[i] = self.fact[i - 1] * i % self.mod self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod def npr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * self.factInv[n - r] % self.mod def ncr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod def factN(self, n): if n < 0: return 0 return self.fact[n] comb = Combination(N + 100) ans = 1 dis = 0 for num, a in enumerate(A, start=1): nowRobot = num - dis maxRobot = -(-a // 2) if maxRobot >= nowRobot: continue else: ans *= comb.npr(nowRobot, nowRobot - maxRobot) ans %= MOD dis += nowRobot - maxRobot ans *= comb.factN(N - dis) ans %= MOD print(ans) ```
output
1
64,693
3
129,387
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,694
3
129,388
"Correct Solution: ``` N,*X=map(int,open(0).read().split()) a=s=1 for x in X: a=a*s%(10**9+7) if 2*~-s<x:s+=1 print(a) ```
output
1
64,694
3
129,389
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,695
3
129,390
"Correct Solution: ``` n,ans,j=input(),1,1 for i in input().split(): ans=ans*j%int(1e9+7) j+=j*2<int(i)+2 print(ans) ```
output
1
64,695
3
129,391
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,696
3
129,392
"Correct Solution: ``` #!/usr/bin/python3.6 MOD = 10**9 + 7 n = int(input()) a = [int(item) for item in input().split()] ans = 1 prev = 0 vacant = 0 robot = 0 for item in a: vacant += item - prev - 1 robot += 1 if vacant <= robot - 2: ans *= robot ans %= MOD robot -= 1 vacant += 1 prev = item for i in range(robot): ans *= i+1 ans %= MOD print(ans) ```
output
1
64,696
3
129,393
Provide a correct Python 3 solution for this coding contest problem. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following operation: * Select a robot on the number line. Let the coordinate of the robot be x. Select the destination coordinate, either x-1 or x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7. Constraints * 2 ≀ N ≀ 10^5 * x_i is an integer. * 0 < x_1 < x_2 < ... < x_N ≀ 10^9 Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7. Examples Input 3 1 2 3 Output 4 Input 3 2 3 4 Output 6 Input 8 1 2 3 5 7 11 13 17 Output 10080 Input 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Output 311014372
instruction
0
64,697
3
129,394
"Correct Solution: ``` import sys input = sys.stdin.readline sys.setrecursionlimit(pow(10, 6)) MOD = pow(10, 9) + 7 def main(): n = int(input()) x = list(map(int, input().split())) fac = [1] for i in range(2, n+1): fac.append(fac[-1]*i%MOD) ans= 1 i = 1 for _x in x: if _x < 2*i-1: ans = ans * i % MOD else: i += 1 ans = ans * fac[i-2] % MOD print(ans) if __name__ == '__main__': main() ```
output
1
64,697
3
129,395