message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2Β·x + 1 ≀ n) and take a coin from each chest with numbers x, 2Β·x, 2Β·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≀ ai ≀ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer β€” the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest. Submitted Solution: ``` n=int(input()) if n==1: print(-1) exit(0) a=list(map(int,input().split(' '))) a=[0]+a # print(a) ans=0 for i in range(1,n+1): if 2*i+1>n: continue if a[i]==0 or a[2*i]==0 or a[2*i+1]==0 : continue mina=min([a[i],a[2*i],a[2*i+1]]) a[i],a[2*i],a[2*i+1]=a[i]-mina,a[2*i]-mina,a[2*i+1]-mina ans+=mina # print(a) for i in range(1,n+1): if 2*i+1>n: continue if a[i]>0 and a[2*i]>0: mina=min([a[i],a[2*i]]) ans+=mina a[i],a[2*i]=a[i]-mina,a[2*i]-mina elif a[2*i+1]>0 and a[2*i]>0: mina=min([a[2*i+1],a[2*i]]) ans+=mina a[2*i+1],a[2*i]=a[2*i+1]-mina,a[2*i]-mina elif a[2*i+1]>0 and a[i]>0: mina=min([a[2*i+1],a[i]]) ans+=mina a[2*i+1],a[i]=a[2*i+1]-mina,a[i]-mina for i in range(1,n+1): if 2*i+1>n: continue if a[i]>0: ans+=a[i] a[i]=0 elif a[2*i]>0: ans+=a[2*i] a[2*i]=0 elif a[2*i+1]>0: ans+=a[2*i+1] a[2*i+1]=0 for i in range(1,n+1): if a[i]>0: print(-1) exit(0) print(ans) ```
instruction
0
92,957
24
185,914
No
output
1
92,957
24
185,915
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2Β·x + 1 ≀ n) and take a coin from each chest with numbers x, 2Β·x, 2Β·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≀ ai ≀ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer β€” the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest. Submitted Solution: ``` import math a = [] a_sum = 0 n = int(input()) a = [0]+[int(i) for i in input().split()] def rex(k): global a_sum for i in range(k,2*k-1): if i%2 == 0: if a[i] >= a[i+1]: a_sum += a[i] a[i//2] = a[i//2] - a[i] else: a_sum += a[i+1] a[i//2] = a[i//2] - a[i+1] a[i] = 0 a[i+1] = 0 i +=1 # if __name__ == '__main__': if n%2 ==0 or n==1: print(-1) exit() else: rec = int(math.log(n) / math.log(2)) +1 x = (n-1)//2 for i in range(rec): rex(x+1) if x>2: if x%2 ==1: x = (x-1)//2 else: max = a[1] if a[2] > a[1]: max = a[2] if a[3] > max: max = a[3] a_sum = a_sum+max print(a_sum) exit() ```
instruction
0
92,958
24
185,916
No
output
1
92,958
24
185,917
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,580
24
187,160
Tags: implementation, math Correct Solution: ``` n, m = map(int, input().split()) if m % n != 0: print(-1) else: x = m / n two = 0 three = 0 while (x % 2 == 0): two += 1 x = x // 2 while (x % 3 == 0): three += 1 x = x // 3 if x != 1: print(-1) else: print(two + three) ```
output
1
93,580
24
187,161
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,581
24
187,162
Tags: implementation, math Correct Solution: ``` import math x, y = map(int, input().split()) v, c = y / x, 0 while v % 3 == 0: v /= 3 c += 1 while v % 2 == 0: v /= 2 c += 1 if v > 1: print(-1) else: print(c) ```
output
1
93,581
24
187,163
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,582
24
187,164
Tags: implementation, math Correct Solution: ``` n,m=map(int,input().split()) if(m%n): print(-1) exit() ans=0 m=m//n while(m>1): if(m%3==0): ans+=1 m=m//3 if(m%2==0): ans+=1 m=m//2 if(m>1 and m%2 and m%3): print(-1) exit() print(ans) ```
output
1
93,582
24
187,165
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,583
24
187,166
Tags: implementation, math Correct Solution: ``` n, m = map(int, input().split()) if m % n: print(-1) exit(0) m //= n a = 0 while m % 2 == 0: m//=2 a+=1 while m % 3 == 0: m//=3 a+=1 if m==1: print(a) else: print(-1) ```
output
1
93,583
24
187,167
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,584
24
187,168
Tags: implementation, math Correct Solution: ``` n,m = list(map(int,input().split())) if m%n == 0: d = m//n if d > 1: count = 0 while d%2 == 0: count += 1 d = d//2 while d%3 == 0: count += 1 d = d//3 if d == 1: print(count) else: print(-1) else: print(0) else: print(-1) ```
output
1
93,584
24
187,169
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,585
24
187,170
Tags: implementation, math Correct Solution: ``` a,b=map(int,input().split()) i=0 if b%a==0: b=b//a while b!=1: if b%2==0: b=b//2 i=i+1 elif b%3==0: b=b//3 i=i+1 elif b%2!=0 and b%3!=0 and b>1: b=1 i=-1 elif b<1: b=1 i=-1 print(i) else: print(-1) ```
output
1
93,585
24
187,171
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,586
24
187,172
Tags: implementation, math Correct Solution: ``` n, m = map(int, input().split()) if m % n: print(-1) else: m //= n k = 0 for d in (2,3): while m % d == 0: m //= d k += 1 print(k if m < 2 else -1) ```
output
1
93,586
24
187,173
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72.
instruction
0
93,587
24
187,174
Tags: implementation, math Correct Solution: ``` x,y=map(int,input().split()) s=0 if y/x==1: print(0) elif int(y/x)!=y/x: print(-1) else: d=y/x while d!=1: if int(d/2)!=d/2 and int(d/3)!=d/3: print(-1) exit() for i in [2,3]: if int(d/i)!=d/i: d=d else: d=d/i s=s+1 print(s) ```
output
1
93,587
24
187,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` # print("Input n and m") n,m = [int(x) for x in input().split()] if m%n != 0: print(-1) else: answer = 0 qu = m//n while qu%2==0: qu = qu // 2 answer += 1 while qu%3==0: qu = qu // 3 answer += 1 if qu == 1: print(str(answer)) else: print(-1) ```
instruction
0
93,588
24
187,176
Yes
output
1
93,588
24
187,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` x,y=map(int,input().split()) k=-1 if y%x==0: k=0 p=y/x while p%2==0: p/=2 k+=1 while p%3==0: p/=3 k+=1 if p!=1:k=-1 print(k) ```
instruction
0
93,589
24
187,178
Yes
output
1
93,589
24
187,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` n,m=map(int,input().split()) r=-1 if m%n==0: m//=n;r=0 for d in 2,3: while m%d==0:m//=d;r+=1 if m>1:r=-1 print(r) ```
instruction
0
93,590
24
187,180
Yes
output
1
93,590
24
187,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` n, m = map(int, input().split()) if m % n: print(-1) else: d = m // n c = 0 while d % 2 == 0: d //= 2 c += 1 while d % 3 == 0: d //= 3 c += 1 if d == 1: print(c) else: print(-1) ```
instruction
0
93,591
24
187,182
Yes
output
1
93,591
24
187,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` n,m=map(int,input().split()) p=m/n sum1=0 if m%n!=0: print(-1) else: while(p%2==0): p/=2 sum1+=1 while(p%3==0): p/=3 sum1+=1 print(sum1) ```
instruction
0
93,592
24
187,184
No
output
1
93,592
24
187,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` n,m=map(int,input().split()) count =0 if not((m//n)%2 == 0 or (m//n)%3==0 or m==n): print(-1) else: if (m//n)%2 == 0 or (m//n)%3==0 or m==n: while m>n : if (m//n)%2 == 0 or (m//n)%3==0 or m==n: if m%2 == 0 and m!=n: m/=2 count +=1 if m%3 == 0 and m!=n: m/=3 count +=1 print(int(count)) ```
instruction
0
93,593
24
187,186
No
output
1
93,593
24
187,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` import math def primeFactors(n): c=[] # Print the number of two's that divide n while n % 2 == 0: c.append(2) n = n // 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3,int(math.sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: c.append(i) n = n // i # Condition if n is a prime # number greater than 2 if n > 2: c.append(n) return c n,m = map(int,input().split()) k = m//n l = m%n if(l!=0 or (k%3!=0 and k%2!=0)): if(n==m): print(0) else: print(-1) else: print(len(primeFactors(k))) ```
instruction
0
93,594
24
187,188
No
output
1
93,594
24
187,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). Input The only line of the input contains two integers n and m (1 ≀ n ≀ m ≀ 5β‹…10^8). Output Print the number of moves to transform n to m, or -1 if there is no solution. Examples Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 Note In the first example, the possible sequence of moves is: 120 β†’ 240 β†’ 720 β†’ 1440 β†’ 4320 β†’ 12960 β†’ 25920 β†’ 51840. The are 7 steps in total. In the second example, no moves are needed. Thus, the answer is 0. In the third example, it is impossible to transform 48 to 72. Submitted Solution: ``` a=input() b=[int(x)for x in a.split()] def func3(number, rezdel): for i in range(number): if ((2**i)*(3**(number-i)))==rezdel: return False return True def func (razdel): for i in range(razdel): if(3**i==razdel): return i def func2(razdel): for i in range(razdel): if(2**i==razdel): return i count=1 if b[1]%b[0]==0: if(b[1]==b[0]): print(0) if(b[1]/b[0])%6==0: while(func3(count,(int(b[1]/b[0])))): count+=1 print(count) elif(b[1]/b[0])%3==0: print(func(int(b[1]/b[0]))) elif (b[1]/b[0])%2==0: print(str(func2(int(b[1]/b[0])))) else: print(-1) ```
instruction
0
93,595
24
187,190
No
output
1
93,595
24
187,191
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,763
24
187,526
Tags: *special, greedy, implementation Correct Solution: ``` num = int(input()) i=0 total=0 k=0 k1=0 k2=0 k3=0 k4=0 arr=[] arr = input().split() for i in range(len(arr)): arr[i]= int(arr[i]) for nmb in arr: nmb= int(nmb) if nmb==4: k4+=1 elif nmb==3: k3+=1 elif nmb==2: k2+=1 elif nmb==1: k1+=1 if k2==0 and k1==0: total=int(k4+k3) elif k1!=0 and k2==0: if k3>=k1: total=k3+k4 else: if k1%4==0: total=k4+k3+((k1-k3)/4) else: total=k4+k3+((k1-k3)/4)+1 elif k1!=0 and k2!=0: if k3>k1: t2=(k2*2) if t2%4==0: total=int(t2/4)+k4+k1+(k3-k1) else: total=int(t2/4)+1+k4+k1+(k3-k1) else: t2=k4*4+k3*3+k2*2+k1 if t2%4==0: total=int(t2/4) else: total=int(t2/4)+1 elif k1==0: if (k2*2)%4==0: total=int(k4+k3+(k2*2/4)) else: total=k4+k3+(int(k2*2/4)+1) print(int(total)) ```
output
1
93,763
24
187,527
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,764
24
187,528
Tags: *special, greedy, implementation Correct Solution: ``` n = int(input()) s = list(map(int, input().split())) cabs = 0 one = s.count(1) two = s.count(2) three = s.count(3) four = s.count(4) cabs += two // 2 + three + four one -= three if two % 2 == 1: cabs += 1 one -= 2 if one > 0: cabs += (one + 3) // 4 print(cabs) ```
output
1
93,764
24
187,529
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,765
24
187,530
Tags: *special, greedy, implementation Correct Solution: ``` n=int(input()) taxi=n1=n2=n3=n4=0 x=[] for i in range(0,n): x.append('0') x=input().split() for i in range(0,n): if(x[i]=='1'): n1+=1 elif(x[i]=='2'): n2+=1 elif(x[i]=='3'): n3+=1 else: n4+=1 taxi+=n4 if(n3>n1 or n3==n1): taxi+=n3 n1=0 else: taxi+=n3 n1=n1-n3 taxi+=n2//2 n2=n2%2 if(n2==1): taxi+=1 if(n1>2): n1-=2 else: n1=0 taxi+=(n1//4) if(n1%4!=0 and n1!=0): taxi+=1 print(taxi) ```
output
1
93,765
24
187,531
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,766
24
187,532
Tags: *special, greedy, implementation Correct Solution: ``` n = int(input()) l = list(map(int, input().split())) f = 0 th = 0 tw = 0 o = 0 for i in range(len(l)): #print (l[i]) if l[i] == 1: o += 1 elif l[i] == 2: tw += 1 elif l[i] == 3: th += 1 elif l[i] == 4: f += 1 #print (f, th, tw, o) ans = f #print(ans) ans += th #print(ans) o = max(0, o - th) ans += tw // 2 #print(ans) if (tw % 2): ans += 1 if (tw % 2) and o: o = max(0, o - 2) ans += o // 4 #print(ans) if o % 4: ans += 1 print(ans) ```
output
1
93,766
24
187,533
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,767
24
187,534
Tags: *special, greedy, implementation Correct Solution: ``` n = input() t = list(map(int,input().split())) a,b,c,d = [t.count(x+1) for x in range(4)] print(d+c--b//2--max(0,a-c-b%2*2)//4) ```
output
1
93,767
24
187,535
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,768
24
187,536
Tags: *special, greedy, implementation Correct Solution: ``` import math cars = 0 n = int(input()) s = [int(i) for i in input().split()] groups = [0,0,0,0] for i in s: groups[i-1] += 1 cars += groups[3] if groups[2] >= groups[0]: cars += groups[0] groups[2] -= groups[0] groups[0] = 0 else: cars += groups[2] groups[0] -= groups[2] groups[2] = 0 cars += groups[1]//2 groups[1] -= groups[1]//2*2 cars += groups[2] if groups[1] == 1: cars += 1 if groups[0] >= 2: groups[0] -= 2 else: groups[0] = 0 cars += int(math.ceil(groups[0]/4)) print(cars) ```
output
1
93,768
24
187,537
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,769
24
187,538
Tags: *special, greedy, implementation Correct Solution: ``` # Solution found online input() arr = [0, 0, 0, 0, 0] for i in input().split(): arr[int(i)] += 1 total = arr[4] + arr[3] + arr[2] // 2 arr[1] -= arr[3] if arr[2] % 2 == 1: total += 1 arr[1] -= 2 if arr[1] > 0: total += (arr[1] + 3) // 4 print(total) # MY ORIGINAL SOLUTION BELOW # Interestingly enough both solutions are the same runtime # obv the above solution is hella cleaner though # input() # arr = [int(i) for i in input().split()] # k = [0, 0, 0, 0, 0] # for i in arr: # k[i] += 1 # t = 0 # t += k[4] # k[4] = 0 # ot = min(k[1], k[3]) # t += ot # k[1] -= ot # k[3] -= ot # twos = k[2] // 2 # t += twos # k[2] -= twos * 2 # k[2] %= 2 # if k[2] == 1: # if k[1] > 0: # t += 1 # k[2] = 0 # k[1] -= min(k[1], 2) # else: # t += 1 # k[2] = 0 # for i in range(4, 0, -1): # num = k[1] // i # t += num # k[1] -= num * i # t += k[3] # print(t) ```
output
1
93,769
24
187,539
Provide tags and a correct Python 3 solution for this coding contest problem. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
instruction
0
93,770
24
187,540
Tags: *special, greedy, implementation Correct Solution: ``` # fails only in 3 3 2 it give 2 but answer is 3 # import math # n=int(input()) # pas=list(map(int,input().split()[:n])) # sums = 0 # for i in range(0,len(pas)): # sums=sums+pas[i] # if(n == 3): # if(pas[0] == 3 and pas[1] == 3 and pas[2]==2): # print('3') # else: # print(math.ceil(sums/4)) # else: # print(math.ceil(sums/4)) # special Implementation input() a,b,c,d=map(input().count,('1','2','3','4')) print(d+c+(b*2+max(0,a-c)+3)//4) ```
output
1
93,770
24
187,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` import collections n = int(input()) a = list(map(int,input().split())) k = collections.Counter(a) r = 0 r+= k[4] temp = k[2] // 2 r+= temp k[2] -= temp*2 k[4] = 0 if k[3]<k[1]: r += k[3] k[1] -= k[3] k[3]-=k[3] else: r += k[1] k[3] -= k[1] k[1] -= k[1] r += k[3] k[3] = 0 if k[1]>=1 and k[2] == 1: r+= 1 k[1] -= 2 k[2] -= 1 if k[2] == 1: r += 1 k[2] = 0 while k[1]>0: r+=1 k[1]-=4 print(r) ```
instruction
0
93,771
24
187,542
Yes
output
1
93,771
24
187,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split(" "))) c1=0 c2=0 c3=0 c4=0 for i in range(0,n): if a[i]==1: c1+=1 elif a[i]==2: c2+=1 elif a[i]==3: c3+=1 elif a[i]==4: c4+=1 count=c4+c3 c1=c1-c3 count=count+(c2//2) if(c2%2>0) : count=count+1 c1=c1-2 if(c1>0) : count=count+(c1//4) if(c1%4>0) : count=count+1 print(count) ```
instruction
0
93,772
24
187,544
Yes
output
1
93,772
24
187,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` arr=[] for i in range(0,5): arr.append(0) n=int(input()) a=list(map(int,input().split())) for i in range(0,n): arr[a[i]]+=1 con=0 con+=arr[4] con+=arr[3] if arr[1]>arr[3]: if arr[2]!=0: if arr[2]%2==0: con+=arr[2]//2 arr[1]=arr[1]-arr[3] if arr[1]%4==0: con+=arr[1]//4 else: con+=(arr[1]//4)+1 else: arr[1] = arr[1]-arr[3] con+=(arr[2]//2)+1 if arr[1]>2: arr[1]-=2 if arr[1]%4==0: con+=arr[1]//4 else: con += (arr[1]//4)+1 else: arr[1] = arr[1] - arr[3] if arr[1] % 4 == 0: con += arr[1] // 4 else: con += (arr[1] //4) + 1 elif arr[1]<=arr[3]: if arr[2]!=0: if arr[2]%2==0: con+=arr[2]//2 else: con+=(arr[2]//2)+1 print(con) ```
instruction
0
93,773
24
187,546
Yes
output
1
93,773
24
187,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` n=int(input()) s=input() o=0 tw=0 t=0 f=0 for i in s: if i=="4": f+=1 elif i=="3": t+=1 elif i=="2": tw+=1 elif i=="1": o+=1 if o-t<=0: l=f+t+tw//2+tw%2 elif o-t<=2 and tw%2!=0: l=f+t+tw//2+tw%2 elif o-t<=4 and tw%2==0: l=f+t+tw//2+1 elif (o-t-(tw%2)*2)%4==0: l=f+t+tw//2+(o-t-(tw%2)*2)//4+tw%2 else: l=f+t+tw//2+(o-t-(tw%2)*2)//4+tw%2+1 print(l) ```
instruction
0
93,774
24
187,548
Yes
output
1
93,774
24
187,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` n =int(input()) x = list(map(int, input().split())) i = 1 r = 0 while i < n+1: r += x[i-1] i += 1 k = (r + 3) // 4 if (n<4)and(k!=n)and(r<=4*k): k = n print(k) ```
instruction
0
93,775
24
187,550
No
output
1
93,775
24
187,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` n = int(input()) s = input() l = s.split(" ") l.sort(reverse=True) for i in range(0, len(l)): l[i] = int(l[i]) c = 0 for x in range(n): if l[x] == 4: c += 1 l[x] = 0 elif l[x] != 0: for y in range(x + 1, n): if l[x] + l[y] == 4 and l[y] != 0: c += 1 l[x] = 0 l[y] = 0 for x in l: if x != 0: c += 1 print(c) ```
instruction
0
93,776
24
187,552
No
output
1
93,776
24
187,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` n = int(input()) arr = list(map(int, input().split())) if sum(arr) >= 4: s = sum(arr) // 4 l = sum(arr) % 4 if l == 0: print(l + s) else: print(s + 1) else: print(1) ```
instruction
0
93,777
24
187,554
No
output
1
93,777
24
187,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: * the third group (consisting of four children), * the fourth group (consisting of three children), * the fifth group (consisting of three children), * the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. Submitted Solution: ``` t = int(input()) a = list(map(int,input().split())) c1 = 0 c2 = 0 c3 = 0 c4 = 0 for i in range(t) : if a[i] == 4 : c4 += 1 if a[i] == 3 : c3 += 1 if a[i] == 2 : c2 += 1 if a[i] == 1 : c1 += 1 ans = c4 + c3 if c2%2 == 0: ans += c2//2 if c2%2 == 1 and c3>=c1: co2 = (c2-1)//2 ans = ans + co2 + 1 elif c3 < c1 : co1 = c1-c3 if co1%4==0: ans += (co1//4) else : ans += (co1//4) + 1 ## if co1%4==0: ## ans += (co1//4) ## elif co1%4==1 : ## ans += (co1+1)//4 ## elif co1%4==2 : ## ans += (co1+2)//4 ## else : ## ans += (co1+3)//4 print(ans) ```
instruction
0
93,778
24
187,556
No
output
1
93,778
24
187,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017. Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes. Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages: * download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package; * download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package. Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds. Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages. Input The first line contains three integer numbers f, T and t0 (1 ≀ f, T, t0 ≀ 107) β€” size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff. The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 ≀ a1, t1, p1 ≀ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles). The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 ≀ a2, t2, p2 ≀ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles). Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Output Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1. Examples Input 120 964 20 26 8 8 13 10 4 Output 40 Input 10 200 20 1 1 1 2 2 3 Output 0 Input 8 81 11 4 10 16 3 10 12 Output 28 Input 8 79 11 4 10 16 3 10 12 Output -1 Note In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26Β·5 = 130 bytes) in 120Β·8 = 960 milliseconds (960 ≀ 964). He spends 8Β·5 = 40 burles on it. In the second example Polycarp has enough time to download 10 bytes. It takes 10Β·20 = 200 milliseconds which equals to upper constraint on download time. In the third example Polycarp has to buy one first additional package and one second additional package. In the fourth example Polycarp has no way to download the file on time. Submitted Solution: ``` f = 0 T = 0 t0 = 0 a1 = 0 t1 = 0 p1 = 0 a2 = 0 t2 = 0 p2 = 0 R = 0 def func(leftt, leftb, mid): global f, T, t0, a1, t1, p1, a2, t2, p2, R ft = 0 if (mid == R): ft += (mid - 1) * a2; keks = (leftt - (mid - 1) * a2 * t2) // t2 ft += keks; else: ft += (leftt - mid * a2 * t2) // t0 ft += mid * a2 return ft >= leftb def keks(cnt): global f, T, t0, a1, t1, p1, a2, t2, p2, R ks = cnt * a1 if (ks * t1 >= T): g = (cnt - 1) * a1 + (T - (cnt - 1) * t1 * a1) // t1 if (g >= f): return cnt * p1 return 1e18 if (ks >= f): return cnt * p1 leftt = T - ks * t1 leftb = f - ks if (t2 < t0): r = (leftt) // (a2 * t2) + 1 R = r diff = leftb * t0 - leftt sf = t0 - t2 keks = (diff * t2 + sf - 1) // sf if (keks % a2 != 0): keks+= a2 - keks % a2 keks //= a2 keks //= t2 ans = 1e18 for i in range(keks - 1, keks + 1): l = i if (l >= 0 and l <= r): if (func(leftt, leftb, l)): ans = min(ans, cnt * p1 + l * p2) return ans; else: if (func(leftt, leftb, 0)): return cnt * p return 1e18; def main(): global f, T, t0, a1, t1, p1, a2, t2, p2, R f, T, t0 = map(int, input().split()) a1, t1, p1 = map(int, input().split()) a2, t2, p2 = map(int, input().split()) ans = 1e18; if (t0 * f <= T): ans = 0; print(ans) return ll = 0; rr = T // (t1 * a1) + 1 for g in range(ll, rr + 1): ans = min(ans, keks(g)) if (ans > 9e17): print(-1) return print(ans) main() ```
instruction
0
94,098
24
188,196
No
output
1
94,098
24
188,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017. Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes. Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages: * download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package; * download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package. Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds. Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages. Input The first line contains three integer numbers f, T and t0 (1 ≀ f, T, t0 ≀ 107) β€” size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff. The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 ≀ a1, t1, p1 ≀ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles). The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 ≀ a2, t2, p2 ≀ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles). Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Output Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1. Examples Input 120 964 20 26 8 8 13 10 4 Output 40 Input 10 200 20 1 1 1 2 2 3 Output 0 Input 8 81 11 4 10 16 3 10 12 Output 28 Input 8 79 11 4 10 16 3 10 12 Output -1 Note In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26Β·5 = 130 bytes) in 120Β·8 = 960 milliseconds (960 ≀ 964). He spends 8Β·5 = 40 burles on it. In the second example Polycarp has enough time to download 10 bytes. It takes 10Β·20 = 200 milliseconds which equals to upper constraint on download time. In the third example Polycarp has to buy one first additional package and one second additional package. In the fourth example Polycarp has no way to download the file on time. Submitted Solution: ``` print("0") ```
instruction
0
94,099
24
188,198
No
output
1
94,099
24
188,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017. Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes. Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages: * download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package; * download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package. Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds. Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages. Input The first line contains three integer numbers f, T and t0 (1 ≀ f, T, t0 ≀ 107) β€” size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff. The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 ≀ a1, t1, p1 ≀ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles). The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 ≀ a2, t2, p2 ≀ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles). Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Output Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1. Examples Input 120 964 20 26 8 8 13 10 4 Output 40 Input 10 200 20 1 1 1 2 2 3 Output 0 Input 8 81 11 4 10 16 3 10 12 Output 28 Input 8 79 11 4 10 16 3 10 12 Output -1 Note In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26Β·5 = 130 bytes) in 120Β·8 = 960 milliseconds (960 ≀ 964). He spends 8Β·5 = 40 burles on it. In the second example Polycarp has enough time to download 10 bytes. It takes 10Β·20 = 200 milliseconds which equals to upper constraint on download time. In the third example Polycarp has to buy one first additional package and one second additional package. In the fourth example Polycarp has no way to download the file on time. Submitted Solution: ``` f = 0 T = 0 t0 = 0 a1 = 0 t1 = 0 p1 = 0 a2 = 0 t2 = 0 p2 = 0 R = 0 def func(leftt, leftb, mid): global f, T, t0, a1, t1, p1, a2, t2, p2, R ft = 0 if (mid == R): ft += (mid - 1) * a2; keks = (leftt - (mid - 1) * a2 * t2) // t2 ft += keks; else: ft += (leftt - mid * a2 * t2) // t0 ft += mid * a2 return ft >= leftb def keks(cnt): global f, T, t0, a1, t1, p1, a2, t2, p2, R ks = cnt * a1 if (ks * t1 >= T): g = (cnt - 1) * a1 + (T - (cnt - 1) * t1 * a1) // t1 if (g >= f): return cnt * p1 return 1e18 if (ks >= f): return cnt * p1 leftt = T - ks * t1 leftb = f - ks if (t2 < t0): r = (leftt) // (a2 * t2) + 1 R = r diff = leftb * t0 - leftt sf = t0 - t2 keks = (diff * t2 + sf - 1) // sf if (keks % a2 != 0): keks+= a2 - keks % a2 keks //= a2 keks //= t2 ans = 1e18 for i in range(keks, keks + 1): l = i if (l >= 0 and l <= r): if (func(leftt, leftb, l)): ans = min(ans, cnt * p1 + l * p2) if (func(leftt, leftb, 0)): ans = min(ans, cnt * p1) return ans; else: if (func(leftt, leftb, 0)): return cnt * p return 1e18; def main(): global f, T, t0, a1, t1, p1, a2, t2, p2, R f, T, t0 = map(int, input().split()) a1, t1, p1 = map(int, input().split()) a2, t2, p2 = map(int, input().split()) ans = 1e18; if (t0 * f <= T): ans = 0; print(ans) return ll = 0; rr = T // (t1 * a1) + 1 for g in range(ll, rr + 1): ans = min(ans, keks(g)) if (ans > 9e17): print(-1) return print(ans) main() ```
instruction
0
94,100
24
188,200
No
output
1
94,100
24
188,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017. Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes. Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages: * download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package; * download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package. Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds. Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages. Input The first line contains three integer numbers f, T and t0 (1 ≀ f, T, t0 ≀ 107) β€” size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff. The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 ≀ a1, t1, p1 ≀ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles). The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 ≀ a2, t2, p2 ≀ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles). Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. Output Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1. Examples Input 120 964 20 26 8 8 13 10 4 Output 40 Input 10 200 20 1 1 1 2 2 3 Output 0 Input 8 81 11 4 10 16 3 10 12 Output 28 Input 8 79 11 4 10 16 3 10 12 Output -1 Note In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26Β·5 = 130 bytes) in 120Β·8 = 960 milliseconds (960 ≀ 964). He spends 8Β·5 = 40 burles on it. In the second example Polycarp has enough time to download 10 bytes. It takes 10Β·20 = 200 milliseconds which equals to upper constraint on download time. In the third example Polycarp has to buy one first additional package and one second additional package. In the fourth example Polycarp has no way to download the file on time. Submitted Solution: ``` f = 0 T = 0 t0 = 0 a1 = 0 t1 = 0 p1 = 0 a2 = 0 t2 = 0 p2 = 0 R = 0 def func(leftt, leftb, mid): global f, T, t0, a1, t1, p1, a2, t2, p2, R ft = 0 if (mid == R): ft += (mid - 1) * a2; keks = (leftt - (mid - 1) * a2 * t2) // t2 ft += keks; else: ft += (leftt - mid * a2 * t2) // t0 ft += mid * a2 return ft >= leftb def keks(cnt): global f, T, t0, a1, t1, p1, a2, t2, p2, R ks = cnt * a1 if (ks * t1 >= T): g = (cnt - 1) * a1 + (T - (cnt - 1) * t1 * a1) // t1 if (g >= f): return cnt * p1 return 1e18 if (ks >= f): return cnt * p1 leftt = T - ks * t1 leftb = f - ks if (t2 < t0): r = (leftt) // (a2 * t2) + 1 R = r diff = leftb * t0 - leftt sf = t0 - t2 keks = (diff * t2 + sf - 1) // sf if (keks % a2 != 0): keks+= a2 - keks % a2 keks //= a2 keks //= t2 ans = 1e18 for i in range(keks - 1, keks + 2): l = i if (l >= 0 and l <= r): if (func(leftt, leftb, l)): ans = min(ans, cnt * p1 + l * p2) l = r; if (func(leftt, leftb, l)): ans = min(ans, cnt * p1 + l * p2) return ans; else: if (func(leftt, leftb, 0)): return cnt * p return 1e18; def main(): global f, T, t0, a1, t1, p1, a2, t2, p2, R f, T, t0 = map(int, input().split()) a1, t1, p1 = map(int, input().split()) a2, t2, p2 = map(int, input().split()) ans = 1e18; if (t0 * f <= T): ans = 0; print(ans) return ll = 0; rr = T // (t1 * a1) + 1 for g in range(ll, rr + 1): ans = min(ans, keks(g)) if (ans > 9e17): print(-1) return print(ans) main() ```
instruction
0
94,101
24
188,202
No
output
1
94,101
24
188,203
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people. But wait, something is still known, because that day a record was achieved β€” M simultaneous users online! In addition, Polycarpus believes that if a user made a request at second s, then he was online for T seconds after that, that is, at seconds s, s + 1, s + 2, ..., s + T - 1. So, the user's time online can be calculated as the union of time intervals of the form [s, s + T - 1] over all times s of requests from him. Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that: * the number of different users online did not exceed M at any moment, * at some second the number of distinct users online reached value M, * the total number of users (the number of distinct identifiers) was as much as possible. Help Polycarpus cope with the test. Input The first line contains three integers n, M and T (1 ≀ n, M ≀ 20 000, 1 ≀ T ≀ 86400) β€” the number of queries, the record number of online users and the time when the user was online after a query was sent. Next n lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [s, s + T - 1] are within one 24-hour range (from 00:00:00 to 23:59:59). Output In the first line print number R β€” the largest possible number of distinct users. The following n lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to R. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes). Examples Input 4 2 10 17:05:53 17:05:58 17:06:01 22:39:47 Output 3 1 2 2 3 Input 1 2 86400 00:00:00 Output No solution Note Consider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because M = 2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 β€” from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 β€” from 22:39:47 to 22:39:56. In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.)
instruction
0
94,800
24
189,600
Tags: greedy, two pointers Correct Solution: ``` def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() [a,b]=[[0]*20002,[0]*20002] if n<m: print("No solution") return for i in range(1,n+1): g = gets() a[i] = int(g[-1]) + int(g[1])*60 + int(g[0])*3600 [p,count,sim,ist] = [1,0,0,False] for i in range(1,n+1): while p<i and a[i] - t + 1>a[p]: p+=1 if b[p]!=b[p-1]: sim = max(sim-1,0) if a[i]<a[p]+t and sim<m: [count,sim] = [count+1,sim+1] if sim==m: ist=True b[i] = count if ist==False: print("No solution") return print(count) for i in range(1,n+1): print(b[i],end=' ') if mode=="file":f.close() if __name__=="__main__": main() ```
output
1
94,800
24
189,601
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people. But wait, something is still known, because that day a record was achieved β€” M simultaneous users online! In addition, Polycarpus believes that if a user made a request at second s, then he was online for T seconds after that, that is, at seconds s, s + 1, s + 2, ..., s + T - 1. So, the user's time online can be calculated as the union of time intervals of the form [s, s + T - 1] over all times s of requests from him. Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that: * the number of different users online did not exceed M at any moment, * at some second the number of distinct users online reached value M, * the total number of users (the number of distinct identifiers) was as much as possible. Help Polycarpus cope with the test. Input The first line contains three integers n, M and T (1 ≀ n, M ≀ 20 000, 1 ≀ T ≀ 86400) β€” the number of queries, the record number of online users and the time when the user was online after a query was sent. Next n lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [s, s + T - 1] are within one 24-hour range (from 00:00:00 to 23:59:59). Output In the first line print number R β€” the largest possible number of distinct users. The following n lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to R. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes). Examples Input 4 2 10 17:05:53 17:05:58 17:06:01 22:39:47 Output 3 1 2 2 3 Input 1 2 86400 00:00:00 Output No solution Note Consider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because M = 2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 β€” from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 β€” from 22:39:47 to 22:39:56. In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.)
instruction
0
94,801
24
189,602
Tags: greedy, two pointers Correct Solution: ``` def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() a=[0]*20002 b=[0]*20002 if n<m: print("No solution") return for i in range(1,1+n): g = gets() a[i] = int(g[-1]) + int(g[1])*60 + int(g[0])*3600 [p,count,sim] = [1,0,0] is_solution_there=False for i in range(1,n+1): while p<i and a[i] - t + 1>a[p]: p+=1 if b[p]!=b[p-1]: sim = max(sim-1,0) if a[i]<a[p]+t and sim<m: count+=1 sim+=1 if sim==m: is_solution_there=True b[i] = count if is_solution_there==False: print("No solution") return print(count) for i in range(1,n+1): print(b[i],end=' ') if mode=="file":f.close() if __name__=="__main__": main() ```
output
1
94,801
24
189,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people. But wait, something is still known, because that day a record was achieved β€” M simultaneous users online! In addition, Polycarpus believes that if a user made a request at second s, then he was online for T seconds after that, that is, at seconds s, s + 1, s + 2, ..., s + T - 1. So, the user's time online can be calculated as the union of time intervals of the form [s, s + T - 1] over all times s of requests from him. Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that: * the number of different users online did not exceed M at any moment, * at some second the number of distinct users online reached value M, * the total number of users (the number of distinct identifiers) was as much as possible. Help Polycarpus cope with the test. Input The first line contains three integers n, M and T (1 ≀ n, M ≀ 20 000, 1 ≀ T ≀ 86400) β€” the number of queries, the record number of online users and the time when the user was online after a query was sent. Next n lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [s, s + T - 1] are within one 24-hour range (from 00:00:00 to 23:59:59). Output In the first line print number R β€” the largest possible number of distinct users. The following n lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to R. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes). Examples Input 4 2 10 17:05:53 17:05:58 17:06:01 22:39:47 Output 3 1 2 2 3 Input 1 2 86400 00:00:00 Output No solution Note Consider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because M = 2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 β€” from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 β€” from 22:39:47 to 22:39:56. In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.) Submitted Solution: ``` def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() a=[0]*20002 b=[0]*20002 if n<m: print("No solution") return for i in range(n): g = gets() temp = int(g[-1]) + int(g[1])*60 + int(g[0])*3600 a[i] = temp [p,count,k,sim] = [0,0,0,0] for i in range(n): if a[p]<a[i] + t and sim<m: count+=1 b[k] = count sim+=1 else: b[k] = count p+=1 sim-=1 k+=1 print(count) for i in range(20002): if b[i] == 0: break print(b[i]) if mode=="file":f.close() if __name__=="__main__": main() ```
instruction
0
94,802
24
189,604
No
output
1
94,802
24
189,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people. But wait, something is still known, because that day a record was achieved β€” M simultaneous users online! In addition, Polycarpus believes that if a user made a request at second s, then he was online for T seconds after that, that is, at seconds s, s + 1, s + 2, ..., s + T - 1. So, the user's time online can be calculated as the union of time intervals of the form [s, s + T - 1] over all times s of requests from him. Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that: * the number of different users online did not exceed M at any moment, * at some second the number of distinct users online reached value M, * the total number of users (the number of distinct identifiers) was as much as possible. Help Polycarpus cope with the test. Input The first line contains three integers n, M and T (1 ≀ n, M ≀ 20 000, 1 ≀ T ≀ 86400) β€” the number of queries, the record number of online users and the time when the user was online after a query was sent. Next n lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [s, s + T - 1] are within one 24-hour range (from 00:00:00 to 23:59:59). Output In the first line print number R β€” the largest possible number of distinct users. The following n lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to R. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes). Examples Input 4 2 10 17:05:53 17:05:58 17:06:01 22:39:47 Output 3 1 2 2 3 Input 1 2 86400 00:00:00 Output No solution Note Consider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because M = 2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 β€” from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 β€” from 22:39:47 to 22:39:56. In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.) Submitted Solution: ``` def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() a=[0]*20002 b=[0]*20002 if n<m: print("No solution") return for i in range(n): g = gets() temp = int(g[-1]) + int(g[1])*60 + int(g[0])*3600 a[i] = temp [p,count,k,sim] = [0,0,0,0] for i in range(n): while p<i and a[i] - t + 1>=a[p]: p+=1 sim = min(sim,m,i-p+1) #print(p,a[p],a[i],a[i] - a[p],sim,i-p) if p==i or (a[i] - t +1<a[p] and sim<m): count+=1 b[k] = count sim+=1 else: b[k] = count k+=1 print(count) for i in range(20002): if b[i] == 0: break print(b[i]) if mode=="file":f.close() if __name__=="__main__": main() ```
instruction
0
94,803
24
189,606
No
output
1
94,803
24
189,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people. But wait, something is still known, because that day a record was achieved β€” M simultaneous users online! In addition, Polycarpus believes that if a user made a request at second s, then he was online for T seconds after that, that is, at seconds s, s + 1, s + 2, ..., s + T - 1. So, the user's time online can be calculated as the union of time intervals of the form [s, s + T - 1] over all times s of requests from him. Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that: * the number of different users online did not exceed M at any moment, * at some second the number of distinct users online reached value M, * the total number of users (the number of distinct identifiers) was as much as possible. Help Polycarpus cope with the test. Input The first line contains three integers n, M and T (1 ≀ n, M ≀ 20 000, 1 ≀ T ≀ 86400) β€” the number of queries, the record number of online users and the time when the user was online after a query was sent. Next n lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [s, s + T - 1] are within one 24-hour range (from 00:00:00 to 23:59:59). Output In the first line print number R β€” the largest possible number of distinct users. The following n lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to R. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes). Examples Input 4 2 10 17:05:53 17:05:58 17:06:01 22:39:47 Output 3 1 2 2 3 Input 1 2 86400 00:00:00 Output No solution Note Consider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because M = 2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 β€” from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 β€” from 22:39:47 to 22:39:56. In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.) Submitted Solution: ``` def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() a=[0]*20002 b=[0]*20002 if n<m: print("No solution") return for i in range(1,1+n): g = gets() temp = int(g[-1]) + int(g[1])*60 + int(g[0])*3600 a[i] = temp [p,count,k,sim] = [1,0,0,0] for i in range(1,n+1): while p<i and a[i] - t + 1>=a[p]: p+=1 if b[p]!=b[p-1]: sim = max(sim-1,0) #print(p,a[p],a[i],a[i] - a[p],sim,i-p) if p==i or (a[i] - t +1<a[p] and sim<m): count+=1 b[k] = count sim+=1 else: b[k] = count k+=1 print(count) for i in range(20002): if b[i] == 0: break print(b[i]) if mode=="file":f.close() if __name__=="__main__": main() ```
instruction
0
94,804
24
189,608
No
output
1
94,804
24
189,609
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people. But wait, something is still known, because that day a record was achieved β€” M simultaneous users online! In addition, Polycarpus believes that if a user made a request at second s, then he was online for T seconds after that, that is, at seconds s, s + 1, s + 2, ..., s + T - 1. So, the user's time online can be calculated as the union of time intervals of the form [s, s + T - 1] over all times s of requests from him. Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that: * the number of different users online did not exceed M at any moment, * at some second the number of distinct users online reached value M, * the total number of users (the number of distinct identifiers) was as much as possible. Help Polycarpus cope with the test. Input The first line contains three integers n, M and T (1 ≀ n, M ≀ 20 000, 1 ≀ T ≀ 86400) β€” the number of queries, the record number of online users and the time when the user was online after a query was sent. Next n lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [s, s + T - 1] are within one 24-hour range (from 00:00:00 to 23:59:59). Output In the first line print number R β€” the largest possible number of distinct users. The following n lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to R. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes). Examples Input 4 2 10 17:05:53 17:05:58 17:06:01 22:39:47 Output 3 1 2 2 3 Input 1 2 86400 00:00:00 Output No solution Note Consider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because M = 2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 β€” from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 β€” from 22:39:47 to 22:39:56. In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.) Submitted Solution: ``` def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() a=[0]*20002 b=[0]*20002 if n<m: print("No solution") return for i in range(1,1+n): g = gets() temp = int(g[-1]) + int(g[1])*60 + int(g[0])*3600 a[i] = temp #print(a[i]) [p,count,k,sim] = [1,0,1,0] for i in range(1,n+1): while p<i and a[i] - t + 1>=a[p]: p+=1 #print("Dec",end=' ') if b[p]!=b[p-1]: #print("yes") sim = max(sim-1,0) #print(p,a[p],a[i],a[i] - a[p],sim,i-p) if a[i]!=82126 and (i==p or (a[i] - t +1<a[p] and sim<m)): count+=1 b[k] = count sim+=1 else: b[k] = count k+=1 print(count) for i in range(1,20002): if b[i] == 0: break print(b[i],end=' ') if mode=="file":f.close() if __name__=="__main__": main() ```
instruction
0
94,805
24
189,610
No
output
1
94,805
24
189,611
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,557
24
191,114
Tags: implementation Correct Solution: ``` n=int(input()) a=[[0, 0], [0, 0]] b=[] for i in range(n): b=input().split() a[int(b[0])-1][0]+=int(b[1]) a[int(b[0])-1][1]+=int(b[2]) if a[0][0]>=a[0][1]: print("LIVE") else: print("DEAD") if a[1][0]>=a[1][1]: print("LIVE") else: print("DEAD") ```
output
1
95,557
24
191,115
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,558
24
191,116
Tags: implementation Correct Solution: ``` n=int(input()) a=[0]*n for i in range(n): a[i] = [0]*3 a[i]=input().split() a1 = a2 = b1 = b2 = 0 for i in range(n): if (a[i][0]=='1'): a1+=int(a[i][1]) a2+=int(a[i][2]) if (a[i][0]=='2'): b1+=int(a[i][1]) b2+=int(a[i][2]) if (a1>=a2): print("LIVE") else: print("DEAD") if (b1>=b2): print("LIVE") else: print("DEAD") ```
output
1
95,558
24
191,117
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,559
24
191,118
Tags: implementation Correct Solution: ``` n=int(input()) pinga=pingb=sum1=sum2=0 for i in range(n): t,x,y=map(int,input().split()) if t==1: pinga+=1 sum1+=x elif t==2: pingb+=1 sum2+=x if sum1>=(pinga*10)//2: print("LIVE") else: print("DEAD") if sum2>=(pingb*10)//2: print("LIVE") else: print("DEAD") ```
output
1
95,559
24
191,119
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,560
24
191,120
Tags: implementation Correct Solution: ``` T = int(input()) a_x,b_y = 0,0 A_x,B_y = 0,0 for i in range(T): t,x,y = map(int,input().split()) if t == 1: a_x += x b_y += y else: A_x += x B_y += y if a_x >= b_y: print('LIVE') else: print('DEAD') if A_x > B_y: print('LIVE') else: print('DEAD') ```
output
1
95,560
24
191,121
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,561
24
191,122
Tags: implementation Correct Solution: ``` n=int(input()) a=0 a1=0 b=0 b1=0 for i in range(n): t,x,y=map(int,input().split()) if t==1: a+=x a1+=y else: b+=x b1+=y if a>=a1: print('LIVE') else: print('DEAD') if b>=b1: print('LIVE') else: print('DEAD') ```
output
1
95,561
24
191,123
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,562
24
191,124
Tags: implementation Correct Solution: ``` n = int(input()) x1, y1, x2, y2 = 0, 0, 0, 0 for _ in range(n): a = list(map(int, input().split())) if a[0] == 1: x1 = x1+a[1] y1 = y1+a[2] else: x2 = x2+a[1] y2 = y2+a[2] if x1>=y1: print("LIVE") else: print("DEAD") if x2>=y2: print("LIVE") else: print("DEAD") ```
output
1
95,562
24
191,125