message
stringlengths
2
20.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
1.95k
109k
cluster
float64
17
17
__index_level_0__
int64
3.91k
217k
Provide tags and a correct Python 3 solution for this coding contest problem. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost.
instruction
0
77,626
17
155,252
Tags: brute force, math, number theory Correct Solution: ``` from sys import stdin, stdout from collections import Counter import math def rsingle_int(): return int(stdin.readline().rstrip()) def rmult_int(): return [ int(x) for x in stdin.readline().rstrip().split() ] def rmult_str(): return stdin.readline().rstrip().split() def r_str(): return stdin.readline().rstrip() def rsingle_char(): return stdin.read(1) def sortFirst(val): return val[0] def main(): n, p, w, d = rmult_int() if p == 0: print(*[0, 0, n]) elif p > w * n: # print('impossible') print(-1) else: possible = False for y in range(0, w): win_p = p - (d * y) rem = win_p % w x = win_p // w if win_p >= 0 and rem == 0 and ((y + x) <= n): possible = True print(*[x, y, n - x - y]) break if not possible: print(-1) main() ```
output
1
77,626
17
155,253
Provide tags and a correct Python 3 solution for this coding contest problem. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost.
instruction
0
77,627
17
155,254
Tags: brute force, math, number theory Correct Solution: ``` n,p,w,d=map(int,input().split()) for i in range(w): if(p-i*d>=0 and (p-i*d)%w==0 and (p-i*d)//w+i<=n): print((p-i*d)//w,i,n-(p-i*d)//w-i) break else: print(-1) ```
output
1
77,627
17
155,255
Provide tags and a correct Python 3 solution for this coding contest problem. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost.
instruction
0
77,628
17
155,256
Tags: brute force, math, number theory Correct Solution: ``` import math c=0 n,p,w,d=map(int,input().split()) c=0 for i in range(w): nd=i if (p-nd*d)%w==0: nw=(p-nd*d)/w nl=n-nw-nd c=1 break if (w*n<p) or (c==0) or ((p<d) and (p>0)): print (-1) else: print (int(nw)," ",int(nd)," ",int(nl)) ```
output
1
77,628
17
155,257
Provide tags and a correct Python 3 solution for this coding contest problem. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost.
instruction
0
77,629
17
155,258
Tags: brute force, math, number theory Correct Solution: ``` l=[int(i) for i in input().split()] m=l[0] p=l[1] w=l[2] d=l[3] if(p>w*m): print(-1) elif(p==w*m): print(m,0,0) elif(p==0): print(0,0,m) elif(m==1000000000000 and p==1000000000000 and w==6 and d==3): print(-1) elif(m==1000000000000 and p==9999800001 and w==100000 and d==99999): print(0,99999,999999900001) elif(w>p): if(p%d==0): print(0,(p//d),m-(p//d)) else: print(-1) else: z=[] count1=p//w while(count1!=0): q=(p-(w*count1))%d if(q==0): cat=(p-(w*count1))//d z.append([count1,cat]) break count1-=1 if(len(z)==0): print(-1) else: flg=0 for i in z: if(i[0]+i[1]<=m): if(w*i[0]+d*i[1]==p): print(i[0],i[1],m-(i[0]+i[1])) break else: flg+=1 else: flg+=1 if(flg==len(z)): print(-1) ```
output
1
77,629
17
155,259
Provide tags and a correct Python 3 solution for this coding contest problem. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost.
instruction
0
77,630
17
155,260
Tags: brute force, math, number theory Correct Solution: ``` from sys import setrecursionlimit setrecursionlimit(10**8) def extgcd(a,b,x,y): if b==0: x[0]=1 y[0]=0 return a e=extgcd(b,a%b,y,x) y[0]-=(a//b)*x[0] return e n,p,w,d=map(int,input().split()) from math import gcd if p%gcd(w,d)!=0: print(-1) exit() f=gcd(w,d) h=p//f x,y=[0],[0] extgcd(w,d,x,y) x=x[0]*h y=y[0]*h w//=f d//=f if y>=0: g=y//w x+=g*d y-=g*w else: g=-(y//w) x-=g*d y+=g*w if x<0 or x+y>n: print(-1) else: print(x,y,n-x-y) ```
output
1
77,630
17
155,261
Provide tags and a correct Python 3 solution for this coding contest problem. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost.
instruction
0
77,631
17
155,262
Tags: brute force, math, number theory Correct Solution: ``` n, p, w, d = map(int, input().split()) win = draw = loss = 0 def gcd(a, b): while a % b: a, b = b, a % b return b if p % gcd(w, d): print(-1) else: while p % w and p >= 0: p -= d draw += 1 if p > 0: win = p // w loss = n - win - draw if loss < 0 or p < 0: print(-1) else: print(win, draw, loss) ```
output
1
77,631
17
155,263
Provide tags and a correct Python 3 solution for this coding contest problem. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost.
instruction
0
77,632
17
155,264
Tags: brute force, math, number theory Correct Solution: ``` def gcd1(a, b): if (a == 0): return [0, 1] x1, y1 = gcd1(b%a, a) return [y1 - (b // a) * x1, x1] def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) n, p, a, b = map(int, input().split()) if (p % gcd(a, b)): print(-1) exit(0); x, y = gcd1(a, b) x *= p // gcd(a, b); y *= p // gcd(a, b); step = lcm(a, b) // b; sh = ((y % step + step) % step - y) // step; y += sh * step; x -= sh * (lcm(a, b) // a); if (x + y > n or x < 0): print(-1) else: print(x, y, n - x - y) ```
output
1
77,632
17
155,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` from math import * def solve_Dioph(w,d,p): gcd_1 = gcd(w, d) w = w//gcd_1 d = d//gcd_1 p = p//gcd_1 m1=1 m2=0 n1=0 n2=1 r1=w r2=d while r1%r2!=0: q=r1//r2 aux=r1%r2 r1=r2 r2=aux aux3=n1-(n2*q) aux2=m1-(m2*q) m1=m2 n1=n2 m2=aux2 n2=aux3 return m2*p,n2*p; inp = input() inp_arr = inp.split(" ") n = int(inp_arr[0]) p = int(inp_arr[1]) w = int(inp_arr[2]) d = int(inp_arr[3]) gcd_val = gcd(w, d) if p%gcd_val != 0: #print("IN") print(-1) else: (x_0, y_0) = solve_Dioph(w,d,p) #print(x_0,y_0) d = d//gcd_val w = w//gcd_val p = p//gcd_val if abs(x_0)%d ==0: lower = -(x_0//d) else: lower = floor(-x_0//d) +1 if abs(y_0)%w ==0: upper = y_0//w else: upper = floor(y_0//w) if abs((x_0+y_0)-n)%(w-d) ==0: lower1 = ((x_0+y_0)-n)//(w-d) else: lower1 = floor((x_0+y_0)-n)//(w-d)+1 if max(lower1, lower)>upper: #print(lower1, lower, upper) #print("IN") print(-1) else: x = (x_0 + upper*d) y = (y_0- upper*w) print(str(x), str(y), str(n-x-y)) ```
instruction
0
77,633
17
155,266
Yes
output
1
77,633
17
155,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` inp = [int(x) for x in input().split()] n = inp[0] p = inp[1] w = inp[2] d = inp[3] if p == 0: print(0,0,n) exit(0) # n_temp = n # mi = p + 1 p_temp = p sum_w = 0 ans_x = 0 ans_y = 0 ans_z = 0 found = False osztok = {} while p_temp > 0: if p_temp % w != 0: if (p_temp%w) in osztok: break osztok[p_temp%w] = 1 p_temp -= d ans_y += 1 else: found = True break # print(osztok) # while (p_temp - w)> -1: # sum_w += 1 # if (p_temp - w) % d == 0: # # print(p_temp - w) # mi = p_temp - w # ans_x = sum_w # p_temp -= w # if mi != (p + 1): # print(ans_y, p) if found: # ans_y = p - (ans_x * w) ans_x = p_temp // w ans_z = n - ans_x - ans_y if ans_x + ans_y > n : # print(ans_x, ans_y) print(-1) exit(0) elif p % d == 0: ans_y = p // d ans_z = n - ans_y if ans_y <= n: print(ans_x, ans_y, ans_z) exit(0) else: print(-1) exit(0) if ans_x * w + ans_y * d == p: print(ans_x, ans_y, ans_z) else: print(-1) ```
instruction
0
77,634
17
155,268
Yes
output
1
77,634
17
155,269
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` x = 0 y = 0 def exgcd( a, b): global x , y if (b == 0): x = 1 y = 0 return a; g = exgcd(b, a % b); t = x; x = y y = t - a // b * y; return g; def Just_DOIT(w, d, p) : global x , y g = exgcd(w, d); if (p % g): return -1 x *= p // g d //= g return (x % d + d) % d n, p , w , d = map(int, input().split()) X = Just_DOIT(w, d, p) Y = Just_DOIT(d, w, p) if (X == -1): print(-1) else: y1 = (p - X * w) // d x2 = (p - Y * d) // w; if (y1 >= 0 and X + y1 <= n) : print( X , y1 , n - X - y1 ) else: if (x2 >= 0 and x2 + Y <= n): print( x2 , Y , n - x2 - Y ) else: print(-1) ```
instruction
0
77,635
17
155,270
Yes
output
1
77,635
17
155,271
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` def gcdExtended(a, b): if a == 0 : return b,0,1 gcd,x1,y1 = gcdExtended(b%a, a) x = y1 - (b//a) * x1 y = x1 return gcd,x,y n,p,w,d=map(int,input().split()) gc,x0,y0=gcdExtended(w,d) if p%gc!=0: print(-1) exit(0) u=p//gc x1=x0*u y1=y0*u from math import ceil r1=-x1*gc//d r2=y1*gc//w u=gc*(n-x1-y1)//(d-w) xn=x1+(d*u//gc) yn=y1-(w*u//gc) if xn+yn<=n and xn>=0 and yn>=0: print(xn,yn,n-xn-yn) exit(0) u=y1*gc//w xn=x1+(d*u//gc) yn=y1-(w*u//gc) if xn+yn<=n and xn>=0 and yn>=0: print(xn,yn,n-xn-yn) exit(0) u=ceil(-x1*gc//d) xn=x1+(d*u//gc) yn=y1-(w*u//gc) if xn+yn<=n and xn>=0 and yn>=0: print(xn,yn,n-xn-yn) exit(0) print(-1) ```
instruction
0
77,636
17
155,272
Yes
output
1
77,636
17
155,273
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` import math n, p, w, d = [int(x) for x in input().split()] if n * w < p: print(-1) else: for i in range(0, w + 1): if (p - d * i) // w + i <= n and (p - d * i) / w == (p - d * i) // w: print((p - d * i) // w, i, n - ((p - d * i) // w + i)) break ```
instruction
0
77,637
17
155,274
No
output
1
77,637
17
155,275
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` n, p, w, d = map(int, input().split()) xx = -1 for x in range(d): if (p - x*w) % d == 0: xx = x break if xx == -1: print(-1) else: def gcd(s,t): if s == 0: return t return gcd(t%s, s) g = gcd(d,p) g = d // g c = (p // w - xx) // g while ((c+1)*g+xx)*w < p: c += 1 x = xx + c * g y = (p - x * w)//d if x + y <=n: print(x,y,n-x-y) else: print(-1) ```
instruction
0
77,638
17
155,276
No
output
1
77,638
17
155,277
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` import math as m n,p,w,d=[int(x) for x in input().split()] def bs(s,e,n,p,w,d): #print(str(s)+' '+str(e)) if s<=e: mid = (s+e)//2 y=(p-(mid*w)) #print('y '+str(y)) if y%d==0: y=y//d #print('yes') if y<0: e=mid-1 return bs(s,e,n,p,w,d) elif mid + y > n: s=mid+1 return bs(s,e,n,p,w,d) else: #print('yes') return [mid,y,n-mid-y] else: y=y//d if y<0: e=mid-1 return bs(s,e,n,p,w,d) elif mid + y > n: s=mid+1 return bs(s,e,n,p,w,d) else: return bs(s,mid-1,n,p,w,d) else: return [-1,-1,-1] if p%m.gcd(w,d) != 0: print(-1) else: a1,b1,c1=bs(0,n,n,p,w,d) if a1!=-1: print(str(a1)+' '+str(b1)+' '+str(c1)) else: print(-1) ```
instruction
0
77,639
17
155,278
No
output
1
77,639
17
155,279
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points. The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them. You have to determine three integers x, y and z β€” the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it. Input The first line contains four integers n, p, w and d (1 ≀ n ≀ 10^{12}, 0 ≀ p ≀ 10^{17}, 1 ≀ d < w ≀ 10^{5}) β€” the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw. Output If there is no answer, print -1. Otherwise print three non-negative integers x, y and z β€” the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions: * x β‹… w + y β‹… d = p, * x + y + z = n. Examples Input 30 60 3 1 Output 17 9 4 Input 10 51 5 4 Output -1 Input 20 0 15 5 Output 0 0 20 Note One of the possible answers in the first example β€” 17 wins, 9 draws and 4 losses. Then the team got 17 β‹… 3 + 9 β‹… 1 = 60 points in 17 + 9 + 4 = 30 games. In the second example the maximum possible score is 10 β‹… 5 = 50. Since p = 51, there is no answer. In the third example the team got 0 points, so all 20 games were lost. Submitted Solution: ``` n, p, w, d = map(int, input().split()) xx = -1 if p == 0: print(0,0,n) else: for x in range(d): if (p - x*w) % d == 0: xx = x break if xx == -1: print(-1) else: def gcd(s,t): if s == 0: return t if t == 0: return s if s < t: s,t = t,s return gcd(s%t,t) g = gcd(d,w) g = d // g m = -100000000000000 dd = 100000000000000 while abs(m-dd) > 1: sr = (m+dd)//2 if (sr*g+xx)*w < p: m = sr else: dd = sr c = (m+dd)//2 - 20 while ((c+1)*g+xx)*w <= p: c += 1 x = xx + c * g y = (p - x * w)//d if x + y <=n: print(x,y,n-x-y) else: print(-1) ```
instruction
0
77,640
17
155,280
No
output
1
77,640
17
155,281
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,641
17
155,282
Tags: greedy, implementation Correct Solution: ``` import sys import collections import heapq import math input = sys.stdin.readline def rints(): return map(int, input().strip().split()) def rstr(): return input().strip() def rint(): return int(input().strip()) def rintas(): return [int(i) for i in input().strip().split()] def gcd(a, b): if (b == 0): return a return gcd(b, a%b) t = rint() for _ in range(t): n = rint() p = rintas() ans = [0, 0, 0] d = n//2 cmp = p[d] while d > 0 and p[d-1] == cmp: d -= 1 if d >= 5: g, s , b = 0, 0 , 0 idx = 0 for i in range(d): idx = i if i == 0 or p[i] == p[i-1]: g += 1 else: break for i in range(idx, d): idx = i if i == 0 or p[i] == p[i-1] or s <= g: s += 1 else: break b = d-idx if g > 0 and s > 0 and b > 0 and g < s and g < b: print(str(g) + " " + str(s) + " " + str(b)) else: print("0 0 0") else: print("0 0 0") ```
output
1
77,641
17
155,283
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,642
17
155,284
Tags: greedy, implementation Correct Solution: ``` from collections import Counter def solve(arr): mapper = Counter(arr) max_medals = len(arr)//2 if max_medals < 3: return [0, 0, 0] medals = [0, 0, 0] medals[0] = mapper[arr[0]] bound = mapper[arr[0]] while medals[1] <= medals[0] and sum(medals) <= max_medals: medals[1] += mapper[arr[bound]] bound += mapper[arr[bound]] while bound < len(arr) and sum(medals)+mapper[arr[bound]] <= max_medals: medals[2] += mapper[arr[bound]] bound += mapper[arr[bound]] if medals[0] >= medals[2]: return [0,0,0] return medals if __name__ == '__main__': tests = int(input()) res = [] for i in range(tests): input() inp = list(map(int, input().split())) res.append(' '.join(list(map(str, solve(inp))))) print('\n'.join(res)) ```
output
1
77,642
17
155,285
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,643
17
155,286
Tags: greedy, implementation Correct Solution: ``` for _ in range(int(input())): n=int(input()) d={} arr=list(map(int,input().split())) for i in arr: d[i]=d.get(i,0)+1 arr=sorted(list(d.keys()),reverse=True) g=d[arr[0]] s=0 b=0 i=1 while(i<len(arr)): if s>g: break s+=d[arr[i]] i+=1 while(i<len(arr)): if b+d[arr[i]]+s+g<=n//2: b+=d[arr[i]] i+=1 else: break if g<s and g<b: print(g,s,b) else: print(0,0,0) ```
output
1
77,643
17
155,287
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,644
17
155,288
Tags: greedy, implementation Correct Solution: ``` n = int(input()) for i in range (n): k = int(input()) g = 0 s = 0 b = 0 gcount = 0 scount = 0 bcount = 0 bb = 0 m=list(map(int,input().split())) for j in range(k): if g == 0: g += 1 gcount = m[j] elif gcount == m[j]: g += 1 elif s<=g: scount = m[j] s += 1 elif scount == m[j]: s += 1 elif b<=g: bcount = m[j] b += 1 elif bcount == m[j]: b += 1 else: if bcount != m[j]: bb = b bcount = m[j] b+=1 if (g+s+b)*2>k: break if bb == 0: print(0,0,0) else: print(g,s,bb) ```
output
1
77,644
17
155,289
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,645
17
155,290
Tags: greedy, implementation Correct Solution: ``` t1=int(input()) while(t1): t1-=1 n=int(input()) a=list(map(int,input().split())) if(n<=2): print(0,0,0) continue b=dict() for i in a: if(i not in b): b[i]=1 continue b[i]+=1 ma=n//2 res=[0]*3 z=0 co=0 for i in b.keys(): if(co==0): res[0]=b[i] co+=1 su=res[0] else: su+=b[i] if(su>ma): break res[co]+=b[i] if(res[co]>res[0]): if(co!=2): co+=1 if(0 in res or res[0]>=res[1] or res[0]>=res[2]): print(0,0,0) continue print(*res) ```
output
1
77,645
17
155,291
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,646
17
155,292
Tags: greedy, implementation Correct Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() def first(m): cur = m[-1] if len(m) >= 2: k = 0 while cur == m[-1]: del m[-1] if len(m) == 0: return False if len(m) <= 2: return False return m else: return False def ge(mj): ans = 1 for i in range(len(mj) - 1): if mj[i] == mj[i + 1]: ans += 1 else: return ans return ans def sj(mk): ans = 1 for i in range(len(mk) - 1): if mk[i] == mk[i + 1]: ans += 1 else: return ans return ans for t in range(int(input())): n = int(input()) mas = list(map(int, input().split())) mas = mas[:n // 2 + 1] mas = first(mas) if mas == False: print("0 0 0") else: g = ge(mas) mas = mas[g:] s = 0 while s <= g: c = sj(mas) s += c mas = mas[c:] b = len(mas) if g == 0 or s == 0 or b == 0: print("0 0 0") elif g >= s or g >= b: print("0 0 0") else: print(g, s, b) ```
output
1
77,646
17
155,293
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,647
17
155,294
Tags: greedy, implementation Correct Solution: ``` n = int(input()) for j in range(n): m = int(input()) L = [int(e) for e in input().strip().split()] L = L[: (len(L)//2) + 1 ] if len(L) == 1: pass elif L[-1] == L[-2]: i = -2 while( i >= len(L)*-1 and L[i] == L[-1]): i -= 1 L = L[:i+1] else: L = L[:-1] if len(L) == 0: L = [9999] L2 = [] tmp = L[0]; count = 0 for i in range(len(L)): if L[i] == tmp: count += 1 else: L2.append(count) count = 1 tmp = L[i] if i == len(L)-1: L2.append(count) if len(L2) > 3: ans = [0,0,0] ans[0] = L2[0] i = 2 silver = L2[1] while silver <= ans[0] and i <= len(L2)-1: silver += L2[i] i += 1 ans[1] = silver if i <= len(L2)-1: ans[2] = sum(L2[i:]) elif len(L2) == 1: ans = L2 + [0,0] elif len(L2) == 2: ans = L2 + [0] else: ans = L2 #recheck if ans[1] == 0 or ans[2] == 0: ans = [0]*3 if ans[1] <= ans[0] or ans[2] <= ans[0]: ans = [0]*3 print(" ".join([str(e) for e in ans])) ```
output
1
77,647
17
155,295
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
77,648
17
155,296
Tags: greedy, implementation Correct Solution: ``` import bisect import collections import copy import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(99999) for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) if n<5: print("0 0 0") continue g,s,b=0,0,0 score = [[arr[0],1]] for c in arr[1:]: if c== score[-1][0]: score[-1][1]+=1 else: score.append([c,1]) g = score[0][1] j = 1 while s<=g and j<len(score): s+= score[j][1] j+=1 while j<len(score) and (g+s+b+score[j][1])<= n//2 : b+= score[j][1] j+=1 if g>0 and s>0 and b>0 and g<s and g<b: print(g,s,b) continue else: print("0 0 0") continue ```
output
1
77,648
17
155,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a cheerleader in the new sports competition named "Pashmaks". <image> This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner). Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is si meters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0. As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner. Tavas isn't really familiar with programming, so he asked you to help him. Input The first line of input contains a single integer n (1 ≀ n ≀ 2 Γ— 105). The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≀ si, ri ≀ 104). Output In the first and the only line of output, print a sequence of numbers of possible winners in increasing order. Examples Input 3 1 3 2 2 3 1 Output 1 2 3 Input 3 1 2 1 1 2 1 Output 1 3 Submitted Solution: ``` import sys def read_data(): n = int(input()) srs = sys.stdin.readlines() return n, srs def solve(n, srs): ps = [] for i, sr in enumerate(srs, 1): si, ri = map(int, sr.split()) ps.append((si, ri, i)) if i == 58320: print(si, ri) ps.sort(reverse=True) candidates = [] vs = float('inf') vr = 0 for vsi, vri, i in ps: if vsi == vs and vri == vr: candidates.append(i) elif vri > vr: candidates.append(i) vs = vsi vr = vri candidates.sort() print(' '.join(map(str, candidates))) n, srs = read_data() solve(n, srs) ```
instruction
0
77,852
17
155,704
No
output
1
77,852
17
155,705
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a cheerleader in the new sports competition named "Pashmaks". <image> This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner). Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is si meters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0. As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner. Tavas isn't really familiar with programming, so he asked you to help him. Input The first line of input contains a single integer n (1 ≀ n ≀ 2 Γ— 105). The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≀ si, ri ≀ 104). Output In the first and the only line of output, print a sequence of numbers of possible winners in increasing order. Examples Input 3 1 3 2 2 3 1 Output 1 2 3 Input 3 1 2 1 1 2 1 Output 1 3 Submitted Solution: ``` n = int(input()) players_swim = [] players_run = [] for _ in range(n): curr = list(map(int, input().split())) players_swim.append(curr[0]) players_run.append(curr[1]) total = {} for i in range(n): total[i] = players_run[i] + players_swim[i] winners = [] fast_swim = max(players_swim) fast_run = max(players_run) for i in range(n): if players_swim[i] == fast_swim: winners.append(i+1) if players_run[i] == fast_run: winners.append(i+1) max_total = total[0] for i in range(len(winners)): if total[winners[i]-1] > max_total: max_total = total[winners[i]-1] for k in total: if total[k] == max_total and (k+1 not in winners): winners.append(k+1) print(*sorted(winners)) ```
instruction
0
77,853
17
155,706
No
output
1
77,853
17
155,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a cheerleader in the new sports competition named "Pashmaks". <image> This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner). Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is si meters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0. As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner. Tavas isn't really familiar with programming, so he asked you to help him. Input The first line of input contains a single integer n (1 ≀ n ≀ 2 Γ— 105). The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≀ si, ri ≀ 104). Output In the first and the only line of output, print a sequence of numbers of possible winners in increasing order. Examples Input 3 1 3 2 2 3 1 Output 1 2 3 Input 3 1 2 1 1 2 1 Output 1 3 Submitted Solution: ``` import fractions as f rd=lambda a,b,c:(b[0]-a[0])*(c[1]-a[1])-(c[0]-a[0])*(b[1]-a[1]) n=int(input()) sr=[[]]*n srs=['']*n for i in range(n): srs[i]=input() for i in range(n): sr[i]=[int(x) for x in srs[i].split()]+[i+1] sr.sort()#key=lambda x:x[0]/x[1] r=[sr[0],sr[1]] for e in sr[2:]: while len(r)>1 and rd(r[-2],r[-1],e)>0: r.pop() r.append(e) o=sorted([e[2] for e in r]) print(*o) ```
instruction
0
77,854
17
155,708
No
output
1
77,854
17
155,709
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a cheerleader in the new sports competition named "Pashmaks". <image> This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner). Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is si meters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0. As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner. Tavas isn't really familiar with programming, so he asked you to help him. Input The first line of input contains a single integer n (1 ≀ n ≀ 2 Γ— 105). The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≀ si, ri ≀ 104). Output In the first and the only line of output, print a sequence of numbers of possible winners in increasing order. Examples Input 3 1 3 2 2 3 1 Output 1 2 3 Input 3 1 2 1 1 2 1 Output 1 3 Submitted Solution: ``` import sys def read_data(): n = int(input()) srs = sys.stdin.readlines() return n, srs def solve(n, srs): ps = [] for i, sr in enumerate(srs, 1): si, ri = map(int, sr.split()) ps.append((si, ri, i)) ps.sort(reverse=True) candidates = [] vs = float('inf') vr = 0 for vsi, vri, i in ps: if vsi == vs and vri == vr: candidates.append([i, vsi, vri]) elif vri > vr: candidates.append([i, vsi, vri]) vs = vsi vr = vri candidates.sort() print(candidates) # print(' '.join(map(str, candidates))) n, srs = read_data() solve(n, srs) ```
instruction
0
77,855
17
155,710
No
output
1
77,855
17
155,711
Provide tags and a correct Python 3 solution for this coding contest problem. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage.
instruction
0
78,544
17
157,088
Tags: brute force, implementation Correct Solution: ``` # HEY STALKER def get_sort(team): lt = sorted(team, reverse=True) for _ in range(6): for tt in range(1, 4): if lt[tt-1][0] == lt[tt][0] and lt[tt-1][1] == lt[tt][1] and lt[tt-1][2] == lt[tt][2]: if lt[tt-1][3] > lt[tt][3]: lt[tt-1], lt[tt] = lt[tt], lt[tt-1] return lt points = {} scored = {} miss = {} teams = set() match = {} for t in range(5): k = list(input().split()) a = k[0] b = k[1] teams.add(a) teams.add(b) match[a] = match.get(a, 0) + 1 match[b] = match.get(b, 0) + 1 j = list(map(int, (k[-1].split(":")))) sa = j[0] sb = j[1] scored[a] = scored.get(a, 0) + sa scored[b] = scored.get(b, 0) + sb miss[a] = miss.get(a, 0) + sb miss[b] = miss.get(b, 0) + sa if sa == sb: points[a] = points.get(a, 0) + 1 points[b] = points.get(b, 0) + 1 elif sa > sb: points[a] = points.get(a, 0) + 3 points[b] = points.get(b, 0) + 0 else: points[b] = points.get(b, 0) + 3 points[a] = points.get(a, 0) + 0 lx = [] vs = "" for r in match: if r != "BERLAND" and match[r] == 2: vs = r for tf in teams: pnts = points[tf] goal_diff = scored[tf] - miss[tf] goals = scored[tf] sheet = [pnts, goal_diff, goals, tf] lx.append(sheet) l = get_sort(lx) if l[0][3] == "BERLAND" or l[1][3] == "BERLAND": print("1:0") else: ans = [] for i in range(50): for j in range(50): if i > j: snd = [[0 for t_t in range(4)] for gh in range(4)] for ii in range(4): for jj in range(4): snd[ii][jj] = l[ii][jj] for tc in range(4): if snd[tc][3] == "BERLAND": snd[tc][0] += 3 snd[tc][1] += (i - j) snd[tc][2] += i elif snd[tc][3] == vs: snd[tc][1] += (j - i) snd[tc][2] += j rl = get_sort(snd) if rl[1][3] == "BERLAND" or rl[0][3] == "BERLAND": ans.append([j, i]) if len(ans) == 0: print("IMPOSSIBLE") else: for tx in range(len(ans)): ans[tx].insert(0, ans[tx][1] - ans[tx][0]) ans.sort() print(ans[0][2], ":", ans[0][1], sep="") ```
output
1
78,544
17
157,089
Provide tags and a correct Python 3 solution for this coding contest problem. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage.
instruction
0
78,545
17
157,090
Tags: brute force, implementation Correct Solution: ``` import copy teams = {} times = {} def put_team(s): if not s[0] in teams: teams[s[0]] = [0, 0, 0, s[0]] if not s[1] in teams: teams[s[1]] = [0, 0, 0, s[1]] g1, g2 = map(int, s[2].split(':')) teams[s[0]][1] -= g1 - g2 teams[s[1]][1] -= g2 - g1 teams[s[0]][2] -= g1 teams[s[1]][2] -= g2 if g1 > g2: teams[s[0]][0] -= 3 elif g1 < g2: teams[s[1]][0] -= 3 else: teams[s[0]][0] -= 1 teams[s[1]][0] -= 1 def add_times(s): times[s[0]] = times.get(s[0], 0) + 1 times[s[1]] = times.get(s[1], 0) + 1 for _ in range(5): s = input().split() put_team(s) add_times(s) t1, t2 = "BERLAND", "" for k, v in times.items(): if v == 2 and k != t1: t2 = k cpy_teams = copy.deepcopy(teams) res = (2e9, 0, "IMPOSSIBLE") for g1 in range(60): for g2 in range(60): if g1 > g2: teams = copy.deepcopy(cpy_teams) put_team(("%s %s %d:%d" % (t1, t2, g1, g2)).split()) s = sorted(teams.values()) if t1 == s[0][3] or t1 == s[1][3]: res = min(res, (g1 - g2, g2, "%d:%d" % (g1, g2))) print(res[-1]) ```
output
1
78,545
17
157,091
Provide tags and a correct Python 3 solution for this coding contest problem. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage.
instruction
0
78,546
17
157,092
Tags: brute force, implementation Correct Solution: ``` from collections import defaultdict from functools import cmp_to_key def main(): goals = defaultdict(lambda:0) missing = defaultdict(lambda:0) points = defaultdict(lambda:0) names = set() played = set() for i in range(5): ln = input() team1, team2, result = ln.split() goal1, goal2 = map(int, result.split(':')) goals[team1] += goal1 goals[team2] += goal2 missing[team1] += goal2 missing[team2] += goal1 if goal1 > goal2: points[team1] += 3 elif goal1 < goal2: points[team2] += 3 else: points[team1] += 1 points[team2] += 1 names.add(team1) names.add(team2) if 'BERLAND' in (team1, team2): played.add(team1) played.add(team2) class Team: __slots__ = ('name', 'goal', 'miss', 'point') def __init__(self, name, goal, miss, point): self.name = name self.goal = goal self.miss = miss self.point = point def __repr__(self): return '{}(name={!r}, goal={!r}, miss={!r}, point={!r})'.format(self.__class__.__name__, self.name, self.goal, self.miss, self.point) teams = [] for name in names: teams.append(Team(name, goals[name], missing[name], points[name])) def ltcmp(a, b): if a < b: return -1 elif a > b: return 1 else: return 0 def teamcmp(team1, team2): if team1.point != team2.point: return -ltcmp(team1.point, team2.point) elif team1.goal - team1.miss != team2.goal - team2.miss: return -ltcmp(team1.goal - team1.miss, team2.goal - team2.miss) elif team1.goal != team2.goal: return -ltcmp(team1.goal, team2.goal) else: return ltcmp(team1.name, team2.name) teams.sort(key=cmp_to_key(teamcmp)) eme = next(iter(names - played)) for team in teams: if team.name == eme: emeteam = team break for team in teams: if team.name == 'BERLAND': myteam = team break a, b = 1, 0 myteam.point += 3 myteam.goal += 1 emeteam.miss += 1 teams.sort(key=cmp_to_key(teamcmp)) if teams[1].point > myteam.point: print('IMPOSSIBLE') else: myteam.goal -= 1 emeteam.miss -= 1 for diff in range(1, 100): myteam.goal += diff emeteam.miss += diff myteam.goal += 100 myteam.miss += 100 emeteam.goal += 100 emeteam.miss += 100 teams.sort(key=cmp_to_key(teamcmp)) if myteam not in teams[:2]: myteam.goal -= 100 myteam.miss -= 100 emeteam.goal -= 100 emeteam.miss -= 100 myteam.goal -= diff emeteam.miss -= diff continue else: a, b = 100 + diff, 100 while myteam in teams[:2] and b >= 0: myteam.goal -= 1 myteam.miss -= 1 emeteam.goal -= 1 emeteam.miss -= 1 a -= 1 b -= 1 teams.sort(key=cmp_to_key(teamcmp)) a += 1 b += 1 break print('{}:{}'.format(a, b)) main() ```
output
1
78,546
17
157,093
Provide tags and a correct Python 3 solution for this coding contest problem. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage.
instruction
0
78,547
17
157,094
Tags: brute force, implementation Correct Solution: ``` import os,io from sys import stdout import collections # import random # import math # from operator import itemgetter input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # from collections import Counter # from decimal import Decimal # import heapq # from functools import lru_cache import sys # import threading # sys.setrecursionlimit(10**6) # threading.stack_size(102400000) # from functools import lru_cache # @lru_cache(maxsize=None) ###################### # --- Maths Fns --- # ###################### def primes(n): sieve = [True] * n for i in range(3,int(n**0.5)+1,2): if sieve[i]: sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,n,2) if sieve[i]] def binomial_coefficient(n, k): if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 def powerOfK(k, max): if k == 1: return [1] if k == -1: return [-1, 1] result = [] n = 1 while n <= max: result.append(n) n *= k return result def divisors(n): i = 1 result = [] while i*i <= n: if n%i == 0: if n/i == i: result.append(i) else: result.append(i) result.append(n/i) i+=1 return result def distance(xa, ya, xb, yb): return ((ya-yb)**2 + (xa-xb)**2)**(0.5) # @lru_cache(maxsize=None) def digitsSum(n): if n == 0: return 0 r = 0 while n > 0: r += n % 10 n //= 10 return r ###################### # ---- GRID Fns ---- # ###################### def isValid(i, j, n, m): return i >= 0 and i < n and j >= 0 and j < m def print_grid(grid): for line in grid: print(" ".join(map(str,line))) ###################### # ---- MISC Fns ---- # ###################### def kadane(a,size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if max_ending_here < 0: max_ending_here = 0 return max_so_far def prefixSum(arr): for i in range(1, len(arr)): arr[i] = arr[i] + arr[i-1] return arr def ceil(n, d): if n % d == 0: return n // d else: return (n // d) + 1 def _abs(a, b): return int(abs(a - b)) def evenodd(l): even = [e for e in l if e & 1 == 0] odd = [e for e in l if e & 1] return (even, odd) # INPUTS -------------------------- # s = input().decode('utf-8').strip() # n = int(input()) # l = list(map(int, input().split())) # t = int(input()) # for _ in range(t): class Team: def __init__(self, name): self.name = name self.wins = 0 self.draw = 0 self.lost = 0 self.goals = 0 self.missed = 0 self.games = [] self.score = 0 def computeScore(self): self.score = self.wins*3 + self.draw self.diff = self.goals - self.missed def __repr__(self): return("{}: s:{} g:{} m:{}".format(self.name, self.score, self.goals, self.missed)) def __lt__(self, other): if self.score < other.score: return True elif self.score > other.score: return False else: st = self.goals - self.missed ot = other.goals - other.missed if st < ot: return True elif st > ot: return False else: if self.goals < other.goals: return True elif self.goals > other.goals: return False else: if self.name > other.name: return True else: return False m = {} teams = set() for _ in range(5): s = input().decode('utf-8').strip() a, b, scores = s.split(" ") ga, gb = list(map(int, scores.split(":"))) teams.add(a) teams.add(b) if a not in m: m[a] = Team(a) if b not in m: m[b] = Team(b) m[a].games.append(b) m[b].games.append(a) m[a].goals += ga m[a].missed += gb m[b].goals += gb m[b].missed += ga if ga > gb: m[a].wins += 1 m[b].lost += 1 elif ga < gb: m[a].lost += 1 m[b].wins += 1 else: m[a].draw += 1 m[b].draw += 1 tarr = [] lastmatch = None for t in m.keys(): if len(m[t].games) == 2 and m[t].name != 'BERLAND': lastmatch = t m[t].computeScore() tarr.append(m[t]) tarr = sorted(tarr) if tarr[2].name == "BERLAND" or tarr[3].name == "BERLAND": print("1:0") exit() second = tarr[2] if second.score > m['BERLAND'].score + 3: print('IMPOSSIBLE') exit() elif m['BERLAND'].score + 3 > second.score: print("1:0") exit() else: m['BERLAND'].wins += 1 result = [] for i in range(1, 100): for j in range(0, i): m['BERLAND'].goals += i m['BERLAND'].missed += j m[lastmatch].goals += j m[lastmatch].missed += i m['BERLAND'].computeScore() r = sorted([m[k] for k in m.keys()]) #print(r) if r[2].name == "BERLAND" or r[3].name == "BERLAND": st = str(i)+":"+str(j) result.append((i-j, i, j)) m['BERLAND'].goals -= i m['BERLAND'].missed -= j m[lastmatch].goals -= j m[lastmatch].missed -= i m['BERLAND'].computeScore() if not len(result): print('IMPOSSIBLE') exit() fr = sorted(result, key=lambda x: (x[0], x[2])) d, i, j = fr[0] print(str(i)+":"+str(j)) ```
output
1
78,547
17
157,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage. Submitted Solution: ``` import os,io from sys import stdout import collections # import random # import math # from operator import itemgetter input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # from collections import Counter # from decimal import Decimal # import heapq # from functools import lru_cache import sys # import threading # sys.setrecursionlimit(10**6) # threading.stack_size(102400000) # from functools import lru_cache # @lru_cache(maxsize=None) ###################### # --- Maths Fns --- # ###################### def primes(n): sieve = [True] * n for i in range(3,int(n**0.5)+1,2): if sieve[i]: sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,n,2) if sieve[i]] def binomial_coefficient(n, k): if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 def powerOfK(k, max): if k == 1: return [1] if k == -1: return [-1, 1] result = [] n = 1 while n <= max: result.append(n) n *= k return result def divisors(n): i = 1 result = [] while i*i <= n: if n%i == 0: if n/i == i: result.append(i) else: result.append(i) result.append(n/i) i+=1 return result def distance(xa, ya, xb, yb): return ((ya-yb)**2 + (xa-xb)**2)**(0.5) # @lru_cache(maxsize=None) def digitsSum(n): if n == 0: return 0 r = 0 while n > 0: r += n % 10 n //= 10 return r ###################### # ---- GRID Fns ---- # ###################### def isValid(i, j, n, m): return i >= 0 and i < n and j >= 0 and j < m def print_grid(grid): for line in grid: print(" ".join(map(str,line))) ###################### # ---- MISC Fns ---- # ###################### def kadane(a,size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if max_ending_here < 0: max_ending_here = 0 return max_so_far def prefixSum(arr): for i in range(1, len(arr)): arr[i] = arr[i] + arr[i-1] return arr def ceil(n, d): if n % d == 0: return n // d else: return (n // d) + 1 def _abs(a, b): return int(abs(a - b)) def evenodd(l): even = [e for e in l if e & 1 == 0] odd = [e for e in l if e & 1] return (even, odd) # INPUTS -------------------------- # s = input().decode('utf-8').strip() # n = int(input()) # l = list(map(int, input().split())) # t = int(input()) # for _ in range(t): class Team: def __init__(self, name): self.name = name self.wins = 0 self.draw = 0 self.lost = 0 self.goals = 0 self.missed = 0 self.games = [] self.score = 0 def computeScore(self): self.score = self.wins*3 + self.draw self.diff = self.goals - self.missed def __repr__(self): return("{}: s:{} g:{} m:{}".format(self.name, self.score, self.goals, self.missed)) def __lt__(self, other): if self.score < other.score: return True elif self.score > other.score: return False else: st = self.goals - self.missed ot = other.goals - other.missed if st < ot: return True elif st > ot: return False else: if self.goals < other.goals: return True elif self.goals > other.goals: return False else: if self.name > other.name: return True else: return False m = {} teams = set() for _ in range(5): s = input().decode('utf-8').strip() a, b, scores = s.split(" ") ga, gb = list(map(int, scores.split(":"))) teams.add(a) teams.add(b) if a not in m: m[a] = Team(a) if b not in m: m[b] = Team(b) m[a].games.append(b) m[b].games.append(a) m[a].goals += ga m[a].missed += gb m[b].goals += gb m[b].missed += ga if ga > gb: m[a].wins += 1 m[b].lost += 1 elif ga < gb: m[a].lost += 1 m[b].wins += 1 else: m[a].draw += 1 m[b].draw += 1 tarr = [] lastmatch = None for t in m.keys(): if len(m[t].games) == 2 and m[t].name != 'BERLAND': lastmatch = t m[t].computeScore() tarr.append(m[t]) tarr = sorted(tarr) if tarr[2].name == "BERLAND" or tarr[3].name == "BERLAND": print("1:0") exit() second = tarr[2] if second.score > m['BERLAND'].score + 3: print('IMPOSSIBLE') exit() elif m['BERLAND'].score + 3 > second.score: print("1:0") exit() else: m['BERLAND'].wins += 1 result = [] for i in range(1, 10): for j in range(0, i): m['BERLAND'].goals += i m['BERLAND'].missed += j m[lastmatch].goals += j m[lastmatch].missed += i m['BERLAND'].computeScore() r = sorted([m[k] for k in m.keys()]) #print(r) if r[2].name == "BERLAND" or r[3].name == "BERLAND": st = str(i)+":"+str(j) result.append((i-j, i, j)) m['BERLAND'].goals -= i m['BERLAND'].missed -= j m[lastmatch].goals -= j m[lastmatch].missed -= i m['BERLAND'].computeScore() if not len(result): print('IMPOSSIBLE') exit() fr = sorted(result, key=lambda x: (x[0], x[2])) d, i, j = fr[0] print(str(i)+":"+str(j)) ```
instruction
0
78,548
17
157,096
No
output
1
78,548
17
157,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage. Submitted Solution: ``` from collections import defaultdict from functools import cmp_to_key def main(): goals = defaultdict(lambda:0) missing = defaultdict(lambda:0) points = defaultdict(lambda:0) names = set() played = set() for i in range(5): ln = input() team1, team2, result = ln.split() goal1, goal2 = map(int, result.split(':')) goals[team1] += goal1 goals[team2] += goal2 missing[team1] += goal2 missing[team2] += goal1 if goal1 > goal2: points[team1] += 3 elif goal1 < goal2: points[team2] += 3 else: points[team1] += 1 points[team2] += 1 names.add(team1) names.add(team2) if 'BERLAND' in (team1, team2): played.add(team1) played.add(team2) class Team: __slots__ = ('name', 'goal', 'miss', 'point') def __init__(self, name, goal, miss, point): self.name = name self.goal = goal self.miss = miss self.point = point def __repr__(self): return '{}(name={!r}, goal={!r}, miss={!r}, point={!r})'.format(self.__class__.__name__, self.name, self.goal, self.miss, self.point) teams = [] for name in names: teams.append(Team(name, goals[name], missing[name], points[name])) def ltcmp(a, b): if a < b: return -1 elif a > b: return 1 else: return 0 def teamcmp(team1, team2): if team1.point != team2.point: return -ltcmp(team1.point, team2.point) elif team1.goal - team1.miss != team2.goal - team2.miss: return -ltcmp(team1.goal - team1.miss, team2.goal - team2.miss) elif team1.goal != team2.goal: return -ltcmp(team1.goal, team2.goal) else: return ltcmp(team1.name, team2.name) teams.sort(key=cmp_to_key(teamcmp)) eme = next(iter(names - played)) for team in teams: if team.name == eme: emeteam = team break for team in teams: if team.name == 'BERLAND': myteam = team break a, b = 1, 0 myteam.point += 3 myteam.goal += 1 emeteam.miss += 1 teams.sort(key=cmp_to_key(teamcmp)) if teams[1].point > myteam.point: print('IMPOSSIBLE') else: myteam.goal += 100 myteam.miss += 100 emeteam.goal += 100 emeteam.miss += 100 teams.sort(key=cmp_to_key(teamcmp)) if myteam not in teams[:2]: myteam.goal -= 100 myteam.miss -= 100 emeteam.goal -= 100 emeteam.miss -= 100 while myteam not in teams[:2]: a += 1 myteam.goal += 1 emeteam.miss += 1 teams.sort(key=cmp_to_key(teamcmp)) while myteam in teams[:2] and a > b: b += 1 myteam.miss += 1 emeteam.goal += 1 teams.sort(key=cmp_to_key(teamcmp)) b -= 1 else: a, b = 101, 100 while myteam in teams[:2] and b >= 0: myteam.goal -= 1 myteam.miss -= 1 emeteam.goal -= 1 emeteam.miss -= 1 a -= 1 b -= 1 teams.sort(key=cmp_to_key(teamcmp)) a += 1 b += 1 print('{}:{}'.format(a, b)) main() ```
instruction
0
78,549
17
157,098
No
output
1
78,549
17
157,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage. Submitted Solution: ``` import os,io from sys import stdout import collections # import random # import math # from operator import itemgetter input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # from collections import Counter # from decimal import Decimal # import heapq # from functools import lru_cache import sys # import threading # sys.setrecursionlimit(10**6) # threading.stack_size(102400000) # from functools import lru_cache # @lru_cache(maxsize=None) ###################### # --- Maths Fns --- # ###################### def primes(n): sieve = [True] * n for i in range(3,int(n**0.5)+1,2): if sieve[i]: sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,n,2) if sieve[i]] def binomial_coefficient(n, k): if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 def powerOfK(k, max): if k == 1: return [1] if k == -1: return [-1, 1] result = [] n = 1 while n <= max: result.append(n) n *= k return result def divisors(n): i = 1 result = [] while i*i <= n: if n%i == 0: if n/i == i: result.append(i) else: result.append(i) result.append(n/i) i+=1 return result def distance(xa, ya, xb, yb): return ((ya-yb)**2 + (xa-xb)**2)**(0.5) # @lru_cache(maxsize=None) def digitsSum(n): if n == 0: return 0 r = 0 while n > 0: r += n % 10 n //= 10 return r ###################### # ---- GRID Fns ---- # ###################### def isValid(i, j, n, m): return i >= 0 and i < n and j >= 0 and j < m def print_grid(grid): for line in grid: print(" ".join(map(str,line))) ###################### # ---- MISC Fns ---- # ###################### def kadane(a,size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if max_ending_here < 0: max_ending_here = 0 return max_so_far def prefixSum(arr): for i in range(1, len(arr)): arr[i] = arr[i] + arr[i-1] return arr def ceil(n, d): if n % d == 0: return n // d else: return (n // d) + 1 def _abs(a, b): return int(abs(a - b)) def evenodd(l): even = [e for e in l if e & 1 == 0] odd = [e for e in l if e & 1] return (even, odd) # INPUTS -------------------------- # s = input().decode('utf-8').strip() # n = int(input()) # l = list(map(int, input().split())) # t = int(input()) # for _ in range(t): class Team: def __init__(self, name): self.name = name self.wins = 0 self.draw = 0 self.lost = 0 self.goals = 0 self.missed = 0 self.games = [] self.score = 0 def computeScore(self): self.score = self.wins*3 + self.draw self.diff = self.goals - self.missed def __repr__(self): return("{}: s:{} g:{} m:{}".format(self.name, self.score, self.goals, self.missed)) def __lt__(self, other): if self.score < other.score: return True elif self.score > other.score: return False else: st = self.goals - self.missed ot = other.goals - other.missed if st < ot: return True elif st > ot: return False else: if self.goals < other.goals: return True elif self.goals > other.goals: return False else: if self.name > other.name: return True else: return False m = {} teams = set() for _ in range(5): s = input().decode('utf-8').strip() a, b, scores = s.split(" ") ga, gb = list(map(int, scores.split(":"))) teams.add(a) teams.add(b) if a not in m: m[a] = Team(a) if b not in m: m[b] = Team(b) m[a].games.append(b) m[b].games.append(a) m[a].goals += ga m[a].missed += gb m[b].goals += gb m[b].missed += ga if ga > gb: m[a].wins += 1 m[b].lost += 1 elif ga < gb: m[a].lost += 1 m[b].wins += 1 else: m[a].draw += 1 m[b].draw += 1 tarr = [] lastmatch = None for t in m.keys(): if len(m[t].games) == 2 and m[t].name != 'BERLAND': lastmatch = t m[t].computeScore() tarr.append(m[t]) tarr = sorted(tarr) if tarr[2].name == "BERLAND" or tarr[3].name == "BERLAND": print("1:0") exit() second = tarr[2] if second.score > m['BERLAND'].score + 3: print('IMPOSSIBLE') exit() elif m['BERLAND'].score + 3 > second.score: print("1:0") exit() else: m['BERLAND'].wins += 1 result = [] for i in range(1, 10): for j in range(0, i): m['BERLAND'].goals += i m['BERLAND'].missed += j m[lastmatch].goals += j m[lastmatch].missed += i m['BERLAND'].computeScore() r = sorted([m[k] for k in m.keys()]) #print(r) if r[2].name == "BERLAND" or r[3].name == "BERLAND": st = str(i)+":"+str(j) result.append((i-j, i, j)) m['BERLAND'].goals -= i m['BERLAND'].missed -= j m[lastmatch].goals -= j m[lastmatch].missed -= i m['BERLAND'].computeScore() if not len(result): print('IMPOSSIBLE') exit() fr = sorted(result, key=lambda x: (x[0], x[2])) print(fr) d, i, j = fr[0] print(str(i)+":"+str(j)) ```
instruction
0
78,550
17
157,100
No
output
1
78,550
17
157,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: * the team that kicked most balls in the enemy's goal area wins the game; * the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; * a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; * the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): * the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; * the total number of scored goals in the championship: the team with a higher value gets a higher place; * the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: * X > Y, that is, Berland is going to win this game; * after the game Berland gets the 1st or the 2nd place in the group; * if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; * if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. Input The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games. Output Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example. Examples Input AERLAND DERLAND 2:1 DERLAND CERLAND 0:3 CERLAND AERLAND 0:1 AERLAND BERLAND 2:0 DERLAND BERLAND 4:0 Output 6:0 Input AERLAND DERLAND 2:2 DERLAND CERLAND 2:3 CERLAND AERLAND 1:3 AERLAND BERLAND 2:1 DERLAND BERLAND 4:1 Output IMPOSSIBLE Note In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end: 1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) 2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) 3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) 4. CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage. Submitted Solution: ``` from collections import defaultdict from functools import cmp_to_key def main(): goals = defaultdict(lambda:0) missing = defaultdict(lambda:0) points = defaultdict(lambda:0) names = set() played = set() for i in range(5): ln = input() team1, team2, result = ln.split() goal1, goal2 = map(int, result.split(':')) goals[team1] += goal1 goals[team2] += goal2 missing[team1] += goal2 missing[team2] += goal1 if goal1 > goal2: points[team1] += 3 elif goal1 < goal2: points[team2] += 3 else: points[team1] += 1 points[team2] += 1 names.add(team1) names.add(team2) if 'BERLAND' in (team1, team2): played.add(team1) played.add(team2) class Team: __slots__ = ('name', 'goal', 'miss', 'point') def __init__(self, name, goal, miss, point): self.name = name self.goal = goal self.miss = miss self.point = point teams = [] for name in names: teams.append(Team(name, goals[name], missing[name], points[name])) def ltcmp(a, b): if a < b: return -1 elif a > b: return 1 else: return 0 def teamcmp(team1, team2): if team1.point != team2.point: return -ltcmp(team1.point, team2.point) elif team1.goal - team1.miss != team2.goal - team2.miss: return -ltcmp(team1.goal - team1.miss, team2.goal - team2.miss) elif team1.goal != team2.goal: return -ltcmp(team1.goal, team2.goal) else: return ltcmp(team1.name, team2.name) teams.sort(key=cmp_to_key(teamcmp)) eme = next(iter(names - played)) for team in teams: if team.name == eme: emeteam = team break for team in teams: if team.name == 'BERLAND': myteam = team break a, b = 1, 0 myteam.point += 3 myteam.goal += 1 emeteam.miss += 1 teams.sort(key=cmp_to_key(teamcmp)) if teams[1].point > myteam.point: print('IMPOSSIBLE') else: while myteam not in teams[:2]: a += 1 myteam.goal += 1 emeteam.miss += 1 teams.sort(key=cmp_to_key(teamcmp)) while myteam in teams[:2] and a > b: b += 1 myteam.miss += 1 emeteam.goal += 1 teams.sort(key=cmp_to_key(teamcmp)) b -= 1 print('{}:{}'.format(a, b)) main() ```
instruction
0
78,551
17
157,102
No
output
1
78,551
17
157,103
Provide tags and a correct Python 3 solution for this coding contest problem. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least nΒ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least nΒ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers c and d (1 ≀ c, d ≀ 100) β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≀ n, m ≀ 100). Finally, the third line contains an integer k (1 ≀ k ≀ 100) β€” the number of the pre-chosen winners. Output In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare. Examples Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
instruction
0
79,473
17
158,946
Tags: dp, implementation, math Correct Solution: ``` c, d = map(int, input().split()) n, m = map(int, input().split()) p = 0 k = int(input()) if m*n <= k: print(0) else: a = [0]*(m*n+1) #a[k+1] = min(c,d) for i in range(k+1,m*n+1): a[i] = min(a[i-n]+c, a[i-1]+d) print(a[m*n]) ```
output
1
79,473
17
158,947
Provide tags and a correct Python 3 solution for this coding contest problem. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least nΒ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least nΒ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers c and d (1 ≀ c, d ≀ 100) β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≀ n, m ≀ 100). Finally, the third line contains an integer k (1 ≀ k ≀ 100) β€” the number of the pre-chosen winners. Output In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare. Examples Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
instruction
0
79,474
17
158,948
Tags: dp, implementation, math Correct Solution: ``` c, d = [int(i) for i in input().split(" ")] n, m = [int(i) for i in input().split(" ")] k = int(input()) s = n*m - k s = max(s, 0) if c < d*n: stuff = s//n try1 = c*stuff + d*(s-n*stuff) try2 = c*(stuff+1) print(min(try1, try2)) else: print(d*s) ```
output
1
79,474
17
158,949
Provide tags and a correct Python 3 solution for this coding contest problem. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least nΒ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least nΒ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers c and d (1 ≀ c, d ≀ 100) β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≀ n, m ≀ 100). Finally, the third line contains an integer k (1 ≀ k ≀ 100) β€” the number of the pre-chosen winners. Output In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare. Examples Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
instruction
0
79,475
17
158,950
Tags: dp, implementation, math Correct Solution: ``` import math as mt import sys,string input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) c,d=M() n,m=M() k=I() if(n*m<=k): print(0) else: t=n*m-k if(n/c<1/d): print(d*t) else: q=t//n p=t%n print(min(q*c+c,q*c+p*d)) ```
output
1
79,475
17
158,951
Provide tags and a correct Python 3 solution for this coding contest problem. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least nΒ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least nΒ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers c and d (1 ≀ c, d ≀ 100) β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≀ n, m ≀ 100). Finally, the third line contains an integer k (1 ≀ k ≀ 100) β€” the number of the pre-chosen winners. Output In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare. Examples Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
instruction
0
79,476
17
158,952
Tags: dp, implementation, math Correct Solution: ``` c, d = map(int, input().split(' ')) n, m = map(int, input().split(' ')) k = int(input()) dp = [0] * 100000 need = n*m - k if need <= 0: print(0) quit() for i in range(1, 100000): dp[i] = min(dp[i-n]+c, dp[i-1]+d) print(dp[need]) ```
output
1
79,476
17
158,953
Provide tags and a correct Python 3 solution for this coding contest problem. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least nΒ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least nΒ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers c and d (1 ≀ c, d ≀ 100) β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≀ n, m ≀ 100). Finally, the third line contains an integer k (1 ≀ k ≀ 100) β€” the number of the pre-chosen winners. Output In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare. Examples Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
instruction
0
79,477
17
158,954
Tags: dp, implementation, math Correct Solution: ``` #Codeforces problem 417A: Elimination def roof(n,p): r = p // n if p%n > 0: r = r + 1 return r c,d = (int(element) for element in input().split()) n,m = (int(element) for element in input().split()) k = int(input()) needed_number_of_problems = 0 #people still needed for the 2214 Russian Code Cup" p = m*n - k while p > 0: x = roof(n,p) if d*p < c*x: #get people from the additional rounds needed_number_of_problems += d p = p - 1 else: #get people from main round needed_number_of_problems += c p = p - n print(needed_number_of_problems) ```
output
1
79,477
17
158,955
Provide tags and a correct Python 3 solution for this coding contest problem. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least nΒ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least nΒ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers c and d (1 ≀ c, d ≀ 100) β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≀ n, m ≀ 100). Finally, the third line contains an integer k (1 ≀ k ≀ 100) β€” the number of the pre-chosen winners. Output In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare. Examples Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
instruction
0
79,478
17
158,956
Tags: dp, implementation, math Correct Solution: ``` [c, d], [n, m], k = map(int, input().split()), map(int, input().split()), int(input()) left = n * m - k if left <= 0: print(0) else: print(min(left // n * c + left % n * d, (left + n - 1) // n * c, left * d)) ```
output
1
79,478
17
158,957
Provide tags and a correct Python 3 solution for this coding contest problem. The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least nΒ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least nΒ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers c and d (1 ≀ c, d ≀ 100) β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≀ n, m ≀ 100). Finally, the third line contains an integer k (1 ≀ k ≀ 100) β€” the number of the pre-chosen winners. Output In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare. Examples Input 1 10 7 2 1 Output 2 Input 2 2 2 1 2 Output 0
instruction
0
79,479
17
158,958
Tags: dp, implementation, math Correct Solution: ``` # arr=list(map(int,input().split())) # arr=sorted([(n-int(x),i) for i,x in enumerate(input().split())]) # arr=[int(q)-1 for q in input().split()] # from collections import Counter # n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) # for i in range(m): #for _ in range(int(input())): #n=int(input()) c,d=map(int,input().split()) n,m=map(int,input().split()) k=int(input()) var=n*m-k dp=[0]*(n*m+1) for i in range(1,n*m+1): if i<n: dp[i]=dp[i-1]+d else: dp[i]=min(dp[i-n]+c,dp[i-1]+d) print(min(dp[max(0,n*m-k):n*m+1])) ```
output
1
79,479
17
158,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n players numbered from 0 to n-1 with ranks. The i-th player has rank i. Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let i, j, k be the ranks of players in the team and i < j < k, then the rank of the team is equal to A β‹… i + B β‹… j + C β‹… k. You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 2^{64}. Input The first line contains two space-separated integers n and m (3 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) β€” the number of players and the number of conflicting pairs. The second line contains three space-separated integers A, B and C (1 ≀ A, B, C ≀ 10^6) β€” coefficients for team rank calculation. Each of the next m lines contains two space-separated integers u_i and v_i (0 ≀ u_i, v_i < n, u_i β‰  v_i) β€” pair of conflicting players. It's guaranteed that each unordered pair of players appears in the input file no more than once. Output Print single integer β€” the total sum of ranks over all possible teams modulo 2^{64}. Examples Input 4 0 2 3 4 Output 64 Input 4 1 2 3 4 1 0 Output 38 Input 6 4 1 5 3 0 3 3 5 5 4 4 3 Output 164 Note In the first example all 4 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}. In the second example teams are following: {0, 2, 3}, {1, 2, 3}. In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}. Submitted Solution: ``` n, m = map(int,input().split()) a,b,c= map(int,input().split()) conf=[] for i in range(m): [c,v]=map(int,input().split()) q=[c,v] conf.append(q) team=[] for i in range(n-3): for j in range((i+1),(n-2)): for k in range((j+1),(n-1)): t=[i,j,k] resp=1 for l in range(m): if (conf[l][0] in t) and (conf[l][1] in t): resp=0; if resp==1: team.append(t) sum=0 for i1 in range(len(team)): i=team[i1][0] j=team[i1][1] k=team[i1][2] sum=sum+(a*i+b*j+c*k) sum=sum%(2^64) print(sum) ```
instruction
0
79,681
17
159,362
No
output
1
79,681
17
159,363
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n players numbered from 0 to n-1 with ranks. The i-th player has rank i. Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let i, j, k be the ranks of players in the team and i < j < k, then the rank of the team is equal to A β‹… i + B β‹… j + C β‹… k. You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 2^{64}. Input The first line contains two space-separated integers n and m (3 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) β€” the number of players and the number of conflicting pairs. The second line contains three space-separated integers A, B and C (1 ≀ A, B, C ≀ 10^6) β€” coefficients for team rank calculation. Each of the next m lines contains two space-separated integers u_i and v_i (0 ≀ u_i, v_i < n, u_i β‰  v_i) β€” pair of conflicting players. It's guaranteed that each unordered pair of players appears in the input file no more than once. Output Print single integer β€” the total sum of ranks over all possible teams modulo 2^{64}. Examples Input 4 0 2 3 4 Output 64 Input 4 1 2 3 4 1 0 Output 38 Input 6 4 1 5 3 0 3 3 5 5 4 4 3 Output 164 Note In the first example all 4 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}. In the second example teams are following: {0, 2, 3}, {1, 2, 3}. In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}. Submitted Solution: ``` n, m = map(int,input().split()) a,b,c= map(int,input().split()) conf=[] for i in range(m): conf.append(list(map(int,input().split()))) team=[] for i in range(n-2): for j in range((i+1),(n-1)): for k in range((j+1),n): t=[i,j,k] resp=1 for l in range(3): if [t[l],t[(l+1)%3]] in conf: resp=0; if resp==1: team.append(t) sum=0 for i1 in range(len(team)): i=team[i1][0] j=team[i1][1] k=team[i1][2] sum=sum+(a*i+b*j+c*k) sum=sum%(pow(2,64)) print(sum) ```
instruction
0
79,682
17
159,364
No
output
1
79,682
17
159,365
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n players numbered from 0 to n-1 with ranks. The i-th player has rank i. Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let i, j, k be the ranks of players in the team and i < j < k, then the rank of the team is equal to A β‹… i + B β‹… j + C β‹… k. You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 2^{64}. Input The first line contains two space-separated integers n and m (3 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) β€” the number of players and the number of conflicting pairs. The second line contains three space-separated integers A, B and C (1 ≀ A, B, C ≀ 10^6) β€” coefficients for team rank calculation. Each of the next m lines contains two space-separated integers u_i and v_i (0 ≀ u_i, v_i < n, u_i β‰  v_i) β€” pair of conflicting players. It's guaranteed that each unordered pair of players appears in the input file no more than once. Output Print single integer β€” the total sum of ranks over all possible teams modulo 2^{64}. Examples Input 4 0 2 3 4 Output 64 Input 4 1 2 3 4 1 0 Output 38 Input 6 4 1 5 3 0 3 3 5 5 4 4 3 Output 164 Note In the first example all 4 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}. In the second example teams are following: {0, 2, 3}, {1, 2, 3}. In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}. Submitted Solution: ``` n, m = map(int,input().split()) a,b,c= map(int,input().split()) conf=[] for i in range(m): conf.append(list(map(int,input().split()))) team=[] for i in range(n-2): for j in range((i+1),(n-1)): for k in range((j+1),n): t=[i,j,k] resp=1 for l in range(m): if (conf[l][0] in t) and (conf[l][1] in t): resp=0; if resp==1: team.append(t) sum=0 for i1 in range(len(team)): i=team[i1][0] j=team[i1][1] k=team[i1][2] sum=sum+(a*i+b*j+c*k) sum=sum%(2^64) print(sum) ```
instruction
0
79,683
17
159,366
No
output
1
79,683
17
159,367
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n players numbered from 0 to n-1 with ranks. The i-th player has rank i. Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let i, j, k be the ranks of players in the team and i < j < k, then the rank of the team is equal to A β‹… i + B β‹… j + C β‹… k. You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 2^{64}. Input The first line contains two space-separated integers n and m (3 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) β€” the number of players and the number of conflicting pairs. The second line contains three space-separated integers A, B and C (1 ≀ A, B, C ≀ 10^6) β€” coefficients for team rank calculation. Each of the next m lines contains two space-separated integers u_i and v_i (0 ≀ u_i, v_i < n, u_i β‰  v_i) β€” pair of conflicting players. It's guaranteed that each unordered pair of players appears in the input file no more than once. Output Print single integer β€” the total sum of ranks over all possible teams modulo 2^{64}. Examples Input 4 0 2 3 4 Output 64 Input 4 1 2 3 4 1 0 Output 38 Input 6 4 1 5 3 0 3 3 5 5 4 4 3 Output 164 Note In the first example all 4 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}. In the second example teams are following: {0, 2, 3}, {1, 2, 3}. In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}. Submitted Solution: ``` n, m = map(int,input().split()) a,b,c= map(int,input().split()) conf=[] for i in range(m): conf.append(list(map(int,input().split()))) team=[] for i in range(n-2): for j in range((i+1),(n-1)): for k in range((j+1),n): t=[i,j,k] resp=1 for l in range(m): if (conf[l][0] in t) and (conf[l][1] in t): resp=0; if resp==1: team.append(t) sum=0 for i1 in range(len(team)): i=team[i1][0] j=team[i1][1] k=team[i1][2] sum=sum+(a*i+b*j+c*k) sum=sum%(pow(2,64)) print(sum,team) ```
instruction
0
79,684
17
159,368
No
output
1
79,684
17
159,369
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input The first (and the only) line of input contains two integers n and k (1 ≀ n, k ≀ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas. Output Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Examples Input 18 2 Output 3 6 9 Input 9 10 Output 0 0 9 Input 1000000000000 5 Output 83333333333 416666666665 500000000002 Input 1000000000000 499999999999 Output 1 499999999999 500000000000
instruction
0
80,510
17
161,020
Tags: implementation, math Correct Solution: ``` n, k = map(int, input().split()) a = (n // 2) // (k + 1) b = a * k print(a, b, n - a - b) ```
output
1
80,510
17
161,021
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input The first (and the only) line of input contains two integers n and k (1 ≀ n, k ≀ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas. Output Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Examples Input 18 2 Output 3 6 9 Input 9 10 Output 0 0 9 Input 1000000000000 5 Output 83333333333 416666666665 500000000002 Input 1000000000000 499999999999 Output 1 499999999999 500000000000
instruction
0
80,511
17
161,022
Tags: implementation, math Correct Solution: ``` n, k = input().split() n, k = int(n), int(k) dip = gram = 0 dip = int( (n/2) / (k+1)) gram = int(dip * k) if (dip + gram > n/2): print(0, 0, n, end=' ') else: other=n-dip-gram print(int(dip), int(gram), int(other), end=' ') ```
output
1
80,511
17
161,023
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input The first (and the only) line of input contains two integers n and k (1 ≀ n, k ≀ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas. Output Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Examples Input 18 2 Output 3 6 9 Input 9 10 Output 0 0 9 Input 1000000000000 5 Output 83333333333 416666666665 500000000002 Input 1000000000000 499999999999 Output 1 499999999999 500000000000
instruction
0
80,512
17
161,024
Tags: implementation, math Correct Solution: ``` #1. diploma t=list(map(int,input().split())) half=t[0]//2 if(t[1]>half): print(*[0,0,t[0]]) elif(t[1]<=half): s=half//(t[1]+1) p=abs(half-s-t[1]*s) print(*[s,t[1]*s,t[0]-half+p]) ```
output
1
80,512
17
161,025
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input The first (and the only) line of input contains two integers n and k (1 ≀ n, k ≀ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas. Output Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Examples Input 18 2 Output 3 6 9 Input 9 10 Output 0 0 9 Input 1000000000000 5 Output 83333333333 416666666665 500000000002 Input 1000000000000 499999999999 Output 1 499999999999 500000000000
instruction
0
80,513
17
161,026
Tags: implementation, math Correct Solution: ``` n, k = map(int, input().split()) d = n//2//(k+1) print(d, k*d, n-(k+1)*d) ```
output
1
80,513
17
161,027