message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,752
14
169,504
Tags: implementation Correct Solution: ``` x,y = map(int,input().split()) if (y==0) or (y==1 and x!=0): print("No") else: if (x-(y-1))%2==0 and x>=(y-1) and y!=0: print("Yes") else: print("No") ```
output
1
84,752
14
169,505
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,753
14
169,506
Tags: implementation Correct Solution: ``` [copies, originals] = input().split() copies = int(copies) originals = int(originals) if originals < 1 : print("No") elif originals == 1 and copies > 0 : print("No") elif originals > copies + 1: print("No") elif (copies - originals) % 2 == 0 : print("No") else : print("Yes") ```
output
1
84,753
14
169,507
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,754
14
169,508
Tags: implementation Correct Solution: ``` def orig_copies(x, y): x1, y1 = y, y - 1 if y1 == 0 and x > 0: return "No" elif y1 > 0 and (x - y1) % 2 == 1: return "No" elif y == 0: return "No" elif x - y1 < 0: return "No" return "Yes" X, Y = [int(i) for i in input().split()] print(orig_copies(X, Y)) ```
output
1
84,754
14
169,509
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,755
14
169,510
Tags: implementation Correct Solution: ``` X,Y= input().split() X,Y = [int(X),int(Y)] if X % 2 == 0 and Y % 2 == 0 or X % 2 != 0 and Y % 2 != 0 or X < Y - 1 or Y == 0 or Y == 1 and X != 0: print("No") else: print("Yes") ```
output
1
84,755
14
169,511
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,756
14
169,512
Tags: implementation Correct Solution: ``` import sys x, y = map(int, input().split()) print("NO" if (y == 1 and x != 0) or x % 2 == y % 2 or y == 0 or y > x + 1 else "YES") ```
output
1
84,756
14
169,513
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,757
14
169,514
Tags: implementation Correct Solution: ``` x,y=map(int,input().split()) if y-1<=0 and x!=0: print("No") elif x<y-1: print("No") else: if (x-y+1)%2==0: print("Yes") else: print("No") ```
output
1
84,757
14
169,515
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` x, y = [int(i) for i in input().split()] if (x>0 and y==1) or y==0 or x+1<y or (x-y+1)%2!=0: print('no') else: print('yes') ```
instruction
0
84,759
14
169,518
Yes
output
1
84,759
14
169,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` import sys f=sys.stdin.read() x,y = f.split() x,y = int(x), int(y) if (x>=y-1 and (x+y)%2==1 and x>=0 and y>=2) or (x==0 and y==1): sys.stdout.write('Yes') else: sys.stdout.write('No') ```
instruction
0
84,760
14
169,520
Yes
output
1
84,760
14
169,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≀ x, y ≀ 109) β€” the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` c,o=[int(i) for i in input().split()] if o>=2 and o%2==0 and c>=o-1 and c%2!=0: print ("yes") elif o%2!=0 and c>=o-1 and c%2==0: print("yes") else: print("no") ```
instruction
0
84,765
14
169,530
No
output
1
84,765
14
169,531
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,766
14
169,532
Tags: graphs, implementation, math Correct Solution: ``` from collections import defaultdict from sys import exit class Graph: def __init__(self): self.adj=defaultdict(list) def add_edge(self,x,y): self.adj[x].append(y) self.adj[y].append(x) def check(self): for i in range(1,6): for j in range(i+1,6): for k in range(j+1,6): if j not in self.adj[i] and k not in self.adj[j] and i not in self.adj[k]: print("WIN") exit(0) if j in self.adj[i] and k in self.adj[j] and i in self.adj[k]: print("WIN") exit(0) print("FAIL") g=Graph() n=int(input()) for _ in range(n): x,y=map(int,input().split()) g.add_edge(x,y) g.check() ```
output
1
84,766
14
169,533
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,767
14
169,534
Tags: graphs, implementation, math Correct Solution: ``` n = int(input()) l = [0, 0, 0, 0, 0] for i in range(n): a, b = map(int, input().split()) for j in range(6): if a == j: l[j-1] += 1 if b == j: l[j-1] += 1 if l.count(2) !=5: print("WIN") else: print("FAIL") # Made By Mostafa_Khaled ```
output
1
84,767
14
169,535
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,768
14
169,536
Tags: graphs, implementation, math Correct Solution: ``` import sys n=int(input()) list1=[[0 for i in range(6)]for i in range(6)] for i in range(n): a,b=map(int,input().split()) list1[a][b]=1 list1[b][a]=1 for i in range(1,6): for j in range(1,6): for k in range(1,6): if(i!=j and j!=k and i!=k): if(list1[i][j]==1 and list1[j][k]==1 and list1[k][i]==1): # print(i,j,k) f=1 print("WIN") sys.exit() elif(list1[i][j]==0 and list1[j][k]==0 and list1[k][i]==0): # print(i,j,k) print("WIN") sys.exit() print("FAIL") ```
output
1
84,768
14
169,537
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,769
14
169,538
Tags: graphs, implementation, math Correct Solution: ``` from collections import defaultdict n = int(input()) d = defaultdict(list) l = [] for i in range(1 , 6): for j in range(i+1 , 6): for k in range(j+1 , 6): l.append([i , j , k]) for i in range(n): u , v = map(int,input().split()) d[u].append(v) d[v].append(u) for i in l : if i[0] in d[i[1]] and i[0] in d[i[2]] and i[1] in d[i[2]]: print('WIN') exit(0) elif i[0] not in d[i[1]] and i[0] not in d[i[2]] and i[1] not in d[i[2]]: print('WIN') exit(0) print('FAIL') ```
output
1
84,769
14
169,539
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,770
14
169,540
Tags: graphs, implementation, math Correct Solution: ``` import sys input = sys.stdin.readline m = int(input()) neigh = {1: [], 2: [], 3: [], 4: [], 5: []} for i in range(m): a, b = map(int, input().split()) neigh[a].append(b) neigh[b].append(a) for key in neigh: if len(neigh[key]) != 2: print("WIN") break else: print("FAIL") ```
output
1
84,770
14
169,541
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,771
14
169,542
Tags: graphs, implementation, math Correct Solution: ``` m = int(input()) L = [[False for i in range(5)] for j in range(5)] for i in range(m): relation = [int(s) for s in input().split()] L[relation[0]-1][relation[1]-1] = True L[relation[1]-1][relation[0]-1] = True bool = False for i in range(3): for j in range(i+1,4): for k in range(j+1,5): bool = bool or (L[i][j] == L[j][k] and L[j][k] == L[i][k]) if bool == False: print("FAIL") else: print("WIN") ```
output
1
84,771
14
169,543
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,772
14
169,544
Tags: graphs, implementation, math Correct Solution: ``` m=int(input()) n={} n[5]=0 n[4]=0 n[3]=0 n[2]=0 n[1]=0 for i in range(m): g=input().split() n[int(g[0])]+=1 n[int(g[1])]+=1 if n[1]==n[2]==n[3]==n[4]==n[5]==2: print('FAIL') exit() print('WIN') ```
output
1
84,772
14
169,545
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL
instruction
0
84,773
14
169,546
Tags: graphs, implementation, math Correct Solution: ``` def s(): m = int(input()) s = set(tuple(sorted(list(map(int,input().split()))))for _ in range(m)) for i in range(1,4): for j in range(i+1,5): for k in range(j+1,6): r = ((i,j)in s) + ((j,k)in s) + ((i,k)in s) if r%3 == 0: print('WIN') return print('FAIL') s() ```
output
1
84,773
14
169,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` m = int(input()) l = [0]*5 for i in range(m): a, b = map(int, input().split()) l[a-1] += 1 l[b-1] += 1 if l.count(2) == 5: print('FAIL') else: print('WIN') ```
instruction
0
84,774
14
169,548
Yes
output
1
84,774
14
169,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` class CodeforcesTask94BSolution: def __init__(self): self.result = '' self.m = 0 self.edges = [] def read_input(self): self.m = int(input()) for x in range(self.m): self.edges.append([int(y) for y in input().split(" ")]) def process_task(self): used = set() conngraph = [set() for x in range(5)] for edge in self.edges: used.add(str(edge)) conngraph[edge[0] - 1].add(edge[1] - 1) conngraph[edge[1] - 1].add(edge[0] - 1) full = {1, 2, 3, 4, 0} nconngraph = [full - x for x in conngraph] has = False for a in range(5): for b in range(5): for c in range(5): if len(set([a, b, c])) == 3: if b in conngraph[a] and c in conngraph[a] and a in conngraph[b] and c in conngraph[b] and b in conngraph[c] and a in conngraph[c]: has = True if b in nconngraph[a] and c in nconngraph[a] and a in nconngraph[b] and c in nconngraph[b] and b in nconngraph[c] and a in nconngraph[c]: has = True self.result = "WIN" if has else "FAIL" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask94BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
instruction
0
84,775
14
169,550
Yes
output
1
84,775
14
169,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` m = int(input()) D = [[0]*5 for i in range(5)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 D[a][b] = 1 D[b][a] = 1 import itertools for c in itertools.combinations(range(5), 3): u, v, w = c if D[u][v] == D[v][w] and D[v][w] == D[w][u]: print('WIN') exit() else: print('FAIL') ```
instruction
0
84,776
14
169,552
Yes
output
1
84,776
14
169,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` #https://codeforces.com/problemset/problem/94/B def main(): ''' if we visualize friends and relations as a graph, any triangle or any missing triangle would represent a WIN the only way that this can not happen is if every node has exactly to relations. furthermore, in order for this to happen there has to be exactly 5 relations''' n = int(input()) if n != 5: print("WIN") else: relations_per_node = [0,0,0,0,0] for i in range(n): friend1, friend2 = (int(f) for f in input().split()) relations_per_node[friend1-1] += 1 relations_per_node[friend2-1] += 1 for i in range(5): if relations_per_node[i] != 2: print("WIN") break else: print("FAIL") if __name__ == '__main__': main() ```
instruction
0
84,777
14
169,554
Yes
output
1
84,777
14
169,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` try: t=int(input()) m=[0]*10 for i in range(0,t): a,b=list(map(int,input().split(" "))) m[a]+=1 m[b]+=1 g=0 for i in range(1,6): if (m[i]!=1 or m[i]!=0) and m[i]!=3: g+=1 if g==5: print("FAIL") else: print("WIN") except: pass ```
instruction
0
84,778
14
169,556
No
output
1
84,778
14
169,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` import sys input = sys.stdin.readline m = int(input()) if m == 0: print("WIN") else: neigh = {1: [], 2: [], 3: [], 4: [], 5: []} for i in range(m): a, b = map(int, input().split()) neigh[a].append(b) neigh[b].append(a) l = len(neigh[1]) for key in neigh: if len(neigh[key]) != l: print("WIN") break else: print("FAIL") ```
instruction
0
84,779
14
169,558
No
output
1
84,779
14
169,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` from collections import defaultdict as df d=df(list) n=int(input()) visited=[0]*6 for i in range(n): a,b=list(map(int,input().split())) d[a].append(b) d[b].append(a) visited[a]=True visited[b]=True count=0 for i in d: if len(d[i])==1: count+=1 flag=0 for i in d: if len(d[i])>=3: flag=1 break for i in range(1,6): if visited[i]==False: flag=1 break if flag: print('WIN') else: print('FAIL') ```
instruction
0
84,780
14
169,560
No
output
1
84,780
14
169,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" β€” he kept on repeating in his mind. β€” "Let's take, say, Max, Ilya, Vova β€” here, they all know each other! And now let's add Dima and Oleg to Vova β€” none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≀ m ≀ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ 5;ai β‰  bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` #problem 2 num = int(input()) val = [[],[],[],[],[]] for i in range(num): a,b = list(map(int,input().split(" "))) val[a-1].append(b-1) val[b-1].append(a-1) one = False three = False for i in val: if len(i) == 3: three = True if len(i) == 1: one = True if(one or three): print("WIN") else: print('FAIL') ```
instruction
0
84,781
14
169,562
No
output
1
84,781
14
169,563
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,022
14
170,044
Tags: binary search, implementation Correct Solution: ``` n = int(input().strip()) m = int(input().strip()) max = 0 total = 0 for i in range(n): a = int(input().strip()) if (a > max): max = a total += a if (total + m <= n * max): print(max) else: print((total+m-1)//n+1) print(m + max) ```
output
1
85,022
14
170,045
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,023
14
170,046
Tags: binary search, implementation Correct Solution: ``` import math for i in range(1): n=int(input()) m=int(input()) l=[] s=0 for i in range(n): k=int(input()) s+=k l.append(k) print(max((m+s+n-1)//n,max(l)),(max(l)+m)) ```
output
1
85,023
14
170,047
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,024
14
170,048
Tags: binary search, implementation Correct Solution: ``` from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math import io import os import math import bisect #?############################################################ def isPrime(x): for i in range(2, x): if i*i > x: break if (x % i == 0): return False return True #?############################################################ def ncr(n, r, p): num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p #?############################################################ def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n))+1, 2): while n % i == 0: l.append(int(i)) n = n / i if n > 2: l.append(n) return list(set(l)) #?############################################################ def power(x, y, p): res = 1 x = x % p if (x == 0): return 0 while (y > 0): if ((y & 1) == 1): res = (res * x) % p y = y >> 1 x = (x * x) % p return res #?############################################################ def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #?############################################################ def digits(n): c = 0 while (n > 0): n //= 10 c += 1 return c #?############################################################ def ceil(n, x): if (n % x == 0): return n//x return n//x+1 #?############################################################ def mapin(): return map(int, input().split()) #?############################################################ # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # python3 15.py<in>op input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n =int(input()) m =int(input()) l = [] for i in range(n): a = int(input()) l.append(a) l.sort() a = l[-1]+m b = l[-1]*n - sum(l) if(b >= m): print(l[-1], a) else: m-=b c = l[-1] if(m%n == 0): print(c+ m//n, a) else: print(c+ 1+ m//n, a) ```
output
1
85,024
14
170,049
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,025
14
170,050
Tags: binary search, implementation Correct Solution: ``` def indmin(m): a=min(m) for i in range(len(m)): if m[i] == a: return i a=int(input()) b=int(input()) m=[] ind=0 d=0 for i in range(a): m.append(int(input())) c=list(m) for i in range(b): c[indmin(c)]+=1 d=max(m) + b print(max(c),d) ```
output
1
85,025
14
170,051
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,026
14
170,052
Tags: binary search, implementation Correct Solution: ``` n = int(input()) m = int(input()) bench = [int(input()) for i in range(n)] mx = max(bench) + m for i in range(m): bench[bench.index(min(bench))] += 1 print(max(bench), mx) ```
output
1
85,026
14
170,053
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,027
14
170,054
Tags: binary search, implementation Correct Solution: ``` #510_A n = int(input()) p = int(input()) ms = [] for i in range(0, n): m = int(input()) ms.append(m) mx = max(ms) m2 = mx + p diffs = sum([mx - i for i in ms]) if p < diffs: m1 = mx else: m1 = (p - diffs) if m1 % n != 0: m1 = m1 // n + 1 else: m1 = m1 // n m1 += mx print(m1, m2) ```
output
1
85,027
14
170,055
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,028
14
170,056
Tags: binary search, implementation Correct Solution: ``` import math n = int(input()) m = int(input()) abc = m a = [] ans = 0 for i in range(n): x = int(input()) a.append(x) a.sort() for j in range(len(a)): ans += a[-1] - a[j] if j == len(a) - 1: if ans >= m: ans = max(a) else: ans = math.ceil((m - ans) / n) + max(a) print(ans, max(a) + abc) ```
output
1
85,028
14
170,057
Provide tags and a correct Python 3 solution for this coding contest problem. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
instruction
0
85,029
14
170,058
Tags: binary search, implementation Correct Solution: ``` def inp(): return list(map(int,input().split())) n,=inp() m,=inp() a = [int(input()) for i in range(n)] s=sum(a) mx=max(a) mi= max([mx, int((s+m+n-1)/n)]) mx= mx + m print(mi,mx) ```
output
1
85,029
14
170,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` def mi(): return map(int, input().split()) n = int(input()) m = int(input()) a = [0]*n for i in range(n): a[i] = int(input()) ma = max(a) maxk = ma+m a.sort() import math for i in a: m-=min(m,ma-i) if m==0: print (ma, maxk) else: print (ma+math.ceil(m/n), maxk) ```
instruction
0
85,030
14
170,060
Yes
output
1
85,030
14
170,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` from math import ceil n = int(input().strip()) m = int(input().strip()) k = [] for i in range(n): ai = int(input().strip()) k.append(ai) if n==1: print(m+ai,m+ai) else: mx = max(k) l = max(k)+m ''' ans = max(k)*n-m if ans>: print(m,l) else: print(abs(m-n)+max(k),l) ''' h = max(mx,ceil((sum(k)+m)/n)) print(h,l) ```
instruction
0
85,031
14
170,062
Yes
output
1
85,031
14
170,063
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` n=int(input()) m=int(input()) l=[int(input()) for i in range(n)] print(max((sum(l)+n+m-1)//n,max(l)),max(l)+m) ```
instruction
0
85,032
14
170,064
Yes
output
1
85,032
14
170,065
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` from math import * n=int(input()) m=int(input()) l=[] for u in range(n): l.append(int(input())) s=sum(l)+m c=ceil(s/n) q=max(l) k=0 for i in range(n): f=l[i]+m if(f>k): k=f if(c>=q): print(c,k) else: print(q,k) ```
instruction
0
85,033
14
170,066
Yes
output
1
85,033
14
170,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` import sys #sys.stdin=open('in','r') #sys.stdout=open('out','w') #import math #import queue #import random #sys.setrecursionlimit(int(1e6)) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ################################################################ ############ ---- THE ACTUAL CODE STARTS BELOW ---- ############ n=inp() m=inp() a=[0]*n for i in range(n): a[i]=inp() mini=min(a) hi=m lo=mini while hi>=lo: mid=(hi+lo)//2 temp=m for x in a: if x<=mid: temp-=min(temp,mid-x) if temp==0: mini=mid hi=mid-1 else: lo=mid+1 maxi=max(a)+m print(mini,maxi) ```
instruction
0
85,034
14
170,068
No
output
1
85,034
14
170,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` x=int(input()) a=int(input()) l=[] for _ in range(x): d=int(input()) l+=[d] max=max(l)+a s=a//x if a%x==0: print(min(l)+s,max) else: print(min(l)+s+1,max) ```
instruction
0
85,035
14
170,070
No
output
1
85,035
14
170,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` #------------------------------------------------------------------------------- #http://codeforces.com/contest/1042/problem/A #------------------------------------------------------------------------------- def main(): n = int(input()) m = int(input()) a = [] for i in range(n): a.append(int(input())) M = max(a) MAX = M + m for i in range(n): while(a[i] < M): if m < 0: break a[i]+= 1 m-=1 average = m//n m = m%n if average: for i in range(n): a[i]+=average m-=1 for i in range(n): if not m: break a[i]+=1 m-=1 MIN = max(a) print(MIN) print(MAX) if __name__ == '__main__': main() ```
instruction
0
85,036
14
170,072
No
output
1
85,036
14
170,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k. Nobody leaves the taken seat during the whole process. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of benches in the park. The second line contains a single integer m (1 ≀ m ≀ 10 000) β€” the number of people additionally coming to the park. Each of the next n lines contains a single integer a_i (1 ≀ a_i ≀ 100) β€” the initial number of people on the i-th bench. Output Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park. Examples Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 Note In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench. The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it. Submitted Solution: ``` n1 = input() n = int(n1) m1 = input() m = int(m1) benches = [] i = 0 while i < n: benches.append(input()) i = i + 1 maxi = int(max(benches)) + m i = 0 while i < n: #przerobione m m = m - int(abs(int(benches[i]) - int(max(benches)))) i += 1 mini = int(max(benches)) + (m // n) if m % n != 0: mini += 1 print(f"{mini} {maxi}") ```
instruction
0
85,037
14
170,074
No
output
1
85,037
14
170,075
Provide tags and a correct Python 3 solution for this coding contest problem. Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent. After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as E = βˆ‘ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords. We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P β‹… Q^{-1} mod (10^9 + 7). Input The first line contains two integers n and T (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ T ≀ 2 β‹… 10^{14}) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains n integers t_1, t_2, ..., t_n (1 ≀ t_i ≀ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. Output Print one integer β€” the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P β‹… Q^{-1} mod (10^9 + 7). Examples Input 3 5 2 2 2 Output 750000007 Input 3 5 2 1 2 Output 125000003 Note The answer for the first sample is equal to 14/8. The answer for the second sample is equal to 17/8.
instruction
0
85,090
14
170,180
Tags: combinatorics, dp, number theory, probabilities, two pointers Correct Solution: ``` mod = 10 ** 9 + 7 MAX = 2 * 10 ** 5+2 r = [1] * MAX factorial = [1] * MAX rfactorial = [1] * MAX rp = [1] * MAX #Permite precalcular factorial hasta "MAX", para evitar tener que calcularlo varias veces #dentro de la ejecucion del programa. for i in range(2, MAX): factorial[i] = i * factorial[i - 1] % mod r[i] = mod - (mod // i) * r[mod%i] % mod rfactorial[i] = rfactorial[i-1] * r[i] % mod #Calcula el inverso de "p" para evitar usar fracciones racionales. for i in range(1, MAX): rp[i] = rp[i - 1] * (mod + 1) // 2 % mod n, T = list(map(int, input().split())) t = list(map(int, input().split())) t.append(10**10+1) #Permite calcular las Combinacione de n en k. def Combination(n,k): return factorial[n]*rfactorial[k]*rfactorial[n-k] S=0 E=0 for i in range(0,n+1): sim = 0 for add in range(2): l_, r_ = max(0, T-S-t[i] + add), min(i, T-S) for x in range(l_, r_+1): sim += Combination(i,x) * rp[i+1] E = (E + i * sim) % mod S += t[i] print(E) ```
output
1
85,090
14
170,181
Provide tags and a correct Python 3 solution for this coding contest problem. Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent. After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as E = βˆ‘ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords. We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P β‹… Q^{-1} mod (10^9 + 7). Input The first line contains two integers n and T (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ T ≀ 2 β‹… 10^{14}) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains n integers t_1, t_2, ..., t_n (1 ≀ t_i ≀ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. Output Print one integer β€” the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P β‹… Q^{-1} mod (10^9 + 7). Examples Input 3 5 2 2 2 Output 750000007 Input 3 5 2 1 2 Output 125000003 Note The answer for the first sample is equal to 14/8. The answer for the second sample is equal to 17/8.
instruction
0
85,091
14
170,182
Tags: combinatorics, dp, number theory, probabilities, two pointers Correct Solution: ``` MOD = 10 ** 9 + 7 MAX = 5 * 10 ** 5 fac, ifac = [1] * MAX, [1] * MAX for i in range(2, MAX): fac[i] = fac[i - 1] * i % MOD ifac[-1] = pow(fac[-1], MOD - 2, MOD) for i in range(MAX - 2, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % MOD ipow2 = [1] * MAX for i in range(1, MAX): ipow2[i] = ipow2[i - 1] * (MOD + 1) // 2 % MOD choose = lambda n, k: fac[n] * ifac[k] % MOD * ifac[n - k] % MOD n, t = map(int, input().split()) a = list(map(int, input().split())) s = 0 p = [1] + [0] * (n + 1) k = cur = 0 for i in range(n): s += a[i] if s > t: break if s + i + 1 <= t: p[i + 1] = 1 continue if not cur: k = t - s for j in range(k + 1): cur += choose(i + 1, j) cur %= MOD else: cur = cur * 2 - choose(i, k) while k > t - s: cur -= choose(i + 1, k) k -= 1 cur %= MOD p[i + 1] = cur * ipow2[i + 1] % MOD print(sum((p[i] - p[i + 1]) * i % MOD for i in range(1, n + 1)) % MOD) ```
output
1
85,091
14
170,183
Provide tags and a correct Python 3 solution for this coding contest problem. Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent. After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as E = βˆ‘ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords. We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P β‹… Q^{-1} mod (10^9 + 7). Input The first line contains two integers n and T (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ T ≀ 2 β‹… 10^{14}) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains n integers t_1, t_2, ..., t_n (1 ≀ t_i ≀ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. Output Print one integer β€” the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P β‹… Q^{-1} mod (10^9 + 7). Examples Input 3 5 2 2 2 Output 750000007 Input 3 5 2 1 2 Output 125000003 Note The answer for the first sample is equal to 14/8. The answer for the second sample is equal to 17/8.
instruction
0
85,092
14
170,184
Tags: combinatorics, dp, number theory, probabilities, two pointers Correct Solution: ``` from sys import stdin, stdout, exit mod = 10**9 + 7 def modinv(x): return pow(x, mod-2, mod) N = 2*10**5 + 10 facts = [1]*N for i in range(1,N): facts[i] = facts[i-1] * i facts[i] %= mod def binom(n, k): ans = modinv(facts[k]) * modinv(facts[n-k]) ans %= mod ans *= facts[n] ans %= mod return ans #print("Finished preprocess") n, T = map(int, stdin.readline().split()) ts = list(map(int, stdin.readline().split())) ans = 0 total = sum(ts) running = total last_idx = n-1 while running > T: running -= ts[last_idx] last_idx -= 1 #print(last_idx+1) last_bd = -1 last_sum = 0 idx = last_idx while running + idx + 1 > T: bd = T - running # print("time remaining for", idx+1, "flips is", bd) cur_sum = last_sum + (binom(idx+1, last_bd) if last_bd >= 0 else 0) cur_sum *= modinv(2) cur_sum %= mod for fresh in range(last_bd+1, bd+1): cur_sum += binom(idx+1, fresh) cur_sum %= mod # print("pr of", idx+1, "flips is", cur_sum, cur_sum / (2**(idx+1))) ans += cur_sum * modinv(pow(2, idx+1, mod)) ans %= mod running -= ts[idx] last_bd = bd last_sum = cur_sum idx -= 1 #print(idx+1, "freebies") ans += idx+1 ans %= mod print(ans) ```
output
1
85,092
14
170,185
Provide tags and a correct Python 3 solution for this coding contest problem. Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent. After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as E = βˆ‘ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords. We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P β‹… Q^{-1} mod (10^9 + 7). Input The first line contains two integers n and T (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ T ≀ 2 β‹… 10^{14}) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains n integers t_1, t_2, ..., t_n (1 ≀ t_i ≀ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. Output Print one integer β€” the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P β‹… Q^{-1} mod (10^9 + 7). Examples Input 3 5 2 2 2 Output 750000007 Input 3 5 2 1 2 Output 125000003 Note The answer for the first sample is equal to 14/8. The answer for the second sample is equal to 17/8.
instruction
0
85,093
14
170,186
Tags: combinatorics, dp, number theory, probabilities, two pointers Correct Solution: ``` mod = 10 ** 9 + 7 MAX = 2 * 10 ** 5+2 r = [1] * MAX factorial = [1] * MAX rfactorial = [1] * MAX rp = [1] * MAX for i in range(2, MAX): factorial[i] = i * factorial[i - 1] % mod r[i] = mod - (mod // i) * r[mod%i] % mod rfactorial[i] = rfactorial[i-1] * r[i] % mod for i in range(1, MAX): rp[i] = rp[i - 1] * (mod + 1) // 2 % mod n, T = list(map(int, input().split())) t = list(map(int, input().split())) t.append(10**10+1) def Combination(n,k): return factorial[n]*rfactorial[k]*rfactorial[n-k] S=0 EX=0 for i in range(len(t)): cof = rp[1] for add in range(2): l_, r_ = max(0, T-S-t[i] + add), min(i, T-S) for x in range(l_, r_+1): EX = ( EX + i * Combination(i,x) * rp[i+1]) % mod S += t[i] print(EX) ```
output
1
85,093
14
170,187
Provide tags and a correct Python 3 solution for this coding contest problem. Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent. After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as E = βˆ‘ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords. We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P β‹… Q^{-1} mod (10^9 + 7). Input The first line contains two integers n and T (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ T ≀ 2 β‹… 10^{14}) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains n integers t_1, t_2, ..., t_n (1 ≀ t_i ≀ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. Output Print one integer β€” the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P β‹… Q^{-1} mod (10^9 + 7). Examples Input 3 5 2 2 2 Output 750000007 Input 3 5 2 1 2 Output 125000003 Note The answer for the first sample is equal to 14/8. The answer for the second sample is equal to 17/8.
instruction
0
85,094
14
170,188
Tags: combinatorics, dp, number theory, probabilities, two pointers Correct Solution: ``` mod = 10 ** 9 + 7 MAX = 2 * 10 ** 5+2 n, T = list(map(int, input().split())) t = [0] t += list(map(int, input().split())) t += [MAX] r = [1] * MAX factorial = [1] * MAX rfactorial = [1] * MAX rp = [1] * MAX sim = 0 sim_n = 0 sim_k = 0 E=0 S = [t[0]]*len(t) for i in range(1,len(t)): S[i] = S[i-1]+t[i] #Permite precalcular factorial hasta "MAX", para evitar tener que calcularlo varias veces #dentro de la ejecucion del programa. for i in range(2, MAX): factorial[i] = i * factorial[i - 1] % mod r[i] = mod - (mod // i) * r[mod%i] % mod rfactorial[i] = rfactorial[i-1] * r[i] % mod #Calcula el inverso de "p" para evitar usar fracciones racionales. for i in range(1, MAX): rp[i] = rp[i - 1] * (mod + 1) // 2 % mod #Permite calcular las Combinaciones de n en k. def Combination(n,k): if n < k: return 0 return factorial[n]*rfactorial[k]*rfactorial[n-k] def simC(x): aux = 0 mi = min(x,T-S[x]) for i in range(0,mi+1): aux += Combination(x,i)%mod return x,mi,aux def next_simC( next_x): mi1 = min(next_x,T-S[next_x]) aux_sim = 2*sim % mod aux_sim = (aux_sim + Combination(sim_n,sim_k + 1))%mod aux_sim_n = sim_n + 1 aux_sim_k = sim_k + 1 while aux_sim_k > mi1: aux_sim = (aux_sim - Combination(aux_sim_n,aux_sim_k)) % mod aux_sim_k -= 1 return aux_sim_n, aux_sim_k, aux_sim i = 1 while i <= n and S[i] + i <= T: i +=1 E +=1 if i <= n: sim_n,sim_k,sim = simC(i) for x in range(i,n+1): E = (E + rp[x]*sim)%mod if T-S[x+1] < 0: break sim_n,sim_k,sim = next_simC(x+1) print(E) ```
output
1
85,094
14
170,189
Provide tags and a correct Python 3 solution for this coding contest problem. Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent. After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as E = βˆ‘ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords. We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P β‹… Q^{-1} mod (10^9 + 7). Input The first line contains two integers n and T (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ T ≀ 2 β‹… 10^{14}) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains n integers t_1, t_2, ..., t_n (1 ≀ t_i ≀ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. Output Print one integer β€” the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P β‹… Q^{-1} mod (10^9 + 7). Examples Input 3 5 2 2 2 Output 750000007 Input 3 5 2 1 2 Output 125000003 Note The answer for the first sample is equal to 14/8. The answer for the second sample is equal to 17/8.
instruction
0
85,095
14
170,190
Tags: combinatorics, dp, number theory, probabilities, two pointers Correct Solution: ``` mod = 10 ** 9 + 7 MAX = 2 * 10 ** 5 + 10 r = [1] * MAX f = [1] * MAX rf = [1] * MAX rp2 = [1] * MAX for i in range(2, MAX): f[i] = f[i - 1] * i % mod r[i] = mod - (mod // i) * r[mod%i] % mod rf[i] = rf[i-1] * r[i] % mod for i in range(1, MAX): rp2[i] = rp2[i - 1] * (mod + 1) // 2 % mod n, T = list(map(int, input().split())) t = list(map(int, input().split())) t.append(10**14+1) S=0 E=0 for i in range(len(t)): cof = rp2[1] for add in range(2): l_, r_ = max(0, T-S-(t[i]-add)), min(i, T-S) for x in range(l_, r_+1): E = ( E + i * (f[i]*rf[x]*rf[i-x]) * rp2[i] * cof ) % mod S += t[i] print(E) ```
output
1
85,095
14
170,191
Provide tags and a correct Python 3 solution for this coding contest problem. Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent. After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as E = βˆ‘ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords. We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P β‹… Q^{-1} mod (10^9 + 7). Input The first line contains two integers n and T (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ T ≀ 2 β‹… 10^{14}) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains n integers t_1, t_2, ..., t_n (1 ≀ t_i ≀ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. Output Print one integer β€” the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P β‹… Q^{-1} mod (10^9 + 7). Examples Input 3 5 2 2 2 Output 750000007 Input 3 5 2 1 2 Output 125000003 Note The answer for the first sample is equal to 14/8. The answer for the second sample is equal to 17/8.
instruction
0
85,096
14
170,192
Tags: combinatorics, dp, number theory, probabilities, two pointers Correct Solution: ``` mod = 10 ** 9 + 7 MAX = 2 * 10 ** 5+1 r = [1] * MAX factorial = [1] * MAX rfactorial = [1] * MAX rp = [1] * MAX for i in range(2, MAX): factorial[i] = i * factorial[i - 1] % mod r[i] = mod - (mod // i) * r[mod%i] % mod rfactorial[i] = rfactorial[i-1] * r[i] % mod for i in range(1, MAX): rp[i] = rp[i - 1] * (mod + 1) // 2 % mod n, T = list(map(int, input().split())) t = list(map(int, input().split())) t.append(10**10+1) S=0 EX=0 for i in range(len(t)): cof = rp[1] for add in range(2): l_, r_ = max(0, T-S-t[i] + add), min(i, T-S) for x in range(l_, r_+1): EX = ( EX + i*(factorial[i]*rfactorial[x]*rfactorial[i-x]) * rp[i]*cof) % mod S += t[i] print(EX) ```
output
1
85,096
14
170,193
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0). Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend. You (suddenly!) have the ability to see the future. You know that during the day you will receive n messages, the i-th message will be received from the friend with ID id_i (1 ≀ id_i ≀ 10^9). If you receive a message from id_i in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages. Otherwise (i.e. if there is no conversation with id_i on the screen): * Firstly, if the number of conversations displayed on the screen is k, the last conversation (which has the position k) is removed from the screen. * Now the number of conversations on the screen is guaranteed to be less than k and the conversation with the friend id_i is not displayed on the screen. * The conversation with the friend id_i appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all n messages. Input The first line of the input contains two integers n and k (1 ≀ n, k ≀ 200) β€” the number of messages and the number of conversations your smartphone can show. The second line of the input contains n integers id_1, id_2, ..., id_n (1 ≀ id_i ≀ 10^9), where id_i is the ID of the friend which sends you the i-th message. Output In the first line of the output print one integer m (1 ≀ m ≀ min(n, k)) β€” the number of conversations shown after receiving all n messages. In the second line print m integers ids_1, ids_2, ..., ids_m, where ids_i should be equal to the ID of the friend corresponding to the conversation displayed on the position i after receiving all n messages. Examples Input 7 2 1 2 3 2 1 3 2 Output 2 2 1 Input 10 4 2 3 3 1 1 2 1 2 3 3 Output 3 1 3 2 Note In the first example the list of conversations will change in the following way (in order from the first to last message): * []; * [1]; * [2, 1]; * [3, 2]; * [3, 2]; * [1, 3]; * [1, 3]; * [2, 1]. In the second example the list of conversations will change in the following way: * []; * [2]; * [3, 2]; * [3, 2]; * [1, 3, 2]; * and then the list will not change till the end.
instruction
0
85,101
14
170,202
Tags: implementation Correct Solution: ``` n,k=map(int, input().split()) l=list(map(int, input().split())) y=[] x=set() for i in l: if i not in x: x.add(i) y.append(i) if len(x)>k: x.remove(y[0]) y.pop(0) print(len(x)) print(*y[::-1]) ```
output
1
85,101
14
170,203
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0). Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend. You (suddenly!) have the ability to see the future. You know that during the day you will receive n messages, the i-th message will be received from the friend with ID id_i (1 ≀ id_i ≀ 10^9). If you receive a message from id_i in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages. Otherwise (i.e. if there is no conversation with id_i on the screen): * Firstly, if the number of conversations displayed on the screen is k, the last conversation (which has the position k) is removed from the screen. * Now the number of conversations on the screen is guaranteed to be less than k and the conversation with the friend id_i is not displayed on the screen. * The conversation with the friend id_i appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all n messages. Input The first line of the input contains two integers n and k (1 ≀ n, k ≀ 200) β€” the number of messages and the number of conversations your smartphone can show. The second line of the input contains n integers id_1, id_2, ..., id_n (1 ≀ id_i ≀ 10^9), where id_i is the ID of the friend which sends you the i-th message. Output In the first line of the output print one integer m (1 ≀ m ≀ min(n, k)) β€” the number of conversations shown after receiving all n messages. In the second line print m integers ids_1, ids_2, ..., ids_m, where ids_i should be equal to the ID of the friend corresponding to the conversation displayed on the position i after receiving all n messages. Examples Input 7 2 1 2 3 2 1 3 2 Output 2 2 1 Input 10 4 2 3 3 1 1 2 1 2 3 3 Output 3 1 3 2 Note In the first example the list of conversations will change in the following way (in order from the first to last message): * []; * [1]; * [2, 1]; * [3, 2]; * [3, 2]; * [1, 3]; * [1, 3]; * [2, 1]. In the second example the list of conversations will change in the following way: * []; * [2]; * [3, 2]; * [3, 2]; * [1, 3, 2]; * and then the list will not change till the end.
instruction
0
85,102
14
170,204
Tags: implementation Correct Solution: ``` n, k = map(int, input().split()) d = {} ls = [] for x in list(map(int, input().split())): if d.get(x) == None: d[x] = 0 ls.append(x) if len(ls) > k: d[ls[0]] = None del ls[0] print(len(ls)) ls.reverse() print(' '.join(map(str, ls))) ```
output
1
85,102
14
170,205