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
Provide tags and a correct Python 3 solution for this coding contest problem. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40
instruction
0
60,013
19
120,026
Tags: greedy Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(n-1): t = 0 while i+2**(t+1)<n: t+=1 a[i+2**t]+= a[i] count += a[i] a[i] = 0 print(count) ```
output
1
60,013
19
120,027
Provide tags and a correct Python 3 solution for this coding contest problem. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40
instruction
0
60,014
19
120,028
Tags: greedy Correct Solution: ``` def main(): from math import floor, log2 n = int(input()) numbers = [0] + [int(_) for _ in input().split()] moves = [0] * (n + 1) for i in range(1, n): t = floor(log2(n - i)) j = i + 2 ** t moves[i] = numbers[i] numbers[j] += numbers[i] numbers[i] = 0 for i in range(2, n): moves[i] += moves[i - 1] print('\n'.join([str(moves[i]) for i in range(1, n)])) if __name__ == '__main__': main() ```
output
1
60,014
19
120,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` import math n = int(input()) a = list(map(int, input().split())) c = 0 for i in range(n-1): j = i + 2**int(math.log(n-1-i, 2)) c += a[i] a[j] += a[i] a[i] = 0 print(c) ```
instruction
0
60,015
19
120,030
Yes
output
1
60,015
19
120,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` import math n = int(input()) seq = list(map(lambda x: int(x), input().split())) last = seq[n - 1] def roundPO2(v): v = v - 1; v = v | v >> 1; v = v | v >> 2; v = v | v >> 4; v = v | v >> 8; v = v | v >> 16; v = v + 1; return v for k in range(1, n): move = 0 stacking = dict() for j in range(1, k + 1): po2 = roundPO2(k + 1 - j) #print('po2 of {0} - {1} is {2}'.format(k, j, po2)) #print('{0} + {1} > {2}'.format(po2, j, n)) while po2 + j > n: po2 = 2 ** (math.log(po2, 2) - 1) movePos = po2 + j #print('movePos: ' + str(movePos)) w = seq[j-1] + (stacking[j] if j in stacking else 0) #print('seq[j-1]' + str(seq[j-1])) #print('weight: ' + str(w)) if movePos <= k: stacking[movePos] = w + (stacking[movePos] if movePos in stacking else 0) move = move + w print(move) ```
instruction
0
60,016
19
120,032
Yes
output
1
60,016
19
120,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) count=0 for i in range(n-1): t = 0 while(i+(2**(t+1))<n): t+=1 a[i+(2**t)] += a[i] count += a[i] a[i] = 0 print(count) ```
instruction
0
60,017
19
120,034
Yes
output
1
60,017
19
120,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` import sys n = int(sys.stdin.readline().strip()) a = list(map(int, sys.stdin.readline().strip().split())) ans = 0 for i in range (0, n-1): e = 0 while i + 2**(e+1) < n: e = e + 1 ans = ans + a[i] a[i + 2**e] = a[i + 2**e] + a[i] a[i] = 0 print(ans) ```
instruction
0
60,018
19
120,036
Yes
output
1
60,018
19
120,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) rs = 0 for i in range(1,n): if a[i - 1]!=0: rs+=a[i - 1] print(rs) t = 0 while(i+2**t <= n): t+=1 t-=1 a[int(i + 2**t) - 1] += a[i - 1] ```
instruction
0
60,019
19
120,038
No
output
1
60,019
19
120,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` import math n = int(input()) a = list(map(int, input().split())) #b = a[:] sum = 0 for i in range(0, n-1): #if b[i] == 0: ##continue sum += a[i] t = int(math.sqrt(n - (i + 1))) if 2**t + i > n - 1: t -= 1 a[2**t + i] += a[i] print(sum) # a = b ```
instruction
0
60,020
19
120,040
No
output
1
60,020
19
120,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` mod = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) n=ii() l=il() i=0 while 2**i<n-1: i+=1 i-=1 sm=0 for j in range(n-1): if j+2**i>n-1: i-=1 sm+=l[j] l[j+2**i]+=l[j] print(sm) if n==1: print(0) ```
instruction
0
60,021
19
120,042
No
output
1
60,021
19
120,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves. One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0). You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n). Input The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 300 The input limitations for getting 50 points are: * 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: * 1 ≤ n ≤ 105 Output Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Examples Input 4 1 0 1 2 Output 1 1 3 Input 8 1 2 3 4 5 6 7 8 Output 1 3 6 10 16 24 40 Submitted Solution: ``` n = int(input()) a = [int(i) for i in input().split()] ans = '' for k in range(1, n): p = 0 for i in range(1, k+1): j = 1 t = 1 r = k - i if a[i - 1] > 0: while r > 0: t *= 2 r //= 2 if i + t > n: q = i j = 0 while q <= k: t //= 2 q += t j += 1 p += j*a[i-1] ans += str(p) + '\n' print(ans) ```
instruction
0
60,022
19
120,044
No
output
1
60,022
19
120,045
Provide tags and a correct Python 3 solution for this coding contest problem. Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 1 2 Output 0.0000000000 Input 3 1 2 10 Output 0.0740740741 Note In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total. In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>.
instruction
0
60,231
19
120,462
Tags: brute force, combinatorics, dp, probabilities Correct Solution: ``` def main(): n = int(input()) a = list(map(int, input().split())) max_element = max(a) + 1 #print(max_element) diff_freq = [0 for i in range(max_element)] for i in range(n): for j in range(i): diff_freq[abs(a[i] - a[j])] += 1 largest = [0 for i in range(max_element)] for i in range(max_element - 2, 0, -1): largest[i] = largest[i + 1] + diff_freq[i + 1] good_ones = 0 #print('diff_freq', diff_freq) #print('largest', largest) for i in range(max_element): for j in range(max_element): if i + j < max_element: good_ones += diff_freq[i] * diff_freq[j] * largest[i + j] #print(good_ones) ans = good_ones / (((n*(n - 1)) / 2) ** 3) print(ans) main() ```
output
1
60,231
19
120,463
Provide tags and a correct Python 3 solution for this coding contest problem. Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 1 2 Output 0.0000000000 Input 3 1 2 10 Output 0.0740740741 Note In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total. In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>.
instruction
0
60,232
19
120,464
Tags: brute force, combinatorics, dp, probabilities Correct Solution: ``` from itertools import accumulate n = int(input()) A = [int(x) for x in input().split()] m = max(A) difference = [0 for i in range(m)] for i in range(n): for j in range(i+1, n): difference[abs(A[i]-A[j])] += 1 diffsum = [0 for i in range(2*m)] for i in range(m): for j in range(m): diffsum[i+j] += difference[i]*difference[j] D = list(accumulate(diffsum)) ans = sum(difference[k] * D[k-1] for k in range(m)) print(8*ans/((n*(n-1)) ** 3)) ```
output
1
60,232
19
120,465
Provide tags and a correct Python 3 solution for this coding contest problem. Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 1 2 Output 0.0000000000 Input 3 1 2 10 Output 0.0740740741 Note In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total. In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>.
instruction
0
60,233
19
120,466
Tags: brute force, combinatorics, dp, probabilities Correct Solution: ``` MAX_N = 5001 a = [0] * MAX_N; raz = [0] * (MAX_N + 10); s = [0] * (MAX_N + 10); n = int(input()) a = list(map(int, input().split())) for i in range(n): for j in range(n): if a[i] - a[j] > 0: raz[a[i] - a[j]] += 1 for i in range(1, MAX_N + 1): s[i] = s[i - 1] + raz[i] ans = 0; for i in range(1, MAX_N): if raz[i] == 0: continue for j in range(1, MAX_N): if i + j > MAX_N: break if raz[j] == 0: continue ans += raz[i] * raz[j] * (s[MAX_N] - s[i + j]) ans = ans * 1.0 ans /= s[MAX_N] ans /= s[MAX_N] ans /= s[MAX_N] print(ans) ```
output
1
60,233
19
120,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 1 2 Output 0.0000000000 Input 3 1 2 10 Output 0.0740740741 Note In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total. In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>. Submitted Solution: ``` ''' D. Jerry's Protest time limit per test: 2 seconds memory limit per test: 256 megabytes Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10**(-6). Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if |a-b|/max(1,b)<=10**(-6) ''' import io import sys import time import random import bisect start = time.clock() #~ test = '''3 #~ 1 2 10''' #~ sys.stdin = io.StringIO(test) n = int(input()) balls = sorted(map(int, input().split())) def find_ge(a, val): ''' a is a sorted, non-empty array finds first index i such that a[i]>=val if no such index exists (max(a)<val) return len(a) ''' return bisect.bisect_left(a,val) #~ print(find_ge([1,2,10],3)) #~ exit() def jerrywinsbytotal(diff): '''Returns the number of times when Jerry wins because J>A+diff, J,A take possible values in sorted array balls''' if diff==0: return n*(n-1)//2 if diff<0: return n*(n-1)//2-jerrywinsbytotal(-diff) # diff>0 # find first index i such that balls[i]>balls[j]+diff c = 0 # count for j in range(n): #~ print("searching for", balls[j]+diff, "with j=",j) i = find_ge(balls, balls[j]+diff) #~ print("idx",i) if i==n: return c c += n-i return c cache = dict() count = 0 for a1 in range(n): for j1 in range(a1): diff = balls[a1]-balls[j1] if balls[-1]<=balls[0]+diff: # Jerry cannot win continue for a2 in range(n): for j2 in range(a2): diff += balls[a2]-balls[j2] # advantage of Andrew if balls[-1]<=balls[0]+diff: # Jerry cannot win continue if diff not in cache: cache[diff] = jerrywinsbytotal(diff) #~ print(a1,j1,a2,j2,diff,cache[diff]) count += cache[diff] s = n*(n-1)//2 print(count/(s**3)) #~ print(0,jerrywinsbytotal(0)) #~ print(1,jerrywinsbytotal(1)) #~ print(2,jerrywinsbytotal(2)) #~ print(10,jerrywinsbytotal(10)) #~ dur = time.clock()-start #~ print("Time:",dur) ```
instruction
0
60,234
19
120,468
No
output
1
60,234
19
120,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 1 2 Output 0.0000000000 Input 3 1 2 10 Output 0.0740740741 Note In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total. In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>. Submitted Solution: ``` from sys import * n = int(input()) m = int(5000) vls = list({int(t) for t in stdin.readline().split()}) r1 = [0 for t in range(m)] for i in range(n-1): for k in range(i+1, n): r1[vls[k] - vls[i]] += 1 r2 = [0 for t in range(m)] for i in range(m): for k in range(m-i): r2[i+k] += r1[i]*r1[k] ans = int(0) for t1 in range(m-1, 0, -1): for t2 in range(t1-1, -1, -1): ans += r1[t1]*r2[t2] d = (n-1)*n/2 print("{0:06f}".format(float(ans)/(d**3))) ```
instruction
0
60,235
19
120,470
No
output
1
60,235
19
120,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 1 2 Output 0.0000000000 Input 3 1 2 10 Output 0.0740740741 Note In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total. In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>. Submitted Solution: ``` n = int(input()) t = sorted(map(int, input().split())) m = 5000 d = [0, 0] * m for a in t: for b in t: d[b - a] += 1 for i in range(m, 2 * m): d[i] = d[i - 1] + d[i] s = 0 for i in range(1, m): for j in range(i, m - i): s += d[i] * d[j] * d[-1 - i - j] print(8 * s / (n * n - n) ** 3) ```
instruction
0
60,236
19
120,472
No
output
1
60,236
19
120,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds. Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew? Input The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. Output Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 1 2 Output 0.0000000000 Input 3 1 2 10 Output 0.0740740741 Note In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total. In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>. Submitted Solution: ``` import sys # sys.stdin = open("ivo.in") n = int(sys.stdin.readline()) a = [int(s) for s in sys.stdin.readline().split()] a.sort() diffs1 = [] for i in range(5000): diffs1.append(0) for i in range(n): for j in range(i + 1, n): diffs1[a[j] - a[i]] += 1 # for i in range(1, n): # diffs1[i] += diffs1[i - 1] diffs2 = [] for i in range(10000): diffs2.append(0) for i in range(len(diffs1)): for j in range(i, len(diffs1)): diffs2[i + j] += diffs1[i] * diffs1[j] for i in range(1, len(diffs2)): diffs2[i] += diffs2[i - 1] good = 0 for u in range(n - 1, 0, -1): for t in range(u - 1, -1, -1): good += diffs2[a[u] - a[t] - 1] all = (n * (n - 1)) // 2 all = all * all * all print(float(good) / float(all)) ```
instruction
0
60,237
19
120,474
No
output
1
60,237
19
120,475
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,543
19
121,086
"Correct Solution: ``` N,A = map(int,input().split()) x = list(map(int,input().split())) X = N*50 dp = [[[0 for i in range(X+1)] for j in range(N+1)] for k in range(N+1)] dp[0][0][0] = 1 for k in range(1,N+1): for j in range(k+1): for i in range(j*50+1): if i - x[k-1] < 0: dp[k][j][i] = dp[k-1][j][i] elif k >= 1: dp[k][j][i] = dp[k-1][j-1][i-x[k-1]] + dp[k-1][j][i] ans = 0 for j in range(1,N+1): ans += dp[-1][j][j*A] print(ans) ```
output
1
60,543
19
121,087
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,544
19
121,088
"Correct Solution: ``` n,a = map(int,input().split()) xl = list(map(int,input().split())) # i個のカードまで使って和がjの組み合わせ dp = [[0 for i in range(50*50+1)] for j in range(51)] dp[0][0] = 1 for i in range(n): for j in range(n-1, -1, -1): for k in range(50*50+1): if k+xl[i] < 50*50+1: dp[j+1][k+xl[i]] += dp[j][k] ans = 0 for i in range(1,n+1): ans += dp[i][i*a] print(ans) ```
output
1
60,544
19
121,089
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,545
19
121,090
"Correct Solution: ``` N, A = map(int, input().split()) X = list(map(int, input().split())) dp = [[[0 for _ in range(3000)] for _ in range(N + 1)] for _ in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for j in range(N): for t in range(2501): dp[i + 1][j][t] += dp[i][j][t] dp[i + 1][j + 1][t + X[i]] += dp[i][j][t] ans = 0 for i in range(1, N + 1): ans += dp[N][i][i * A] print(ans) ```
output
1
60,545
19
121,091
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,546
19
121,092
"Correct Solution: ``` N, A = map(int,input().split()) x = list(map(int,input().split())) dp = [[[0]*(max(sum(x),N*A)+1) for k in range(N+1)] for l in range(N+1)] # dp[i][j][k] := i番目まででj枚選んで和がkになる組み合わせの数 dp[0][0][0] = 1 for i in range(N): for j in range(N): for k in range(sum(x)+1): dp[i+1][j][k] += dp[i][j][k] if k-x[i] >= 0: dp[i+1][j+1][k] += dp[i][j][k-x[i]] ans = 0 for k in range(1,N+1): ans += dp[N][k][A*k] print(ans) ```
output
1
60,546
19
121,093
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,547
19
121,094
"Correct Solution: ``` N,A = map(int,input().split()) X = list(map(int,input().split())) for i in range(N): X[i] -= A from collections import defaultdict counter = defaultdict(int) counter[0] = 1 for x in X: copy = dict(counter) for k,v in copy.items(): counter[k+x] += v print(counter[0]-1) ```
output
1
60,547
19
121,095
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,548
19
121,096
"Correct Solution: ``` n,a=map(int,input().split()) X=list(map(int,input().split())) m=max(X) Y=map(lambda x:x-a,X) DP=[[0]*(2*m*n+1) for _ in range(n+1)] DP[0][m*n]=1 for i,y in enumerate(Y): for j in range(2*m*n+1): DP[i+1][j]=DP[i][j] if 0<=j-y<=2*m*n: DP[i+1][j]+=DP[i][j-y] print(DP[n][m*n]-1) ```
output
1
60,548
19
121,097
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,549
19
121,098
"Correct Solution: ``` def main(): N, A = map(int, input().split()) x = list(map(int, input().split())) x.insert(0, 0) dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)] for i in range(N + 1): dp[i][0][0] = 1 for i in range(1, N + 1): for j in range(1, i + 1): for k in range(1, N * A + 1): dp[i][j][k] = dp[i - 1][j][k] if k >= x[i]: dp[i][j][k] += dp[i - 1][j - 1][k - x[i]] ans = 0 for j in range(1, N + 1): ans += dp[N][j][A * j] print(ans) if __name__ == '__main__': main() ```
output
1
60,549
19
121,099
Provide a correct Python 3 solution for this coding contest problem. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
instruction
0
60,550
19
121,100
"Correct Solution: ``` import sys import copy readline = sys.stdin.buffer.readline def main(): N, A = map(int, readline().split()) X = list(map(int, readline().split())) X = [x - A for x in X] dp = [0] * 5050 dp[2525] = 1 for i in range(N): next_dp = copy.copy(dp) for t in range(5050): if X[i] + t < 5050: next_dp[X[i] + t] += dp[t] dp = next_dp print(dp[2525] - 1) if __name__ == '__main__': main() ```
output
1
60,550
19
121,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` n,a = map(int,input().split()) x = list(map(int,input().split())) dp = [] for i in range(n+1): dp.append([[] for j in range(i+1)]) for k in range(i+1): dp[i][k] = [0 for y in range(50*k)] for i in range(n+1): dp[i][0].append(0) for i in range(1,n+1): for j in range(1,i+1): if j == 1: dp[i][j][x[i-1]-1] += 1 for k in range(50*(j-1)): dp[i][j][k+x[i-1]] += dp[i-1][j-1][k] dp[i][j-1][k] += dp[i-1][j-1][k] count = 0 for j in range(1,i+1): for k in range(len(dp[i][j])): if k + 1 == j*a: count += dp[n][j][k] print(count) ```
instruction
0
60,551
19
121,102
Yes
output
1
60,551
19
121,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` N,A=map(int,input().split()) X=[x-A for x in map(int,input().split())] dp=[0]*(N*100+1) dp[0]=1 for x in X: if x>0: for i in range(N*50,-N*50-1,-1): if dp[i]>0: dp[i+x]+=dp[i] else: for i in range(-N*50,N*50+1): if dp[i]>0: dp[i+x]+=dp[i] print(dp[0]-1) ```
instruction
0
60,552
19
121,104
Yes
output
1
60,552
19
121,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` n,a = map(int, input().split()) x = list(map(int,input().split())) x = [i-a for i in x] d = {} d[0] = 1 for i in x: for j,k in list(d.items()): d[j+i] = d.get(j+i,0)+k print(d[0]-1) ```
instruction
0
60,553
19
121,106
Yes
output
1
60,553
19
121,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` n,a=map(int,input().split()) x=list(map(int,input().split())) p=min(a*n,sum(x)) dp=[[[0]*(n+1)for _ in range(p+1)]for _ in range(n+1)] dp[0][0][0]=1 for i in range(1,n+1): for j in range(p+1): for k in range(n+1): dp[i][j][k]+=dp[i-1][j][k] if j-x[i-1]>=0 and k>=1: dp[i][j][k]+=dp[i-1][j-x[i-1]][k-1] ans=0 for i in range(1,n+1): if i*a>p: break ans+=dp[-1][i*a][i] print(ans) ```
instruction
0
60,554
19
121,108
Yes
output
1
60,554
19
121,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` N,A=map(int,input().split()) a=list(map(int, input().split())) def hiku(kazu): return kazu-A b=[] for i in range(N): b.append(hiku(a[i])) X=max(a) def hai(s,t): if s==0 and t==NX: return 1 elif s>=1 and (t-b[s]<0 or t-b[s]>2NX): return hai(s-1,t) elif s>=1 and (0<=t-b[s]<=2NX): return hai(s-1,t)+hai(s-1,t-b[s]) else: return 0 print(hai(N,NX)-1) ```
instruction
0
60,555
19
121,110
No
output
1
60,555
19
121,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` N,A = map(int,input().split()) X = [0]+list(map(int,input().split())) dp = [] for i in range(N+1): K = [] for j in range(N+1): J = [0]*(N*max(X)+1) K.append(J) dp.append(K) for j in range(N+1): for k in range(N+1): for s in range(N*max(X)+1): if j >= 1: if s < X[j]: dp[j][k][s] = dp[j-1][k][s] elif s >= X[j] and k >= 1: dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-X[j]] else: dp[j][k][s] = 0 else: if k == 0 and s == 0: dp[j][k][s] = 1 else: dp[j][k][s] = 0 ans = 0 for i in range(1,N+1): ans += dp[N][i][i*A] print(ans) ```
instruction
0
60,556
19
121,112
No
output
1
60,556
19
121,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` n,a = map(int,input().split()) x = list(map(int,input().split())) for i in range(n): x[i] -= a ans = 0 for i in range(1,2**n): b,t,j = i,0,0 while b > 0: if b % 2 != 0: t += x[j] b = b // 2 j += 1 if t == 0: ans += 1 print(ans) ```
instruction
0
60,557
19
121,114
No
output
1
60,557
19
121,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591 Submitted Solution: ``` N, A = map(int, input().split()) x= [int(i) for i in input().split()] X = max(x) dp = [[[0]*(X*N+1) for i in range(N+1)] for j in range(N+1)] dp[0][0][0] = 1 ans = 0 for j in range(1,N+1): for k in range(j+1): for s in range(X*N+1): dp[j][k][s] = dp[j-1][k][s] if s >= x[j-1]: dp[j][k][s] += dp[j-1][k-1][s-x[j-1]] for i in range(1,N+1): ans += dp[-1][i][i*A] if (i+1)*A > X*N: break print(ans) ```
instruction
0
60,558
19
121,116
No
output
1
60,558
19
121,117
Provide a correct Python 3 solution for this coding contest problem. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20
instruction
0
60,575
19
121,150
"Correct Solution: ``` def solve(X, Y, Z, V, E, A): dp = [[0.0] * 6001 for _ in range(Y + 11)] dp[0][0] = 1.0 for i in range(Y): for j in range(5001): if dp[i][j] <= 0.0: continue for k in V: t = i + k if t > Y: dp[Y][j] += dp[i][j]/X elif E[t] == 1: dp[min(Y, t+A[t])][j] += dp[i][j]/X else: dp[t][max(0, j+A[t])] += dp[i][j]/X s = 0 for i in range(5001): s += i * dp[Y][i] print(int(s)) if __name__ == "__main__": while True: X, Y, Z = map(int, input().split()) if X | Y | Z == 0: break V = list(map(int, input().split())) E = [0] * 100 A = [0] * 100 for _ in range(Z): n, e, a = map(int, input().split()) E[n] = e if e == 3: A[n] = -a else: A[n] = a solve(X, Y, Z, V, E, A) ```
output
1
60,575
19
121,151
Provide a correct Python 3 solution for this coding contest problem. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20
instruction
0
60,576
19
121,152
"Correct Solution: ``` def solve(X, Y, Z, V, E, A): dp = [[0.0] * 6001 for _ in range(Y + 11)] dp[0][0] = 1.0 for i in range(Y): for j in range(5001): if dp[i][j] <= 0.0: continue for k in V: t = i + k if t > Y: dp[Y][j] += dp[i][j]/X elif E[t] == 1: dp[min(Y, t+A[t])][j] += dp[i][j]/X else: dp[t][max(0, j+A[t])] += dp[i][j]/X s = 0 for i in range(5001): s += i * dp[Y][i] print(int(s)) if __name__ == "__main__": import sys while True: X, Y, Z = map(int, input().split()) if X | Y | Z == 0: sys.exit() V = list(map(int, input().split())) E = [0] * 100 A = [0] * 100 for _ in range(Z): n, e, a = map(int, input().split()) E[n] = e if e == 3: A[n] = -a else: A[n] = a solve(X, Y, Z, V, E, A) ```
output
1
60,576
19
121,153
Provide a correct Python 3 solution for this coding contest problem. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20
instruction
0
60,577
19
121,154
"Correct Solution: ``` def solve(X, Y, Z, V, E, A): dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)] dp[0][0] = 1.0 for i in range(Y): for j in range(5001): if dp[i][j] <= 0.0: continue for k in V: t = i + k if t > Y: dp[Y][j] += dp[i][j]/X elif E[t] == 1: dp[min(Y, t+A[t])][j] += dp[i][j]/X else: dp[t][max(0, j+A[t])] += dp[i][j]/X s = 0 for i in range(5001): s += i * dp[Y][i] print(int(s)) if __name__ == "__main__": import sys while True: X, Y, Z = map(int, input().split()) if X | Y | Z == 0: sys.exit() V = list(map(int, input().split())) E = [0] * 100 A = [0] * 100 for _ in range(Z): n, e, a = map(int, input().split()) E[n] = e if e == 3: A[n] = -a else: A[n] = a solve(X, Y, Z, V, E, A) ```
output
1
60,577
19
121,155
Provide a correct Python 3 solution for this coding contest problem. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20
instruction
0
60,578
19
121,156
"Correct Solution: ``` def solve(X, Y, Z, V, E, A): dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)] dp[0][0] = 1.0 for i in range(Y): for j in range(5001): if dp[i][j] <= 0.0: continue for k in V: t = i + k if t > Y: dp[Y][j] += dp[i][j]/X elif E[t] == 1: dp[min(Y, t+A[t])][j] += dp[i][j]/X else: dp[t][max(0, j+A[t])] += dp[i][j]/X s = 0 for i in range(5001): if dp[Y][i] <= 0.0: continue s += i * dp[Y][i] print(int(s)) if __name__ == "__main__": import sys while True: X, Y, Z = map(int, input().split()) if X | Y | Z == 0: sys.exit() V = list(map(int, input().split())) E = [0] * 100 A = [0] * 100 for _ in range(Z): n, e, a = map(int, input().split()) E[n] = e if e == 3: A[n] = -a else: A[n] = a solve(X, Y, Z, V, E, A) ```
output
1
60,578
19
121,157
Provide a correct Python 3 solution for this coding contest problem. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20
instruction
0
60,579
19
121,158
"Correct Solution: ``` from heapq import heappush, heappop def main(): while True: x, y, z = map(int, input().split()) if x == 0:break vlst = list(map(int, input().split())) events = {} for _ in range(z): n, e, a = map(int, input().split()) events[n] = (e, a) que = [] heappush(que, (0, 0)) cnt = [[0] * (100 * y + 1) for _ in range(y + 1)] init = x ** y cnt[0][0] = init visited = {} while que: pos, score = heappop(que) for v in vlst: new_pos = pos + v new_score = score if new_pos in events: event, value = events[new_pos] if event == 1: new_pos += value elif event == 2: new_score += value else: new_score = max(new_score - value, 0) if new_pos >= y: cnt[y][new_score] += cnt[pos][score] // x else: cnt[new_pos][new_score] += cnt[pos][score] // x if (new_pos, new_score) not in visited: visited[(new_pos, new_score)] = True heappush(que, (new_pos, new_score)) total = 0 for score in range(100 * y + 1): total += cnt[y][score] * score print(total // init) main() ```
output
1
60,579
19
121,159
Provide a correct Python 3 solution for this coding contest problem. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20
instruction
0
60,580
19
121,160
"Correct Solution: ``` def solve(X, Y, Z, V, E, A): dp = [[0.0] * 6001 for _ in range(Y + 11)] dp[0][0] = 1.0 for i in range(Y): for j in range(5001): if dp[i][j] <= 0.0: continue for k in V: t = i + k if t > Y: dp[Y][j] += dp[i][j]/X elif E[t] == 1: dp[min(Y, t+A[t])][j] += dp[i][j]/X else: dp[t][max(0, j+A[t])] += dp[i][j]/X s = 0 for i in range(5001): if dp[Y][i] <= 0.0: continue s += i * dp[Y][i] print(int(s)) if __name__ == "__main__": import sys while True: X, Y, Z = map(int, input().split()) if X | Y | Z == 0: sys.exit() V = list(map(int, input().split())) E = [0] * 100 A = [0] * 100 for _ in range(Z): n, e, a = map(int, input().split()) E[n] = e if e == 3: A[n] = -a else: A[n] = a solve(X, Y, Z, V, E, A) ```
output
1
60,580
19
121,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20 Submitted Solution: ``` def solve(X, Y, Z, V, E, A): dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)] dp[0][0] = 1.0 for i in range(Y): for j in range(5001): if dp[i][j] <= 0.0: continue for k in V: t = i + k if t > Y: dp[Y][j] += dp[i][j]/X elif E[t] == 1: dp[min(Y, t+A[t])][j] += dp[i][j]/X else: dp[t][max(0, j+A[t])] += dp[i][j]/X s = 0 for i in range(5001): if dp[Y][i] <= 0.0: continue s += i * dp[Y][i] print(int(s)) if __name__ == "__main__": import sys while True: X, Y, Z = map(int, input().split()) if X | Y | Z == 0: sys.exit() V = map(int, input().split()) E = [0] * 100 A = [0] * 100 for _ in range(Z): n, e, a = map(int, input().split()) E[n] = e if e == 3: A[n] = -a else: A[n] = a solve(X, Y, Z, V, E, A) ```
instruction
0
60,581
19
121,162
No
output
1
60,581
19
121,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the pieces are advanced according to the number of pieces that are turned by turning the roulette wheel. Depending on the square, there are event squares where you can earn money or change the position of the pieces by stopping or passing there. The final victory or defeat is determined by the amount of money you have when the piece reaches the goal point. <image> The interesting thing about the game of life at this company is that the size of the roulette eyes, the number of squares to the goal, and the arrangement of the event squares are different for each package. They are written on the case and can be confirmed by reading it. Taro wants to choose the life game that earns the most money, and wants to buy the one with the highest expected value of money. So you decided to help Taro choose a game. Suppose a roulette wheel divides its circumference into X equal parts, each filled with the values ​​V1, V2, ..., VX. The board has squares numbered 0, 1, ..., Y, and they are connected in order. There are Z special squares called event squares in the squares, and when they reach them, they perform special actions. The number of the square of the event square is given by Ni. There are 1 to 3 types (Ei) of event masses, each of which performs the following actions: Type (Ei) | Special Behavior | Value (Ai) Range --- | --- | --- 1 | Advance by the specified value Ai | 1 ~ 10 2 | Get the amount of the specified value Ai | 1 ~ 100 3 | Pay the amount of the specified value Ai | 1 ~ 100 The first amount of money you have is 0 yen, starting from the 0th square and reaching the goal when you reach the Yth square. If you exceed the goal, it is also considered as a goal. There are no events at the start and goal, and multiple events do not overlap in one square. Ignore the events in the squares that are advanced by the event. If the amount of money you have is less than 0 yen, it will be 0 yen. For example, the expected value of money earned in a life game can be calculated as follows. <image> This example shows a life game consisting of three squares: start, event square (get 100 yen), goal, and roulette with 1 or 2. First, when you turn the roulette wheel for the first time, if you get a 1, you will reach the event square and your money will be 100 yen. On the other hand, if you get a 2, you will reach the goal and your money will remain at 0 yen. Both of these occur with a one-half chance. In addition, if you reach the event square the first time, you will turn the roulette wheel the second time, but you will reach the goal no matter what value you get, and you will have 100 yen in each case. As you can see, there are three ways to reach the goal. Focusing on the amount of money you have when you reach the goal, there is one case where the amount is 0 yen and the probability is one half, and there are two cases where the probability is 100 yen and the probability is one quarter. In this case, the expected value of the amount of money you have at the goal is the sum of (the amount of money you have x the probability) for each goal method, and the expected value of this life game is 50 yen. Create a program that inputs roulette information and board information and outputs the expected value of the amount of money you have at the goal. Input A sequence of multiple datasets is given as input. The end of the input is indicated by three zero lines. Each dataset is given in the following format: X Y Z V1 V2 ... VX N1 E1 A1 N2 E2 A2 :: NZ EZ AZ X (1 ≤ X ≤ 4), Vi (1 ≤ Vi ≤ 10), Y (1 ≤ Y ≤ 50), Ni (1 ≤ Ni ≤ Y-1), Z (0 ≤ Z ≤ Y-1), Ei (1 ≤ Ei ≤ 3), Ai (1 ≤ Ai ≤ 100) are given as integers. The number of datasets does not exceed 100. Output For each input dataset, the expected value of the final amount of money is output on one line. Please output the expected value of your money as an integer rounded down to the nearest whole number. Example Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output 0 100 0 50 20 Submitted Solution: ``` def solve(X, Y, Z, V, E, A): dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)] dp[0][0] = 1.0 for i in range(Y): for j in range(5001): if dp[i][j] <= 0.0: continue for k in V: t = i + k if t > Y: dp[Y][j] += dp[i][j]/X elif E[t] == 1: dp[min(Y, t+A[t])][j] += dp[i][j]/X else: dp[t][max(0, j+A[t])] += dp[i][j]/X s = 0 for i in range(5001): if dp[Y][i] <= 0.0: continue s += i * dp[Y][i] print int(s) if __name__ == "__main__": import sys while True: X, Y, Z = map(int, input().split()) if X | Y | Z == 0: sys.exit() V = map(int, input().split()) E = [0] * 100 A = [0] * 100 for _ in range(Z): n, e, a = map(int, input().split()) E[n] = e if e == 3: A[n] = -a else: A[n] = a solve(X, Y, Z, V, E, A) ```
instruction
0
60,582
19
121,164
No
output
1
60,582
19
121,165
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
61,051
19
122,102
Tags: constructive algorithms, greedy, math Correct Solution: ``` a, b = map(int, input().split(' ')) print((6*a-1)*b) for i in range(a): print((6*i+1)*b, (6*i+2)*b, (6*i+3)*b, (6*i+5)*b) ```
output
1
61,051
19
122,103
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
61,053
19
122,106
Tags: constructive algorithms, greedy, math Correct Solution: ``` n,k=[int(x) for x in input().split()] print((6*n-1)*k) for i in range(n): print (k*(6*i+1),k*(6*i+2),k*(6*i+3),k*(6*i+5)) ```
output
1
61,053
19
122,107
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
61,054
19
122,108
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, k = list(map(int,input().split())) print((6*n-1)*k) for i in range(0, n): print((6*i+1)*k,(6*i+2)*k,(6*i+3)*k,(6*i+5)*k) ```
output
1
61,054
19
122,109
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
61,055
19
122,110
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, k = map(int, input().split()) print(k*(6*n-1)) for i in range (n): print(k*(6*i+1), k * (6*i+3), k*(6*i+4), k * (6*i+5)) ```
output
1
61,055
19
122,111
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
61,056
19
122,112
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys def main(): # fin = open("input.txt", "r") fin = sys.stdin fout = sys.stdout n, k = map(int, fin.readline().split()) m = 5 + 6 * (n - 1) m *= k print(m) print(k, 2 * k, 3 * k, 5 * k) idx = 1 for i in range(1, n): idx += 6 print(idx * k, (idx + 1) * k, (idx + 2) * k, (idx + 4) * k) fin.close() fout.close() main() ```
output
1
61,056
19
122,113
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
61,057
19
122,114
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, k = map(int, input().split()) m = 6 * n - 1 print(m * k) for i in range(n): for j in [1, 2, 3, 5]: print(k * (6 * i + j), end = ' ') print() ```
output
1
61,057
19
122,115
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
61,058
19
122,116
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys def solve(): n, k, = rv() res = list() cur = 1 for i in range(n): while cur % 2 == 0: cur+=1 res.append(((cur) * k, (cur + 1) * k, (cur + 2) * k, (cur + 4) * k)) cur += 5 print(res[-1][-1]) print('\n'.join((' '.join(map(str, l))) for l in res)) #12 14 16 20 # 2 * 2 * 3 2 * 7 2 * 2 * 2 * 2 2 * 3 * 3 # 1 2 3 5 # 7 8 9 11 # 13 # 19 # 25 # 31 def prt(l): return print(' '.join(l)) def rv(): return map(int, input().split()) def rl(n): return [list(map(int, input().split())) for _ in range(n)] if sys.hexversion == 50594544 : sys.stdin = open("test.txt") solve() ```
output
1
61,058
19
122,117
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>. Submitted Solution: ``` n, k = map(int, input().split()) print(k * (6 * n - 1)) for i in range(1, n + 1): x = (i - 1) * 6 + 1 print(k * x, end = ' ') print(k * (x + 1), end = ' ') print(k * (x + 2), end = ' ') print(k * (x + 4)) ```
instruction
0
61,059
19
122,118
Yes
output
1
61,059
19
122,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>. Submitted Solution: ``` n,k = [int(i) for i in input().split()] print((6*n-1)*k) for a in range(n): val = 6*a print((val+1)*k,(val+2)*k,(val+3)*k,(val+5)*k) ```
instruction
0
61,060
19
122,120
Yes
output
1
61,060
19
122,121