message
stringlengths
2
67k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
463
109k
cluster
float64
19
19
__index_level_0__
int64
926
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible. Input The first line of the input contains integer n (2 ≀ n ≀ 100) β€” the number of cards in the deck. It is guaranteed that n is even. The second line contains the sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is equal to the number written on the i-th card. Output Print n / 2 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them. Examples Input 6 1 5 7 4 4 3 Output 1 3 6 2 4 5 Input 4 10 10 10 10 Output 1 2 3 4 Note In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values ai are equal. Thus, any distribution is acceptable. Submitted Solution: ``` n = int(int(input())/2) a = list(map(int, input().split())) x = int(sum(a)/n) b = [] for i in range(len(a)): if i in b: continue else: for j in range(i+1,len(a)): if a[i] + a[j] == x: print(i+1, j+1, sep=' ') b.append(i) b.append(j) ```
instruction
0
70,326
19
140,652
No
output
1
70,326
19
140,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible. Input The first line of the input contains integer n (2 ≀ n ≀ 100) β€” the number of cards in the deck. It is guaranteed that n is even. The second line contains the sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is equal to the number written on the i-th card. Output Print n / 2 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them. Examples Input 6 1 5 7 4 4 3 Output 1 3 6 2 4 5 Input 4 10 10 10 10 Output 1 2 3 4 Note In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values ai are equal. Thus, any distribution is acceptable. Submitted Solution: ``` n = int(input()) l = list(map(int, input().split())) k = sorted(l) m = [] for i in range(n//2): m.append((l.index(k[i]) + 1, l.index(k[n-1]) + 1)) n -= 1 for j in m: print(*j) ```
instruction
0
70,327
19
140,654
No
output
1
70,327
19
140,655
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,377
19
140,754
Tags: implementation Correct Solution: ``` ##n children are standing in a circle and playing the counting-out game. ##Children are numbered clockwise from 1 to n. In the beginning, ##the first child is considered the leader. The game is played in k steps. ##In the i-th step the leader counts out ai people in clockwise order, ##starting from the next person. The last one to be pointed at by the ##leader is eliminated, and the next player after him becomes the new leader. ## ##For example, if there are children with numbers [8, 10, 13, 14, 16] ##currently in the circle, the leader is child 13 and ai = 12, then counting-out ##rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. ## ##You have to write a program which prints the number of the child to be ##eliminated on every step. ## ##Input ##The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). ## ##The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). ## ##Output ##Print k numbers, the i-th one corresponds to the number of child to be ##eliminated at the i-th step. ##input ##7 5 ##10 4 11 4 1 ##output ##4 2 5 6 1 n, k = map( int, input().split() ) a = list( map(int, input().split() ) ) x = [0] * n y = "" for i in range(n): x[i] = i+1 c = 0 for j in range(len(a)): a[j] = (a[j]+c) % (n-j) y += str(x[a[j]]) + " " del x[a[j]] c = a[j] print( y) ```
output
1
70,377
19
140,755
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,378
19
140,756
Tags: implementation Correct Solution: ``` n,k=map(int,input().split()) a=[i+1 for i in range(n)] for m in map(int,input().split()): m%=len(a) print(a[m],end=" ") a=a[m+1:]+a[:m] # Made By Mostafa_Khaled ```
output
1
70,378
19
140,757
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,379
19
140,758
Tags: implementation Correct Solution: ``` n, k = list(map(int, input().split())) arr = list(map(int, input().split())) child = list(range(1, n + 1)) main = 0 for i in range(k): j = (main + arr[i]) % len(child) print(child[j]) del child[j] main = j % len(child) ```
output
1
70,379
19
140,759
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,380
19
140,760
Tags: implementation Correct Solution: ``` #import sys #sys.stdin = open('in', 'r') #n = int(input()) #a = [int(x) for x in input().split()] n,k = map(int, input().split()) cs = [i + 1 for i in range(n)] rem = 0 for v in map(int, input().split()): rem = (rem + v) % len(cs) print(cs[rem], end=' ') cs.remove(cs[rem]) ```
output
1
70,380
19
140,761
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,381
19
140,762
Tags: implementation Correct Solution: ``` n, x=map(int, input().split()) a=[] for x in range(1,n+1): a.append(x) b=list(map(int, input().split())) for z in b: z%=len(a) print(a[z], end=' ') a=a[z+1:]+a[:z] ```
output
1
70,381
19
140,763
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,382
19
140,764
Tags: implementation Correct Solution: ``` import sys def solve(): n, k = map(int, input().split()) ch = [i + 1 for i in range(n)] a = [int(i) for i in input().split()] live = n leader = 0 ans = [] for v in a: v = v % live j = 0 cnt = 0 while cnt < v: if ch[(leader + j + 1) % n]: cnt += 1 j += 1 ans.append((leader + j) % n + 1) ch[(leader + j) % n] = 0 live -= 1 leader = (leader + j + 1) % n while ch[leader] == 0: leader = (leader + 1) % n # print(ch) # print(leader + 1) print(*ans) def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None if __name__ == '__main__': solve() ```
output
1
70,382
19
140,765
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,383
19
140,766
Tags: implementation Correct Solution: ``` def find_eliminatee(l, offset): c = l for _ in range(offset): c = next(c) return c def next(c): t = (c+1) % len(es) while es[t]: t = (t+1) % len(es) return t n,k = map(int, input().split()) a = list(map(int, input().split())) l = 0 es = [False]*n for i in range(k): e = find_eliminatee(l ,(a[i] % n)) es[e] = True n -= 1 l = next(e) #print ("state", e+1, n, l+1) print(e+1, end=' ') ```
output
1
70,383
19
140,767
Provide tags and a correct Python 3 solution for this coding contest problem. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader.
instruction
0
70,384
19
140,768
Tags: implementation Correct Solution: ``` import sys import bisect from bisect import bisect_left as lb input_=lambda: sys.stdin.readline().strip("\r\n") from math import log from math import gcd from math import atan2,acos from random import randint sa=lambda :input_() sb=lambda:int(input_()) sc=lambda:input_().split() sd=lambda:list(map(int,input_().split())) sflo=lambda:list(map(float,input_().split())) se=lambda:float(input_()) sf=lambda:list(input_()) flsh=lambda: sys.stdout.flush() #sys.setrecursionlimit(10**6) mod=10**9+7 mod1=998244353 gp=[] cost=[] dp=[] mx=[] ans1=[] ans2=[] special=[] specnode=[] a=0 kthpar=[] def dfs(root,par): if par!=-1: dp[root]=dp[par]+1 for i in range(1,20): if kthpar[root][i-1]!=-1: kthpar[root][i]=kthpar[kthpar[root][i-1]][i-1] for child in gp[root]: if child==par:continue kthpar[child][0]=root dfs(child,root) ans=0 def hnbhai(tc): n,k=sd() a=sd() temp=[i for i in range(1,n+1)] lead=0 ans=[] for i in range(k): tot=a[i] ind=(lead+tot)%len(temp) if ind==n-1: ans.append(temp.pop()) lead=0 continue ans.append(temp.pop(ind)) lead=ind print(*ans) for _ in range(1): hnbhai(_+1) ```
output
1
70,384
19
140,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` n,k=list(map(int,input().split())) a=list(map(int,input().split())) leaderidx=0 children=[i for i in range(1,n+1)] ans=[] for i in range(k): mov=a[i]%len(children) leaderidx=(leaderidx+mov)%len(children) ans.append(str(children[leaderidx])) del(children[leaderidx]) print(" ".join(ans)) ```
instruction
0
70,385
19
140,770
Yes
output
1
70,385
19
140,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` n,y=input().split() n=int(n) y=int(y) liste=list(range(1,n+1)) x=0 z=0 liste2=list(map(int,input().split())) liste3=[] while x<y: z=((z+liste2[x])%len(liste)) liste3.append(liste[z]) liste.pop(z) x+=1 for i in liste3: print(i) ```
instruction
0
70,386
19
140,772
Yes
output
1
70,386
19
140,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` s = input().split() n = int(s[0]) k = int(s[1]) s = input().split() v = [] for w in s: v.append(int(w)) kids = [] for i in range(1, n + 1): kids.append(i) actual = 0 for i in range(k): actual = (actual + v[i]) % n print(kids.pop(actual)) n -= 1 actual = actual % n ```
instruction
0
70,387
19
140,774
Yes
output
1
70,387
19
140,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) pos = 0 d = [] m = n R = list(range(0, n)) for i in range(k): s = a[i] % (n - i) pos = pos + s if pos >= (n - i): pos -= n - i d.append(R[pos] + 1) R.remove(R[pos]) if pos >= (n - i): pos -= n - i print(*d) ```
instruction
0
70,388
19
140,776
Yes
output
1
70,388
19
140,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` (n,k)=list(map(int,input().split())) input2=list(map(int,input().split())) outputlist=[] currentl=[i for i in range(0,n)] ved=1 for i in range(len(input2)): number=input2[i]%len(currentl) while number>0: ved+=1 ved%=len(currentl) number-=1 outputlist.append(currentl[ved]) del currentl[ved] ved%=len(currentl) print(' '.join(map(str, outputlist))) ```
instruction
0
70,389
19
140,778
No
output
1
70,389
19
140,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` n,y=input().split() n=int(n) y=int(y) liste=list(range(1,n+1)) x=0 z=0 liste2=list(map(int,input().split())) liste3=[] print(liste2) while x<y: z=((z+liste2[x])%len(liste)) liste3.append(liste[z]) liste.pop(z) x+=1 for i in liste3: print(i) ```
instruction
0
70,390
19
140,780
No
output
1
70,390
19
140,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` import math (n,k)=list(map(int,input().split())) input2=list(map(int,input().split())) outputlist=[] currentar=[] cycles=0 ved=1 for i in range(len(input2)): ind=0 if input2[i]>n-i: ost=input2[i]%(n-i)+ved if ost>n: ost=ost-n else: ost=input2[i]+ved if ost>n: ost=ost-n for j in range(len(currentar)): if ved>ost: if ved<currentar[j] or ost>=currentar[j]: ind+=1 else: if ved<currentar[j] and ost>=currentar[j]: ind+=1 sum=ost+ind while sum in currentar: sum+=1 if sum>n: sum=1 currentar.append(sum) ved=sum+1 if ved>n: ved=ved-n while ved in currentar: ved+=1 if ved>n: ved=ved-n print(' '.join(map(str, currentar))) ```
instruction
0
70,391
19
140,782
No
output
1
70,391
19
140,783
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. Input The first line contains two integer numbers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≀ ai ≀ 109). Output Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step. Examples Input 7 5 10 4 11 4 1 Output 4 2 5 6 1 Input 3 2 2 5 Output 3 2 Note Let's consider first example: * In the first step child 4 is eliminated, child 5 becomes the leader. * In the second step child 2 is eliminated, child 3 becomes the leader. * In the third step child 5 is eliminated, child 6 becomes the leader. * In the fourth step child 6 is eliminated, child 7 becomes the leader. * In the final step child 1 is eliminated, child 3 becomes the leader. Submitted Solution: ``` n, k = map(int, input().split()) a_data = list(map(int, input().split())) data_check = {i: True for i in range(1, n+1)} data = list(range(1, n+1)) * 3 result = [] player = 1 n_d = n for i in a_data: if i < n: step = i else: if i % n_d == 0: step = n else: step = i % n_d n_d -= 1 num = 1 for i in data[player:]: if data_check[i]: if num == step: data_check[i] = not data_check[i] player = i + 1 result.append(str(i)) break num += 1 print(' '.join(result)) ```
instruction
0
70,392
19
140,784
No
output
1
70,392
19
140,785
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gates and Jackie, the cats, came up with the rules for a card game played by two people. The rules are as follows. First, shuffle the cards with the numbers 1 to 18 and deal 9 to each player. Both players issue one card at the same time and get a score based on the value. The player who issues the higher value card adds the sum of the higher value and the lower value to his score. At that time, the player who issued the card with the smaller value cannot get the score. Also, once a card is put into play, it cannot be used again. The player with the highest score after using all the cards wins. Gates and Jackie decided to randomly pick and play cards from each other. Find the odds that Gates and Jackie will win when the first card dealt is given. Notes on Submission Multiple datasets are given in the above format. The first line of input data gives the number of datasets. Create a program that outputs the output for each data set in order in the above format. Input Each of Gates and Jackie's hand consists of nine integers. Both players' hands are different integers from 1 to 18. The first line of input is given nine integers representing Gates'hand, and the second line is given nine integers representing Jackie's hand. There is a single space between integers. Output Output the probability that Gates and Jackie will win, separated by a space, up to 5 digits after the decimal point. Errors within 10-5 are acceptable, but values ​​less than 0 or greater than 1 must not be output. Example Input 2 1 3 5 7 9 11 13 15 17 2 4 6 8 10 12 14 16 18 1 5 7 9 11 13 15 17 18 2 3 4 6 8 10 12 14 16 Output 0.30891 0.69109 0.92747 0.07253 Submitted Solution: ``` import math from decimal import Decimal, ROUND_HALF_UP for _ in range(int(input())): a, b = tuple(sorted(map(int, input().split()), reverse = True)), tuple(sorted(map(int, input().split()))) c = 0 q = {():(0, 0)} for i in range(9): nq = {} for k in q: for j in b: if j not in k: x = q[k][0] + (a[i] + j) * (a[i] > j) y = q[k][1] + (a[i] + j) * (a[i] < j) if x > 85:c += math.factorial(9 - i - 1) elif y < 85:nq[tuple(list(k) + [j])] = (x, y) q = nq c /= 362880 print("{} {}".format(Decimal(c).quantize(Decimal('0.00001'), rounding=ROUND_HALF_UP), Decimal(1 - c).quantize(Decimal('0.00001'), rounding=ROUND_HALF_UP))) ```
instruction
0
70,694
19
141,388
No
output
1
70,694
19
141,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gates and Jackie, the cats, came up with the rules for a card game played by two people. The rules are as follows. First, shuffle the cards with the numbers 1 to 18 and deal 9 to each player. Both players issue one card at the same time and get a score based on the value. The player who issues the higher value card adds the sum of the higher value and the lower value to his score. At that time, the player who issued the card with the smaller value cannot get the score. Also, once a card is put into play, it cannot be used again. The player with the highest score after using all the cards wins. Gates and Jackie decided to randomly pick and play cards from each other. Find the odds that Gates and Jackie will win when the first card dealt is given. Notes on Submission Multiple datasets are given in the above format. The first line of input data gives the number of datasets. Create a program that outputs the output for each data set in order in the above format. Input Each of Gates and Jackie's hand consists of nine integers. Both players' hands are different integers from 1 to 18. The first line of input is given nine integers representing Gates'hand, and the second line is given nine integers representing Jackie's hand. There is a single space between integers. Output Output the probability that Gates and Jackie will win, separated by a space, up to 5 digits after the decimal point. Errors within 10-5 are acceptable, but values ​​less than 0 or greater than 1 must not be output. Example Input 2 1 3 5 7 9 11 13 15 17 2 4 6 8 10 12 14 16 18 1 5 7 9 11 13 15 17 18 2 3 4 6 8 10 12 14 16 Output 0.30891 0.69109 0.92747 0.07253 Submitted Solution: ``` import itertools from decimal import Decimal, ROUND_HALF_UP for _ in range(int(input())): a, b = tuple(map(int, input().split())), tuple(map(int, input().split())) c = 0 for i in itertools.permutations(b): s = 0 for j in range(9):s += (a[j] + i[j]) * (a[j] > i[j]) if s > 85:c += 1 c /= 362880 print("{} {}".format(Decimal(c).quantize(Decimal('0.00001'), rounding=ROUND_HALF_UP), Decimal(1 - c).quantize(Decimal('0.00001'), rounding=ROUND_HALF_UP))) ```
instruction
0
70,695
19
141,390
No
output
1
70,695
19
141,391
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gates and Jackie, the cats, came up with the rules for a card game played by two people. The rules are as follows. First, shuffle the cards with the numbers 1 to 18 and deal 9 to each player. Both players issue one card at the same time and get a score based on the value. The player who issues the higher value card adds the sum of the higher value and the lower value to his score. At that time, the player who issued the card with the smaller value cannot get the score. Also, once a card is put into play, it cannot be used again. The player with the highest score after using all the cards wins. Gates and Jackie decided to randomly pick and play cards from each other. Find the odds that Gates and Jackie will win when the first card dealt is given. Notes on Submission Multiple datasets are given in the above format. The first line of input data gives the number of datasets. Create a program that outputs the output for each data set in order in the above format. Input Each of Gates and Jackie's hand consists of nine integers. Both players' hands are different integers from 1 to 18. The first line of input is given nine integers representing Gates'hand, and the second line is given nine integers representing Jackie's hand. There is a single space between integers. Output Output the probability that Gates and Jackie will win, separated by a space, up to 5 digits after the decimal point. Errors within 10-5 are acceptable, but values ​​less than 0 or greater than 1 must not be output. Example Input 2 1 3 5 7 9 11 13 15 17 2 4 6 8 10 12 14 16 18 1 5 7 9 11 13 15 17 18 2 3 4 6 8 10 12 14 16 Output 0.30891 0.69109 0.92747 0.07253 Submitted Solution: ``` import math from decimal import Decimal, ROUND_HALF_UP for _ in range(int(input())): a, b = tuple(sorted(map(int, input().split()), reverse = True)), tuple(sorted(map(int, input().split()))) c = 0 q = {():(0, 0)} for i in range(9): nq = {} for k in q: for j in b: if j not in k: x = q[k][0] + (a[i] + j) * (a[i] > j) y = q[k][1] + (a[i] + j) * (a[i] < j) if x > 85:c += math.factorial(9 - i - 1) elif y < 85:nq[tuple(list(k) + [j])] = (x, y) q = nq c /= 362880 print("{} {}".format(Decimal(c).quantize(Decimal('0.000001'), rounding=ROUND_HALF_UP), Decimal(1 - c).quantize(Decimal('0.000001'), rounding=ROUND_HALF_UP))) ```
instruction
0
70,696
19
141,392
No
output
1
70,696
19
141,393
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,119
19
142,238
Tags: dp Correct Solution: ``` def max_points(n, given_sequence): sequence = sorted(given_sequence) table_size = sequence[-1] + 1 seq_count = [0]*table_size for number in sequence: seq_count[number] += number point_history = [0]*len(seq_count) point_history[0] = seq_count[0] point_history[1] = max(seq_count[0], seq_count[1]) for i in range(2,len(seq_count)): maxValue = max(point_history[i-2] + seq_count[i], point_history[i-1]) point_history[i] = maxValue return point_history[-1] if __name__ == "__main__": n = int(input()) sequence_input = input() seqStrList = sequence_input.split() sequence = [] for item in seqStrList: sequence.append(int(item)) print(max_points(n,sequence)) ```
output
1
71,119
19
142,239
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,120
19
142,240
Tags: dp Correct Solution: ``` n = int(input()) lis = list(map(int, input().split())) set_lis = set(lis) x = [0]*(max(set_lis)+2) for i in lis: x[i] = x[i]+i a, b = 0, 0 for i in x: a, b = max(a, i+b), a print(a) ```
output
1
71,120
19
142,241
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,121
19
142,242
Tags: dp Correct Solution: ``` import sys, threading sys.setrecursionlimit(3*10**6) threading.stack_size(2**20) n = int(input()) a = list(map(int, input().split())) N = 10**5 + 1 count = [0] * N for i in range(n): count[a[i]] += 1 dp = [0] * N dp[1] = count[1] for i in range(2, N): dp[i] = max(dp[i - 1], dp[i - 2] + count[i] * i) print(max(dp)) ```
output
1
71,121
19
142,243
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,122
19
142,244
Tags: dp Correct Solution: ``` # Description of the problem can be found at http://codeforces.com/problemset/problem/455/A n = int(input()) l_n = list(map(int, input().split())) dp = [0]*(10**6) for n_t in l_n: dp[n_t] += 1 for i in range(2, 10**6): dp[i] = max(dp[i - 1], dp[i - 2] + dp[i]*i) print(dp[10**6 - 1]) ```
output
1
71,122
19
142,245
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,123
19
142,246
Tags: dp Correct Solution: ``` N = 100000 n = int(input()) a = list(map(int, input().split())) c = [0]*(N+1) for i in range(n): c[a[i]] += 1 dp = [0]*(N+1) dp[0] = 0 dp[1] = c[1] for i in range(2, N+1): dp[i] = max(dp[i-1], c[i]*i + dp[i-2]) print(dp[N]) ```
output
1
71,123
19
142,247
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,124
19
142,248
Tags: dp Correct Solution: ``` n=int(input()) number=list(map(int,input().split())) option={} for j in number: if j in option: option[j]+=j else: option[j]=j dp=[0]*(max(number)+1) dp[0]=0 dp[1]=option[1] if 1 in option else 0 for i in range(2,max(number)+1): if i in option: dp[i]=max(dp[i-2]+option[i], dp[i-1]) else: dp[i]=dp[i-1] print(max(dp)) ```
output
1
71,124
19
142,249
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,125
19
142,250
Tags: dp Correct Solution: ``` from collections import Counter as C def eleadj(i): if score.get(elements[i]-1,-1)==-1: return True #It means that we just have to add the dp at i-1 to dp at i return False def eleNotadj(i,j): if j<i-1: return j j-=1 while j>=0 and score.get(elements[j],-1)==-1: j-=1 else: return j n=int(input()) a=list(map(int,input().split())) c=C(a) score={i:(i*c[i]) for i in c} elements=list(score.keys()) elements.sort() l=len(elements) dp=[0]*l dp[0]=score[elements[0]] for i in range(1,l): if eleadj(i)==True: dp[i]=score[elements[i]]+dp[i-1] else: dp[i]=max(score[elements[i]]+dp[i-2],dp[i-1]) #print(elements) #print(dp) print(max(dp)) #dp[i]=max(score of the element at i + the max attainable score at the element at least smaller than the element-1, # the max attainable score at the element-1 scenerio ```
output
1
71,125
19
142,251
Provide tags and a correct Python 3 solution for this coding contest problem. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
instruction
0
71,126
19
142,252
Tags: dp Correct Solution: ``` from collections import defaultdict n = int(input()) a = list(map(int,input().split())) d = defaultdict(int) for i in a: d[i] += 1 s = list(set(a)) p = [0]*100003 for i in range(100000,0,-1): p[i] = max(d[i]*i+p[i+2], p[i+1]) print(p[1]) ```
output
1
71,126
19
142,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` n=int(input()) a=[int(x) for x in input().split()] m=max(a) cnt=(m+1)*[0] for i in range(n): cnt[a[i]]+=1 #每一δΈͺζ•°ηš„δΈͺζ•° f=(m+1)*[0] f[0]=0 f[1]=cnt[1] for i in range(2,m+1): if f[i-1]>f[i-2]+cnt[i]*i: f[i]=f[i-1] else: f[i]=f[i-2]+cnt[i]*i print(f[m]) ```
instruction
0
71,127
19
142,254
Yes
output
1
71,127
19
142,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` n=int(input()) l=[0]*(10**5+1) dp=[0]*(10**5+1) a=list(map(int,input().split())) for i in a: l[i]+=1 dp[1]=l[1] for i in range(2,(10**5+1)): dp[i]=max(dp[i-1],dp[i-2]+i*l[i]) print(dp[10**5]) ```
instruction
0
71,128
19
142,256
Yes
output
1
71,128
19
142,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` def dpSolve(sequence): freqArray = [0] * 100001 dp = [0] * 100001 for num in sequence: freqArray[num] += 1 dp[1] = freqArray[1] for i in range(2, len(dp)): dp[i] = max(dp[i-1], i * freqArray[i] + dp[i-2]) return dp[len(dp)-1] numInts = int(input().strip()) sequence = [int(n) for n in input().strip().split()] print(dpSolve(sequence)) ```
instruction
0
71,129
19
142,258
Yes
output
1
71,129
19
142,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` a = int(input()) c = [0 for i in range(100001)] for i in input().split(): c[int(i)] = c[int(i)] + int(i) dp = [0 for i in range(100001)] for i in range(100001): if i == 0 or i == 1: dp[i] = c[i] else: dp[i] = max(dp[i-1], dp[i-2] + c[i]) print(dp[100000]) ```
instruction
0
71,130
19
142,260
Yes
output
1
71,130
19
142,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` n=int(input()) lista=[int(x) for x in input().split()] lista.sort() dict1=dict.fromkeys([x+1 for x in range(10**5)],0) for i in range(n): x=lista[i] dict1[x]=dict1[x]+x i=1 m=0 while i<lista[-1]-1: x=dict1[i] y=dict1[i+1] z=dict1[i+2] if x<y and y<x+z and i<lista[-1]-3: dict1[i+3]=dict1[i+3]+y dict1[i+4]=dict1[i+4]+x+z i+=3 elif y>=x+z: m+=y i+=3 elif x>=y: m+=x i+=2 elif i==lista[-1]-3: w=dict1[i+3] if x+z>y+w: m+=x+z i=lista[-1]+1 else: m+=y+w i=lista[-1]+1 else: m+=x+z i=lista[-1]+1 if i==lista[-1]-1: m+=max(dict1[lista[-1]-1],dict1[lista[-1]]) elif i==lista[-1]: m+=dict1[lista[-1]] print(m) ```
instruction
0
71,131
19
142,262
No
output
1
71,131
19
142,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` from collections import * def dp(): mem[0, coun[a[0]]], l = coun[a[0]] * a[0], len(a) for i in range(1, l): mem[i, coun[a[i]]] += mem[i - 1, 0] + (coun[a[i]] * a[i]) mem[i, 0] += max(mem[i - 1, 0], mem[i - 1, coun[a[i - 1]]]) return max(mem[l - 1, 0], mem[l - 1, coun[a[l - 1]]]) n, a = int(input()), list(map(int, input().split())) coun, a, mem = Counter(a), list(set(a)), defaultdict(int) print(dp()) ```
instruction
0
71,132
19
142,264
No
output
1
71,132
19
142,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` n = int(input()) A = list(map(int, input().split())) cnt = [0 for i in range(max(A) + 1)] for i in A: cnt[i] += 1 dp = [0 for i in range(max(A) + 1)] dp[0] = 0 dp[1] = 1 for i in range(2, max(A) + 1): dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i) print(dp[-1]) ```
instruction
0
71,133
19
142,266
No
output
1
71,133
19
142,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer n (1 ≀ n ≀ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Print a single integer β€” the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. Submitted Solution: ``` n = int(input()) a = list(map(int,input().strip().split()))[:n] rows = len(set(a)) cols = n lst = list(set(a)) table = [[0 for i in range(cols+1)] for j in range(rows+1)] for i in range(rows): for j in range(cols): if(table[i+1][j] == 0 and lst[i]<a[j]): table[i+1][j+1] = table[i+1][j] elif(lst[i]==a[j]-1 or lst[i]==a[j]+1): table[i+1][j+1]=table[i+1][j] elif(lst[i]==a[j] or a[j]>(lst[i]+1)): table[i+1][j+1] = table[i+1][j]+a[j] max_ = 0 for i in range(rows): if(table[i+1][cols]>max_): max_=table[i+1][cols] print(max_) ```
instruction
0
71,134
19
142,268
No
output
1
71,134
19
142,269
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,242
19
142,484
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` k = int(input()) n = list(map(int, input().split())) for i in range(k): n[i] = bin(n[i]) n[i] = n[i][2:] magic = 1000000007 def par(s): if s[-1] == '0': return True else: return False def mod_pow(x, s, p): ans = 1 for i in range(len(s)): if s[i] == '1': ans = (((ans * ans) % p) * x) % p else: ans = (ans * ans) % p return ans def div_in_field(a, b, p): b_op = pow(b, p - 2, p) return (b_op * a) % p denominator = 2 n_par = False for i in range(len(n)): denominator = mod_pow(denominator, n[i], magic) if par(n[i]): n_par = True denominator = div_in_field(denominator, 2, magic) numerator = 0 if n_par: numerator = div_in_field(1 + denominator, 3, magic) else: numerator = div_in_field(-1 + denominator, 3, magic) ans = str(numerator) + '/' + str(denominator) print(ans) ```
output
1
71,242
19
142,485
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,243
19
142,486
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` class Matrix: def __init__(self, n, m, arr=None): self.n = n self.m = m self.arr = [[0] * m for i in range(n)] if arr is not None: for i in range(n): for j in range(m): self.arr[i][j] = arr[i][j] def __mul__(self, other): assert self.m == other.n ans = Matrix(self.n, other.m) for i in range(self.n): for j in range(other.m): for k in range(self.m): ans.arr[i][j] = (ans.arr[i][j] + self.arr[i][k] * other.arr[k][j]) % (10 ** 9 + 7) return ans def __imul__(self, other): self = self * other return self def __pow__(self, n): if n == 0: ans = Matrix(self.n, self.n) for i in range(self.n): ans.arr[i][i] = 1 return ans elif n & 1 == 1: return self * (self ** (n - 1)) else: t = self ** (n >> 1) return t * t def __ipow__(self, n): self = self ** n return self def __eq__(self, other): if self.n != other.n or self.m != other.m: return False for i in range(self.n): for j in range(self.m): if self.arr[i][j] != other.arr[i][j]: return False return True def fpow(a, n): if n == 0: return 1 elif n & 1 == 1: return (a * fpow(a, n - 1)) % (10 ** 9 + 7) else: t = fpow(a, n >> 1) return (t * t) % (10 ** 9 + 7) transform = Matrix(2, 2, [[1, 1], [0, 4]]) mtx = transform k = int(input()) a = list(map(int, input().split())) x = 1 for j in a: x = (x * j) % (10 ** 9 + 6) x = (x - 1) % (10 ** 9 + 6) if x % 2 == 0: ans = (transform ** (x // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % (ans.arr[0][0], fpow(2, x))) else: y = (x - 1) % (10 ** 9 + 6) ans = (transform ** (y // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % ((ans.arr[0][0] * 2 + 1) % (10 ** 9 + 7), (ans.arr[1][0] * 2) % (10 ** 9 + 7))) ```
output
1
71,243
19
142,487
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,244
19
142,488
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` m = 1000000007 input() n, d = 2, 1 for q in map(int, input().split()): d, n = q & d, pow(n, q, m) n = n * pow(2, m - 2, m) % m k = (n + 1 - 2 * d) * pow(3, m - 2, m) % m print(str(k) + '/' + str(n)) ```
output
1
71,244
19
142,489
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,245
19
142,490
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` p = int(1e9)+7 inv2 = int(5e8)+4 inv3 = (p+1)//3 def binpower(b,e): r = 1 while e: if e&1: r = (r*b)%p e = e>>1 b = (b*b)%p return r def f(l): r = 2 #will=2^n%p odd = True for a in l: odd = odd and a%2 r = binpower(r,a%(p-1)) #Fermat's Little Theorem fm = (r*inv2)%p fz = fm + (-1 if odd else 1) fz = (fz*inv3)%p return '%d/%d'%(fz,fm) _ = input() l = list(map(int,input().split())) print(f(l)) ```
output
1
71,245
19
142,491
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,246
19
142,492
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` mod = 1000000007 input() numbers = list(map(int, input().split())) b = 2 flag = 1 if len(list(filter(lambda x : x % 2 == 0, numbers))) else -1 for num in numbers: b = pow(b, num, mod) b = b * pow(2, mod - 2, mod) % mod a = (b + flag) * pow(3, mod - 2, mod) % mod print("%d/%d"%(a, b)) ```
output
1
71,246
19
142,493
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,247
19
142,494
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` mod = int(1e9+7) k = int(input()) top = 1 yoink = 1 a = list(map(int, input().split())) for thing in a: top *= thing yoink *= thing yoink %= 2 top %= (mod-1) def extended_gcd(aa, bb): lastremainder, remainder = abs(aa), abs(bb) x, lastx, y, lasty = 0, 1, 1, 0 while remainder: lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder) x, lastx = lastx - quotient*x, x y, lasty = lasty - quotient*y, y return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) def modinv(a, m): g, x, y = extended_gcd(a, m) if g != 1: raise ValueError return x % m if top == 0: bot = modinv(2, mod) else: bot = pow(2, top-1, mod) #print(bot) # odd case if yoink % 2 == 0: blah = modinv(3, mod) blah *= (bot+1) blah %= mod print(str(blah) + '/' + str(bot)) else: blah = modinv(3, mod) blah *= (bot+2) blah %= mod print(str(blah-1) + '/' + str(bot)) ```
output
1
71,247
19
142,495
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,248
19
142,496
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` mod = 10**9 + 7 k = int(input()) arr = [int(j) for j in input().split()] findeven = 0 for i in range(k): if arr[i]%2 == 0: findeven = 1 cur = pow(2, arr[0], mod) for i in range(1, k): cur = pow(cur, arr[i], mod) # print(cur) inv2 = pow(2, mod-2, mod) inv3 = pow(3, mod-2, mod) if findeven == 1: lr = (cur-1)*inv3 m = (cur-1)*inv3 + 1 else: lr = (cur-2)*inv3 + 1 m = (cur-2)*inv3 lr = lr*inv2 % mod m = m*inv2 % mod cur = cur*inv2 % mod # print(lr, m, lr) print(m, '/', cur, sep='') ```
output
1
71,248
19
142,497
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
71,249
19
142,498
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` n = int(input()) ls = [int(x) for x in input().split(' ')] t = 1 mod = 1000000007 def qpow(n: int, m: int): m %= mod - 1 ans = 1 while m: if m & 1: ans = ans * n % mod n = n * n % mod m >>= 1 return ans k = 0 r=mod*2-2 for x in ls: t = t * x % (mod * 2 - 2) if x % 2 == 0: k = 1 t = (t - 1 + r) % r fz = (qpow(4, t >> 1) - 1) * qpow(3, mod - 2) % mod if k == 1: fz = (fz * 2 + 1) % mod fm = qpow(2, t) print('{}/{}'.format(fz, fm)) ```
output
1
71,249
19
142,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` k = int(input()) MOD = 10 ** 9 + 7 antithree = pow(3, MOD - 2, MOD) antitwo = pow(2, MOD - 2, MOD) power = 1 parity = False for t in map(int, input().split()): power *= t power %= MOD - 1 if t % 2 == 0: parity = True q = pow(2, power, MOD) * antitwo q %= MOD if parity: p = (q + 1) * antithree p %= MOD else: p = (q - 1) * antithree p %= MOD print(p, q, sep = '/') # Made By Mostafa_Khaled ```
instruction
0
71,250
19
142,500
Yes
output
1
71,250
19
142,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq,bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10**8) mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=2**51, func=lambda a, b: a & b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ def multiply(a, b): mul = [[0 for x in range(2)]for y in range(2)] for i in range(2): for j in range(2): mul[i][j] = 0 for k in range(2): mul[i][j] += a[i][k] * b[k][j] mul[i][j]%=mod for i in range(2): for j in range(2): a[i][j] = mul[i][j] # Updating our matrix return a def power(M,n): if n==0: res=[[0 for i in range(2)]for j in range(2)] res[0][0]=1 res[1][1]=1 return res if n==1: return M else: res=[[1,0],[0,1]] if n%2==1: res=multiply(res,M) re=power(M,n//2) re=multiply(re,re) re=multiply(re,res) return re n=int(input()) l=list(map(int,input().split())) req=1 for i in l: req*=i req%=mod-1 if req==0: req=mod-1 if req==1: print("0/1") sys.exit(0) M=[[0 for i in range(2)]for j in range(2)] M[0][0]=1 M[0][1]=2 M[1][0]=1 M[1][1]=0 M=power(M,req-2) num=M[0][0]%mod de=pow(2,req-1,mod) print(str(num)+"/"+str(de)) ```
instruction
0
71,251
19
142,502
Yes
output
1
71,251
19
142,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` #!/usr/bin/python3 class Matrix: def __init__(self, n, m, arr=None): self.n = n self.m = m self.arr = [[0] * m for i in range(n)] if arr is not None: for i in range(n): for j in range(m): self.arr[i][j] = arr[i][j] def __mul__(self, other): assert self.m == other.n ans = Matrix(self.n, other.m) for i in range(self.n): for j in range(other.m): for k in range(self.m): ans.arr[i][j] = (ans.arr[i][j] + self.arr[i][k] * other.arr[k][j]) % (10 ** 9 + 7) return ans def __imul__(self, other): self = self * other return self def __pow__(self, n): if n == 0: ans = Matrix(self.n, self.n) for i in range(self.n): ans.arr[i][i] = 1 return ans elif n & 1 == 1: return self * (self ** (n - 1)) else: t = self ** (n >> 1) return t * t def __ipow__(self, n): self = self ** n return self def __eq__(self, other): if self.n != other.n or self.m != other.m: return False for i in range(self.n): for j in range(self.m): if self.arr[i][j] != other.arr[i][j]: return False return True def fpow(a, n): if n == 0: return 1 elif n & 1 == 1: return (a * fpow(a, n - 1)) % (10 ** 9 + 7) else: t = fpow(a, n >> 1) return (t * t) % (10 ** 9 + 7) transform = Matrix(2, 2, [[1, 1], [0, 4]]) mtx = transform k = int(input()) a = list(map(int, input().split())) """ f = False for j in a: if j % 2 == 0: f = True break if f: print(a) tp = 1 for j in a: if f and j % 2 == 0: j //= 2 f = False print(j) mtx **= j ans = Matrix(2, 1, [[0], [1]]) ans = mtx * ans print(ans.arr) print("%d/%d" % (ans.arr[0][0], ans.arr[1][0])) """ x = 1 for j in a: x = (x * j) % (10 ** 9 + 6) x = (x - 1) % (10 ** 9 + 6) if x % 2 == 0: ans = (transform ** (x // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % (ans.arr[0][0], fpow(2, x))) else: y = (x - 1) % (10 ** 9 + 6) ans = (transform ** (y // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % ((ans.arr[0][0] * 2 + 1) % (10 ** 9 + 7), (ans.arr[1][0] * 2) % (10 ** 9 + 7))) ```
instruction
0
71,252
19
142,504
Yes
output
1
71,252
19
142,505
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` k = int(input()) n = list(map(int, input().split())) for i in range(k): n[i] = bin(n[i]) n[i] = n[i][2:] magic = 1000000007 def mod_pow(x, s, p): ans = 1 for i in range(len(s)): if s[i] == '1': ans = (((ans * ans) % p) * x) % p else: ans = (ans * ans) % p return ans def div_in_field(a, b, p): b_op = pow(b, p - 2, p) return (b_op * a) % p denominator = 2 numerator = -1 for i in range(len(n)): denominator = mod_pow(denominator, n[i], magic) numerator = mod_pow(numerator, n[i], magic) denominator = div_in_field(denominator, 2, magic) numerator = div_in_field(1 + numerator * denominator, 3, magic) ans = str(numerator) + '/' + str(denominator) print(ans) ```
instruction
0
71,253
19
142,506
No
output
1
71,253
19
142,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≀ k ≀ 105) β€” the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≀ ai ≀ 1018) β€” the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` mod = int(1e9+7) k = int(input()) top = 1 yoink = 1 a = list(map(int, input().split())) for thing in a: top *= thing yoink *= thing yoink %= 2 top %= (mod-1) def extended_gcd(aa, bb): lastremainder, remainder = abs(aa), abs(bb) x, lastx, y, lasty = 0, 1, 1, 0 while remainder: lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder) x, lastx = lastx - quotient*x, x y, lasty = lasty - quotient*y, y return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) def modinv(a, m): g, x, y = extended_gcd(a, m) if g != 1: raise ValueError return x % m if top == 0: top = mod bot = pow(2, top-1, mod) #print(bot) # odd case if yoink % 2 == 0: blah = modinv(3, mod) blah *= (bot+1) blah %= mod print(str(blah) + '/' + str(bot)) else: blah = modinv(3, mod) blah *= (bot+2) blah %= mod print(str(blah-1) + '/' + str(bot)) ```
instruction
0
71,254
19
142,508
No
output
1
71,254
19
142,509