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. There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|. Here, |x| denotes the absolute value of x. If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to? Constraints * 1 \leq N,M \leq 50 * -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8 * All input values are integers. Input The input is given from Standard Input in the following format: N M a_1 b_1 : a_N b_N c_1 d_1 : c_M d_M Output Print N lines. The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go. Examples Input 2 2 2 0 0 0 -1 0 1 0 Output 2 1 Input 3 4 10 10 -10 -10 3 3 1 2 2 3 3 5 3 5 Output 3 1 2 Input 5 5 -100000000 -100000000 -100000000 100000000 100000000 -100000000 100000000 100000000 0 0 0 0 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 Output 5 4 3 2 1 Submitted Solution: ``` n, m = map(int, input().split()) AB = [[int(i) for i in input().split()] for i in range(n)] CD = [[int(i) for i in input().split()] for i in range(m)] for ab in AB: dist = [abs(ab[0] - cd[0]) + abs(ab[1] - cd[1]) for cd in CD] print(dist.index(min(dist)) + 1) ```
instruction
0
86,428
3
172,856
Yes
output
1
86,428
3
172,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|. Here, |x| denotes the absolute value of x. If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to? Constraints * 1 \leq N,M \leq 50 * -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8 * All input values are integers. Input The input is given from Standard Input in the following format: N M a_1 b_1 : a_N b_N c_1 d_1 : c_M d_M Output Print N lines. The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go. Examples Input 2 2 2 0 0 0 -1 0 1 0 Output 2 1 Input 3 4 10 10 -10 -10 3 3 1 2 2 3 3 5 3 5 Output 3 1 2 Input 5 5 -100000000 -100000000 -100000000 100000000 100000000 -100000000 100000000 100000000 0 0 0 0 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 Output 5 4 3 2 1 Submitted Solution: ``` N, M = map(int,input().split()) list_a = [] list_b = [] ans_x = [10**8 for i in range(N)] count = 0 for i in range(N): a = [int(i) for i in input().split()] list_a.append(a) for i in range(M): b = [int(i) for i in input().split()] list_b.append(b) for i in range(N): for j in range(M): x = abs(list_a[i][0]-list_b[j][0]) y = abs(list_a[i][1]-list_b[j][1]) xxx = x + y if xxx < ans_x[i]: ans_x[i] = xxx count = j+1 print(count) ```
instruction
0
86,429
3
172,858
No
output
1
86,429
3
172,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|. Here, |x| denotes the absolute value of x. If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to? Constraints * 1 \leq N,M \leq 50 * -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8 * All input values are integers. Input The input is given from Standard Input in the following format: N M a_1 b_1 : a_N b_N c_1 d_1 : c_M d_M Output Print N lines. The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go. Examples Input 2 2 2 0 0 0 -1 0 1 0 Output 2 1 Input 3 4 10 10 -10 -10 3 3 1 2 2 3 3 5 3 5 Output 3 1 2 Input 5 5 -100000000 -100000000 -100000000 100000000 100000000 -100000000 100000000 100000000 0 0 0 0 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 Output 5 4 3 2 1 Submitted Solution: ``` #!/usr/bin/env python nm = [int(i) for i in input().split()] n = nm[0] m = nm[1] student = list() point = list() for i in range(n): student.append([int(a) for a in input().split()]) for j in range(m): point.append([int(b) for b in input().split()]) mat = [[abs(student[i][0]-point[j][0]) + abs(student[i][1]-point[j][1]) for i in range(n)] for j in range(m)] for i in range(n): print(mat[i].index(min(mat[i]))+1) ```
instruction
0
86,430
3
172,860
No
output
1
86,430
3
172,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|. Here, |x| denotes the absolute value of x. If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to? Constraints * 1 \leq N,M \leq 50 * -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8 * All input values are integers. Input The input is given from Standard Input in the following format: N M a_1 b_1 : a_N b_N c_1 d_1 : c_M d_M Output Print N lines. The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go. Examples Input 2 2 2 0 0 0 -1 0 1 0 Output 2 1 Input 3 4 10 10 -10 -10 3 3 1 2 2 3 3 5 3 5 Output 3 1 2 Input 5 5 -100000000 -100000000 -100000000 100000000 100000000 -100000000 100000000 100000000 0 0 0 0 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 Output 5 4 3 2 1 Submitted Solution: ``` if __name__ == '__main__': a, b = map(int, input().split()) lista=[] for i in range(a): c = [int(i) for i in input().split()] lista.append(c) listb=[] for i in range(b): c = [int(i) for i in input().split()] listb.append(c) listc =[] for i in lista: min = 51*51 minroot=-1 for j in range(len(listb)): root = (i[0] - listb[j][0]) + (i[1] - listb[j][1]) if root <min: min =root minroot=j+1 listc.append(minroot) for i in listc: print(i) ```
instruction
0
86,431
3
172,862
No
output
1
86,431
3
172,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|. Here, |x| denotes the absolute value of x. If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to? Constraints * 1 \leq N,M \leq 50 * -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8 * All input values are integers. Input The input is given from Standard Input in the following format: N M a_1 b_1 : a_N b_N c_1 d_1 : c_M d_M Output Print N lines. The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go. Examples Input 2 2 2 0 0 0 -1 0 1 0 Output 2 1 Input 3 4 10 10 -10 -10 3 3 1 2 2 3 3 5 3 5 Output 3 1 2 Input 5 5 -100000000 -100000000 -100000000 100000000 100000000 -100000000 100000000 100000000 0 0 0 0 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 Output 5 4 3 2 1 Submitted Solution: ``` N,M=map(int,input().split()) stand=[list(map(int,input().split())) for _ in range(N)] point=[list(map(int,input().split())) for _ in range(M)] new_stand=[None]*N for i in range(N): nearest=abs(stand[i][0]-point[0][0])+abs(stand[i][1]-point[i][1]) near_ind=M for j in range(N): man=abs(point[j][0]-stand[i][0]) + abs(point[j][1]-stand[i][1]) if nearest>man: nearest=man near_ind=j new_stand[i]=near_ind+1 for i in range(N): print(new_stand[i]) ```
instruction
0
86,432
3
172,864
No
output
1
86,432
3
172,865
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing. A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0. Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change. Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units. Input The input is given in the following format. N a1 b1 a2 b2 :: aN bN The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given. Output The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized. Examples Input 3 2 1 1 3 2 2 Output 3 0 5 0 Input 1 100000 2 Output 100002 0 Submitted Solution: ``` n = int(input()) s = 0 for i in range(n): a, b = map(int, input().split()) s += 1 << (a+b) i = 0 ans = [] while s: if s & 1: ans.append(i) s >>= 1 i += 1 print(len(ans)) for e in ans: print(e, 0) ```
instruction
0
86,484
3
172,968
No
output
1
86,484
3
172,969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Step up and down Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and he was so lacking in exercise that he was tired even if he moved a little. Therefore, Kerr decided to start an easy-to-start exercise, "stepping up and down," as the first step to achieve good results with ICPC. As the name suggests, stepping up and down is a simple exercise that simply repeats going up and down between the step and the floor. However, in stepping up and down, the effect cannot be obtained unless the feet are raised and lowered correctly. Correct ascent and descent is the movement of the foot that satisfies either of the following two types. * From the state where both feet are on the floor, the left foot and the right foot are raised on the stepping stone, and both feet are on the stepping stone. Either the left foot or the right foot may be raised first. * From the state where both feet are on the platform, the left foot and the right foot are lowered to the floor, and both feet are on the floor. Either the left foot or the right foot may be lowered first. As can be seen from the above, raising and lowering only one leg continuously from the state of being on the floor or stepping stone does not result in correct raising and lowering. In the stepping up / down movement, when any of the above correct up / down movements is satisfied, it is counted as one time, and the larger the count number, the more effective the effect can be obtained. Note that even if you don't go back and forth between the floor and the platform, it counts as one only one way. You want your teammate, Kerr, to be as strong as possible. So you decided to write a program and check if Kerr was skipping the step up and down. Since the information of the foot that Kerr moved by going up and down the platform is given, find the number of times that he went up and down correctly. However, it is assumed that both feet are on the floor before going up and down the platform. Input The input consists of multiple data sets, and the number of data sets contained in one input is 150 or less. The format of each data set is as follows. > $ n $ > $ f_1 $ $ f_2 $ ... $ f_n $ In the first line, the integer $ n $ ($ 1 \ le n \ le 100 $) representing the number of times the foot is moved is given. In the second line, $ f_i $, which is a character string representing the movement of the foot, is given in chronological order by $ n $, separated by spaces. $ f_i $ is one of the following four types of character strings. * "lu": Raise your left foot to the platform. * "ru": Raise your right foot to the platform. * "ld": Lower your left foot to the floor. * "rd": Lower your right foot to the floor. It can be assumed that no action is input that lowers the foot on the floor or raises the foot on the platform. The line where $ n $ is 0 indicates the end of input. Do not process this data. Output For each dataset, output the number of correct steps up and down in one line. Note that if you do not output a line break at the end of each line, or if you output unnecessary characters, it will be judged as an incorrect answer. Sample Input Four lu ru ld rd Four lu ld lu ru 1 lu Ten ru lu ld rd ru rd ru lu lu rd ld 0 Output for Sample Input 2 1 0 Four Example Input 4 lu ru ld rd 4 lu ld lu ru 1 lu 10 ru lu ld rd ru rd ru lu rd ld 0 Output 2 1 0 4 Submitted Solution: ``` def main(): N = int(input()) answer = [] while N != 0: cmd = [i for i in input().split()] ans = 0 g_flag = True p = ["ld", "rd"] for c in cmd: if c[0] == "l": p[0] = c else: p[1] = c if g_flag and p[0] == "lu" and p[1] == "ru": g_flag = False ans += 1 if not g_flag and p[0] == "ld" and p[1] == "rd": g_flag = True ans += 1 answer.append(ans) N = int(input()) print(*answer,sep="\n") if __name__ == '__main__': main() ```
instruction
0
86,533
3
173,066
Yes
output
1
86,533
3
173,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Step up and down Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and he was so lacking in exercise that he was tired even if he moved a little. Therefore, Kerr decided to start an easy-to-start exercise, "stepping up and down," as the first step to achieve good results with ICPC. As the name suggests, stepping up and down is a simple exercise that simply repeats going up and down between the step and the floor. However, in stepping up and down, the effect cannot be obtained unless the feet are raised and lowered correctly. Correct ascent and descent is the movement of the foot that satisfies either of the following two types. * From the state where both feet are on the floor, the left foot and the right foot are raised on the stepping stone, and both feet are on the stepping stone. Either the left foot or the right foot may be raised first. * From the state where both feet are on the platform, the left foot and the right foot are lowered to the floor, and both feet are on the floor. Either the left foot or the right foot may be lowered first. As can be seen from the above, raising and lowering only one leg continuously from the state of being on the floor or stepping stone does not result in correct raising and lowering. In the stepping up / down movement, when any of the above correct up / down movements is satisfied, it is counted as one time, and the larger the count number, the more effective the effect can be obtained. Note that even if you don't go back and forth between the floor and the platform, it counts as one only one way. You want your teammate, Kerr, to be as strong as possible. So you decided to write a program and check if Kerr was skipping the step up and down. Since the information of the foot that Kerr moved by going up and down the platform is given, find the number of times that he went up and down correctly. However, it is assumed that both feet are on the floor before going up and down the platform. Input The input consists of multiple data sets, and the number of data sets contained in one input is 150 or less. The format of each data set is as follows. > $ n $ > $ f_1 $ $ f_2 $ ... $ f_n $ In the first line, the integer $ n $ ($ 1 \ le n \ le 100 $) representing the number of times the foot is moved is given. In the second line, $ f_i $, which is a character string representing the movement of the foot, is given in chronological order by $ n $, separated by spaces. $ f_i $ is one of the following four types of character strings. * "lu": Raise your left foot to the platform. * "ru": Raise your right foot to the platform. * "ld": Lower your left foot to the floor. * "rd": Lower your right foot to the floor. It can be assumed that no action is input that lowers the foot on the floor or raises the foot on the platform. The line where $ n $ is 0 indicates the end of input. Do not process this data. Output For each dataset, output the number of correct steps up and down in one line. Note that if you do not output a line break at the end of each line, or if you output unnecessary characters, it will be judged as an incorrect answer. Sample Input Four lu ru ld rd Four lu ld lu ru 1 lu Ten ru lu ld rd ru rd ru lu lu rd ld 0 Output for Sample Input 2 1 0 Four Example Input 4 lu ru ld rd 4 lu ld lu ru 1 lu 10 ru lu ld rd ru rd ru lu rd ld 0 Output 2 1 0 4 Submitted Solution: ``` ansli=[] while 1: n=input() if n=="0": break a=input().split() up=0 down=1 lu=0 ru=0 ld=0 rd=0 count=0 for i in a: if i=="ru": ru=1 rd=0 elif i=="lu": lu=1 ld=0 elif i=="rd": rd=1 ru=0 elif i=="ld": ld=1 lu=0 if ru==1 and lu==1 and down==1: count+=1 down=0 up=1 elif rd==1 and ld==1 and up==1: count+=1 down=1 up=0 ansli.append(count) #print(count) for i in ansli: print(i) ```
instruction
0
86,534
3
173,068
Yes
output
1
86,534
3
173,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Step up and down Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and he was so lacking in exercise that he was tired even if he moved a little. Therefore, Kerr decided to start an easy-to-start exercise, "stepping up and down," as the first step to achieve good results with ICPC. As the name suggests, stepping up and down is a simple exercise that simply repeats going up and down between the step and the floor. However, in stepping up and down, the effect cannot be obtained unless the feet are raised and lowered correctly. Correct ascent and descent is the movement of the foot that satisfies either of the following two types. * From the state where both feet are on the floor, the left foot and the right foot are raised on the stepping stone, and both feet are on the stepping stone. Either the left foot or the right foot may be raised first. * From the state where both feet are on the platform, the left foot and the right foot are lowered to the floor, and both feet are on the floor. Either the left foot or the right foot may be lowered first. As can be seen from the above, raising and lowering only one leg continuously from the state of being on the floor or stepping stone does not result in correct raising and lowering. In the stepping up / down movement, when any of the above correct up / down movements is satisfied, it is counted as one time, and the larger the count number, the more effective the effect can be obtained. Note that even if you don't go back and forth between the floor and the platform, it counts as one only one way. You want your teammate, Kerr, to be as strong as possible. So you decided to write a program and check if Kerr was skipping the step up and down. Since the information of the foot that Kerr moved by going up and down the platform is given, find the number of times that he went up and down correctly. However, it is assumed that both feet are on the floor before going up and down the platform. Input The input consists of multiple data sets, and the number of data sets contained in one input is 150 or less. The format of each data set is as follows. > $ n $ > $ f_1 $ $ f_2 $ ... $ f_n $ In the first line, the integer $ n $ ($ 1 \ le n \ le 100 $) representing the number of times the foot is moved is given. In the second line, $ f_i $, which is a character string representing the movement of the foot, is given in chronological order by $ n $, separated by spaces. $ f_i $ is one of the following four types of character strings. * "lu": Raise your left foot to the platform. * "ru": Raise your right foot to the platform. * "ld": Lower your left foot to the floor. * "rd": Lower your right foot to the floor. It can be assumed that no action is input that lowers the foot on the floor or raises the foot on the platform. The line where $ n $ is 0 indicates the end of input. Do not process this data. Output For each dataset, output the number of correct steps up and down in one line. Note that if you do not output a line break at the end of each line, or if you output unnecessary characters, it will be judged as an incorrect answer. Sample Input Four lu ru ld rd Four lu ld lu ru 1 lu Ten ru lu ld rd ru rd ru lu lu rd ld 0 Output for Sample Input 2 1 0 Four Example Input 4 lu ru ld rd 4 lu ld lu ru 1 lu 10 ru lu ld rd ru rd ru lu rd ld 0 Output 2 1 0 4 Submitted Solution: ``` while True: n = int(input()) if n == 0: break step = list(input().split()) l = r = 0 ne = 1 cnt = 0 for mov in step: if mov == "lu": l = 1 elif mov == "ru": r = 1 elif mov == "ld": l = 0 else: r = 0 if l == r == ne: cnt += 1 ne = (ne + 1) % 2 print(cnt) ```
instruction
0
86,535
3
173,070
Yes
output
1
86,535
3
173,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Step up and down Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and he was so lacking in exercise that he was tired even if he moved a little. Therefore, Kerr decided to start an easy-to-start exercise, "stepping up and down," as the first step to achieve good results with ICPC. As the name suggests, stepping up and down is a simple exercise that simply repeats going up and down between the step and the floor. However, in stepping up and down, the effect cannot be obtained unless the feet are raised and lowered correctly. Correct ascent and descent is the movement of the foot that satisfies either of the following two types. * From the state where both feet are on the floor, the left foot and the right foot are raised on the stepping stone, and both feet are on the stepping stone. Either the left foot or the right foot may be raised first. * From the state where both feet are on the platform, the left foot and the right foot are lowered to the floor, and both feet are on the floor. Either the left foot or the right foot may be lowered first. As can be seen from the above, raising and lowering only one leg continuously from the state of being on the floor or stepping stone does not result in correct raising and lowering. In the stepping up / down movement, when any of the above correct up / down movements is satisfied, it is counted as one time, and the larger the count number, the more effective the effect can be obtained. Note that even if you don't go back and forth between the floor and the platform, it counts as one only one way. You want your teammate, Kerr, to be as strong as possible. So you decided to write a program and check if Kerr was skipping the step up and down. Since the information of the foot that Kerr moved by going up and down the platform is given, find the number of times that he went up and down correctly. However, it is assumed that both feet are on the floor before going up and down the platform. Input The input consists of multiple data sets, and the number of data sets contained in one input is 150 or less. The format of each data set is as follows. > $ n $ > $ f_1 $ $ f_2 $ ... $ f_n $ In the first line, the integer $ n $ ($ 1 \ le n \ le 100 $) representing the number of times the foot is moved is given. In the second line, $ f_i $, which is a character string representing the movement of the foot, is given in chronological order by $ n $, separated by spaces. $ f_i $ is one of the following four types of character strings. * "lu": Raise your left foot to the platform. * "ru": Raise your right foot to the platform. * "ld": Lower your left foot to the floor. * "rd": Lower your right foot to the floor. It can be assumed that no action is input that lowers the foot on the floor or raises the foot on the platform. The line where $ n $ is 0 indicates the end of input. Do not process this data. Output For each dataset, output the number of correct steps up and down in one line. Note that if you do not output a line break at the end of each line, or if you output unnecessary characters, it will be judged as an incorrect answer. Sample Input Four lu ru ld rd Four lu ld lu ru 1 lu Ten ru lu ld rd ru rd ru lu lu rd ld 0 Output for Sample Input 2 1 0 Four Example Input 4 lu ru ld rd 4 lu ld lu ru 1 lu 10 ru lu ld rd ru rd ru lu rd ld 0 Output 2 1 0 4 Submitted Solution: ``` Set = [("lu", "ru"), ("ru","lu"), ("ld","rd"), ("rd","ld")] while True : n = int(input()) if(n == 0) : break else : F = list(map(str, input().split())) cnt = 0 while(len(F) > 1) : if((F[0], F[1]) in Set) : cnt += 1 del F[0 : 2] else : del F[0] print(cnt) ```
instruction
0
86,536
3
173,072
Yes
output
1
86,536
3
173,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Step up and down Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and he was so lacking in exercise that he was tired even if he moved a little. Therefore, Kerr decided to start an easy-to-start exercise, "stepping up and down," as the first step to achieve good results with ICPC. As the name suggests, stepping up and down is a simple exercise that simply repeats going up and down between the step and the floor. However, in stepping up and down, the effect cannot be obtained unless the feet are raised and lowered correctly. Correct ascent and descent is the movement of the foot that satisfies either of the following two types. * From the state where both feet are on the floor, the left foot and the right foot are raised on the stepping stone, and both feet are on the stepping stone. Either the left foot or the right foot may be raised first. * From the state where both feet are on the platform, the left foot and the right foot are lowered to the floor, and both feet are on the floor. Either the left foot or the right foot may be lowered first. As can be seen from the above, raising and lowering only one leg continuously from the state of being on the floor or stepping stone does not result in correct raising and lowering. In the stepping up / down movement, when any of the above correct up / down movements is satisfied, it is counted as one time, and the larger the count number, the more effective the effect can be obtained. Note that even if you don't go back and forth between the floor and the platform, it counts as one only one way. You want your teammate, Kerr, to be as strong as possible. So you decided to write a program and check if Kerr was skipping the step up and down. Since the information of the foot that Kerr moved by going up and down the platform is given, find the number of times that he went up and down correctly. However, it is assumed that both feet are on the floor before going up and down the platform. Input The input consists of multiple data sets, and the number of data sets contained in one input is 150 or less. The format of each data set is as follows. > $ n $ > $ f_1 $ $ f_2 $ ... $ f_n $ In the first line, the integer $ n $ ($ 1 \ le n \ le 100 $) representing the number of times the foot is moved is given. In the second line, $ f_i $, which is a character string representing the movement of the foot, is given in chronological order by $ n $, separated by spaces. $ f_i $ is one of the following four types of character strings. * "lu": Raise your left foot to the platform. * "ru": Raise your right foot to the platform. * "ld": Lower your left foot to the floor. * "rd": Lower your right foot to the floor. It can be assumed that no action is input that lowers the foot on the floor or raises the foot on the platform. The line where $ n $ is 0 indicates the end of input. Do not process this data. Output For each dataset, output the number of correct steps up and down in one line. Note that if you do not output a line break at the end of each line, or if you output unnecessary characters, it will be judged as an incorrect answer. Sample Input Four lu ru ld rd Four lu ld lu ru 1 lu Ten ru lu ld rd ru rd ru lu lu rd ld 0 Output for Sample Input 2 1 0 Four Example Input 4 lu ru ld rd 4 lu ld lu ru 1 lu 10 ru lu ld rd ru rd ru lu rd ld 0 Output 2 1 0 4 Submitted Solution: ``` def main(): while True: n = int(input()) if n == 0: exit() f = [s for input().split()] pm = 'd' cnt = 0 for m in f: if m[1] == pm: cnt += 1 pm = m[1] print(cnt) if __name__ == '__main__': main() ```
instruction
0
86,537
3
173,074
No
output
1
86,537
3
173,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three numbers: position (x_i), radius of sight (r_i) and IQ (q_i). Since they are intelligent robots, some of them will talk if they see each other. Radius of sight is inclusive, so robot can see other all robots in range [x_i - r_i, x_i + r_i]. But they don't walk to talk with anybody, but only with robots who have similar IQ. By similar IQ we mean that their absolute difference isn't more than K. Help us and calculate how many pairs of robots are going to talk with each other, so we can timely update their software and avoid any potential quarrel. Input The first line contains two integers, numbers N (1 ≤ N ≤ 10^5) and K (0 ≤ K ≤ 20). Next N lines contain three numbers each x_i, r_i, q_i (0 ≤ x_i,r_i,q_i ≤ 10^9) — position, radius of sight and IQ of every robot respectively. Output Output contains only one number — solution to the problem. Example Input 3 2 3 6 1 7 3 10 10 5 8 Output 1 Note The first robot can see the second, but not vice versa. The first robot can't even see the third. The second and the third robot can see each other and their IQs don't differ more than 2 so only one conversation will happen. Submitted Solution: ``` import math def get_input_list(): return list(map(int, input().split())) N,K = get_input_list() data = [] for i in range(N): data.append(get_input_list()) data.sort() def search(data,l,n,p=0,): if data[0][0] > n: return -1 mid = int(l/2) if l <= 1 or data[mid][0] == n: return (p + mid) if data[mid][0] > n: return search(data[:mid],mid,n,p) else: return search(data[mid:],l-mid,n,p+mid) l = len(data) ans = 0 for i in range(len(data) - 1): data_ = data[i+1:] list_ai = data_[:search(data_,l-i-1,data[i][0] + data[i][1]) + 1] iq = data[i][2] p = data[i][0] for ai in list_ai: if abs(iq - ai[2]) <= K and abs(p - ai[0])<=ai[1]: ans += 1 print(ans) ```
instruction
0
86,609
3
173,218
No
output
1
86,609
3
173,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three numbers: position (x_i), radius of sight (r_i) and IQ (q_i). Since they are intelligent robots, some of them will talk if they see each other. Radius of sight is inclusive, so robot can see other all robots in range [x_i - r_i, x_i + r_i]. But they don't walk to talk with anybody, but only with robots who have similar IQ. By similar IQ we mean that their absolute difference isn't more than K. Help us and calculate how many pairs of robots are going to talk with each other, so we can timely update their software and avoid any potential quarrel. Input The first line contains two integers, numbers N (1 ≤ N ≤ 10^5) and K (0 ≤ K ≤ 20). Next N lines contain three numbers each x_i, r_i, q_i (0 ≤ x_i,r_i,q_i ≤ 10^9) — position, radius of sight and IQ of every robot respectively. Output Output contains only one number — solution to the problem. Example Input 3 2 3 6 1 7 3 10 10 5 8 Output 1 Note The first robot can see the second, but not vice versa. The first robot can't even see the third. The second and the third robot can see each other and their IQs don't differ more than 2 so only one conversation will happen. Submitted Solution: ``` x = [] r = [] q = [] answer=0 nk=str(input()) N = int(nk.split(' ')[0]) K = int(nk.split(' ')[1]) arr = [ str(input()) for i in range(N)] x = [ arr[i].split(' ',1)[0] for i in range(N)] r = [ arr[i].split(' ',3)[1] for i in range(N)] q = [ arr[i].split(' ',3)[2] for i in range(N)] for i in range(N-1): if int(x[i])-int(r[i])<=int(x[i+1]) and int(x[i+1])<=int(x[i])+int(r[i]) and int(q[i+1])-int(q[i])<=K : answer=answer+1 print(answer) ```
instruction
0
86,610
3
173,220
No
output
1
86,610
3
173,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three numbers: position (x_i), radius of sight (r_i) and IQ (q_i). Since they are intelligent robots, some of them will talk if they see each other. Radius of sight is inclusive, so robot can see other all robots in range [x_i - r_i, x_i + r_i]. But they don't walk to talk with anybody, but only with robots who have similar IQ. By similar IQ we mean that their absolute difference isn't more than K. Help us and calculate how many pairs of robots are going to talk with each other, so we can timely update their software and avoid any potential quarrel. Input The first line contains two integers, numbers N (1 ≤ N ≤ 10^5) and K (0 ≤ K ≤ 20). Next N lines contain three numbers each x_i, r_i, q_i (0 ≤ x_i,r_i,q_i ≤ 10^9) — position, radius of sight and IQ of every robot respectively. Output Output contains only one number — solution to the problem. Example Input 3 2 3 6 1 7 3 10 10 5 8 Output 1 Note The first robot can see the second, but not vice versa. The first robot can't even see the third. The second and the third robot can see each other and their IQs don't differ more than 2 so only one conversation will happen. Submitted Solution: ``` b=input().split() n=int(b[0]) k=int(b[1]) x='' r='' q='' for i in range(0,n): a=input().split() x=x+' '+str(a[0]) r=r+' '+str(a[1]) q=q+' '+str(a[2]) m=0 x=x.split() r=r.split() q=q.split() for i in range(0,n): for j in range(i,n): if i!=j: if int(x[i])+int(r[i])<=int(x[j]): if abs(int(q[i])-int(q[j]))<=k: m=m+1 print(m) ```
instruction
0
86,611
3
173,222
No
output
1
86,611
3
173,223
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three numbers: position (x_i), radius of sight (r_i) and IQ (q_i). Since they are intelligent robots, some of them will talk if they see each other. Radius of sight is inclusive, so robot can see other all robots in range [x_i - r_i, x_i + r_i]. But they don't walk to talk with anybody, but only with robots who have similar IQ. By similar IQ we mean that their absolute difference isn't more than K. Help us and calculate how many pairs of robots are going to talk with each other, so we can timely update their software and avoid any potential quarrel. Input The first line contains two integers, numbers N (1 ≤ N ≤ 10^5) and K (0 ≤ K ≤ 20). Next N lines contain three numbers each x_i, r_i, q_i (0 ≤ x_i,r_i,q_i ≤ 10^9) — position, radius of sight and IQ of every robot respectively. Output Output contains only one number — solution to the problem. Example Input 3 2 3 6 1 7 3 10 10 5 8 Output 1 Note The first robot can see the second, but not vice versa. The first robot can't even see the third. The second and the third robot can see each other and their IQs don't differ more than 2 so only one conversation will happen. Submitted Solution: ``` n, k = [int(x) for x in input().split()] l=[] for i in range(n): l.append([int(y) for y in input().split()]) counter = 0 for i in range(n): for j in range(i+1,n): if l[i][0] + l[i][1] >= l[j][0] and l[j][0] - l[j][1] <= l[i][0] and abs(l[i][2]-l[j][2]) <= k: counter += 1 print(counter) ```
instruction
0
86,612
3
173,224
No
output
1
86,612
3
173,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All you need to do is call for them. Now the space rescuers plan to build the largest in the history of the Galaxy rescue station; however, the rescue station's location is yet to be determined. As some cases are real emergencies, the rescuers want to find such a point in the Galaxy from which it would be possible to get to the remotest planet in the minimum possible time. In other words, the rescuers need such point in the space that the distance between it and the planet remotest from it was minimal (if we compare this point with all other possible points in the space). Unfortunately, the rescuers can't sole this problem. As the planets are quite remote from each other, they can be considered as points in Euclidean three-dimensional space. The distance between points (xi, yi, zi) and (xj, yj, zj) can be calculated by the formula <image>. The rescue station can be positioned in any point in the space. It can also coincide with some planet. Galaxy is in danger! Save the space rescuers and find the required point for them. Input The first line of the input file contains integer n — the number of planets (1 ≤ N ≤ 100). Each of the following n lines contains information about the planets. The i-th line contains three integers xi, yi, zi — the coordinates of the i-th planet ( - 104 ≤ xi, yi, zi ≤ 104, 1 ≤ i ≤ n). No two planets coincide. Output Print on the first line of the output file three space-separated real numbers x0, y0, z0 — the coordinates for the future base. If there are several solutions, you are allowed to print any of them. The answer will be accepted if the distance from this point to the remotest planet will differ from the juries' variant in no more than 10 - 6 in absolute or relative value. Examples Input 5 5 0 0 -5 0 0 0 3 4 4 -3 0 2 2 -2 Output 0.000 0.000 0.000 Submitted Solution: ``` import math n=int(input()) list1=[] x1=[] y1=[] z1=[] for i in range(n): x,y,z=map(int,input().split()) x1.append(x) y1.append(y) z1.append(z) X=sum(x1)//n Y=sum(y1)//n Z=sum(z1)//n P=float(0.1); for i in range(5000): f=0 dist1=float(math.sqrt(((X-x1[0])*(X-x1[0]))+((Y-y1[0])*(Y-y1[0]))+((Z-z1[0])*(Z-z1[0])))) for j in range(1,n): dist2=float(math.sqrt(((X-x1[j])*(X-x1[j]))+((Y-y1[j])*(Y-y1[j]))+((Z-z1[j])*(Z-z1[j])))) if (dist1<dist2): dist1=dist2 f=j X += (x1[f]-X)*P Y += (y1[f]-Y)*P Z += (z1[f]-Z)*P P *= 0.9993 print(X, Y, Z) ```
instruction
0
86,613
3
173,226
No
output
1
86,613
3
173,227
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All you need to do is call for them. Now the space rescuers plan to build the largest in the history of the Galaxy rescue station; however, the rescue station's location is yet to be determined. As some cases are real emergencies, the rescuers want to find such a point in the Galaxy from which it would be possible to get to the remotest planet in the minimum possible time. In other words, the rescuers need such point in the space that the distance between it and the planet remotest from it was minimal (if we compare this point with all other possible points in the space). Unfortunately, the rescuers can't sole this problem. As the planets are quite remote from each other, they can be considered as points in Euclidean three-dimensional space. The distance between points (xi, yi, zi) and (xj, yj, zj) can be calculated by the formula <image>. The rescue station can be positioned in any point in the space. It can also coincide with some planet. Galaxy is in danger! Save the space rescuers and find the required point for them. Input The first line of the input file contains integer n — the number of planets (1 ≤ N ≤ 100). Each of the following n lines contains information about the planets. The i-th line contains three integers xi, yi, zi — the coordinates of the i-th planet ( - 104 ≤ xi, yi, zi ≤ 104, 1 ≤ i ≤ n). No two planets coincide. Output Print on the first line of the output file three space-separated real numbers x0, y0, z0 — the coordinates for the future base. If there are several solutions, you are allowed to print any of them. The answer will be accepted if the distance from this point to the remotest planet will differ from the juries' variant in no more than 10 - 6 in absolute or relative value. Examples Input 5 5 0 0 -5 0 0 0 3 4 4 -3 0 2 2 -2 Output 0.000 0.000 0.000 Submitted Solution: ``` def dist(x,y,z): return (x*x+y*y+z*z)**(1/2) n=int(input()) sumx=0 sumy=0 sumz=0 listx=[] listy=[] listz=[] for i in range(n): x,y,z=map(int,input().split()) listx.append(x) listy.append(y) listz.append(z) sumx=sumx+x sumy=sumy+y sumz=sumz+z sumx=sumx/n sumy=sumy/n sumz=sumz/n P=0.1 for i in range(5000): f=0 d=dist(sumx-listx[0],sumy-listy[0],sumz-listz[0]) for j in range(1,n): e=dist(sumx-listx[j],sumy-listy[j],sumz-listz[j]) if(d < e): d=e f=j sumx=sumx+(listx[f]-sumx)*P sumy=sumy+(listy[f]-sumy)*P sumz=sumz+(listz[f]-sumz)*P P=P*0.9993 print(sumx,sumy,sumz) ```
instruction
0
86,614
3
173,228
No
output
1
86,614
3
173,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All you need to do is call for them. Now the space rescuers plan to build the largest in the history of the Galaxy rescue station; however, the rescue station's location is yet to be determined. As some cases are real emergencies, the rescuers want to find such a point in the Galaxy from which it would be possible to get to the remotest planet in the minimum possible time. In other words, the rescuers need such point in the space that the distance between it and the planet remotest from it was minimal (if we compare this point with all other possible points in the space). Unfortunately, the rescuers can't sole this problem. As the planets are quite remote from each other, they can be considered as points in Euclidean three-dimensional space. The distance between points (xi, yi, zi) and (xj, yj, zj) can be calculated by the formula <image>. The rescue station can be positioned in any point in the space. It can also coincide with some planet. Galaxy is in danger! Save the space rescuers and find the required point for them. Input The first line of the input file contains integer n — the number of planets (1 ≤ N ≤ 100). Each of the following n lines contains information about the planets. The i-th line contains three integers xi, yi, zi — the coordinates of the i-th planet ( - 104 ≤ xi, yi, zi ≤ 104, 1 ≤ i ≤ n). No two planets coincide. Output Print on the first line of the output file three space-separated real numbers x0, y0, z0 — the coordinates for the future base. If there are several solutions, you are allowed to print any of them. The answer will be accepted if the distance from this point to the remotest planet will differ from the juries' variant in no more than 10 - 6 in absolute or relative value. Examples Input 5 5 0 0 -5 0 0 0 3 4 4 -3 0 2 2 -2 Output 0.000 0.000 0.000 Submitted Solution: ``` def dist(x,y,z,p): sum1=0 for i in range(len(p)): sum1=sum1+(round(((x-p[i][0])**2 + (y-p[i][1])**2 + (z-p[i][1])**2 )**(0.5),4)) return sum1 n=int(input()) points=[] for i in range(n): p=list(map(int,input().split())) points.append(p) mind1=dist(0.0000,0.0000,0.0000,points) xp=0.0000 yp=0.0000 zp=0.0000 for i in range(n): xp=xp+points[i][0] yp=yp+points[i][1] zp=zp+points[i][2] xp=xp/n yp=yp/n zp=zp/n mind=dist(xp,yp,zp,points) if(mind1 < mind): print(0.0000,0.0000,0.0000) else: print(round(xp,4),round(yp,4),round(zp,0)) ```
instruction
0
86,615
3
173,230
No
output
1
86,615
3
173,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All you need to do is call for them. Now the space rescuers plan to build the largest in the history of the Galaxy rescue station; however, the rescue station's location is yet to be determined. As some cases are real emergencies, the rescuers want to find such a point in the Galaxy from which it would be possible to get to the remotest planet in the minimum possible time. In other words, the rescuers need such point in the space that the distance between it and the planet remotest from it was minimal (if we compare this point with all other possible points in the space). Unfortunately, the rescuers can't sole this problem. As the planets are quite remote from each other, they can be considered as points in Euclidean three-dimensional space. The distance between points (xi, yi, zi) and (xj, yj, zj) can be calculated by the formula <image>. The rescue station can be positioned in any point in the space. It can also coincide with some planet. Galaxy is in danger! Save the space rescuers and find the required point for them. Input The first line of the input file contains integer n — the number of planets (1 ≤ N ≤ 100). Each of the following n lines contains information about the planets. The i-th line contains three integers xi, yi, zi — the coordinates of the i-th planet ( - 104 ≤ xi, yi, zi ≤ 104, 1 ≤ i ≤ n). No two planets coincide. Output Print on the first line of the output file three space-separated real numbers x0, y0, z0 — the coordinates for the future base. If there are several solutions, you are allowed to print any of them. The answer will be accepted if the distance from this point to the remotest planet will differ from the juries' variant in no more than 10 - 6 in absolute or relative value. Examples Input 5 5 0 0 -5 0 0 0 3 4 4 -3 0 2 2 -2 Output 0.000 0.000 0.000 Submitted Solution: ``` def dist(x,y,z,p): sum1=[] for i in range(len(p)): sum1.append(round(((x-p[i][0])**2 + (y-p[i][1])**2 + (z-p[i][1])**2 )**(0.5),4)) return sum1 n=int(input()) points=[] for i in range(n): p=list(map(int,input().split())) points.append(p) mind1=dist(0.0000,0.0000,0.0000,points) xp=0.0000 yp=0.0000 zp=0.0000 for i in range(n): xp=xp+points[i][0] yp=yp+points[i][1] zp=zp+points[i][2] xp=xp/n yp=yp/n zp=zp/n mind=dist(xp,yp,zp,points) if(mind1 < mind): print(0.0000,0.0000,0.0000) else: print(round(xp,4),round(yp,4),round(zp,0)) ```
instruction
0
86,616
3
173,232
No
output
1
86,616
3
173,233
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,672
3
173,344
Tags: geometry, math Correct Solution: ``` h,l=map(int,input().split()) a=((l*l)-(h*h))/(2*h) print(a) ```
output
1
86,672
3
173,345
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,673
3
173,346
Tags: geometry, math Correct Solution: ``` H,L=input().split() H=int(H) L=int(L) num = L**2 - H**2 den = 2*H x = num/den print('%.13f'%x) ```
output
1
86,673
3
173,347
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,674
3
173,348
Tags: geometry, math Correct Solution: ``` h,l=map(int,input().split()) a = (l**2 - h**2)/(2*h) print(a) ```
output
1
86,674
3
173,349
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,675
3
173,350
Tags: geometry, math Correct Solution: ``` def main(): h,l=list(map(int,input().split())) print((l**2-h**2)/(2*h)) main() ```
output
1
86,675
3
173,351
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,676
3
173,352
Tags: geometry, math Correct Solution: ``` import math h,l=map(int,input().split()) x=(math.pow(l,2)-math.pow(h,2))/(2*h) print(x) ```
output
1
86,676
3
173,353
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,677
3
173,354
Tags: geometry, math Correct Solution: ``` h,l=map(int,input().split()) a=(l**2-h**2)/(2*h) print(round(a,7)) ```
output
1
86,677
3
173,355
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,678
3
173,356
Tags: geometry, math Correct Solution: ``` h1,l1=input().split() h=int(h1) l=int(l1) x=((l*l)-(h*h))/(2*h) print(x) ```
output
1
86,678
3
173,357
Provide tags and a correct Python 3 solution for this coding contest problem. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667
instruction
0
86,679
3
173,358
Tags: geometry, math Correct Solution: ``` h, l = map(int, input().split()) ans = round(((l**2 - h**2)/2)/h, 6) print('{:.8f}'.format(((l**2 - h**2)/2)/h)) ```
output
1
86,679
3
173,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` import sys input = sys.stdin.readline H, L = list(map(int, input().split())) A = (H**2 + L**2) / (2*H) print(A - H) ```
instruction
0
86,680
3
173,360
Yes
output
1
86,680
3
173,361
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` h, l = map(int, input().split()) sq = abs((-l**2+h**2)/(2*h)) print(sq) ```
instruction
0
86,681
3
173,362
Yes
output
1
86,681
3
173,363
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` h, l = map(int, input().split()) print((((h**2) + (l**2)) / (2*h)) - h) ```
instruction
0
86,682
3
173,364
Yes
output
1
86,682
3
173,365
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` #----Kuzlyaev-Nikita-Codeforces----- #------------03.04.2020------------- alph="abcdefghijklmnopqrstuvwxyz" #----------------------------------- h,l=map(int,input().split()) k=(l*l-h*h)/2/h print("%.10f"%k) ```
instruction
0
86,683
3
173,366
Yes
output
1
86,683
3
173,367
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` L,H=map(int,input().split()) print((L*L-H*H)/2*H) ```
instruction
0
86,684
3
173,368
No
output
1
86,684
3
173,369
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` """ H cm above surface of water sailed distance of L cm, where water touched surface determine the depth of lake """ H,L= map(int,input().split()) k=(1.0*(L**2-H**2)/(2*H)) print(str(int(k))+(str(k-k//1))[1:]) ```
instruction
0
86,685
3
173,370
No
output
1
86,685
3
173,371
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` from math import sqrt h, left = map(int, input().split()) l = 0 r = 2000000 while r - l > 0.00000001: x = (l + r) / 2 a = x + h b = sqrt(left * left + x * x) print(a, b, x) if b - a > 0.00000001: l = x else: r = x print(l) ```
instruction
0
86,686
3
173,372
No
output
1
86,686
3
173,373
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface. <image> Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A? Input The only line contains two integers H and L (1 ≤ H < L ≤ 10^{6}). Output Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^{-6}. Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if \frac{|A - B|}{max{(1, |B|)}} ≤ 10^{-6}. Examples Input 1 2 Output 1.5000000000000 Input 3 5 Output 2.6666666666667 Submitted Solution: ``` h,l=input().split() H=int(h) L=int(l) d=(((L**2)-(H**2))/2*H) print(format(d , '.13f')) ```
instruction
0
86,687
3
173,374
No
output
1
86,687
3
173,375
Provide tags and a correct Python 3 solution for this coding contest problem. Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k. The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ m2). Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the sought number modulo 1000000007 (109 + 7). Examples Input 3 3 2 ab ba Output 17 Input 3 3 0 Output 27 Input 2 1 1 aa Output 0 Note In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.
instruction
0
86,914
3
173,828
Tags: dp, matrices Correct Solution: ``` import os from io import BytesIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline import string def main(): d = 0 class Matrix(): def __init__(self,ar): self.ar = ar def __mul__(self,other): n = d m = d p = d ans = [[0 for i in range(p)] for i in range(m)] for i in range(m): for j in range(p): for k in range(n): ans[i][j] += self[i][k] * other[k][j] ans[i][j] %= mod return Matrix(ans) def __mod__(self,other): m = len(self[0]) for i in range(len(self.ar)): for j in range(m): self[i][j] %= other return self def __getitem__(self, key): return self.ar[key] mod = 10**9 + 7 def power(number, n): res = number while(n): if n & 1: res *= number n -= 1 number *= number n >>= 1 return res n,m,k = map(int,input().split()) d = m m2 = Matrix([[1 for i in range(m)]for i in range(m)]) alth = string.ascii_letters for i in range(k): s = str(input()) temp = alth.find(s[2]) temp2 = alth.find(s[3]) m2[temp2][temp] = 0 if n == 1: print(m) elif n==2: print(m**2-k) else: ar = power(m2,n-2).ar ans = 0 for i in range(m): for j in range(m): ans += ar[i][j] ans %= mod print(ans) main() ```
output
1
86,914
3
173,829
Provide tags and a correct Python 3 solution for this coding contest problem. Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k. The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ m2). Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the sought number modulo 1000000007 (109 + 7). Examples Input 3 3 2 ab ba Output 17 Input 3 3 0 Output 27 Input 2 1 1 aa Output 0 Note In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.
instruction
0
86,915
3
173,830
Tags: dp, matrices Correct Solution: ``` import sys def pyes_no(condition) : if condition : print ("YES") else : print ("NO") def plist(a, s = ' ') : print (s.join(map(str, a))) def rint() : return int(sys.stdin.readline()) def rints() : return map(int, sys.stdin.readline().split()) def rfield(n, m = None) : if m == None : m = n field = [] for i in xrange(n) : chars = sys.stdin.readline().strip() assert(len(chars) == m) field.append(chars) return field def pfield(field, separator = '') : print ('\n'.join(map(lambda x: separator.join(x), field))) def check_field_equal(field, i, j, value) : if i >= 0 and i < len(field) and j >= 0 and j < len(field[i]) : return value == field[i][j] return None def digits(x, p) : digits = [] while x > 0 : digits.append(x % p) x /= p return digits def modpower(a, n, mod) : r = a ** (n % 2) if n > 1 : r *= modpower(a, n / 2, mod) ** 2 return r % mod def modmatrixproduct(a, b, mod) : n, m1 = len(a), len(a[0]) m2, k = len(b), len(b[0]) assert(m1 == m2) m = m1 r = [[0] * k for i in range(n)] for i in range(n) : for j in range(k) : for l in range(m) : r[i][j] += a[i][l] * b[l][j] r[i][j] %= mod return r def modmatrixpower(a, n, mod) : magic = 2 for m in [2, 3, 5, 7] : if n % m == 0 : magic = m break r = None if n < magic : r = a n -= 1 else : s = modmatrixpower(a, n // magic, mod) r = s for i in range(magic - 1) : r = modmatrixproduct(r, s, mod) for i in range(n % magic) : r = modmatrixproduct(r, a, mod) return r def gcd(a, b) : if a > b : a, b = b, a while a > 0 : a, b = b % a, a return b n, m, k = rints() charn = dict(zip('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', range(52))) matrix = [[1] * m for i in range(m)] for i in range(k) : a, b = map(lambda c: charn[c], list(sys.stdin.readline().strip())) matrix[a][b] = 0 mod = 1000000007 if n > 1 : matrix = modmatrixpower(matrix, n - 1, mod) results = modmatrixproduct([[1] * m], matrix, mod) print (sum(map(sum, results)) % mod) else : print (m) ```
output
1
86,915
3
173,831
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k. The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ m2). Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the sought number modulo 1000000007 (109 + 7). Examples Input 3 3 2 ab ba Output 17 Input 3 3 0 Output 27 Input 2 1 1 aa Output 0 Note In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively. Submitted Solution: ``` # How many ways to generate length-N array where elements can take one of m values (m <= 52; denoted a..z,A..Z) # s.t. none of k ordered value pair appears: # e.g. ab = ab can't appear but ba can; aa = aa can't appear # Input: N (N < 10^18), m (n<=52), k patterns 0 <= k <= m^2 # E.g. # N=3, m=3, k=2 # ab # ba # -> return 17 # Ideas # * divide and conquer # * for each n, memo[n][i][j] = number of paths of length n satisfying bans, that start at i and end at j MOD = 1000000007 memo = {} def _solve(n, m, ban): if n in memo: return memo[n] if n == 0: return [[0]*m for _ in range(m)] if n == 1: memo[n] = [[0]*m for _ in range(m)] for i in range(m): memo[n][i][i] = 1 return memo[n] left, right = _solve(n // 2, m, ban), _solve(n - n // 2, m, ban) memo[n] = [[0]*m for _ in range(m)] # count all paths starting at i, ending at j si, sj = [0]*m, [0]*m for i in range(m): si[i] = sum(left[i]) % MOD for j in range(m): sj[j] = sum(right[s][j] for s in range(m)) % MOD for i in range(m): for j in range(m): memo[n][i][j] = si[i]*sj[j]%MOD # subtract left path ending at x * right path ending at y for each banned pair (x, y) si, sj = [0]*m, [0]*m for i in range(m): si[i] = sum(left[s][i] for s in range(m)) for j in range(m): sj[j] = sum(right[j]) % MOD for x, y in ban: memo[n][i][j] -= si[x] * sj[y] % MOD memo[n][i][j] %= MOD return memo[n] def solve(n, m, ban): counts = _solve(n, m, ban) return sum(sum(row) for row in counts)%MOD def main(): from sys import stdin n, m, k = list(map(int, stdin.readline().strip().split())) ban = set() for _ in range(k): x, y = list(stdin.readline().strip()) x = ord(x)-97 if 'a' <= x <= 'z' else ord(x)-39 y = ord(y)-97 if 'a' <= y <= 'z' else ord(y)-39 ban.add((x,y)) out = solve(n, m, ban) print('{}'.format(out)) if __name__ == '__main__': main() ```
instruction
0
86,916
3
173,832
No
output
1
86,916
3
173,833
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k. The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ m2). Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the sought number modulo 1000000007 (109 + 7). Examples Input 3 3 2 ab ba Output 17 Input 3 3 0 Output 27 Input 2 1 1 aa Output 0 Note In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively. Submitted Solution: ``` import math __author__ = 'esadeqia' import operator def toInd(c): if c.islower(): return ord(c)-ord('a') elif c.isupper(): return ord(c)-ord('A')+26 def toInd(c): x=ord(c) if ord('a')<=x and x<=ord('z'): return x-ord('a') elif ord('A')<=x and x<=ord('Z'): return x-ord('A')+26 def emptyMatrix(a,b,value=None): return [[value]*b for j in range(a)] def eyeMatrix(a): return [[0]*j+[1]+[0]*(a-j-1) for j in range(a)] def multiply(A,B,p): C=emptyMatrix(len(A),len(B[0])) for i in range(len(A)): for j in range(len(B[0])): t=0 for k in range(len(B)): t+=(A[i][k]*B[k][j]) C[i][j]=t%p return C def fourSplits(M): horizontal=int(len(M)/2) vertical=int(len(M[0])/2) up=M[:horizontal] down=M[horizontal:] return (([x[:vertical] for x in up], [x[vertical:] for x in up]), ([x[:vertical] for x in down], [x[vertical:] for x in down])) def addMatrix(A,B): return [list(map(operator.add, A[i], B[i])) for i in range(len(A))] def subMatrix(A,B): assert len(A)==len(B) return [ list( map( operator.sub, A[i], B[i])) for i in range(len(A))] def allResidual(M,p): return [[x%p for x in y] for y in M] def strassen(A,B,p): if len(A)<2 or len(B)<2 or len(B[0])<2: return multiply(A,B,p) As=fourSplits(A) Bs=fourSplits(B) m=[None]*8 m[1]=strassen(addMatrix(As[0][0],As[1][1]), addMatrix(Bs[0][0],Bs[1][1]),p) m[2]=strassen(addMatrix(As[1][0],As[1][1]), Bs[0][0] ,p) m[3]=strassen( As[0][0] , subMatrix(Bs[0][1],Bs[1][1]) ,p) m[4]=strassen( As[1][1] , subMatrix(Bs[1][0],Bs[0][0]) ,p) m[5]=strassen(addMatrix(As[0][0],As[0][1]), Bs[1][1] ,p) m[6]=strassen(subMatrix(As[1][0],As[0][0]), addMatrix(Bs[0][0],Bs[0][1]),p) m[7]=strassen(subMatrix(As[0][1],As[1][1]), addMatrix(Bs[1][0],Bs[1][1]),p) C=emptyMatrix(len(A),len(B[0])) c11=addMatrix(subMatrix(addMatrix(m[1],m[4]),m[5]),m[7]) c21=addMatrix(m[3],m[5]) c12=addMatrix(m[2],m[4]) c22=addMatrix(addMatrix(subMatrix(m[1],m[2]),m[3]),m[6]) return allResidual(list(map(operator.concat, c11+c12,c21+c22)),p) def strassenPower(M,n,p): l=len(M) newl=int(2**math.ceil(math.log2(l))) padding=[0]*(newl-l) M=[x+padding for x in M] M+=emptyMatrix(newl-l,newl,0) # print(l,newl) # print(M) # exit(0) powers=M result=eyeMatrix(len(M)) while n>0: # print(n) if n%2==1: result=strassen(result,powers,p) powers=strassen(powers,powers,p) n=n>>1 return result def fastMethod(n,allowedpairs): m=len(allowedPairs) result=strassenPower(allowedPairs,n-1,p) return sum(map(sum, result))%p p=1000000007 #(10**9 + 7) n,m,k=map(int,input().split()) allowedPairs=emptyMatrix(m,m,1) for i in range(k): pair=input() allowedPairs[toInd(pair[0])][toInd(pair[1])]=0 resultMain=fastMethod(n,allowedPairs) print(resultMain) ```
instruction
0
86,917
3
173,834
No
output
1
86,917
3
173,835
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k. The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ m2). Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the sought number modulo 1000000007 (109 + 7). Examples Input 3 3 2 ab ba Output 17 Input 3 3 0 Output 27 Input 2 1 1 aa Output 0 Note In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively. Submitted Solution: ``` MOD = 1000000007 def _solve(n, m, ban, memo): if n in memo: return memo[n] if n == 0: return [[0]*m for _ in range(m)] if n == 1: memo[n] = [[0]*m for _ in range(m)] for i in range(m): memo[n][i][i] = 1 return memo[n] left, right = _solve(n // 2, m, ban, memo), _solve(n - n // 2, m, ban, memo) memo[n] = [[0]*m for _ in range(m)] # count all paths starting at i, ending at j for i in range(m): for j in range(m): memo[n][i][j] = sum(left[i])*sum(right[s][j] for s in range(m)) % MOD # subtract left path ending at x * right path ending at y for each banned pair (x, y) for x, y in ban: for i in range(m): for j in range(m): memo[n][i][j] -= left[i][x] * right[y][j] % MOD memo[n][i][j] %= MOD return memo[n] def solve(n, m, ban): counts = _solve(n, m, ban, {}) return sum(sum(row) for row in counts) def main(): from sys import stdin n, m, k = list(map(int, stdin.readline().strip().split())) ban = set() for _ in range(k): x, y = list(stdin.readline().strip()) x = ord(x)-97 if 'a' <= x <= 'z' else ord(x)-39 y = ord(y)-97 if 'a' <= y <= 'z' else ord(y)-39 ban.add((x,y)) out = solve(n, m, ban) print('{}'.format(out)) if __name__ == '__main__': main() ```
instruction
0
86,918
3
173,836
No
output
1
86,918
3
173,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k. The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ m2). Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Print a single integer — the sought number modulo 1000000007 (109 + 7). Examples Input 3 3 2 ab ba Output 17 Input 3 3 0 Output 27 Input 2 1 1 aa Output 0 Note In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively. Submitted Solution: ``` mul=lambda A,B,r:[[sum([A[i][k]*B[k][j] for k in r]) for j in r] for i in r] def binpower(A,e): r = range(len(A)) B = A e -= 1 while True: if e &1: B = mul(B,A,r) e =e>>1 if e==0: break A =mul(A,A,r) return B c2i = lambda c: ord(c)-ord('a') if c.islower() else ord(c)-ord('A')+26 def f(l1,l2): n,m,_ = l1 if n==1: return m M = [[1]*m for _ in range(m)] for s in l2: i = c2i(s[0]) j = c2i(s[1]) M[i][j]=0 return sum([sum(l) for l in binpower(M,n-1)]) l1 = list(map(int,input().split())) l2 = [input() for _ in range(l1[2])] print(f(l1,l2)) ```
instruction
0
86,919
3
173,838
No
output
1
86,919
3
173,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible attack by hackers on a major computer network. In this network are n vertices, some pairs of vertices are connected by m undirected channels. It is planned to transfer q important messages via this network, the i-th of which must be sent from vertex si to vertex di via one or more channels, perhaps through some intermediate vertices. To protect against attacks a special algorithm was developed. Unfortunately it can be applied only to the network containing directed channels. Therefore, as new channels can't be created, it was decided for each of the existing undirected channels to enable them to transmit data only in one of the two directions. Your task is to determine whether it is possible so to choose the direction for each channel so that each of the q messages could be successfully transmitted. Input The first line contains three integers n, m and q (1 ≤ n, m, q ≤ 2·105) — the number of nodes, channels and important messages. Next m lines contain two integers each, vi and ui (1 ≤ vi, ui ≤ n, vi ≠ ui), that means that between nodes vi and ui is a channel. Between a pair of nodes can exist more than one channel. Next q lines contain two integers si and di (1 ≤ si, di ≤ n, si ≠ di) — the numbers of the nodes of the source and destination of the corresponding message. It is not guaranteed that in it initially possible to transmit all the messages. Output If a solution exists, print on a single line "Yes" (without the quotes). Otherwise, print "No" (without the quotes). Examples Input 4 4 2 1 2 1 3 2 3 3 4 1 3 4 2 Output Yes Input 3 2 2 1 2 3 2 1 3 2 1 Output No Input 3 3 2 1 2 1 2 3 2 1 3 2 1 Output Yes Note In the first sample test you can assign directions, for example, as follows: 1 → 2, 1 → 3, 3 → 2, 4 → 3. Then the path for for the first message will be 1 → 3, and for the second one — 4 → 3 → 2. In the third sample test you can assign directions, for example, as follows: 1 → 2, 2 → 1, 2 → 3. Then the path for the first message will be 1 → 2 → 3, and for the second one — 2 → 1. Submitted Solution: ``` print("No") ```
instruction
0
87,065
3
174,130
No
output
1
87,065
3
174,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible attack by hackers on a major computer network. In this network are n vertices, some pairs of vertices are connected by m undirected channels. It is planned to transfer q important messages via this network, the i-th of which must be sent from vertex si to vertex di via one or more channels, perhaps through some intermediate vertices. To protect against attacks a special algorithm was developed. Unfortunately it can be applied only to the network containing directed channels. Therefore, as new channels can't be created, it was decided for each of the existing undirected channels to enable them to transmit data only in one of the two directions. Your task is to determine whether it is possible so to choose the direction for each channel so that each of the q messages could be successfully transmitted. Input The first line contains three integers n, m and q (1 ≤ n, m, q ≤ 2·105) — the number of nodes, channels and important messages. Next m lines contain two integers each, vi and ui (1 ≤ vi, ui ≤ n, vi ≠ ui), that means that between nodes vi and ui is a channel. Between a pair of nodes can exist more than one channel. Next q lines contain two integers si and di (1 ≤ si, di ≤ n, si ≠ di) — the numbers of the nodes of the source and destination of the corresponding message. It is not guaranteed that in it initially possible to transmit all the messages. Output If a solution exists, print on a single line "Yes" (without the quotes). Otherwise, print "No" (without the quotes). Examples Input 4 4 2 1 2 1 3 2 3 3 4 1 3 4 2 Output Yes Input 3 2 2 1 2 3 2 1 3 2 1 Output No Input 3 3 2 1 2 1 2 3 2 1 3 2 1 Output Yes Note In the first sample test you can assign directions, for example, as follows: 1 → 2, 1 → 3, 3 → 2, 4 → 3. Then the path for for the first message will be 1 → 3, and for the second one — 4 → 3 → 2. In the third sample test you can assign directions, for example, as follows: 1 → 2, 2 → 1, 2 → 3. Then the path for the first message will be 1 → 2 → 3, and for the second one — 2 → 1. Submitted Solution: ``` print("Yes") ```
instruction
0
87,066
3
174,132
No
output
1
87,066
3
174,133
Provide tags and a correct Python 3 solution for this coding contest problem. There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a new one from them. That results in a new atom, whose number is equal to the sum of the numbers of original atoms. The fusion operation can be performed several times. The aim is getting a new pregiven set of k atoms. The puzzle's difficulty is that it is only allowed to fuse two atoms into one, it is not allowed to split an atom into several atoms. You are suggested to try to solve the puzzle. Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 17). The second line contains space-separated symbols of elements of n atoms, which are available from the start. The third line contains space-separated symbols of elements of k atoms which need to be the result of the fusion. The symbols of the elements coincide with the symbols from the periodic table of the chemical elements. The atomic numbers do not exceed 100 (elements possessing larger numbers are highly unstable). Some atoms can have identical numbers (that is, there can be several atoms of the same element). The sum of numbers of initial atoms is equal to the sum of numbers of the atoms that need to be synthesized. Output If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next k lines print the way of synthesizing each of k atoms as equations. Each equation has the following form: "x1+x2+...+xt->yi", where xj is the symbol of the element of some atom from the original set, and yi is the symbol of the element of some atom from the resulting set. Each atom from the input data should occur in the output data exactly one time. The order of summands in the equations, as well as the output order does not matter. If there are several solutions, print any of them. For a better understanding of the output format, see the samples. Examples Input 10 3 Mn Co Li Mg C P F Zn Sc K Sn Pt Y Output YES Mn+C+K-&gt;Sn Co+Zn+Sc-&gt;Pt Li+Mg+P+F-&gt;Y Input 2 1 H H He Output YES H+H-&gt;He Input 2 2 Bk Fm Cf Es Output NO Note The reactions from the first example possess the following form (the atomic number is written below and to the left of the element): <image> <image> <image> To find a periodic table of the chemical elements, you may use your favorite search engine. The pretest set contains each of the first 100 elements of the periodic table at least once. You can use that information to check for misprints.
instruction
0
87,142
3
174,284
Tags: bitmasks, dp Correct Solution: ``` numbersDict = { "1": "H", "2": "He", "3": "Li", "4": "Be", "5": "B", "6": "C", "7": "N", "8": "O", "9": "F", "10": "Ne", "11": "Na", "12": "Mg", "13": "Al", "14": "Si", "15": "P", "16": "S", "17": "Cl", "18": "Ar", "19": "K", "20": "Ca", "21": "Sc", "22": "Ti", "23": "V", "24": "Cr", "25": "Mn", "26": "Fe", "27": "Co", "28": "Ni", "29": "Cu", "30": "Zn", "31": "Ga", "32": "Ge", "33": "As", "34": "Se", "35": "Br", "36": "Kr", "37": "Rb", "38": "Sr", "39": "Y", "40": "Zr", "41": "Nb", "42": "Mo", "43": "Tc", "44": "Ru", "45": "Rh", "46": "Pd", "47": "Ag", "48": "Cd", "49": "In", "50": "Sn", "51": "Sb", "52": "Te", "53": "I", "54": "Xe", "55": "Cs", "56": "Ba", "57": "La", "58": "Ce", "59": "Pr", "60": "Nd", "61": "Pm", "62": "Sm", "63": "Eu", "64": "Gd", "65": "Tb", "66": "Dy", "67": "Ho", "68": "Er", "69": "Tm", "70": "Yb", "71": "Lu", "72": "Hf", "73": "Ta", "74": "W", "75": "Re", "76": "Os", "77": "Ir", "78": "Pt", "79": "Au", "80": "Hg", "81": "Tl", "82": "Pb", "83": "Bi", "84": "Po", "85": "At", "86": "Rn", "87": "Fr", "88": "Ra", "89": "Ac", "90": "Th", "91": "Pa", "92": "U", "93": "Np", "94": "Pu", "95": "Am", "96": "Cm", "97": "Bk", "98": "Cf", "99": "Es", "100": "Fm" } lettersDict = { "H": "1", "He": "2", "Li": "3", "Be": "4", "B": "5", "C": "6", "N": "7", "O": "8", "F": "9", "Ne": "10", "Na": "11", "Mg": "12", "Al": "13", "Si": "14", "P": "15", "S": "16", "Cl": "17", "Ar": "18", "K": "19", "Ca": "20", "Sc": "21", "Ti": "22", "V": "23", "Cr": "24", "Mn": "25", "Fe": "26", "Co": "27", "Ni": "28", "Cu": "29", "Zn": "30", "Ga": "31", "Ge": "32", "As": "33", "Se": "34", "Br": "35", "Kr": "36", "Rb": "37", "Sr": "38", "Y": "39", "Zr": "40", "Nb": "41", "Mo": "42", "Tc": "43", "Ru": "44", "Rh": "45", "Pd": "46", "Ag": "47", "Cd": "48", "In": "49", "Sn": "50", "Sb": "51", "Te": "52", "I": "53", "Xe": "54", "Cs": "55", "Ba": "56", "La": "57", "Ce": "58", "Pr": "59", "Nd": "60", "Pm": "61", "Sm": "62", "Eu": "63", "Gd": "64", "Tb": "65", "Dy": "66", "Ho": "67", "Er": "68", "Tm": "69", "Yb": "70", "Lu": "71", "Hf": "72", "Ta": "73", "W": "74", "Re": "75", "Os": "76", "Ir": "77", "Pt": "78", "Au": "79", "Hg": "80", "Tl": "81", "Pb": "82", "Bi": "83", "Po": "84", "At": "85", "Rn": "86", "Fr": "87", "Ra": "88", "Ac": "89", "Th": "90", "Pa": "91", "U": "92", "Np": "93", "Pu": "94", "Am": "95", "Cm": "96", "Bk": "97", "Cf": "98", "Es": "99", "Fm": "100" } _ = input() # Supposed to be n, k but we do not need them atoms = input().split(" ") outAtoms = input().split(" ") atoms = sorted(list(map(lambda x: int(lettersDict[x]), atoms))) outAtoms = sorted(list(map(lambda x: int(lettersDict[x]), outAtoms))) sumAtoms = 0 def testIfPossible(): atomsx = atoms.copy() outAtomsx = outAtoms.copy() for i in range(len(atoms) - 1, -1, -1): if atomsx[i] > outAtomsx[-1]: atomsx.pop() if sum(outAtomsx) > sum(atomsx): print("NO") exit() testIfPossible() for at in atoms: sumAtoms += at outAtom = 0 for at in outAtoms: outAtom += at def dfs(i: int, currentSum: int, arr: [int], searchSum: int) -> [[int]]: if i >= len(arr) or currentSum + arr[i] > searchSum: return [] totalRes = [] # we take res = dfs(i + 1, currentSum + arr[i], arr, searchSum) totalRes += [[i] + a for a in res] # we don't take res = dfs(i + 1, currentSum, arr, searchSum) totalRes += [a for a in res] if currentSum + arr[i] == searchSum: totalRes.append([i]) return totalRes allCombos = [[set(x) for x in dfs(0, 0, atoms, out)] for out in outAtoms] currentSet = set() stack = [] resultFound = False def dfs2(i: int): global resultFound global stack global currentSet if i >= len(allCombos): resultFound = True return for set in allCombos[i]: if not set & currentSet: stack.append(set) currentSet = currentSet | set dfs2(i + 1) if resultFound: break stack.pop() currentSet = currentSet - set isAnyEmpty = False for comb in allCombos: if not comb: isAnyEmpty = True if not isAnyEmpty: dfs2(0) if resultFound: print("YES") res = list(map(lambda x: "+".join(list(map(lambda y: numbersDict[f"{atoms[y]}"],list(x)))), stack)) outs = list(map(lambda x: numbersDict[f"{x}"], outAtoms)) tot = list(map(lambda x: x[0] + "->" + x[1], zip(res, outs))) for t in tot: print(t) else: print("NO") ```
output
1
87,142
3
174,285
Provide tags and a correct Python 3 solution for this coding contest problem. There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a new one from them. That results in a new atom, whose number is equal to the sum of the numbers of original atoms. The fusion operation can be performed several times. The aim is getting a new pregiven set of k atoms. The puzzle's difficulty is that it is only allowed to fuse two atoms into one, it is not allowed to split an atom into several atoms. You are suggested to try to solve the puzzle. Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 17). The second line contains space-separated symbols of elements of n atoms, which are available from the start. The third line contains space-separated symbols of elements of k atoms which need to be the result of the fusion. The symbols of the elements coincide with the symbols from the periodic table of the chemical elements. The atomic numbers do not exceed 100 (elements possessing larger numbers are highly unstable). Some atoms can have identical numbers (that is, there can be several atoms of the same element). The sum of numbers of initial atoms is equal to the sum of numbers of the atoms that need to be synthesized. Output If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next k lines print the way of synthesizing each of k atoms as equations. Each equation has the following form: "x1+x2+...+xt->yi", where xj is the symbol of the element of some atom from the original set, and yi is the symbol of the element of some atom from the resulting set. Each atom from the input data should occur in the output data exactly one time. The order of summands in the equations, as well as the output order does not matter. If there are several solutions, print any of them. For a better understanding of the output format, see the samples. Examples Input 10 3 Mn Co Li Mg C P F Zn Sc K Sn Pt Y Output YES Mn+C+K-&gt;Sn Co+Zn+Sc-&gt;Pt Li+Mg+P+F-&gt;Y Input 2 1 H H He Output YES H+H-&gt;He Input 2 2 Bk Fm Cf Es Output NO Note The reactions from the first example possess the following form (the atomic number is written below and to the left of the element): <image> <image> <image> To find a periodic table of the chemical elements, you may use your favorite search engine. The pretest set contains each of the first 100 elements of the periodic table at least once. You can use that information to check for misprints.
instruction
0
87,143
3
174,286
Tags: bitmasks, dp Correct Solution: ``` #!/usr/bin/env python3 import itertools # Initialize look-up tables element_to_value = { 'H':1, 'He':2, 'Li':3, 'Be':4, 'B':5, 'C':6, 'N':7, 'O':8, 'F':9, 'Ne':10, 'Na':11, 'Mg':12, 'Al':13, 'Si':14, 'P':15, 'S':16, 'Cl':17, 'Ar':18, 'K':19, 'Ca':20, 'Sc':21, 'Ti':22, 'V':23, 'Cr':24, 'Mn':25, 'Fe':26, 'Co':27, 'Ni':28, 'Cu':29, 'Zn':30, 'Ga':31, 'Ge':32, 'As':33, 'Se':34, 'Br':35, 'Kr':36, 'Rb':37, 'Sr':38, 'Y':39, 'Zr':40, 'Nb':41, 'Mo':42, 'Tc':43, 'Ru':44, 'Rh':45, 'Pd':46, 'Ag':47, 'Cd':48, 'In':49, 'Sn':50, 'Sb':51, 'Te':52, 'I':53, 'Xe':54, 'Cs':55, 'Ba':56, 'La':57, 'Ce':58, 'Pr':59, 'Nd':60, 'Pm':61, 'Sm':62, 'Eu':63, 'Gd':64, 'Tb':65, 'Dy':66, 'Ho':67, 'Er':68, 'Tm':69, 'Yb':70, 'Lu':71, 'Hf':72, 'Ta':73, 'W':74, 'Re':75, 'Os':76, 'Ir':77, 'Pt':78, 'Au':79, 'Hg':80, 'Tl':81, 'Pb':82, 'Bi':83, 'Po':84, 'At':85, 'Rn':86, 'Fr':87, 'Ra':88, 'Ac':89, 'Th':90, 'Pa':91, 'U':92, 'Np':93, 'Pu':94, 'Am':95, 'Cm':96, 'Bk':97, 'Cf':98, 'Es':99, 'Fm':100 } value_to_element = dict() for (element, value) in element_to_value.items(): value_to_element[value] = element # Read inputs (n,k) = map(int,input().split()) products_start_str = input().split() products_end_str = input().split() # Translate elements to their values products_start = [element_to_value[elem] for elem in products_start_str] products_end = [element_to_value[elem] for elem in products_end_str] # Filter out duplicates; keep track of ingredient values and their number products_start.sort() ingredient_value = [] ingredient_count = [] for (key, lst) in itertools.groupby(products_start): ingredient_value.append(key) ingredient_count.append(len(list(lst))) nr_ingredients = len(ingredient_value) # Figure out the options for constructing the final products construction_options = [[] for i in range(k)] for combination in itertools.product(*[range(l+1) for l in ingredient_count]): value = sum(combination[i]*ingredient_value[i] for i in range(nr_ingredients)) if (value in products_end): for i in range(k): if products_end[i] == value: construction_options[i].append(combination) # Do a depth-first search on the construction options for a possible solution solution = [None for i in range(k)] def find_solution(used = [0 for i in range(nr_ingredients)], next = 0): if (next == k): return all(used[i] == ingredient_count[i] for i in range(nr_ingredients)) else: for option in construction_options[next]: usage = [used[i]+option[i] for i in range(nr_ingredients)] if all(used[i] <= ingredient_count[i] for i in range(nr_ingredients)): possible = find_solution(usage, next+1) if (possible): solution[next] = option return True return False possible = find_solution() # Print the answer if not possible: print("NO") exit() def combination_to_recipe(combination): recipe = [] for i in range(nr_ingredients): for j in range(combination[i]): recipe.append(value_to_element[ingredient_value[i]]) return recipe print("YES") for i in range(k): recipe = combination_to_recipe(solution[i]) print("%s->%s" % ("+".join(recipe),products_end_str[i])) ```
output
1
87,143
3
174,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a new one from them. That results in a new atom, whose number is equal to the sum of the numbers of original atoms. The fusion operation can be performed several times. The aim is getting a new pregiven set of k atoms. The puzzle's difficulty is that it is only allowed to fuse two atoms into one, it is not allowed to split an atom into several atoms. You are suggested to try to solve the puzzle. Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 17). The second line contains space-separated symbols of elements of n atoms, which are available from the start. The third line contains space-separated symbols of elements of k atoms which need to be the result of the fusion. The symbols of the elements coincide with the symbols from the periodic table of the chemical elements. The atomic numbers do not exceed 100 (elements possessing larger numbers are highly unstable). Some atoms can have identical numbers (that is, there can be several atoms of the same element). The sum of numbers of initial atoms is equal to the sum of numbers of the atoms that need to be synthesized. Output If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next k lines print the way of synthesizing each of k atoms as equations. Each equation has the following form: "x1+x2+...+xt->yi", where xj is the symbol of the element of some atom from the original set, and yi is the symbol of the element of some atom from the resulting set. Each atom from the input data should occur in the output data exactly one time. The order of summands in the equations, as well as the output order does not matter. If there are several solutions, print any of them. For a better understanding of the output format, see the samples. Examples Input 10 3 Mn Co Li Mg C P F Zn Sc K Sn Pt Y Output YES Mn+C+K-&gt;Sn Co+Zn+Sc-&gt;Pt Li+Mg+P+F-&gt;Y Input 2 1 H H He Output YES H+H-&gt;He Input 2 2 Bk Fm Cf Es Output NO Note The reactions from the first example possess the following form (the atomic number is written below and to the left of the element): <image> <image> <image> To find a periodic table of the chemical elements, you may use your favorite search engine. The pretest set contains each of the first 100 elements of the periodic table at least once. You can use that information to check for misprints. Submitted Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') elem = ['*'] + ''' H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm'''.split() n, k = map(int, input().split()) a = [elem.index(e) for e in input().split()] b = [elem.index(e) for e in input().split()] req = [[] for _ in range(k)] for i in range(k): for bit in range(1 << n): if sum(a[j] for j in range(n) if (1 << j) & bit) == b[i]: req[i].append(bit) for i in range(k): req[i] = req[i][:50] dp = [array('i', [-1]) * (1 << n) for _ in range(k + 1)] dp[0][0] = 0 full_bit = (1 << n) - 1 bs_set = {0} for i in range(k): next_bs = set() for bitset in list(bs_set)[:15000]: if dp[i][bitset] != -1: for req_bit in req[i]: if not (bitset & req_bit): next_bs.add(bitset + req_bit) dp[i + 1][bitset | req_bit] = bitset bs_set = next_bs bitset = -1 for bit in range(1 << n): if dp[-1][bit] != -1: bitset = bit break if bitset == -1: print('NO') exit() ans = [] for i in range(k, 0, -1): prev = dp[i][bitset] delta = bitset - prev s = '+'.join(elem[a[j]] for j in range(n) if (1 << j) & delta) ans.append(s + '->' + elem[b[i - 1]]) bitset = prev print('YES') print(*reversed(ans), sep='\n') ```
instruction
0
87,144
3
174,288
No
output
1
87,144
3
174,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a new one from them. That results in a new atom, whose number is equal to the sum of the numbers of original atoms. The fusion operation can be performed several times. The aim is getting a new pregiven set of k atoms. The puzzle's difficulty is that it is only allowed to fuse two atoms into one, it is not allowed to split an atom into several atoms. You are suggested to try to solve the puzzle. Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 17). The second line contains space-separated symbols of elements of n atoms, which are available from the start. The third line contains space-separated symbols of elements of k atoms which need to be the result of the fusion. The symbols of the elements coincide with the symbols from the periodic table of the chemical elements. The atomic numbers do not exceed 100 (elements possessing larger numbers are highly unstable). Some atoms can have identical numbers (that is, there can be several atoms of the same element). The sum of numbers of initial atoms is equal to the sum of numbers of the atoms that need to be synthesized. Output If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next k lines print the way of synthesizing each of k atoms as equations. Each equation has the following form: "x1+x2+...+xt->yi", where xj is the symbol of the element of some atom from the original set, and yi is the symbol of the element of some atom from the resulting set. Each atom from the input data should occur in the output data exactly one time. The order of summands in the equations, as well as the output order does not matter. If there are several solutions, print any of them. For a better understanding of the output format, see the samples. Examples Input 10 3 Mn Co Li Mg C P F Zn Sc K Sn Pt Y Output YES Mn+C+K-&gt;Sn Co+Zn+Sc-&gt;Pt Li+Mg+P+F-&gt;Y Input 2 1 H H He Output YES H+H-&gt;He Input 2 2 Bk Fm Cf Es Output NO Note The reactions from the first example possess the following form (the atomic number is written below and to the left of the element): <image> <image> <image> To find a periodic table of the chemical elements, you may use your favorite search engine. The pretest set contains each of the first 100 elements of the periodic table at least once. You can use that information to check for misprints. Submitted Solution: ``` numbersDict = { "1": "H", "2": "He", "3": "Li", "4": "Be", "5": "B", "6": "C", "7": "N", "8": "O", "9": "F", "10": "Ne", "11": "Na", "12": "Mg", "13": "Al", "14": "Si", "15": "P", "16": "S", "17": "Cl", "18": "Ar", "19": "K", "20": "Ca", "21": "Sc", "22": "Ti", "23": "V", "24": "Cr", "25": "Mn", "26": "Fe", "27": "Co", "28": "Ni", "29": "Cu", "30": "Zn", "31": "Ga", "32": "Ge", "33": "As", "34": "Se", "35": "Br", "36": "Kr", "37": "Rb", "38": "Sr", "39": "Y", "40": "Zr", "41": "Nb", "42": "Mo", "43": "Tc", "44": "Ru", "45": "Rh", "46": "Pd", "47": "Ag", "48": "Cd", "49": "In", "50": "Sn", "51": "Sb", "52": "Te", "53": "I", "54": "Xe", "55": "Cs", "56": "Ba", "57": "La", "58": "Ce", "59": "Pr", "60": "Nd", "61": "Pm", "62": "Sm", "63": "Eu", "64": "Gd", "65": "Tb", "66": "Dy", "67": "Ho", "68": "Er", "69": "Tm", "70": "Yb", "71": "Lu", "72": "Hf", "73": "Ta", "74": "W", "75": "Re", "76": "Os", "77": "Ir", "78": "Pt", "79": "Au", "80": "Hg", "81": "Tl", "82": "Pb", "83": "Bi", "84": "Po", "85": "At", "86": "Rn", "87": "Fr", "88": "Ra", "89": "Ac", "90": "Th", "91": "Pa", "92": "U", "93": "Np", "94": "Pu", "95": "Am", "96": "Cm", "97": "Bk", "98": "Cf", "99": "Es", "100": "Fm" } lettersDict = { "H": "1", "He": "2", "Li": "3", "Be": "4", "B": "5", "C": "6", "N": "7", "O": "8", "F": "9", "Ne": "10", "Na": "11", "Mg": "12", "Al": "13", "Si": "14", "P": "15", "S": "16", "Cl": "17", "Ar": "18", "K": "19", "Ca": "20", "Sc": "21", "Ti": "22", "V": "23", "Cr": "24", "Mn": "25", "Fe": "26", "Co": "27", "Ni": "28", "Cu": "29", "Zn": "30", "Ga": "31", "Ge": "32", "As": "33", "Se": "34", "Br": "35", "Kr": "36", "Rb": "37", "Sr": "38", "Y": "39", "Zr": "40", "Nb": "41", "Mo": "42", "Tc": "43", "Ru": "44", "Rh": "45", "Pd": "46", "Ag": "47", "Cd": "48", "In": "49", "Sn": "50", "Sb": "51", "Te": "52", "I": "53", "Xe": "54", "Cs": "55", "Ba": "56", "La": "57", "Ce": "58", "Pr": "59", "Nd": "60", "Pm": "61", "Sm": "62", "Eu": "63", "Gd": "64", "Tb": "65", "Dy": "66", "Ho": "67", "Er": "68", "Tm": "69", "Yb": "70", "Lu": "71", "Hf": "72", "Ta": "73", "W": "74", "Re": "75", "Os": "76", "Ir": "77", "Pt": "78", "Au": "79", "Hg": "80", "Tl": "81", "Pb": "82", "Bi": "83", "Po": "84", "At": "85", "Rn": "86", "Fr": "87", "Ra": "88", "Ac": "89", "Th": "90", "Pa": "91", "U": "92", "Np": "93", "Pu": "94", "Am": "95", "Cm": "96", "Bk": "97", "Cf": "98", "Es": "99", "Fm": "100" } _ = input() # Supposed to be n, k but we do not need them atoms = sorted(list(map(lambda x: int(lettersDict[x]), input().split(" ")))) outAtoms = sorted(list(map(lambda x: int(lettersDict[x]), input().split(" ")))) allStack = [] currentSet = set() stack = [] resultFound = False memo = set() cycles = 0 def dfs3(i: int, currentSum: int): global cycles cycles += 1 if cycles >= 250000: print("NO") exit() return global stack global allStack global currentSet global resultFound if i == len(outAtoms): resultFound = True return if currentSum > outAtoms[i]: return if currentSum == outAtoms[i]: previousStack = stack.copy() allStack.append(stack.copy()) stack = [] dfs3(i + 1, 0) if resultFound: return allStack.pop() stack = previousStack return for j in range(len(atoms)): if j in currentSet: continue currentSet.add(j) stack.append(j) dfs3(i, currentSum + atoms[j]) if resultFound: return currentSet.remove(j) stack.remove(j) dfs3(0, 0) if resultFound: print("YES") res = [[numbersDict[f"{atoms[s]}"] for s in st] for st in allStack] res = ["+".join(x) for x in res] outs = list(map(lambda x: numbersDict[f"{x}"], outAtoms)) tot = list(map(lambda x: x[0] + "->" + x[1], zip(res, outs))) for t in tot: print(t) else: print("NO") ```
instruction
0
87,145
3
174,290
No
output
1
87,145
3
174,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a new one from them. That results in a new atom, whose number is equal to the sum of the numbers of original atoms. The fusion operation can be performed several times. The aim is getting a new pregiven set of k atoms. The puzzle's difficulty is that it is only allowed to fuse two atoms into one, it is not allowed to split an atom into several atoms. You are suggested to try to solve the puzzle. Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 17). The second line contains space-separated symbols of elements of n atoms, which are available from the start. The third line contains space-separated symbols of elements of k atoms which need to be the result of the fusion. The symbols of the elements coincide with the symbols from the periodic table of the chemical elements. The atomic numbers do not exceed 100 (elements possessing larger numbers are highly unstable). Some atoms can have identical numbers (that is, there can be several atoms of the same element). The sum of numbers of initial atoms is equal to the sum of numbers of the atoms that need to be synthesized. Output If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next k lines print the way of synthesizing each of k atoms as equations. Each equation has the following form: "x1+x2+...+xt->yi", where xj is the symbol of the element of some atom from the original set, and yi is the symbol of the element of some atom from the resulting set. Each atom from the input data should occur in the output data exactly one time. The order of summands in the equations, as well as the output order does not matter. If there are several solutions, print any of them. For a better understanding of the output format, see the samples. Examples Input 10 3 Mn Co Li Mg C P F Zn Sc K Sn Pt Y Output YES Mn+C+K-&gt;Sn Co+Zn+Sc-&gt;Pt Li+Mg+P+F-&gt;Y Input 2 1 H H He Output YES H+H-&gt;He Input 2 2 Bk Fm Cf Es Output NO Note The reactions from the first example possess the following form (the atomic number is written below and to the left of the element): <image> <image> <image> To find a periodic table of the chemical elements, you may use your favorite search engine. The pretest set contains each of the first 100 elements of the periodic table at least once. You can use that information to check for misprints. Submitted Solution: ``` en={'H': '1', 'He': '2', 'Li': '3', 'Be': '4', 'B': '5', 'C': '6', 'N': '7', 'O': '8', 'F': '9', 'Ne': '10', 'Na': '11', 'Mg': '12', 'Al': '13', 'Si': '14', 'P': '15', 'S': '16', 'Cl': '17', 'Ar': '18', 'K': '19', 'Ca': '20', 'Sc': '21', 'Ti': '22', 'V': '23', 'Cr': '24', 'Mn': '25', 'Fe': '26', 'Co': '27', 'Ni': '28', 'Cu': '29', 'Zn': '30', 'Ga': '31', 'Ge': '32', 'As': '33', 'Se': '34', 'Br': '35', 'Kr': '36', 'Rb': '37', 'Sr': '38', 'Y': '39', 'Zr': '40', 'Nb': '41', 'Mo': '42', 'Tc': '43', 'Ru': '44', 'Rh': '45', 'Pd': '46', 'Ag': '47', 'Cd': '48', 'In': '49', 'Sn': '50', 'Sb': '51', 'Te': '52', 'I': '53', 'Xe': '54', 'Cs': '55', 'Ba': '56', 'La': '57', 'Ce': '58', 'Pr': '59', 'Nd': '60', 'Pm': '61', 'Sm': '62', 'Eu': '63', 'Gd': '64', 'Tb': '65', 'Dy': '66', 'Ho': '67', 'Er': '68', 'Tm': '69', 'Yb': '70', 'Lu': '71', 'Hf': '72', 'Ta': '73', 'W': '74', 'Re': '75', 'Os': '76', 'Ir': '77', 'Pt': '78', 'Au': '79', 'Hg': '80', 'Tl': '81', 'Pb': '82', 'Bi': '83', 'Po': '84', 'At': '85', 'Rn': '86', 'Fr': '87', 'Ra': '88', 'Ac': '89', 'Th': '90', 'Pa': '91', 'U': '92', 'Np': '93', 'Pu': '94', 'Am': '95', 'Cm': '96', 'Bk': '97', 'Cf': '98', 'Es': '99', 'Fm': '100', 'Md': '101', 'No': '102', 'Lr': '103', 'Rf': '104', 'Db': '105', 'Sg': '106', 'Bh': '107', 'Hs': '108', 'Mt': '109', 'Ds ': '110', 'Rg ': '111', 'Cn ': '112', 'Nh': '113', 'Fl': '114', 'Mc': '115', 'Lv': '116', 'Ts': '117', 'Og': '118'} ne={en[x]:x for x in en} n,m=map(int,input().split()) e=[int(en[x])for x in input().split()] r=[int(en[x])for x in input().split()] print(e) a=1<<n ans=[] for q in r: for i in range(a): s=0 l=[] for j in range(n): if 1<<j&i: s+=e[j] l+=[ne[str(e[j])]] if s==q:ans+=[l];break if len(ans)==m: print('YES') for i in range(m): print('+'.join(ans[i])+'->'+ne[str(r[i])]) else:print('NO') ```
instruction
0
87,146
3
174,292
No
output
1
87,146
3
174,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a new one from them. That results in a new atom, whose number is equal to the sum of the numbers of original atoms. The fusion operation can be performed several times. The aim is getting a new pregiven set of k atoms. The puzzle's difficulty is that it is only allowed to fuse two atoms into one, it is not allowed to split an atom into several atoms. You are suggested to try to solve the puzzle. Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 17). The second line contains space-separated symbols of elements of n atoms, which are available from the start. The third line contains space-separated symbols of elements of k atoms which need to be the result of the fusion. The symbols of the elements coincide with the symbols from the periodic table of the chemical elements. The atomic numbers do not exceed 100 (elements possessing larger numbers are highly unstable). Some atoms can have identical numbers (that is, there can be several atoms of the same element). The sum of numbers of initial atoms is equal to the sum of numbers of the atoms that need to be synthesized. Output If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next k lines print the way of synthesizing each of k atoms as equations. Each equation has the following form: "x1+x2+...+xt->yi", where xj is the symbol of the element of some atom from the original set, and yi is the symbol of the element of some atom from the resulting set. Each atom from the input data should occur in the output data exactly one time. The order of summands in the equations, as well as the output order does not matter. If there are several solutions, print any of them. For a better understanding of the output format, see the samples. Examples Input 10 3 Mn Co Li Mg C P F Zn Sc K Sn Pt Y Output YES Mn+C+K-&gt;Sn Co+Zn+Sc-&gt;Pt Li+Mg+P+F-&gt;Y Input 2 1 H H He Output YES H+H-&gt;He Input 2 2 Bk Fm Cf Es Output NO Note The reactions from the first example possess the following form (the atomic number is written below and to the left of the element): <image> <image> <image> To find a periodic table of the chemical elements, you may use your favorite search engine. The pretest set contains each of the first 100 elements of the periodic table at least once. You can use that information to check for misprints. Submitted Solution: ``` import random from itertools import combinations, product from functools import reduce symbol_value = {'Br': 35, 'Pm': 61, 'At': 85, 'Xe': 54, 'Pu': 94, 'Tl': 81, 'Mg': 12, 'Fe': 26, 'Kr': 36, 'Ar': 18, 'I': 53, 'Ga': 31, 'Sn': 50, 'Pd': 46, 'Fr': 87, 'Lu': 71, 'Dy': 66, 'Ac': 89, 'Gd': 64, 'Nd': 60, 'Bk': 97, 'Sb': 51, 'H': 1, 'Al': 13, 'Mo': 42, 'Sr': 38, 'Re': 75, 'Es': 99, 'Au': 79, 'Ra': 88, 'Cu': 29, 'Ca': 20, 'Am': 95, 'Pa': 91, 'U': 92, 'Ti': 22, 'Y': 39, 'Ag': 47, 'Hg': 80, 'F': 9, 'Cd': 48, 'Cs': 55, 'Rh': 45, 'Os': 76, 'Pr': 59, 'Ni': 28, 'Bi': 83, 'La': 57, 'Ta': 73, 'S': 16, 'Ir': 77, 'Rn': 86, 'Zn': 30, 'Se': 34, 'Li': 3, 'Ge': 32, 'Cr': 24, 'W': 74, 'Cm': 96, 'Hf': 72, 'Fm': 100, 'In': 49, 'Si': 14, 'Cl': 17, 'Sc': 21, 'Tc': 43, 'V': 23, 'O': 8, 'Rb': 37, 'Np': 93, 'Mn': 25, 'Te': 52, 'Ba': 56, 'Tb': 65, 'Po': 84, 'B': 5, 'Ru': 44, 'Eu': 63, 'Na': 11, 'Ce': 58, 'Yb': 70, 'Ho': 67, 'Nb': 41, 'Er': 68, 'Co': 27, 'Zr': 40, 'Ne': 10, 'As': 33, 'Sm': 62, 'Pb': 82, 'K': 19, 'Tm': 69, 'C': 6, 'Cf': 98, 'P': 15, 'Pt': 78, 'Th': 90, 'He': 2, 'N': 7, 'Be': 4} value_symbol = {1: 'H', 2: 'He', 3: 'Li', 4: 'Be', 5: 'B', 6: 'C', 7: 'N', 8: 'O', 9: 'F', 10: 'Ne', 11: 'Na', 12: 'Mg', 13: 'Al', 14: 'Si', 15: 'P', 16: 'S', 17: 'Cl', 18: 'Ar', 19: 'K', 20: 'Ca', 21: 'Sc', 22: 'Ti', 23: 'V', 24: 'Cr', 25: 'Mn', 26: 'Fe', 27: 'Co', 28: 'Ni', 29: 'Cu', 30: 'Zn', 31: 'Ga', 32: 'Ge', 33: 'As', 34: 'Se', 35: 'Br', 36: 'Kr', 37: 'Rb', 38: 'Sr', 39: 'Y', 40: 'Zr', 41: 'Nb', 42: 'Mo', 43: 'Tc', 44: 'Ru', 45: 'Rh', 46: 'Pd', 47: 'Ag', 48: 'Cd', 49: 'In', 50: 'Sn', 51: 'Sb', 52: 'Te', 53: 'I', 54: 'Xe', 55: 'Cs', 56: 'Ba', 57: 'La', 58: 'Ce', 59: 'Pr', 60: 'Nd', 61: 'Pm', 62: 'Sm', 63: 'Eu', 64: 'Gd', 65: 'Tb', 66: 'Dy', 67: 'Ho', 68: 'Er', 69: 'Tm', 70: 'Yb', 71: 'Lu', 72: 'Hf', 73: 'Ta', 74: 'W', 75: 'Re', 76: 'Os', 77: 'Ir', 78: 'Pt', 79: 'Au', 80: 'Hg', 81: 'Tl', 82: 'Pb', 83: 'Bi', 84: 'Po', 85: 'At', 86: 'Rn', 87: 'Fr', 88: 'Ra', 89: 'Ac', 90: 'Th', 91: 'Pa', 92: 'U', 93: 'Np', 94: 'Pu', 95: 'Am', 96: 'Cm', 97: 'Bk', 98: 'Cf', 99: 'Es', 100: 'Fm'} def translate_tuple(t): return '+'.join(str(value_symbol[item]) for item in t) + '->' + value_symbol[sum(t)] def get_start_pos(n_values, k, number): pos = None for i, n in enumerate(n_values): if i < k - 1: # can be improved continue if number > k * n: continue tk = 1 total = n while tk < k: total += n_values[i - tk] tk += 1 if total > number: pos = i - k + 1 break return pos def find_valid_answer(alternatives): keys = alternatives.keys() for indices in product(*(range(len(alternatives[a])) for a in keys)): item = [alternatives[k][i] for k,i in zip(keys, indices)] expected_sum = sum(len(a) for a in item) if len(reduce(lambda a,b: a.union(b),item)) == expected_sum: return item return None while True: try: line = input() except: break n, k = map(int, line.split()) n_values = sorted([symbol_value[x] for x in input().strip().split()]) k_values = sorted([symbol_value[x] for x in input().strip().split()]) alternatives = {k:[] for k in k_values} sample = sorted(n_values) desired = set(k_values) stop = max(desired) for i in range(1,len(sample)+1): min = 100000 for comb in combinations(sample, i): current = sum(comb) if current < min: min = current sum_comb = sum(comb) if sum_comb in desired: alternatives[sum_comb].append(set(comb)) if min > stop: break answer = find_valid_answer(alternatives) if answer: print('YES') for i in answer: print(translate_tuple(i)) else: print('NO') ```
instruction
0
87,147
3
174,294
No
output
1
87,147
3
174,295
Provide tags and a correct Python 3 solution for this coding contest problem. There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: * this list contains all Jinotega's flights in this year (in arbitrary order), * Jinotega has only flown from his hometown to a snooker contest and back, * after each competition Jinotega flies back home (though they may attend a competition in one place several times), * and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location! Input In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. Output If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". Examples Input 4 SVO SVO-&gt;CDG LHR-&gt;SVO SVO-&gt;LHR CDG-&gt;SVO Output home Input 3 SVO SVO-&gt;HKT HKT-&gt;SVO SVO-&gt;RAP Output contest Note In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
instruction
0
87,164
3
174,328
Tags: implementation, math Correct Solution: ``` t = int(input()) if t % 2 == 1: print("contest") else: print("home") ```
output
1
87,164
3
174,329