message
stringlengths
2
45.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
254
108k
cluster
float64
3
3
__index_level_0__
int64
508
217k
Provide tags and a correct Python 3 solution for this coding contest problem. 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->CDG LHR->SVO SVO->LHR CDG->SVO Output home Input 3 SVO SVO->HKT HKT->SVO SVO->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,165
3
174,330
Tags: implementation, math Correct Solution: ``` n=int(input()) home=str(input()) k=n l=[] while(n): l.append(str(input())) n-=1 # print(l) chk=l[-1][-3:] # if(chk==home): # print('home') # else: # print('contest') if(k%2==0): print("home") else: print("contest") ```
output
1
87,165
3
174,331
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->CDG LHR->SVO SVO->LHR CDG->SVO Output home Input 3 SVO SVO->HKT HKT->SVO SVO->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,166
3
174,332
Tags: implementation, math Correct Solution: ``` print("home" if int(input()) % 2 == 0 else "contest") ```
output
1
87,166
3
174,333
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->CDG LHR->SVO SVO->LHR CDG->SVO Output home Input 3 SVO SVO->HKT HKT->SVO SVO->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,167
3
174,334
Tags: implementation, math Correct Solution: ``` import sys raw_data = list() for line in sys.stdin: raw_data.append(line) nr = int(raw_data[0]) home = raw_data[1][0:3] dept = list() dest = list() for idx in range(2, 2 + nr): dept.append(raw_data[idx][0:3]) dest.append(raw_data[idx][5:8]) nxt = home cnt = 0 while cnt != nr: try: idx = dept.index(nxt) nxt = dest[idx] last = nxt except: break dept[idx] = '' cnt += 1 if cnt == nr and last == home: print('home') else: print('contest') ```
output
1
87,167
3
174,335
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->CDG LHR->SVO SVO->LHR CDG->SVO Output home Input 3 SVO SVO->HKT HKT->SVO SVO->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,168
3
174,336
Tags: implementation, math Correct Solution: ``` n = int(input()) s = input() c = 0 for i in range(n): mass = input() mass = mass.split("->") if s in mass: c+=1 if(not (c % 2)): print("home") else: print("contest") ```
output
1
87,168
3
174,337
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->CDG LHR->SVO SVO->LHR CDG->SVO Output home Input 3 SVO SVO->HKT HKT->SVO SVO->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,169
3
174,338
Tags: implementation, math Correct Solution: ``` #Rohan Bojja #rohan.bojja@gmail.com from collections import defaultdict ####################################### c=1 cases=1 while(c<=cases): n=int(input()) home=input() iten=defaultdict(list) for i in range(0,n): cur=input().split("->") iten[cur[0]].append(cur[1]) ans="home" cur=home while(True): #print(cur,iten) if(cur in iten): if(cur!=home and home in iten[cur]): del iten[cur][iten[cur].index(home)] cur=home elif(cur!=home): ans="contest" break elif(cur==home and len(iten[cur])>0): cur2=iten[cur][0] iten[cur].pop(0) cur=cur2 elif(cur==home): break else: ans="contest" break #print(cur,iten) print(ans) c=c+1 ```
output
1
87,169
3
174,339
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,170
3
174,340
Tags: implementation, math Correct Solution: ``` n = int(input()) a = input() q = [] w = [] for i in range(n): b = input() l = b[:b.find('-')] r = b[b.find('>')+1:] q.append(l) w.append(r) e = q.count(a) t = w.count(a) if e == t: print("home") else: print("contest") ```
output
1
87,170
3
174,341
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,171
3
174,342
Tags: implementation, math Correct Solution: ``` X = int(input()) Home = input() counter = 0 for i in range(X): h, c = list(input().split('->')) if h == Home: counter += 1 elif c == Home: counter -= 1 print("home" if counter == 0 else "contest") ```
output
1
87,171
3
174,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` n=int(input()) h=input() c1,c2=0,0 for i in range(n): x,y=input().split('->') if x==h: c1=c1+1 elif y==h: c2=c2+1 if c1==c2: print('home') else: print('contest') ```
instruction
0
87,172
3
174,344
Yes
output
1
87,172
3
174,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` if __name__ == "__main__": n = int(input()) home = input() flights = [] while n > 0: s, t = input().split("->") flights.append(s) flights.append(t) n -= 1 count = 0 for flight in flights: if flight == home: count += 1 if count % 2 == 0: print("home") else: print("contest") ```
instruction
0
87,173
3
174,346
Yes
output
1
87,173
3
174,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` #!/usr/bin/python3 n = int(input()) if n % 2 == 0: print("home") else: print("contest") ```
instruction
0
87,174
3
174,348
Yes
output
1
87,174
3
174,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` if int(input()) & 1: print('contest') else: print('home') ```
instruction
0
87,175
3
174,350
Yes
output
1
87,175
3
174,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` n = int(input()) home = input() i = 0 lst = [] while i < n: lst.append(input()) i += 1 last_fly = lst.count(lst[len(lst) - 1]) last = lst[len(lst) - 1][:3] first = lst[len(lst) - 1][-3:] cnt = lst.count(first + "->" + last) if cnt == last_fly: print("home") else: print("contest") ```
instruction
0
87,176
3
174,352
No
output
1
87,176
3
174,353
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` x=int(input()) for i in range(x+1): y=input() print(['home','conrest'][x%2]) ```
instruction
0
87,177
3
174,354
No
output
1
87,177
3
174,355
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` x = int(input()) a = input() t = [] k = 0 i = 0 t1 = 0 t3 = 1 for i in range(x): a1 = input().split("->") t.append(a1) while i <= x - 1: if t[i][0] == a: k = 1 for j in range(len(t)): if t[j][0] == t[i][1] and t[j][1] == t[i][0]: t.pop(j) i=i-1 t1 = 1 k = 0 break elif i == x-1: print("contest") t3 = 2 k = 1 break if k == 1: break if k == 1: break if t1 != 1: i = i + 1 if k == 0: print("home") elif k == 1 and t3 == 1: print("contest") ```
instruction
0
87,178
3
174,356
No
output
1
87,178
3
174,357
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. Submitted Solution: ``` n=int(input()) home=str(input()) k=n l=[] while(n): l.append(str(input())) n-=1 print(l) chk=l[-1][-3:] if(chk==home): print('home') else: print('contest') ```
instruction
0
87,179
3
174,358
No
output
1
87,179
3
174,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration <image>. The drink should also be tasty, so the glass can contain only integer number of liters of each Coke type (some types can be not presented in the glass). Also, they want to minimize the total volume of Coke in the glass. Carbon dioxide concentration is defined as the volume of carbone dioxide in the Coke divided by the total volume of Coke. When you mix two Cokes, the volume of carbon dioxide sums up, and the total volume of Coke sums up as well. Help them, find the minimal natural number of liters needed to create a glass with carbon dioxide concentration <image>. Assume that the friends have unlimited amount of each Coke type. Input The first line contains two integers n, k (0 ≀ n ≀ 1000, 1 ≀ k ≀ 106) β€” carbon dioxide concentration the friends want and the number of Coke types. The second line contains k integers a1, a2, ..., ak (0 ≀ ai ≀ 1000) β€” carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration. Output Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration <image>, or -1 if it is impossible. Examples Input 400 4 100 300 450 500 Output 2 Input 50 2 100 25 Output 3 Note In the first sample case, we can achieve concentration <image> using one liter of Coke of types <image> and <image>: <image>. In the second case, we can achieve concentration <image> using two liters of <image> type and one liter of <image> type: <image>. Submitted Solution: ``` ## ## ## import sys def line(): return sys.stdin.readline() def numbers(): return list(map(int, line().split())) def number(): return int(line()) adjlist = {} n, k = 0, 0 mark = [False]*1010 edges = [False]*1010 # bfs for "ssph" def bfs(s): i = 0 frontier = [s] while frontier: if mark[s]: break; next_frontier = [] for u in frontier: # check next state for v, isState in enumerate(edges): if isState: # check new node state = u + n - v if state >= 0 and state <= n and not mark[state]: mark[state] = True next_frontier.append(state) frontier = next_frontier i += 1 if mark[s]: return i else: return -1 # main program [n, k] = numbers() concentrations = numbers() # reading edges for x in concentrations: edges[x] = True ans = bfs(0) print(ans) # 1496437499797 ```
instruction
0
87,187
3
174,374
No
output
1
87,187
3
174,375
Provide a correct Python 3 solution for this coding contest problem. The earth is under an attack of a deadly virus. Luckily, prompt actions of the Ministry of Health against this emergency successfully confined the spread of the infection within a square grid of areas. Recently, public health specialists found an interesting pattern with regard to the transition of infected areas. At each step in time, every area in the grid changes its infection state according to infection states of its directly (horizontally, vertically, and diagonally) adjacent areas. * An infected area continues to be infected if it has two or three adjacent infected areas. * An uninfected area becomes infected if it has exactly three adjacent infected areas. * An area becomes free of the virus, otherwise. Your mission is to fight against the virus and disinfect all the areas. The Ministry of Health lets an anti-virus vehicle prototype under your command. The functionality of the vehicle is summarized as follows. * At the beginning of each time step, you move the vehicle to one of the eight adjacent areas. The vehicle is not allowed to move to an infected area (to protect its operators from the virus). It is not allowed to stay in the same area. * Following vehicle motion, all the areas, except for the area where the vehicle is in, change their infection states according to the transition rules described above. Special functionality of the vehicle protects its area from virus infection even if the area is adjacent to exactly three infected areas. Unfortunately, this virus-protection capability of the vehicle does not last. Once the vehicle leaves the area, depending on the infection states of the adjacent areas, the area can be infected. The area where the vehicle is in, which is uninfected, has the same effect to its adjacent areas as an infected area as far as the transition rules are concerned. The following series of figures illustrate a sample scenario that successfully achieves the goal. Initially, your vehicle denoted by @ is found at (1, 5) in a 5 Γ— 5-grid of areas, and you see some infected areas which are denoted by #'s. <image> Firstly, at the beginning of time step 1, you move your vehicle diagonally to the southwest, that is, to the area (2, 4). Note that this vehicle motion was possible because this area was not infected at the start of time step 1. Following this vehicle motion, infection state of each area changes according to the transition rules. The column "1-end" of the figure illustrates the result of such changes at the end of time step 1. Note that the area (3, 3) becomes infected because there were two adjacent infected areas and the vehicle was also in an adjacent area, three areas in total. In time step 2, you move your vehicle to the west and position it at (2, 3). Then infection states of other areas change. Note that even if your vehicle had exactly three infected adjacent areas (west, southwest, and south), the area that is being visited by the vehicle is not infected. The result of such changes at the end of time step 2 is as depicted in "2-end". Finally, in time step 3, you move your vehicle to the east. After the change of the infection states, you see that all the areas have become virus free! This completely disinfected situation is the goal. In the scenario we have seen, you have successfully disinfected all the areas in three time steps by commanding the vehicle to move (1) southwest, (2) west, and (3) east. Your mission is to find the length of the shortest sequence(s) of vehicle motion commands that can successfully disinfect all the areas. Input The input is a sequence of datasets. The end of the input is indicated by a line containing a single zero. Each dataset is formatted as follows. n a11 a12 ... a1n a21 a22 ... a2n ... an1 an2 ... ann Here, n is the size of the grid. That means that the grid is comprised of n Γ— n areas. You may assume 1 ≀ n ≀ 5. The rest of the dataset consists of n lines of n letters. Each letter aij specifies the state of the area at the beginning: '#' for infection, '.' for free of virus, and '@' for the initial location of the vehicle. The only character that can appear in a line is '#', '.', or '@'. Among n Γ— n areas, there exists exactly one area which has '@'. Output For each dataset, output the minimum number of time steps that is required to disinfect all the areas. If there exists no motion command sequence that leads to complete disinfection, output -1. The output should not contain any other extra character. Examples Input 3 ... .@. ... 3 .## .#. @## 3 ##. #.. @.. 5 ....@ ##... #.... ...#. ##.## 5 #...# ...#. #.... ...## ..@.. 5 #.... ..... ..... ..... ..@.. 5 #..#. #.#.# .#.#. ....# .#@## 5 ..##. ..#.. #.... #.... .#@.. 0 Output 0 10 -1 3 2 1 6 4 Input 3 ... .@. ... 3 .## .#. @## 3 . .. @.. 5 ....@ ... .... ...#. .## 5 ...# ...#. .... ...## ..@.. 5 .... ..... ..... ..... ..@.. 5 ..#. .#.# .#.#. ....# .#@## 5 ..##. ..#.. .... .... .#@.. 0 Output 0 10 -1 3 2 1 6 4
instruction
0
87,467
3
174,934
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] oks = collections.defaultdict(set) def a2k(a, n): r = 0 for i in range(n): for j in range(n): r *= 3 r += a[i][j] return r def k2a(k, n): a = [] for i in range(n): t = [] for j in range(n): t.append(k%3) k //= 3 a.append(t[::-1]) return a def moves(a,n): si = sj = -1 for i in range(n): for j in range(n): if a[i][j] == 2: si = i sj = j break if si >= 0: break r = set() a[si][sj] = 0 for i in range(max(0,si-1), min(n,si+2)): for j in range(max(0,sj-1), min(n,sj+2)): if a[i][j] != 0 or (si == i and sj == j): continue a[i][j] = 2 na = [[0]*n for _ in range(n)] zf = 1 for k in range(n): for l in range(n): if a[k][l] == 2: continue c = 0 for m in range(max(0, k-1), min(n, k+2)): for o in range(max(0, l-1), min(n, l+2)): if m == k and o == l: continue if a[m][o] > 0: c += 1 if (a[k][l] == 0 and c == 3) or (a[k][l] == 1 and 2 <= c <= 3): na[k][l] = 1 zf = 0 na[i][j] = 2 if zf == 1: return 'ok' r.add(a2k(na, n)) a[i][j] = 0 return r def f(n): sd = {} sd['.'] = 0 sd['#'] = 1 sd['@'] = 2 a = [[sd[c] for c in S()] for _ in range(n)] zf = 1 for i in range(n): for j in range(n): if a[i][j] == 1: zf = 0 break if zf == 1: return 0 r = inf d = collections.defaultdict(lambda: inf) k = a2k(a,n) q = set([k]) d[k] = 0 t = 0 while q: t += 1 nq = set() if q & oks[n]: return t for k in q: a = k2a(k,n) r = moves(a,n) if r == 'ok': oks[n].add(k) return t for nk in r: if d[nk] > t: d[nk] = t nq.add(nk) q = nq return -1 while 1: n = I() if n == 0: break rr.append(f(n)) return '\n'.join(map(str, rr)) print(main()) ```
output
1
87,467
3
174,935
Provide a correct Python 3 solution for this coding contest problem. The earth is under an attack of a deadly virus. Luckily, prompt actions of the Ministry of Health against this emergency successfully confined the spread of the infection within a square grid of areas. Recently, public health specialists found an interesting pattern with regard to the transition of infected areas. At each step in time, every area in the grid changes its infection state according to infection states of its directly (horizontally, vertically, and diagonally) adjacent areas. * An infected area continues to be infected if it has two or three adjacent infected areas. * An uninfected area becomes infected if it has exactly three adjacent infected areas. * An area becomes free of the virus, otherwise. Your mission is to fight against the virus and disinfect all the areas. The Ministry of Health lets an anti-virus vehicle prototype under your command. The functionality of the vehicle is summarized as follows. * At the beginning of each time step, you move the vehicle to one of the eight adjacent areas. The vehicle is not allowed to move to an infected area (to protect its operators from the virus). It is not allowed to stay in the same area. * Following vehicle motion, all the areas, except for the area where the vehicle is in, change their infection states according to the transition rules described above. Special functionality of the vehicle protects its area from virus infection even if the area is adjacent to exactly three infected areas. Unfortunately, this virus-protection capability of the vehicle does not last. Once the vehicle leaves the area, depending on the infection states of the adjacent areas, the area can be infected. The area where the vehicle is in, which is uninfected, has the same effect to its adjacent areas as an infected area as far as the transition rules are concerned. The following series of figures illustrate a sample scenario that successfully achieves the goal. Initially, your vehicle denoted by @ is found at (1, 5) in a 5 Γ— 5-grid of areas, and you see some infected areas which are denoted by #'s. <image> Firstly, at the beginning of time step 1, you move your vehicle diagonally to the southwest, that is, to the area (2, 4). Note that this vehicle motion was possible because this area was not infected at the start of time step 1. Following this vehicle motion, infection state of each area changes according to the transition rules. The column "1-end" of the figure illustrates the result of such changes at the end of time step 1. Note that the area (3, 3) becomes infected because there were two adjacent infected areas and the vehicle was also in an adjacent area, three areas in total. In time step 2, you move your vehicle to the west and position it at (2, 3). Then infection states of other areas change. Note that even if your vehicle had exactly three infected adjacent areas (west, southwest, and south), the area that is being visited by the vehicle is not infected. The result of such changes at the end of time step 2 is as depicted in "2-end". Finally, in time step 3, you move your vehicle to the east. After the change of the infection states, you see that all the areas have become virus free! This completely disinfected situation is the goal. In the scenario we have seen, you have successfully disinfected all the areas in three time steps by commanding the vehicle to move (1) southwest, (2) west, and (3) east. Your mission is to find the length of the shortest sequence(s) of vehicle motion commands that can successfully disinfect all the areas. Input The input is a sequence of datasets. The end of the input is indicated by a line containing a single zero. Each dataset is formatted as follows. n a11 a12 ... a1n a21 a22 ... a2n ... an1 an2 ... ann Here, n is the size of the grid. That means that the grid is comprised of n Γ— n areas. You may assume 1 ≀ n ≀ 5. The rest of the dataset consists of n lines of n letters. Each letter aij specifies the state of the area at the beginning: '#' for infection, '.' for free of virus, and '@' for the initial location of the vehicle. The only character that can appear in a line is '#', '.', or '@'. Among n Γ— n areas, there exists exactly one area which has '@'. Output For each dataset, output the minimum number of time steps that is required to disinfect all the areas. If there exists no motion command sequence that leads to complete disinfection, output -1. The output should not contain any other extra character. Examples Input 3 ... .@. ... 3 .## .#. @## 3 ##. #.. @.. 5 ....@ ##... #.... ...#. ##.## 5 #...# ...#. #.... ...## ..@.. 5 #.... ..... ..... ..... ..@.. 5 #..#. #.#.# .#.#. ....# .#@## 5 ..##. ..#.. #.... #.... .#@.. 0 Output 0 10 -1 3 2 1 6 4 Input 3 ... .@. ... 3 .## .#. @## 3 . .. @.. 5 ....@ ... .... ...#. .## 5 ...# ...#. .... ...## ..@.. 5 .... ..... ..... ..... ..@.. 5 ..#. .#.# .#.#. ....# .#@## 5 ..##. ..#.. .... .... .#@.. 0 Output 0 10 -1 3 2 1 6 4
instruction
0
87,468
3
174,936
"Correct Solution: ``` from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write dd0 = ((-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1)) DD = [] for k in range(6): ddk = [] for y in range(k): for x in range(k): v = 0 for dx, dy in dd0: nx = x + dx; ny = y + dy if not 0 <= nx < k or not 0 <= ny < k: continue v |= 1 << (ny*k + nx) ddk.append(v) DD.append(ddk) L = (1 << 16) bc = [0]*L for v in range(1, L): bc[v] = bc[v ^ (v & -v)] + 1 def solve(): N = int(readline()) if N == 0: return False dd = dd0 dk = DD[N] state = 0 for i in range(N): s = readline().strip() for j, c in enumerate(s): if c == '#': state |= 1 << (N*i + j) elif c == '@': sx = j; sy = i U = {(state, sx, sy): 0} que = deque([(state, sx, sy)]) while que: state, x, y = key = que.popleft() d = U[key] if state == 0: write("%d\n" % d) break for dx, dy in dd: nx = x + dx; ny = y + dy if not 0 <= nx < N or not 0 <= ny < N: continue b = 1 << (ny*N + nx) if state & b: continue state ^= b n_state = 0 for k in range(N*N): v = state & dk[k] if state & (1 << k): if v and 2 <= bc[v // (v & -v)] <= 3: n_state |= (1 << k) else: if v and bc[v // (v & -v)] == 3: n_state |= (1 << k) if n_state & b: n_state ^= b n_key = (n_state, nx, ny) if n_key not in U: U[n_key] = d+1 que.append(n_key) state ^= b else: write("-1\n") return True while solve(): ... ```
output
1
87,468
3
174,937
Provide a correct Python 3 solution for this coding contest problem. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T
instruction
0
87,479
3
174,958
"Correct Solution: ``` n=int(input()) tf=list(map(str,input().split())) tf_r=tf[::-1] while n!=1: if tf_r[-1]=="T" and tf_r[-2]=="F": del tf_r[-2:] tf_r.append("F") n-=1 else: del tf_r[-2:] tf_r.append("T") n-=1 print(tf_r[0]) ```
output
1
87,479
3
174,959
Provide a correct Python 3 solution for this coding contest problem. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T
instruction
0
87,480
3
174,960
"Correct Solution: ``` n=int(input()) p=list(map(str,input().split())) m=p[0] for i in range(1,n): if m+p[i]=="TF": m="F" else: m="T" print(m) ```
output
1
87,480
3
174,961
Provide a correct Python 3 solution for this coding contest problem. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T
instruction
0
87,481
3
174,962
"Correct Solution: ``` from functools import reduce def M(x, y): if x == 'T' and y == 'F': return 'F' else: return 'T' _ = input() P = input().split() print(reduce(M, P)) ```
output
1
87,481
3
174,963
Provide a correct Python 3 solution for this coding contest problem. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T
instruction
0
87,482
3
174,964
"Correct Solution: ``` n = int(input()) li = input().split() bef = li[0] for i in range(1, n): bef = "F" if bef == "T" and li[i] == "F" else "T" print(bef) ```
output
1
87,482
3
174,965
Provide a correct Python 3 solution for this coding contest problem. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T
instruction
0
87,483
3
174,966
"Correct Solution: ``` def inpl(): return list(map(int, input().split())) N = int(input()) P = input().split() def calc(a, b): if a == "T" and b == "F": return "F" else: return "T" a = P[0] for b in P[1:]: a = calc(a, b) print(a) ```
output
1
87,483
3
174,967
Provide a correct Python 3 solution for this coding contest problem. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T
instruction
0
87,484
3
174,968
"Correct Solution: ``` from functools import reduce def M(x, y): if x == 'T' and y == 'T': return 'T' elif x == 'T' and y == 'F': return 'F' elif x == 'F' and y == 'T': return 'T' else: return 'T' _ = input() P = input().split() print(reduce(M, P)) ```
output
1
87,484
3
174,969
Provide a correct Python 3 solution for this coding contest problem. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T
instruction
0
87,486
3
174,972
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A """ h,w = LI() a,b = LI() y = h//a x = w//b ans = h*w-a*y*b*x print(ans) """ #B def m(x,y): if x == y: return "T" if x == "F": return "T" return "F" n = I() p = input().split() ans = p[0] for i in range(1,n): ans = m(ans,p[i]) print(ans) #C """ s = [[1]*8 for i in range(4)] for i in range(4): s.insert(2*i,[1,0,1,0,1,0,1,0]) for j in range(8): for i in range(1,8): s[j][i] += s[j][i-1] for j in range(8): for i in range(1,8): s[i][j] += s[i-1][j] s.insert(0,[0,0,0,0,0,0,0,0,0]) for i in range(1,9): s[i].insert(0,0) q = I() for _ in range(q): a,b,c,d = LI() print(s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1]) """ #D """ n = I() a = LI() dp = [float("inf") for i in range(n)] b = [[] for i in range(n)] ind = [0 for i in range(100001)] for i in range(n): k = bisect.bisect_left(dp,a[i]) dp[k] = a[i] b[k].append(a[i]) ind[a[i]] = max(i,ind[a[i]]) for i in range(n): if dp[i] == float("inf"):break b[i].sort() b[i] = b[i][::-1] i -= 1 ans = b[i][0] now_ind = ind[b[i][0]] now_v = b[i][0] while i >= 0: for j in b[i]: if ind[j] < now_ind and j < now_v: ans += j now_ind = ind[j] now_v = j i -= 1 print(ans) """ #E #F #G #H #I #J #K #L #M #N #O #P #Q #R #S #T ```
output
1
87,486
3
174,973
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of various trials, the following was found. $ M (T, T) = T $ $ M (T, F) = F $ $ M (F, T) = T $ $ M (F, F) = T $ You put the animals in a row $ P_1, P_2, ..., P_N $ into the device as follows. $ M (.... M (M (P_1, P_2), P_3) ...., P_N) $ Answer the last animal that appears. output Output the last animal character $ T $ or $ F $, and also a newline at the end. Example Input 3 F T T Output T Submitted Solution: ``` N = int(input()) P = input().split() if P[0]=="T" and P[1]=="F": out = "F" else: out = "T" for i in range(N-2): if out == "T" and P[i+2] == "F": out = "F" else: out = "T" print(out) ```
instruction
0
87,489
3
174,978
Yes
output
1
87,489
3
174,979
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,525
3
175,050
Tags: binary search, math Correct Solution: ``` n = int(input()) m = int(input()) aj = list(map(int, input().split())) bj = list(map(int, input().split())) res = 0 if not (1 in aj) and not (1 in bj): i = 0 for num in range(len(aj) * 2): if num % 2 == 0: i -= 1 x = (m + res) / (bj[i] - 1) res += x else: x = (m + res) / (aj[i] - 1) res += x print(res) else: print('-1') ```
output
1
87,525
3
175,051
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,526
3
175,052
Tags: binary search, math Correct Solution: ``` import sys n = int(input()) # number planets m = int(input()) # weight of payload a = list(map(int,input().split())) # tons lifted b = list(map(int,input().split())) # tons landed # no more than 10**9 tons of fuel def get_landing(w,stage): #w +x = y*x #x = w / (y-1) return w/ (b[stage]-1) def get_takeoff(w,stage): return w/ (a[stage]-1) try: total_fuel = 0 land_earth = get_landing(m,0) total_fuel += land_earth m += land_earth for i in range(n-1,0,-1): take = get_takeoff(m,i) m += take total_fuel += take land = get_landing(m,i) total_fuel += land m += land total_fuel += get_takeoff(m,0) print (total_fuel) except: print (-1) ```
output
1
87,526
3
175,053
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,527
3
175,054
Tags: binary search, math Correct Solution: ``` n = int(input()) m = int(input()) coeffs = [] coeffs.append(list(map(int, input().split()))) coeffs.append(list(map(int, input().split()))) coeffs[1].append(coeffs[1][0]) m_orig = m #print(coeffs) def getFuel(): global m for i in range(n): for parity in range(2): coeff = coeffs[1-parity][-1-i] if coeff == 1: return -1 else: f = m / (coeff-1) m = m+f #print(m, coeff) return m - m_orig print(getFuel()) ```
output
1
87,527
3
175,055
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,528
3
175,056
Tags: binary search, math Correct Solution: ``` from itertools import chain n = int(input()) m = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) res = m cont = 1 for x in chain(a, b): if cont == 1: if x == 1: cont = 2 else: res /= 1-1/x if cont == 1: print(res-m) else: print('-1') ```
output
1
87,528
3
175,057
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,529
3
175,058
Tags: binary search, math Correct Solution: ``` n = int(input()) m = int(input()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] k = 1 for i in A: k *= (1 - (1 / i)) for i in B: k *= (1 - (1 / i)) if k == 0: ans = -1 else: ans = (m - (k * m)) / k print(ans) ```
output
1
87,529
3
175,059
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,530
3
175,060
Tags: binary search, math Correct Solution: ``` n=int(input()) m=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=m if b[0]-1==0: print(-1) else: m=m+(m/(b[0]-1)) counter=False for i in range(n-1,0,-1): if a[i]-1 ==0 or b[i]-1 ==0: counter=True else: m=m+(m/(a[i]-1)) m=m+(m/(b[i]-1)) #print(m) if counter==True or a[0]-1 ==0 : print(-1) else: m=m+(m/(a[0]-1)) print(m-ans) ```
output
1
87,530
3
175,061
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,531
3
175,062
Tags: binary search, math Correct Solution: ``` # your code goes here def predicate(x, m, a): rhs = 0 for i in range(len(a)): cv = (m+(x-rhs))/a[i] #print(cv) if cv<-5e-7: return False rhs+= cv #print(rhs) if(x-rhs >= -5e-7): return True return False n = int(input()) m = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for i in range( n-1): c.append(a[i]) c.append(b[i+1]) c.append(a[-1]) c.append(b[0]) #predicate(10, m, c) lo = 0 hi = 1e10 i = 0 while i < 100: mid = (hi+lo)/2 if predicate(mid, m, c): hi = mid else: lo = mid i+=1 print(lo) if lo <= 1e9+5e-7 else print(-1) ```
output
1
87,531
3
175,063
Provide tags and a correct Python 3 solution for this coding contest problem. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
instruction
0
87,532
3
175,064
Tags: binary search, math Correct Solution: ``` n = int(input()) m = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) start = m if b[0]-1 <= 0: print(-1) else: m += m/(b[0]-1) flag = True for i in range(n-1,0,-1): if a[i] - 1 <= 0: flag = False print(-1) break else: m += m/(a[i]-1) if b[i] - 1 <= 0: flag = False print(-1) break else: m += m/(b[i]-1) if flag: if a[0] - 1 <= 0: print(-1) else: m += m/(a[0]-1) print(m-start) ```
output
1
87,532
3
175,065
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` n = int(input()) m = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) def f(x): summ = x + m #print(summ, x, "summ") for i in range(n): summ -= summ / a[i % n] #print(summ, x, "summ") summ -= summ / b[(i + 1) % n] #print(summ, x, "summ") if summ < m: return False #print(summ, x, "summ") if summ < m: return False return True left = 0 right = 10 ** 9 + 1 while (right - left) >= 10 ** (-6): mid = (left + right) / 2 if f(mid): right = mid else: left = mid if right > 10 ** 9 + 10 ** (-5): print(-1) else: print(right) ```
instruction
0
87,533
3
175,066
Yes
output
1
87,533
3
175,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` n=int(input()) m=int(input()) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] z=(a[0]-1)/a[0] l=0 for i in range(1,n): z=z*(b[i]-1)/b[i] z=z*(a[i]-1)/a[i] z=z*(b[0]-1)/b[0] try: print("{0:.10f}".format(m/z-m)) except: print(-1) ```
instruction
0
87,534
3
175,068
Yes
output
1
87,534
3
175,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` n = int(input()) rm = m = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) if min(a+b) is 1: print(-1) else: for i in range(n-1,-1,-1): m += m / (a[(i + 1) % n] - 1) m += m / (b[i] - 1) print(round(m - rm,7)) ```
instruction
0
87,535
3
175,070
Yes
output
1
87,535
3
175,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` n = int(input()) m = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) def f(x,a): if a == 0 or a == 1: print(-1) import sys;sys.exit(0) return x*(1/a)/(1-1/a) cur_wt = m for bi in b: cur_wt = cur_wt + f(cur_wt, bi) for ai in reversed(a): cur_wt = cur_wt + f(cur_wt, ai) print("%f"%(cur_wt - m)) ```
instruction
0
87,536
3
175,072
Yes
output
1
87,536
3
175,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` def solve(n): n = n - n/s[0]; for i in range(1, len(s)): n = n - n/s1[i] n = n - n/s[i]; if n < m : return False n = n - n/s1[0] return n>=m n = int(input()) m = int(input()) s = list( int(x) for x in input().split( )) s1 = list(int(x)for x in input().split( )) low = 1 high = (10**9) + 5 while(high - low > 0.000001): mid = (high+low)/2 if solve(mid + m ): high= mid; else: low = mid; if(solve(low + m )): print(low); elif(solve(high+ m)): print(high) else: print(-1) ```
instruction
0
87,537
3
175,074
No
output
1
87,537
3
175,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` n=int(input()) m=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) l=0 r=1000000001 def can(w): z=w+m x=w-z/a[0] if x<0: return 0 for i in range(1,n): x=x-(x+m)/b[i] if x<0: return 0 x=x-(x+m)/a[i] if x<0: return 0 x=x-(x+m)/b[0] if x<0: return 0 return 1 while r-l>=0.0000001: w=(r+l)/2 if can(w): r=w else: l=w print(round(r,6)) ```
instruction
0
87,538
3
175,076
No
output
1
87,538
3
175,077
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` import math import itertools getInputList = lambda : list(input().split()) getInputIntList = lambda : list(map(int,input().split())) n = int(input()) m = int(input()) a = getInputIntList() b = getInputIntList() w = a+b left = 0 right = 10**9 best = -1 """ 2 12 11 8 7 5 11 5 8 7 """ while left <= right: md = (left + right)//2 iw = md + m for i in w: iw -= iw/i if iw >= m: best = md right = md -1 else: left = md + 1 left = 0 right = 10**6 ans = best while left <= right: md = (left + right)//2 iw = (md/10**6) + m + best -1 for i in w: iw -= iw/i if iw >= m: ans = (md/10**6) + best -1 right = md-1 else: left = md+1 print(min(best,ans)) ```
instruction
0
87,539
3
175,078
No
output
1
87,539
3
175,079
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n - 2 intermediate planets. Formally: we number all the planets from 1 to n. 1 is Earth, n is Mars. Natasha will make exactly n flights: 1 β†’ 2 β†’ … n β†’ 1. Flight from x to y consists of two phases: take-off from planet x and landing to planet y. This way, the overall itinerary of the trip will be: the 1-st planet β†’ take-off from the 1-st planet β†’ landing to the 2-nd planet β†’ 2-nd planet β†’ take-off from the 2-nd planet β†’ … β†’ landing to the n-th planet β†’ the n-th planet β†’ take-off from the n-th planet β†’ landing to the 1-st planet β†’ the 1-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is m tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 1 ton of fuel can lift off a_i tons of rocket from the i-th planet or to land b_i tons of rocket onto the i-th planet. For example, if the weight of rocket is 9 tons, weight of fuel is 3 tons and take-off coefficient is 8 (a_i = 8), then 1.5 tons of fuel will be burnt (since 1.5 β‹… 8 = 9 + 3). The new weight of fuel after take-off will be 1.5 tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” number of planets. The second line contains the only integer m (1 ≀ m ≀ 1000) β€” weight of the payload. The third line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 1000), where a_i is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains n integers b_1, b_2, …, b_n (1 ≀ b_i ≀ 1000), where b_i is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. Output If Natasha can fly to Mars through (n - 2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number -1. It is guaranteed, that if Natasha can make a flight, then it takes no more than 10^9 tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, let your answer be p, and the jury's answer be q. Your answer is considered correct if \frac{|p - q|}{max{(1, |q|)}} ≀ 10^{-6}. Examples Input 2 12 11 8 7 5 Output 10.0000000000 Input 3 1 1 4 1 2 5 3 Output -1 Input 6 2 4 6 3 3 5 6 2 6 3 6 5 3 Output 85.4800000000 Note Let's consider the first example. Initially, the mass of a rocket with fuel is 22 tons. * At take-off from Earth one ton of fuel can lift off 11 tons of cargo, so to lift off 22 tons you need to burn 2 tons of fuel. Remaining weight of the rocket with fuel is 20 tons. * During landing on Mars, one ton of fuel can land 5 tons of cargo, so for landing 20 tons you will need to burn 4 tons of fuel. There will be 16 tons of the rocket with fuel remaining. * While taking off from Mars, one ton of fuel can raise 8 tons of cargo, so to lift off 16 tons you will need to burn 2 tons of fuel. There will be 14 tons of rocket with fuel after that. * During landing on Earth, one ton of fuel can land 7 tons of cargo, so for landing 14 tons you will need to burn 2 tons of fuel. Remaining weight is 12 tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth. Submitted Solution: ``` N,M=int(input()),int(input()) u,d=[*map(int,input().split())],[*map(int,input().split())] if d[0] == 1: print(-1) exit(0) need = M / (d[0] - 1) if need <= 0 or need > 10**9: print(-1) exit(0) for i in range(N - 1, 0, -1): if u[i] == 1: print(-1) exit(0) need = (M+need*u[i])/(u[i]-1) if need <= 0 or need > 10**9: print(-1) exit(0) if d[i] == 1: print(-1) exit(0) need = (M+need*d[i])/(d[i]-1) if need <= 0 or need > 10**9: print(-1) exit(0) if u[0] == 1: print(-1) exit(0) need = (M+need*u[0])/(u[0]-1) if need <= 0 or need > 10**9: print(-1) exit(0) print('%.15f' % need) ```
instruction
0
87,540
3
175,080
No
output
1
87,540
3
175,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` # Made By Mostafa_Khaled bot = True input() s = input() c1 = s.count('x') c2 = s.count('X') s = s.replace('x', 'X', max(0, (c1-c2)//2)) s = s.replace('X', 'x', max(0, (c2-c1)//2)) print(abs(c2-c1)//2) print(s) # Made By Mostafa_Khaled ```
instruction
0
87,924
3
175,848
Yes
output
1
87,924
3
175,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` n = int(input()) s = input() numX = s.count("X"); if numX < n // 2: print(n // 2 - numX) print(str.replace(s, "x", "X", n // 2 - numX)) else: print(numX - n // 2) print(str.replace(s, "X", "x", numX - n // 2)) ```
instruction
0
87,925
3
175,850
Yes
output
1
87,925
3
175,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` n = int(input()) line = list(input()) x = line.count('x') X = line.count('X') res = max(x, X) - n//2 if x < n//2: for i in range(n): if line[i] == 'X': line[i] = 'x' x+=1 if x==n//2: break elif x>n//2: for i in range(n): if line[i]=='x': line[i] = 'X' X+=1 if n//2==X: break print(res) print(''.join(line)) ```
instruction
0
87,926
3
175,852
Yes
output
1
87,926
3
175,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` n = int(input()) ls = input() val = abs(ls.count('X')-ls.count('x'))/2 print(int(val)) if val!=0: ch = 'X' if ls.count('X')<ls.count('x') else 'x' nstr = '' for i in ls: if val>0: if i!=ch: nstr+=ch val-=1 else: nstr+=ch else: nstr+=i print(nstr) else: print(ls) ```
instruction
0
87,927
3
175,854
Yes
output
1
87,927
3
175,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return list(s[:len(s) - 1]) def invr(): return (map(int, input().split())) n = inp() s = insr() i = 0 j = 0 for a in range(len(s)): if s[a] == 'x': i = i+1 elif s[a] == 'X': j = j+1 if i == j: print(0) elif i > j: n = n - 2*j print(int(n/2)) elif j > i: n = n - 2*i print(int(n/2)) ```
instruction
0
87,928
3
175,856
No
output
1
87,928
3
175,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` # Codeforces A. Squats # Created by Abdulrahman Elsayed on 13/01/2021 n = int(input()) pos1 = list(input()) down = 0 up = 0 for c in pos1: if c == 'x': down +=1 else: up +=1 t = 1 i = 0 if (up > down): r = up - down - 1 print(r) while(t): if (pos1[i] == 'X'): pos1[i] = 'x' r -= 1 i += 1 if (r == 0): t = 0 elif (up < down): r = down - up - 1 print(r) while(t): if (pos1[i] == 'x'): pos1[i] = 'X' r -= 1 i += 1 if (r == 0): t = 0 else: print(0) pos2 = str() for c in pos1: pos2 += c print(pos2) ```
instruction
0
87,929
3
175,858
No
output
1
87,929
3
175,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` #! /usr/bin/env python n = int(input()) s = list(input()) cnt = s.count('x') ans = cnt - n // 2; if ans > 0: tmp = ans; for i, x in enumerate(s): if x == 'x': s[i] = 'X' tmp -= 1 if tmp == 0: break elif ans < 0: tmp = -ans; for i, x in enumerate(s): if x == 'X': s[i] = 'x' tmp -= 1 if tmp == 0: break print(ans) print(''.join(s)) ```
instruction
0
87,930
3
175,860
No
output
1
87,930
3
175,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input The first line contains integer n (2 ≀ n ≀ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. Output In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Examples Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx Submitted Solution: ``` n = int(input("")) hams = input() x = [0 if char == "x" else 1 for char in hams] counter = 0 sit = x.count(0) stand = x.count(1) diff = abs(sit-stand) if diff == 0: print(0, hams, sep='\n') else: for i in range(n): if stand == sit: break if x[i] == 0 and stand <= diff//2: counter += 1 x[i] = 1 sit -= 1 stand += 1 elif x[i] == 1 and stand >= diff//2: counter += 1 x[i] = 0 sit += 1 stand -= 1 print(counter, "x"*sit+"X"*stand, sep='\n') ```
instruction
0
87,931
3
175,862
No
output
1
87,931
3
175,863