message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
42
109k
cluster
float64
5
5
__index_level_0__
int64
84
217k
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,320
5
174,640
"Correct Solution: ``` MOD = 10 ** 9 + 7 FACT_MAX = 10 ** 5 fact = [1] * FACT_MAX for i in range(1, FACT_MAX): fact[i] = fact[i - 1] * i % MOD def comb(n, r): return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD) N, K = map(int, input().split()) A = sorted(map(int, input().split())) print(sum(comb(i, K - 1) * (A[i] - A[N - i - 1]) % MOD for i in range(K - 1, N)) % MOD) ```
output
1
87,320
5
174,641
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,321
5
174,642
"Correct Solution: ``` N,K=map(int,input().split()) A=list(map(int,input().split())) mod = 10**9+7 if K==1:print(0) else: factorial=[1 for i in range(N+1)] for i in range(1,N+1): if i==1:factorial[i]=1 else:factorial[i] = factorial[i-1]*i % mod def comb(n,k): return factorial[n]*pow(factorial[n-k]*factorial[k], -1, mod) A1=sorted(A) A2=A1[::-1] ans=0 for i in range(N-K+1): ans += (A2[i]-A1[i])*comb(N-i-1,K-1) ans %= mod print(ans) ```
output
1
87,321
5
174,643
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,322
5
174,644
"Correct Solution: ``` N,K=map(int,input().split()) A=sorted(map(int,input().split())) r=0 MOD=10**9+7 max_n=10**5 fac=[1]*(max_n+1) inv=[1]*(max_n+1) ifac=[1]*(max_n+1) for n in range(2,max_n+1): fac[n]=(fac[n-1]*n)%MOD inv[n]=MOD-inv[MOD%n]*(MOD//n)%MOD ifac[n]=(ifac[n-1]*inv[n])%MOD def comb(n,k): if n<k: return 0 if n<0 or k<0: return 0 return (fac[n]*ifac[k]*ifac[n-k])%MOD for i,a in enumerate(A): r=(r+(comb(i,K-1)-comb(N-1-i,K-1))*a)%MOD print(r) ```
output
1
87,322
5
174,645
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,323
5
174,646
"Correct Solution: ``` n,k=[int(i) for i in input().split()] arr=[int(i) for i in input().split()] ans=0 mod=10**9+7 arr.sort() c=[0 for i in range(n)] r=k-1 c[r]=1 def modinv(x,mod): return pow(x,mod-2,mod) for i in range(r+1,n): c[i]=((c[i-1]*(i))*modinv(i-r,mod))%mod pos=0 neg=0 for i in range(n): pos+=(arr[-1-i]*c[-1-i])%mod neg+=(arr[i]*c[-1-i])%mod pos%=mod neg%=mod print((pos-neg)%mod) ```
output
1
87,323
5
174,647
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,324
5
174,648
"Correct Solution: ``` MOD = 10 ** 9 + 7 def comb(n, r): return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD) N, K = map(int, input().split()) fact = [1] * N for i in range(1, N): fact[i] = fact[i - 1] * i % MOD A = sorted(map(int, input().split())) print(sum(comb(i, K - 1) * (A[i] - A[N - i - 1]) % MOD for i in range(K - 1, N)) % MOD) ```
output
1
87,324
5
174,649
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,325
5
174,650
"Correct Solution: ``` MOD = 1000000007 N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() step =[1]*(N+1) for i in range(1,N+1,1): step[i]= (step[i-1]*i)%MOD def nCk(n,k): return (step[n]*pow(step[k],MOD-2,MOD)*pow(step[n-k],MOD-2,MOD))%MOD max_sum=0 min_sum=0 for i in range(0,N,1): if i+1 < K: continue max_sum += (A[i]*nCk(i,K-1) + MOD)%MOD min_sum += (A[N-1-i]*nCk(i,K-1) + MOD)%MOD print((max_sum-min_sum)%MOD) ```
output
1
87,325
5
174,651
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,326
5
174,652
"Correct Solution: ``` from itertools import accumulate mod = 10 ** 9 + 7 N, K = map(int, input().split()) A = sorted([int(x) for x in input().split()]) f = [1 for _ in range(N + 1)] inv = [1 for _ in range(N + 1)] finv = [1 for _ in range(N + 1)] for i in range(2, N + 1): f[i] = f[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod comb = [f[n] * (finv[K - 1] * finv[n - (K - 1)] % mod) % mod for n in range(K - 1, N)] ans = 0 for i in range(N - K + 1): ans += comb[i] * (A[i + K - 1] - A[N - i - K]) ans %= mod print(ans) ```
output
1
87,326
5
174,653
Provide a correct Python 3 solution for this coding contest problem. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537
instruction
0
87,327
5
174,654
"Correct Solution: ``` mod = 10**9+7 f = [1] for i in range(10**5+7): f.append(f[-1]*(i+1)%mod) def comb(n, r,mod=mod): return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod n, k = map(int, input().split()) a = sorted(list(map(int, input().split())), reverse=True) ans = 0 for i in range(n-k+1): ans += (a[i] - a[-1-i]) * comb(n-1-i, k-1) ans %= mod print(ans) ```
output
1
87,327
5
174,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` m = 10 ** 9 + 7 f = [1] for i in range(10 ** 5 + 5): f.append(f[-1] * (i + 1) % m) def nCr(n,r,mod = m): return f[n] * pow(f[r],m - 2,m) * pow(f[n-r],m - 2,m) % m n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() ans = 0 for i in range(n - k + 1): ans += (a[-1-i] - a[i]) * nCr(n - 1 - i,k - 1) ans %= m print(ans) ```
instruction
0
87,328
5
174,656
Yes
output
1
87,328
5
174,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` n_=10**5+3 mod=10**9+7 fac=[1]*(n_+1) for i in range(1,n_+1): fac[i]=fac[i-1]*i%mod inv =[1]*(n_+1) inv[n_]=pow(fac[n_],mod-2,mod) for i in range(n_-1,0,-1): inv[i]=inv[i+1]*(i+1)%mod def nCr(n,r): if n<=0 or r<0 or r>n: return 0 return fac[n]*inv[r]%mod*inv[n-r]%mod n,k=map(int,input().split()) A=list(map(int,input().split())) A.sort() ans=0 for i in range(n-k+1): ans=(ans+(A[n-i-1]-A[i])*nCr(n-i-1,k-1))%mod print(ans) ```
instruction
0
87,329
5
174,658
Yes
output
1
87,329
5
174,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` MOD = 10**9 + 7 fac = [1 for k in range(200010)] inv = [1 for k in range(200010)] finv = [1 for k in range(200010)] for k in range(2,200010): fac[k] = (fac[k-1]*k)%MOD inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD finv[k] = (finv[k - 1] * inv[k]) % MOD; def nCr(n,r): return (fac[n]*finv[r]*finv[n-r])%MOD N, K = map(int,input().split()) A = sorted(list(map(int,input().split()))) m = 0 for k in range(N-K+1): m += A[k]*nCr(N-k-1,K-1) m %= MOD A = A[::-1] M = 0 for k in range(N-K+1): M += A[k]*nCr(N-k-1,K-1) M %= MOD print(M-m if M>=m else M-m+MOD) ```
instruction
0
87,330
5
174,660
Yes
output
1
87,330
5
174,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` N, K = map(int, input().split()) *A, = map(int, input().split()) A.sort() mod = 10**9+7 fac = [1]*(N+1) rev = [1]*(N+1) for i in range(1,N+1): fac[i] = i*fac[i-1]%mod rev[i] = pow(fac[i], mod-2, mod) comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod maxX, minX = 0, 0 for i in range(N-K+1): minX += A[i]*comb(N-i-1, K-1) for j in range(K-1, N): maxX += A[j]*comb(j, K-1) print((maxX-minX)%mod) ```
instruction
0
87,331
5
174,662
Yes
output
1
87,331
5
174,663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` # -*- coding: utf-8 -*- import numpy as np iNum, iK = map(int, input().split()) iK -= 1 naA = np.array(list(map(int, input().split())), dtype = "int64") naA = np.sort(naA) #print(naA) iMod = 1000000007 iRet = 1000000000000000 iRet*=0 iNmrt = 1 iDnmt = 1 for iK0 in range(iK): iNmrt *= iNum - iK0 iDnmt *= iK0 + 1 iU0= iNmrt // iDnmt #print(iNum, iK, iU0) iL0=0 iU = iNum for iL, iA in enumerate(naA): iU -= 1 if iL > iK: iL0 *= iL iL0//= iL - iK elif iL == iK: iL0 = 1 else: iL0 = 0 if iU >= iK: iU0 *= iU+1-iK iU0 //= iU+1 else: iU0 = 0 #print("iU, iK, iU0, iA :",iU,iK,iU0, iA) #print("iL, iK, iL0, iA :",iL,iK,iL0, iA) iL0mU0= iL0 - iU0 iRet0 = (iL0mU0 * iA) % iMod iRet += iRet0 #print(iRet0) iAp = iA print(iRet%iMod) ```
instruction
0
87,332
5
174,664
No
output
1
87,332
5
174,665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` import itertools N,K = map(int,input().split()) A = [int(x) for x in input().split()] def madfd(b): return max(b)-min(b) total = 0 mod = 10**9+7 for i in list(itertools.combinations(A,K)): total+=madfd(i) print(total%mod) ```
instruction
0
87,333
5
174,666
No
output
1
87,333
5
174,667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` """ ジャガー「わからん」 先にmax,minそれぞれの和を求める """ import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) def getComb(n, k, MOD): if n < k: return 0 if n-k < k: k = n-k # n!/(n-k)! comb = 1 for x in range(n-k+1, n+1): comb = (comb * x) % MOD # k! d = 1 for x in range(1, k+1): d = (d * x) % MOD # n!/((n-k)!*k!) comb *= pow(d, MOD-2, MOD) return comb % MOD def main(): N,K = map(int,input().split()) A = sorted([int(i) for i in input().split()]) #print(A) mod = 10**9+7 cmb = [0] * (N-K+1) for i in range(N-K+1): cmb[i] = getComb(i+(K-1),K-1,mod) #print(cmb) sum_max = 0 for i in range(K-1,N): sum_max = (sum_max + cmb[i-(K-1)] * A[i]) % mod #print(sum_max) sum_min = 0 for i in range(N-K,-1,-1): sum_min = (sum_min + cmb[(N-K)-i] * A[i]) % mod #print(sum_min) answer = sum_max - sum_min print(answer % mod) if __name__ == "__main__": main() ```
instruction
0
87,334
5
174,668
No
output
1
87,334
5
174,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints * 1 \leq N \leq 10^5 * 1 \leq K \leq N * |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7). Examples Input 4 2 1 1 3 4 Output 11 Input 6 3 10 10 10 -10 -10 -10 Output 360 Input 3 1 1 1 1 Output 0 Input 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Output 999998537 Submitted Solution: ``` import itertools nk = list(map(int, input().split())) a = list(map(int, input().split())) S = 0 allpat = list(itertools.combinations(a, nk[1])) for i in range(len(allpat)): S = (S + max(allpat[i]) - min(allpat[i])) % 1000000007 print(S) ```
instruction
0
87,335
5
174,670
No
output
1
87,335
5
174,671
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,392
5
174,784
"Correct Solution: ``` l = input() print(eval(l)) ```
output
1
87,392
5
174,785
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,393
5
174,786
"Correct Solution: ``` # -*- coding: utf-8 -*- # problem A print(eval(input())) ```
output
1
87,393
5
174,787
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,394
5
174,788
"Correct Solution: ``` a, b, c = input().split() x = int(a) y = int(c) print(x + y if b=='+' else x - y) ```
output
1
87,394
5
174,789
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,395
5
174,790
"Correct Solution: ``` a,b,c = input().split() print(int(a)+int(c) if b == "+" else int(a) - int(c)) ```
output
1
87,395
5
174,791
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,396
5
174,792
"Correct Solution: ``` str=input() print(eval(str)) ```
output
1
87,396
5
174,793
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,397
5
174,794
"Correct Solution: ``` print(eval(input().replace(' ',''))) ```
output
1
87,397
5
174,795
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,398
5
174,796
"Correct Solution: ``` A, op, B = map(str, input().split()) C = A + op + B print(eval(C)) ```
output
1
87,398
5
174,797
Provide a correct Python 3 solution for this coding contest problem. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2
instruction
0
87,399
5
174,798
"Correct Solution: ``` print(eval(input().strip())) ```
output
1
87,399
5
174,799
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` a=input().split() b,c=int(a[0]),int(a[2]) if a[1]=="+":print(b+c) else:print(b-c) ```
instruction
0
87,400
5
174,800
Yes
output
1
87,400
5
174,801
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` A,op,B=input().split() A,B=int(A),int(B) if op=="+": print(A+B) else: print(A-B) ```
instruction
0
87,401
5
174,802
Yes
output
1
87,401
5
174,803
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` # python my_input = str(input()) print(str(eval(my_input))) ```
instruction
0
87,402
5
174,804
Yes
output
1
87,402
5
174,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` a,c,b=input().split() print(int(a)+int(b) if c=="+" else int(a)-int(b)) ```
instruction
0
87,403
5
174,806
Yes
output
1
87,403
5
174,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` a = input().split() return int(a[0]) + int(a[2]) if a[1] == "+" else int(a[0]) - int(a[2]) ```
instruction
0
87,404
5
174,808
No
output
1
87,404
5
174,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` # python user_input = input("Input in format A op B") input_sep = user_input.split() input_a = int(input_sep[0]) operator = input_sep[1] input_b = int(input_sep[2]) if operator is '+': print(int(input_a + input_b)) elif operator is '-': print(int(input_a - input_b)) ```
instruction
0
87,405
5
174,810
No
output
1
87,405
5
174,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` A = int(input()) B = int(input()) OP = input(plus_minus) if OP == "-": print(int(A) + int(B)) elif OP == "+": print(int(A) - int(B)) ```
instruction
0
87,406
5
174,812
No
output
1
87,406
5
174,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Output Evaluate the formula and print the result. Examples Input 1 + 2 Output 3 Input 5 - 7 Output -2 Submitted Solution: ``` a,op,b=input() a=int(a) b=int(b) if op=="+": print(a+b) else: print(a-b) ```
instruction
0
87,407
5
174,814
No
output
1
87,407
5
174,815
Provide a correct Python 3 solution for this coding contest problem. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0
instruction
0
87,424
5
174,848
"Correct Solution: ``` dp = [[0 for _ in range(1001)] for _ in range(10)] dp[1][0] = dp[0][0] = 1 for now in range(1, 101): for used in range(9, 0, -1): dpu = dp[used] dpu_1 = dp[used - 1] for s in range(now, 1001): dpu[s] = dpu_1[s - now] + dpu[s] while True: n, s = map(int, input().split()) if not n: break print(dp[n][s]) ```
output
1
87,424
5
174,849
Provide a correct Python 3 solution for this coding contest problem. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0
instruction
0
87,425
5
174,850
"Correct Solution: ``` dp = [[0 for j in range(1001)] for i in range(10)] dp[0][0] = 1 for j in range(1, 1001): dp[0][j] = 0 for k in range(0, 101): for i in range(9, 0, -1): for j in range(k, 1001): dp[i][j] += dp[i - 1][j - k] while True: n, s = map(int, input().split()) if n + s == 0: break print(dp[n][s]) ```
output
1
87,425
5
174,851
Provide a correct Python 3 solution for this coding contest problem. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0
instruction
0
87,426
5
174,852
"Correct Solution: ``` ans = [[0 for i in range(1001)] for j in range(11)] ans[0][0] = 1 for i in range(101): for n in range(9, -1, -1): for s in range(1001 - i): ans[n + 1][s + i] += ans[n][s] while True: n, s = map(int, input().split()) if n == 0: break print(ans[n][s]) ```
output
1
87,426
5
174,853
Provide a correct Python 3 solution for this coding contest problem. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0
instruction
0
87,427
5
174,854
"Correct Solution: ``` """ now...今注目する値 used...使った数字の数 sum...それまでの合計 dp[now][used][sum]...nowまででused個の数字を使って合計sumの場合の数 dp[now][used][sum] = dp[now - 1][used - 1][sum - now] + dp[now - 1][used][sum] (used >= 1 and sum >= now) dp[now - 1][used][sum] (used == 0 or sum < now) 2次元化 dp[used][sum]...used個の数字を使って合計sumの場合の数 dp[used][sum] = dp[used - 1][sum - now] + dp[used][sum] (used >= 1 and sum >= now) ただし、usedの大きい順に更新する(更新がかぶるため) """ dp = [[0 for _ in range(1001)] for _ in range(10)] dp[1][0] = 1 dp[0][0] = 1 for now in range(1, 101): for used in range(9, 0, -1): for s in range(now, 1001): dp[used][s] = dp[used - 1][s - now] + dp[used][s] while True: n, s = map(int, input().split()) if not n: break print(dp[n][s]) ```
output
1
87,427
5
174,855
Provide a correct Python 3 solution for this coding contest problem. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0
instruction
0
87,428
5
174,856
"Correct Solution: ``` # AOJ 0097 Sum of Integers II # Python3 2018.6.15 bal4u dp = [[0 for s in range(1001)] for n in range(11)] dp[0][0] = 1 for k in range(101): for n in range(9, -1, -1): for s in range(1001-k): dp[n+1][s+k] += dp[n][s] while True: n, s = list(map(int, input().split())) if n == 0: break print(dp[n][s]) ```
output
1
87,428
5
174,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0 Submitted Solution: ``` def dp(m,n,s): if n == 1: if s > 100 or s < m: return 0 else: return 1 else: sum_ = 0 for i in range(m,min(s,100)+1): sum_ += dp(i+1,n-1,s-i) return sum_ while(1): n,s = [int(i) for i in input().split()] if n == 0 and s == 0: break print(dp(0,n,s)) ```
instruction
0
87,429
5
174,858
No
output
1
87,429
5
174,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0 Submitted Solution: ``` from itertools import combinations from sys import stdin sample = [_ for _ in range(101)] for _ in stdin.readlines() : n, s = map(int, _.split()) if n == 0 and s == 0 : break print(len([_2 for _2, _3 in enumerate(combinations(sample[:s], n)) if sum(_3) == s])) ```
instruction
0
87,430
5
174,860
No
output
1
87,430
5
174,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0 Submitted Solution: ``` def dp(m,n,s): if n == 1: if s > 100 or s < m: return 0 else: return 1 else: sum_ = 0 for i in range(m,min(s,100)+1): sum_ += dp(i,n-1,s-i) return sum_ fact = [0,0,1,3,6,10,15,21,28,36,45] while(1): n,s = [int(i) for i in input().split()] if n == 0 and s == 0: break print(dp(0,n,s-fact[n])) ```
instruction
0
87,431
5
174,862
No
output
1
87,431
5
174,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 1000) are given on one line, separated by a space. When both n and s are 0, it is the end of the input. The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. No input is given with more than 1010 combinations. Example Input 3 6 3 1 0 0 Output 3 0 Submitted Solution: ``` from copy import copy from itertools import combinations from sys import stdin sample = [_ for _ in range(101)] for _ in stdin.readlines() : n, s = map(int, _.split()) if n == 0 and s == 0 : break print(len([_2 for _2 in combinations(sample[:s], n) if sum(_2) == s])) ```
instruction
0
87,432
5
174,864
No
output
1
87,432
5
174,865
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,509
5
175,018
"Correct Solution: ``` import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) Max = sys.maxsize def l(): #intのlist return list(map(int,input().split())) def m(): #複数文字 return map(int,input().split()) def onem(): #Nとかの取得 return int(input()) def s(x): #圧縮 a = [] aa = x[0] su = 1 for i in range(len(x)-1): if aa == x[i+1]: a.append([aa,su]) aa = x[i+1] su = 1 else: su += 1 a.append([aa,su]) return a def jo(x): #listをスペースごとに分ける return " ".join(map(str,x)) def max2(x): #他のときもどうように作成可能 return max(map(max,x)) import fractions from functools import reduce def gcd(*numbers): return reduce(fractions.gcd, numbers) def gcd_list(numbers): return reduce(fractions.gcd, numbers) def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) n = onem() l = l() print(lcm_list(l)) ```
output
1
87,509
5
175,019
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,510
5
175,020
"Correct Solution: ``` # python template for atcoder1 from functools import reduce import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline def gcd(a, b): """ return gcd of a,b ユークリッド """ while b: a, b = b, a % b return a def list_gcd(l): """ l: list l のgcd を返す """ return reduce(gcd, l) def lcm(a, b): """ a,bの最小公倍数 """ return a*b//gcd(a, b) def list_lcm(l): """ l:list lのlcmを返す """ return reduce(lcm, l) n = int(input()) l = list(map(int, input().split())) print(list_lcm(l)) ```
output
1
87,510
5
175,021
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,511
5
175,022
"Correct Solution: ``` from functools import reduce def gcd(a,b): #最小公約数 if ((a%b) == 0 ): return b else: return (gcd(b,a%b)) def lcm(a,b): return a * b // gcd(a,b) n = int(input()) l = list(map(int,input().split())) print (reduce(lcm,l)) ```
output
1
87,511
5
175,023
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,512
5
175,024
"Correct Solution: ``` import math from functools import reduce n=int(input()) z=list(map(int,input().split())) def lcm_b(x,y): return (x*y)//(math.gcd(x,y)) def lcm(*z): return reduce(lcm_b,z,1) print(lcm(*z)) ```
output
1
87,512
5
175,025
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,513
5
175,026
"Correct Solution: ``` n = int(input()) A = tuple(map(int, input().split())) def gcd(a, b): if a < b: a, b = b, a while b != 0: a, b = b, a % b return a b = A[0] for a in A: b = a * b // gcd(a, b) print(b) ```
output
1
87,513
5
175,027
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,514
5
175,028
"Correct Solution: ``` import math input() b = 1 for a in [int(x) for x in input().split()]: b = a * b // math.gcd(a, b) print(b) ```
output
1
87,514
5
175,029
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,515
5
175,030
"Correct Solution: ``` from fractions import gcd def lcm(a,n): x = a[0] for i in range(1,n): x = (x * a[i]) // gcd(x,a[i]) return x n = int(input()) a = list(map(int,input().split())) print(lcm(a,n)) ```
output
1
87,515
5
175,031
Provide a correct Python 3 solution for this coding contest problem. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
instruction
0
87,516
5
175,032
"Correct Solution: ``` import fractions n=int(input()) a=list(map(int, input().split())) b=a[0] for i in range(1, n): b=b*a[i]//fractions.gcd(b, a[i]) print(b) ```
output
1
87,516
5
175,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` def gcd(a,b): while b != 0: a,b = b,a%b return a def lcm(a,b): return a*b//gcd(a,b) N = int(input()) a = list(map(int,input().split())) f = a[0] for i in range(1,N): f = lcm(f,a[i]) print(f) ```
instruction
0
87,517
5
175,034
Yes
output
1
87,517
5
175,035