output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s732227182
Wrong Answer
p03331
Input is given from Standard Input in the following format: N
N = int(input("input integer:")) hoge = [(A, B) for A in range(N) for B in range(N) if A + B == N] hogehoge = [] for C in range(len(hoge)): ini0 = 0 ini1 = 0 for i0 in list(str(hoge[C][0])): ini0 += int(i0) for i1 in list(str(hoge[C][1])): ini1 += int(i1) hoho = ini0 + ini1 hogehoge.append(hoho) print(min(hogehoge))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s011583191
Wrong Answer
p03331
Input is given from Standard Input in the following format: N
N = int(input()) results = [] for i in range(N + 1): for j in range(N + 1): if i + j == N: si = str(i) sj = str(j) count1 = 0 for x in si: count1 += int(x) for y in sj: count1 += int(y) results.append(count1) print(min(results))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s585541340
Accepted
p03331
Input is given from Standard Input in the following format: N
N = int(input()) p = 100 for i in range(1, N, 1): s = i t = 0 while s > 0: t += s % 10 s = (s - s % 10) // 10 u = N - i v = 0 while u > 0: v += u % 10 u = (u - u % 10) // 10 n = t + v if p > n: p = n print(p)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s162741822
Accepted
p03331
Input is given from Standard Input in the following format: N
def getinputdata(): array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() if data != "": array_result.append(data.split(" ")) else: flg = 0 finally: return array_result arr_data = getinputdata() n = int(arr_data[0][0]) cnt = 1 mindata = float("inf") while cnt < n: mysum = 0 for v in str(cnt): mysum += int(v) for v in str(n - cnt): mysum += int(v) mindata = min(mindata, mysum) cnt += 1 print(mindata)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s608793204
Accepted
p03331
Input is given from Standard Input in the following format: N
n = sum(map(int, input())) print([n, 10][n == 1])
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s064829652
Runtime Error
p03331
Input is given from Standard Input in the following format: N
N = int(input()) LR = [tuple(map(int, input().split())) for i in [None] * N] Lmin = sorted(LR, key=lambda x: x[0]) Rmax = sorted(LR, key=lambda x: x[1], reverse=True) T = 0 def t_len(lr): a = lr[1] - T b = T - lr[0] return a if a > b else b def select(l): return sorted(l, key=t_len, reverse=True)[0] def select2(l): a = abs(Lmin[0][0] - T) b = abs(Rmax[0][1] - T) return Lmin[0] if a > b else Rmax[0] def selectT(lr): if lr[0] <= T <= lr[1]: return T a = lr[1] - T b = T - lr[0] return lr[0] if a > b else lr[1] K = 0 for i in [None] * N: s = select2(LR) nextT = selectT(s) K += abs(nextT - T) T = nextT LR.remove(s) Lmin.remove(s) Rmax.remove(s) K += abs(T) print(K)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s171619209
Runtime Error
p03331
Input is given from Standard Input in the following format: N
N = int(input()) range_A = range(2,100001) min_total = 1000 for a in range_A: b = N - a if b < 1:continue sum_a = findSumOfDigits(a) sum_b = findSumOfDigits(b) total = sum_a + sum_b if total < min_total: min_total = total print(min_total)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s565855499
Runtime Error
p03331
Input is given from Standard Input in the following format: N
digit(num): sum = 0 while(num > 0): sum += num % 10 num = int(num / 10) return sum for a in range(2,n): sum_A =sum_digit(a) sum_B =sum_digit(n-a) all=min(all,(sum_A + sum_B)) print(all)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s878366086
Accepted
p03331
Input is given from Standard Input in the following format: N
l = [int(i) for i in input()] s = sum(l) print(s if s != 1 else 10)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s603635556
Runtime Error
p03331
Input is given from Standard Input in the following format: N
s = sum(list(input())) print(10 if s == 1 else s)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s997355098
Runtime Error
p03331
Input is given from Standard Input in the following format: N
from math import log10 n = int(input()) ans=0 l = log10(n) if int(l)==l: ans=10 else: while n>0: ans+=n%10 n//=10 print(ans)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s527383363
Runtime Error
p03331
Input is given from Standard Input in the following format: N
n=input() print(sum([int(i) for i in n])
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s446613263
Runtime Error
p03331
Input is given from Standard Input in the following format: N
N = int(input()) if N=10*i for i in range(1,5+1): print("10") else print(sum(int(str(N)))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s694853610
Runtime Error
p03331
Input is given from Standard Input in the following format: N
n = int(input() list = [] for a in range(2,n-1): sum = 0 sum1 = 0 b = n - a for j in range(len(str(a))): sum += int(str(a)[j]) for k in range(len(str(b))): sum1 += int(str(b)[k]) list.append(sum + sum1) print(min(list))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s330206788
Runtime Error
p03331
Input is given from Standard Input in the following format: N
N = int(input()) ans = float("inf") A = 0 B = N for i in range(N//2): A += 1 B -= 1 if A + B > N: break else: s_a = str(A) s_b = list(str(B)) a = [int(i) for i in s_a] b = [int(i) for i in s_b] ans = min(ans, sum(a)+sum(b) print(ans)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s159574372
Runtime Error
p03331
Input is given from Standard Input in the following format: N
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <limits.h> #include <assert.h> #include <math.h> #include <iostream> #include <algorithm> #include <map> #include <set> #include <stack> #include <queue> #include <string> #include <bitset> #include <vector> using namespace std; #define LL long long #define fi first #define se second #define lson l,mid,id<<1 #define rson mid+1,r,id<<1|1 #define ls id<<1 #define rs id<<1|1 #define MID(a,b) (((a)+(b))>>1) #define maxx(a,b) ((a)<(b)?(b):(a)) #define minx(a,b) ((a)<(b)?(a):(b)) #define absx(a) ((a)<0?-(a):(a)) #define mk(a,b) make_pair(a,b) #define pb(a) push_back(a) #define itr iterator #define lowbit(x) ((x)&-(x)) typedef unsigned LL ULL; typedef unsigned uint; typedef map<int,int> mii; typedef pair<int,int> pii; typedef pair<double,double> pdd; typedef pair<LL,LL> pLL; template< typename T > inline void read(T &x) { static bool fr_f; static char fr_ch; fr_f=0; x=0; fr_ch=getchar(); while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();} while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();} if(fr_f) x=-x; } template< typename T > inline void Max (T &a, T b) {if(a<b) a=b;} template< typename T > inline void Min (T &a, T b) {if(b<a) a=b;} template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;} template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;} const double pi = acos(-1.0) ; const int MOD = (int)1e9+7 ; const int INF = (int)0x3f3f3f3f ; const LL LINF = (LL)INF<<32|INF ; const int SINF = (uint)(-1)>>1 ; const LL SLINF = (ULL)(-1)>>1 ; const double DINF = 1e50 ; const double eps = 1e-5 ; const int maxn = (int) 1e5+20 ; const int maxm = (int) 1e6+20 ; const int maxk = (int) 1000+20 ; inline int sig(double x) {return x<-eps?-1:x>eps;} inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;} template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;} //--------------------start-------------------- int func(int x) { int res = 0; while(x) { res += x % 10; x /= 10; } return res; } void work() { int n; read(n); int ans = n; for(int i = 0; i <= n; i++) { Min(ans, func(i) + func(n - i)); } cout <<ans <<endl; } //---------------------end--------------------- int main() { #ifdef yukihana0416 freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); #endif // yukihana0416 work(); return 0; }
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s160419758
Runtime Error
p03331
Input is given from Standard Input in the following format: N
n = int(input()) x = n - 2 y = n - x if n < 10: print(n) if n = 10: print(1) else: resulty, resultx = 0, 0 while(x > 0): resultx += x % 10 x = x // 10 while(y > 0): resulty += y % 10 y = y // 10 #print(resulty+resultx) z = n//2 result = 0 while(z > 0): result += z % 10 z = z // 10 if result*2 < resulty+resultx: print(result*2) else: print(resulty+resultx)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s552284536
Runtime Error
p03331
Input is given from Standard Input in the following format: N
def findSumOfDigits(n): sum_digits = 0 while n > 0 : sum_digits += n % 10 n //= 10 return sum_digits N = int(input()) range_A = range(2,100001) min_total = 1000 for a in range_A: b = N - a if b < 1:continue sum_a = findSumOfDigits(a) sum_b = findSumOfDigits(b) total = sum_a + sum_b if total < min_total: min_total = total print(min_total)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s764255363
Runtime Error
p03331
Input is given from Standard Input in the following format: N
n = int(input()) def func(x) : res = 0 while x : x, res = x/10, res + x % 10 return res ans = n for i range(n + 1) : min(ans, func(i) + func(n - i)) print(ans)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s425005368
Runtime Error
p03331
Input is given from Standard Input in the following format: N
import math N = int(input()) n = N amari = 0 for i in range (len(str(N))): amari += n % 10 n = math.floor(n / 10) if amari = 1: print(10) else: print(amari)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s929426381
Accepted
p03331
Input is given from Standard Input in the following format: N
a = sum(int(i) for i in input()) print(10 if a == 1 else a)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s214836642
Wrong Answer
p03331
Input is given from Standard Input in the following format: N
n = int(input()) n4 = 0 n3 = 0 n2 = 0 n1 = 0 if n >= 10**4: n4 = n // 10**4 n = n - n4 * 10**4 if n >= 10**3: n3 = n // 10**3 n = n - n3 * 10**3 if n >= 10**2: n2 = n // 10**2 n = n - n2 * 10**2 if n >= 10: n1 = n // 10 n = n - n1 * 10 n0 = n print(n0 + n1 + n2 + n3 + n4)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Find the maximum possible number of operations. * * *
s727106404
Wrong Answer
p03018
Input is given from Standard Input in the following format: s
print("No")
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s553456483
Wrong Answer
p03018
Input is given from Standard Input in the following format: s
print("5")
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s682841485
Runtime Error
p03018
Input is given from Standard Input in the following format: s
import sys def check(abc_lst, idx, cnt): if abc_lst[idx:idx+3] == [1,2,3]: cnt += 1 abc_lst[idx] = 2 abc_lst[idx+1] = 3 abc_lst[idx+2] = 1 if idx > 0 and abc_lst[idx-1] == 1: cnt = check(abc_lst, idx-1, cnt) while idx < len(abc_lst) - 2: if abc_lst[idx+1:idx+4] == [1,2,3] cnt = check(abc_lst, idx+1, cnt) idx += 1 return cnt sys.setrecursionlimit(10**9) S = input() ABC_dict = {'A':1, 'B':2, 'C':3} abc_lst = [ABC_dict[S[i]] for i in range(len(S))] print(check(abc_lst, 0, 0))
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s792489818
Accepted
p03018
Input is given from Standard Input in the following format: s
S = input().replace("BC", "D").split("B") T = [] for t in S: for u in t.split("C"): T.append(u) # print(T) ans = 0 for s in T: n = len(s) k = 0 for i in range(n): if s[i] == "D": ans += i - k k += 1 print(ans)
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s882225083
Accepted
p03018
Input is given from Standard Input in the following format: s
#!/usr/bin/env python3 ##### Binary Indexed Tree ##### class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def __iter__(self): psum = 0 for i in range(self.size): csum = self.sum(i + 1) yield csum - psum psum = csum raise StopIteration() def __str__(self): # O(nlogn) return str(list(self)) def sum(self, i): # [0, i) の要素の総和を返す if not (0 <= i <= self.size): raise ValueError("error!") s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): if not (0 <= i < self.size): raise ValueError("error!") i += 1 while i <= self.size: self.tree[i] += x i += i & -i def __getitem__(self, key): if not (0 <= key < self.size): raise IndexError("error!") return self.sum(key + 1) - self.sum(key) def __setitem__(self, key, value): # 足し算と引き算にはaddを使うべき if not (0 <= key < self.size): raise IndexError("error!") self.add(key, value - self[key]) # 転倒数 def mergecount(A: list): if not A: return 0 bit = Bit(max(A) + 1) cnt = 0 for i, a in enumerate(A): cnt += i - bit.sum(a + 1) bit.add(a, 1) return cnt import re print( sum( mergecount([*map(int, i)]) for i in re.split("[BC]", input().replace("A", "1").replace("BC", "0")) ) )
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s555292744
Runtime Error
p03018
Input is given from Standard Input in the following format: s
import sys def main(): input = sys.stdin.readline S = list(input().strip()) n = len(S) ans = 0 cnt = 0 for i in range(n): if S[i:i+3] == ['A', 'B', 'C']: cnt += 1 S[i] = 'B' S[i+1] = 'C' S[i+2] = 'A' S = S[::-1] for i in range(n): if S[i:i+3] == ['C', 'B', 'A']: cnt += 1 S[i] = 'A' S[i+1] = 'C' S[i+2] = 'B' ans += cnt while cnt > 0: cnt = 0 S = S[::-1] for i in range(n): if S[i:i+3] == ['A', 'B', 'C']: cnt += 1 S[i] = 'B' S[i+1] = 'C' S[i+2] = 'A' S = S[::-1] for i in range(n): if S[i:i+3] == ['C', 'B', 'A']: cnt += 1 S[i] = 'A' S[i+1] = 'C' S[i+2] = 'B' ans += cnt return ans if __name__ == '__main__': print(main())
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s584338778
Wrong Answer
p03018
Input is given from Standard Input in the following format: s
t = input().replace("ABC", "T") s = t.replace("BC", "Z") l = [] flagA = False cntA = 0 cnt = 0 count = 0 flag = False comb = False cmcnt = 0 tmp = 0 # print(s) for i in range(len(s)): if s[i] == "T": if comb: cmcnt = 1 count += 1 flag = True if flagA: flagA = False cntA = tmp continue if flag: if s[i] == "Z": cnt += 1 else: l.append([cmcnt, cntA, count, cnt]) comb = True flag = False flagA = False cnt = 0 count = 0 cntA = 0 if s[i] == "A": tmp += 1 flagA = True else: if s[i] == "A": tmp += 1 flagA = True else: tmp = 0 comb = False ans = 0 if count > 0: l.append([cmcnt, cntA, count, cnt]) # print(l) for i in range(len(l)): ans += l[i][0] ans += l[i][1] ans += (l[i][2] * (l[i][2] + 1)) // 2 ans += l[i][3] print(ans)
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s137591384
Wrong Answer
p03018
Input is given from Standard Input in the following format: s
import sys sys.setrecursionlimit(10000) mod = 1000000007 def mul(a, b): return ((a % mod) * (b % mod)) % mod def power(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return power(x, y / 2) ** 2 % mod else: return power(x, y / 2) ** 2 * x % mod def div(a, b): return mul(a, power(b, mod - 2)) # def gcd(a_gcd, b_gcd): # while b_gcd != 0: # a_gcd, b_gcd = b_gcd, a_gcd % b_gcd # return a_gcd # # # def lcm(a_lcm, b_lcm): # return a_lcm * b // gcd(a_lcm, b_lcm) # # # def max_sum(N_max_sum, a_max_sum): # dp = [0] * (N_max_sum + 1) # for i in range(N_max_sum): # dp[i + 1] = max(dp[i], dp[i] + a_max_sum[i]) # return dp[N] # # # def knapsack(N_knapsack, W, weight, value): # inf = float("inf") # dp = [[-inf for _ in range(W+1)] for j in range(N_knapsack + 1)] # for i in range(W+1): # dp[0][i] = 0 # # for i in range(N_knapsack): # for w in range(W+1): # if weight[i] <= w: # dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w]) # else: # dp[i+1][w] = dp[i][w] # return dp[N_knapsack][W] # # # class UnionFind: # def __init__(self, n): # self.par = [i for i in range(n+1)] # self.rank = [0] * (n+1) # # # 検索 # def find(self, x): # if self.par[x] == x: # return x # else: # self.par[x] = self.find(self.par[x]) # return self.par[x] # # # 併合 # def union(self, x, y): # x = self.find(x) # y = self.find(y) # if self.rank[x] < self.rank[y]: # self.par[x] = y # else: # self.par[y] = x # if self.rank[x] == self.rank[y]: # self.rank[x] += 1 # # # 同じ集合に属するか判定 # def same_check(self, x, y): # return self.find(x) == self.find(y) S = input() # N = int(input()) # A = list(map(int, input().split())) # X = [int(input()) for _ in range(N)] ans = 0 a_count = 0 bc_count = 0 bc_frag = False i = 0 while i < len(S) - 2: # print(S[i]) if bc_frag: if S[i : i + 2] == "BC": ans += 1 i += 2 a_count = 0 else: bc_frag = False if S[i] == "A": a_count += 1 else: a_count = 0 if S[i : i + 3] == "ABC": ans += 2 ans += a_count - 1 bc_frag = True i += 3 a_count = 0 else: if S[i] == "A": a_count += 1 else: a_count = 0 if S[i : i + 3] == "ABC": ans += 1 ans += a_count - 1 bc_frag = True i += 3 a_count = 0 else: i += 1 print(ans)
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s739132624
Accepted
p03018
Input is given from Standard Input in the following format: s
import sys input = sys.stdin.readline ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print("YES") if b else print("NO") yn = lambda b: print("Yes") if b else print("No") OE = lambda x: print("Odd") if x % 2 else print("Even") INF = 10**18 MOD = 10**9 + 7 S = input() len_S = len(S) set_map = [] state = 0 st = 0 en = 0 for i in range(len_S): s = S[i] if state == 0: if s == "A": state = 1 st = i elif state == 1: if s == "B": state = 2 elif s == "C": state = 0 elif state == 2: if s == "A": state = 1 st = i elif s == "B": state = 0 elif s == "C": state = 3 en = i elif state == 3: if s == "A": state = 5 elif s == "B": state = 4 elif s == "C": set_map.append([st, en]) state = 0 elif state == 4: if s == "A": set_map.append([st, en]) state = 1 st = i elif s == "B": set_map.append([st, en]) state = 0 elif s == "C": state = 3 en = i elif state == 5: if s == "B": state = 6 elif s == "C": set_map.append([st, en]) state = 0 elif state == 6: if s == "A": set_map.append([st, en]) state = 1 st = i elif s == "B": set_map.append([st, en]) state = 0 elif s == "C": state = 7 en = i elif state == 7: if s == "A": state = 5 elif s == "B": state = 8 elif s == "C": set_map.append([st, en]) state = 0 elif state == 8: if s == "A": set_map.append([st, en]) state = 1 st = i elif s == "B": set_map.append([st, en]) state = 0 elif s == "C": state = 7 en = i if state >= 3: set_map.append([st, en]) ans = 0 for st, en in set_map: cnt = 0 for i in range(st, en): if S[i] == "A": cnt += 1 elif S[i] == "B": ans += cnt print(ans)
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s688666017
Wrong Answer
p03018
Input is given from Standard Input in the following format: s
from sys import stdin s = stdin.readline().rstrip() l = [] for i in range(len(s) - 2): if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C": l.append(i) # print(l) ll = [] count = 0 def souwa(n): sum = 0 while 0 < n: sum += n n -= 1 return sum for i in range(len(l)): # 前にaがあればcount if l[i] > 0: j = l[i] - 1 while 0 <= j: if s[j] != "A": break count += 1 j -= 1 # うしろにbcがあればcount j = l[i] + 3 while j < len(s) - 1: if s[j] != "B" or s[j + 1] != "C": break count += 1 j += 2 # print(l, count) for i in range(len(l)): if l[i] < 0: continue join = 0 j = i + 1 while j < len(l): # print(l[j-1], l[j]) if l[j - 1] == (l[j] - 3): join += 1 j += 1 continue k = l[j - 1] + 3 # print (k, s[k], s[k+1]) while k < len(s) - 1: if s[k] != "B" or s[k + 1] != "C": break k += 2 # print ("BC CHECK", k, l[j]) if k == l[j]: # print("BC JOIN") join += 1 j += 1 continue while k < l[j]: if s[k] != "A": break k += 1 # print ("A CHECK", k, l[j]) if k == l[j]: # print("A JOIN") join += 1 j += 1 continue break count += souwa(join + 1) # print("COUNT", count, join+1) while 0 < join: l[i + join] = -1 join -= 1 print(count)
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Find the maximum possible number of operations. * * *
s920674515
Wrong Answer
p03018
Input is given from Standard Input in the following format: s
S = input() count = 0 for i in range(2, len(S) - 1): if S[i - 2 : i + 1] == "ABC": count_A = 1 count_B = 1 k = i + 2 while S[k - 1 : k + 1] == "BC" and k <= len(S) - 1: k = k + 2 if S[k - 1 : k + 1] == "BC": count_B += 1 j = i - 2 while S[j] == "A" and j - 1 >= 0: j = j - 1 if S[j] == "A": count_A += 1 count += count_A + count_B - 1 S = ( S[0 : i - count_A - 1] + "BC" * count_B + "A" * count_A + S[i + count_B * 2 - 1 : len(S)] ) i = len(S) - 1 if S[i - 2 : i + 1] == "ABC": count_A = 1 j = i - 2 while S[j] == "A" and j - 1 >= 0: j = j - 1 if S[j] == "A": count_A += 1 count += count_A print(count)
Statement You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number of operations.
[{"input": "ABCABC", "output": "3\n \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]
Print the number of ways to select coins. * * *
s285312619
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
I = input A, B, C, X, s = int(I()), int(I()), int(I()), int(I()), 0 for i in range(A + 1): for j in range(int(B) + 1): for k in range(int(C) + 1): if 500 * i + 100 * j + 50 * k == int(X): s += 1 print(s)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s474087432
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a,b,c x = map(int, open(0)) print(sum( 500*i + 100*l + 50*k == x for i in range(a+1) for j in range(b+1) for k in range(c+1)))
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s601877773
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a,b,c,x=map(int,input() for i in range(4)) count=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if k*50+j*100+i*500==x: count+=1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s043286301
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a,b,c,x=map(int,[input() for i in range(4)]) count=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if k*50+j*100+i*500==x: count+=1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s265244781
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10**20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def nck(n, k, kaijyo): return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD def npk(n, k, kaijyo): if k == 0 or k == n: return n % MOD return (kaijyo[n] * divide(kaijyo[n - k])) % MOD def kaijyo(n): ret = [1] for i in range(1, n + 1): ret.append((ret[-1] * i) % MOD) return ret def solve(): a = getN() b = getN() c = getN() x = getN() ans = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: ans += 1 print(ans) def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": # main() solve()
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s191963483
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def inputI(): return int(input().strip()) def inputS(): return input().strip() def inputIL(): return list(map(int, input().split())) def inputSL(): return list(map(str, input().split())) def inputILs(n): return list(int(input()) for _ in range(n)) def inputSLs(n): return list(input().strip() for _ in range(n)) def inputILL(n): return [list(map(int, input().split())) for _ in range(n)] def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def Yes(): print("Yes") return def No(): print("No") return #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def Base_10_to_n(X, n): if X // n: return Base_10_to_n(X // n, n) + [X % n] return [X % n] def Base_n_to_10(X, n): return sum(int(str(X)[-i]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# A, B, C, X = inputILs(4) ans = 0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): if 500 * i + 100 * j + 50 * k == X: ans += 1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s321799686
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
# Coins """ 問題: あなたは500円玉をA枚、100円玉をB枚、50円玉をC枚持っています。 これらの硬貨の中から何枚かを選び、合計金額をちょうどX円にする方法は何通りありますか。 同じ種類の硬貨同士は区別できない。 2通りの硬貨の選び方は、ある種類の硬貨についてその硬貨を選ぶ枚数が異なる時区別される。 制約: 0 <= A,B,C <= 50 A+B+C >= 1 50 <= X <= 20,000 A, B, C は整数である。 Xは50の倍数である。 入力: 入力は以下の形式で標準入力から与えられる。 A B C X 出力: 硬貨を選ぶ方法の個数を出力せよ。 """ # for文を3周回してゴリゴリとく # 入力した値を変数に入れる five = int(input()) # 500 hundred = int(input()) # 100 fifty = int(input()) # 50 total = int(input()) # 求める合計 # 何枚使用しているかカウントする。 used50 = 0 used100 = 0 used500 = 0 usedTotal = 0 ways = 0 while used500 <= five: while used100 <= hundred: while used50 <= fifty: usedTotal = 50 * used50 + 100 * used100 + 500 * used500 # print(usedTotal) if total == usedTotal: ways += 1 used50 += 1 used50 = 0 used100 += 1 # print("a") used50 = 0 used100 = 0 used500 += 1 # 2 # 2 # 2 # 100 print(ways)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s321428855
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
n = int(input()) a = list(map(int, input().split())) Count = 0 while 1: count = 0 for i in range(n): if a[i] % 2 == 0: count += 1 if count != n: break for i in range(n): a[i] /= 2 Count += 1 print(Count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s903953085
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem B if __name__ == "__main__": five_hundred_yen_count = int(input()) one_hundred_yen_count = int(input()) fifty_yen_count = int(input()) total_yen = int(input()) pattern_count = 0 for i in range(five_hundred_yen_count + 1): for j in range(one_hundred_yen_count + 1): for k in range(fifty_yen_count + 1): summed_yen = 500 * i + 100 * j + 50 * k if total_yen - summed_yen == 0: pattern_count += 1 print(pattern_count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s658359861
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
# -*- coding: utf-8 -*- # 整数値入力 1文字の入力 def input_one_number(): return int(input()) # 整数値龍力 複数の入力 def input_multiple_number(): return map(int, input().split()) # 整数値龍力 複数の入力(配列) def input_multiple_number_as_list(): return list(map(int, input().split())) # 2次元配列入力 def input_map(): return [list(map(int, list(input()))) for i in range(h)] # リスト出力 def print_list(list): print(*list) return # 2次元配列出力 def print_map(maplist): for i in maplist: print(*i, sep="") return # 素数生成 def generate_primenums(): n = 100 primes = set(range(2, n + 1)) for i in range(2, int(n**0.5 + 1)): primes.difference_update(range(i * 2, n + 1, i)) primes = list(primes) return primes def memo(): a = [0] * 5 b = a # 良くない配列のコピー b2 = a[:] # 1次元のときはコピーはこれで良い a[1] = 3 print("b:{}, b2:{}".format(b, b2)) # b:[0, 3, 0, 0, 0], b2:[0, 0, 0, 0, 0] import copy a = [[0] * 3 for i in range(5)] # 2次元配列はこう準備、[[0]*3]*5だとだめ b = copy.deepcopy(a) # 2次元配列はこうコピーする # 内包表記奇数のみ odd = [i for i in range(100) if i % 2 == 1] # [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] # 二部探索 import bisect a = [1, 2, 3, 5, 6, 7, 8, 9] b = bisect.bisect_left(a, 8) # combinations、組み合わせ、順列 from itertools import ( permutations, combinations, combinations_with_replacement, product, ) a = ["a", "b", "C"] print(list(permutations(a))) print(list(combinations(a, 2))) print(list(combinations_with_replacement(a, 3))) # 階乗 def kaijo(n): import math return math.factorial(n) # 選び方(コンビネーション nCr) def num_combination(n, r): import math return math.factorial(n) // math.factorial(n - r) # 最大公約数、最小公倍数 def calc_gcd(a, b): import fractions GCD = fractions.gcd(a, b) lcm = a * b // gcd return gcd, lcm # 複数の最大公約数 def calc_gcd_list(l): import numpy as np return np.gcd.reduce(l) A = input_one_number() B = input_one_number() C = input_one_number() X = input_one_number() cnt = 0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): if i * 500 + j * 100 + k * 50 == X: cnt += 1 print(cnt)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s490995975
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) x = list(map(int, input().split())) A = a[0] B = b[0] C = c[0] X = x[0] Count = 0 for i in range(A + 1): for k in range(B + 1): for t in range(C + 1): if 500 * i + 100 * k + 50 * t == X: Count += 1 print(Count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s262820483
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for a in range(A + 1): for b in range(B + 1): fo c in range(C + 1): if X == 500 * a + 100 * b +50 * c: count = count + 1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s848201308
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) B = int(input()) C = int(input()) X = int(input()) res = 0 for a500 in range(A + 1): for b100 in range(B + 1): for c50 in range(C + 1): if a500 * 500 + b100 * 100 + c50 * 50 = X: res += 1 print(res)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s026637014
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a=int(input("")) b=int(input("")) c=int(input("")) x=int(input("")) def countcourse(r,t,y,u): cnt=0 for h in range(r): for l in range(t): for y range(y): if 500*h+100*l+50*y==u: cnt+=1 return cnt print(countcourse(a,b,c,x))
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s804692374
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a=int(input("")) b=int(input("")) c=int(input("")) x=int(input("")) def countcourse(r,t,y,u): cnt=0 for h in range(r): for l in range(t): for o range(y): if 500*h+100*l+50*o==u: cnt+=1 return cnt print(countcourse(a,b,c,x))
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s611515798
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a=int(input()) b=int(input()) c=int(input()) s=int(input()) n=0 for x in range(a): for y in range(b): for z in range(c): if 500x+100y+50z==s: n=n+1 print(n)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s420219202
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a=int(input()) b=int(input()) c=int(input()) x=int(input()) s=50*c print(len[1 if 0<<x-500*i+100*m<<s for i in range(a+1) for m in range(b+1)])
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s497306188
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a, b, c, x = map(int, [input() fot i in range(4)]) ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if i*500 + j*100 + k*50 == x: ans += 1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s100055710
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a, b, c, x = map(int, [input() fot z in range(4)]) ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if i*500 + j*100 + k*50 == x: ans += 1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s138962558
Wrong Answer
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) # 500
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s617446868
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a=int(input()) b=int(input()) c=int(input()) x=int(input()) s=50*c print(len[1 for i in range(a+1) for m in range(b+1) if 0<<x-500*i+100*m<<s ])
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s618674708
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a=int(input()) b=int(input()) c=int(input()) x=int(input()) s=50*c print(len[1 for i in range(a+1) for m in range(b+1) if 0<=x-500*i+100*m<=s])
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s630472560
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) B = int(input()) C = int(input()) X = int(input()) pat = 0 for a in range(A): for b in range(B): for c in range(C): if a*500+B*100+c*50 == X: pat += 1 print(pat)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s667398897
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a, b, c, x = map(int, open(0).read().split()) ans = 0 for i in range(x // a + 1): for j in range(x // b + 1): if (x - (a * i + b * j)) % c == 0 ans += 1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s828614333
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = [int(input()) for i in range(4)] count = 0 for (i = 0; i <= a[0]; i++) : for (j = 0; j <= a[1]; j++) : for (k = 0; k <= a[2]; k++) : sum = 500*i + 100*j + 50*k if sum == a[3] : count += 1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s345106273
Accepted
p03448
Input is given from Standard Input in the following format: A B C X
mycode = r""" # distutils: language=c++ # cython: language_level=3 # cython: boundscheck=False # cython: wraparound=False # cython: infer_types=True # cython: cdivision=True # False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。 # define ctypedef long long LL # 読み込みはpython側で行う import sys readline = sys.stdin.buffer.readline read = sys.stdin.readline #文字列読み込む時はこっち cdef LL a_int(): return int(readline()) cdef LL i,j,k,_ A=a_int() B=a_int() C=a_int() X=a_int() #あえて型をつけない(→実装が早くなる) # 愚直にシミュレーション cdef LL a,b,c,ans #他の定数はぶっちゃけ型を付ける必要がないですが、ループにはしっかりつけないと速度が低下する for a in range(A+1): for b in range(B+1): for c in range(C+1): ans += (500*a + 100*b + 50*c == X) print(ans) """ import sys if sys.argv[-1] == "ONLINE_JUDGE": # コンパイル時 import os with open("mycode.pyx", "w") as f: f.write(mycode) os.system("cythonize -i -3 -b mycode.pyx") import mycode
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s131462247
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = [int(input()) for i in range(4)] count = 0 for i in range(a[0], -1, -1) : y = a[3] if (y > 500*i): y -= i*500 if y == 0: count += 1 continue for j in range(a[1], -1, -1) : if (y > j*100) : y -= j*100 if y == 0: count += 1 continue for k in range(a[2], -1, -1) : if (y > k*50) : y -= k*50 if y == 0: count += 1 continue print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s061759988
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
# distutils: language=c++ # cython: language_level=3 # cython: boundscheck=False # cython: wraparound=False # cython: infer_types=True # cython: cdivision=True # False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。 # define ctypedef long long LL # 読み込みはpython側で行う import sys readline = sys.stdin.buffer.readline read = sys.stdin.readline #文字列読み込む時はこっち cdef LL a_int(): return int(readline()) cdef LL i,j,k,_ cdef LL A=a_int() cdef LL B=a_int() cdef LL C=a_int() cdef LL X=a_int() # 愚直にシミュレーション cdef LL a,b,c,ans for a in range(A+1): for b in range(B+1): for c in range(C+1): ans += (500*a + 100*b + 50*c == X) print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s247013505
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
[a,b,c,d]=[int(input()) for i in range(1,4+1)] a1 = d // 500 b1 = d// 100 c1 = d// 50 coun = 0 for i in range(0,min([a+1,a1+1])): a = 500*i if a == d: coun = coun +1 break for j in range(0,min([b+1,b1+1-5*i])): s = a + 100*j if s == d : coun = coun +1 break for k in range(0,min([c,c1+1-10*i-2*j]): v = s + 50*k if v == d : coun = coun+1 break print(coun)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s617702460
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = input() b = input() c = input() x = input() cnt = 0 for i in range(a + 1): if 500 * i <= x: p = x - 500 * i for j in range(b + 1): if 100 * j <= p: q = p - 100 * j: for k in range(c + 1): if q - 50 * k == 0: cnt += 1 print(cnt)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s488058964
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
N, K = map(int, input().split()) if K % 2: print((N // K) ** 3) else: print((N // K) ** 3 + ((N + K // 2) // K) ** 3)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s145283721
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
coins = [int(input()) / 10 for _ in range(3)] x = int(input()) / 10 ans = [1 for A in range(coins[0]) for B in range(coins[1]) if x - A - B <= coins[2]] print(len(ans))
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s928645023
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
N = int(input()) A = list() for i in range(N):   A.append(int(input())) print(len(set(A)))
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s740045795
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) B = int(input()) C = int(input()) X = int(input()) n = 0 for i in range(A): for j in range(B): for k in range(C): if 500*i + 100*j + 50*k = X: n += 1 print(n)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s246061909
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) B = int(input()) C = int(input()) X = int(input()) ans = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): value = 500*a + 100*b + 50*c if value == X: ans += 1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s275741241
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) B = int(input()) C = int(input()) X = int(input()) res=0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if 500*i + 100*j + 50*k == X: res + = 1 print(res)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s714406101
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = list(map(int, input().split())) N, A, B = a[0], a[1], a[2] k = 1 x = True while x: if 10 ** (k - 1) <= N and N < 10**k: x = False else: k += 1 u = 1 M = 0 while u <= k: if u == 1: v = 1 while v <= 9: if v >= A and v <= B and v <= N: M += v v += 1 elif u == 2: v, w = 1, 0 while v <= 9: while w <= 9: if v + w <= B and v + w >= A and 10 * v + w <= N: M += 10 * v + w w += 1 w = 0 v += 1 else: v, w, x = 1, 0, 0 while v <= 9: while w <= 9: while x <= 9: if v + w + x >= A and v + w + x <= B and 100 * v + 10 * w + x <= N: M += 100 * v + 10 * w + x x += 1 x = 0 w += 1 w = 0 v += 1 u += 1 print(M)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s670754507
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
arr = input() for i in range(4) count = 0 sum = 0 for fihun in range(int(arr[0]) + 1): for hun in range(int(arr[1]) + 1): for fi in range(int(arr[2]) + 1): sum = fihun * 500 + hun * 100 + fi * 50 if sum == int(arr[3]): count += 1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s942253021
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = int(input()) b = int(input()) c = int(input()) x = int(input()) count = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if x == (i * 500 + j * 100 + k * 50): count += 1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s822138440
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = int(input()) b = int(input()) c = int(input()) x = int(input()) result= 0 for ai in range(a+1): for bi in range(b+1): for ci in range(c+1): amount = 500 * ai + 100 * bi + 50 * ci if amount == x: result += 1 print(result)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s853303676
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
numof500 = int(input()) numof100 = int(input()) numof50 = int(input()) moneyneeded = int(input()) counter = 0 for i in range(numof500): for j in range(numof100): for k in range(numof50): if 500 * i + 100 * j + 50 * k == moneyneeded: counter += 1 print(counter)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s359541366
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A, B, C, X = map(int, input().split()) I = 0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): if 500 * i + 100 * j + 50 * k == X: I++ print(I)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s467621078
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A=int(input()) B=int(input()) C=int(input()) X=int(input()) cnt=0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): if (500*i + 100*j + 50*k) == X cnt += 1 print(cnt)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s639521034
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A,B,C,X = [int(input()) for i in range(4)] print(sum(500*a + 100*b + 50*c for a in range(A+1) for b in range(B+1) for c in range(C+1))
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s090529351
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A, B, C, X = (int(input()) for i in range(4)) cnt = 0 for a in range(A+1): for b in range(B+1) for c in range(C+1) if 500*a + 100*b + 50*c == X: cnt += 1 print(cnt)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s438907113
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a, b, c, x = [int(input()) for _ in range(4)] cnt = 0 for ai in range(a): for bi in range(b): for ci in range(c): if 500*ai + 100*bi + 50*ci == x: cnt += 1 print(cnt)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s414895529
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
import sys a = [] for line in sys.stdin: a.append(int(line)) #a[0]*500 + a[1]*100 + a[2]*50 = a[3] if a[3]/50 == 0 && a[3]/100 != 0: if a[2] == 0: print("0")
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s709916752
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A,B,C,X = int(input()) for i in range(4) print(sum(500*a+100*b+50*c == X for a in range(A+1) for b in range(B+1) for c in range(C+1)))
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s136312229
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = input() b = input() c = input() x = input() ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if 500*i+100*j+50*k=x: ans += 1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s898918619
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a=int(input()) b=int(input()) c=int(input()) x=int(input()) ans=0 for i in range(a+1): A=i*500 for j in range(b+1): B=j*100 for k in range(c+1): C=k*50 if A+B+C=x: ans+=1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s886757280
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a, b, c, x = map(int,[input() for i in range(4)]) count = 0 for i in range(a+1): for j in range(b+1): for n in range(c+1): if t = i*500 + j*100 + n*50 == x: count += 1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s752052119
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
five = int(input()) hand = int(input()) fives = int(input()) ans = int(input()) tmp = 0 for i in range(five): for j in range(hand): for k in range(fives): ask = 500 * i + 100 * j + 50 *k if ask == ans: tmp = tmp + 1
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s379901671
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a,b,c,x = map(int,[input() for i in range(4)]) count = 0 for i in range(a+1): for j in range(b+1): for n in range(c+1): if t = i*500 + j*100 + n*50 == x: count = count + 1 print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s373549029
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
A = int(input()) B = int(input()) C = int(input()) X = int(input()) res=0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if 500*i + 100*j + 50*k == X: res + = 1 print(res)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s473325068
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(a+1): for j in range(b+1): nc = (500 * i + 100 * j) // 50 if nc < 0 || c < nc: continue ans += 1 print(ans)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s027409895
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a,b,c,x = map(int,[input() for i in range(4)]): ans = 0: for i in range(a+1): for i in range(b+1): for i in range(c+1): if a*500 + b*100 + c*50 == x: ans +=1: print(ans):
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s137592836
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping? Constraints 1 ≤ A , B ≤ 1 000 A + B ≤ X ≤ 10 000 X , A and B are integers.
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s405961313
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a = int(input()) b = int(input()) c = int(input()) x = int(input()) result= 0 for xx in range(a+1): A = 500*xx for y in range(b+1) : B = 100*y for z in range(c+1): C = 50*z if x == A+B+C: result += 1 else: continue print(result)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print the number of ways to select coins. * * *
s236517125
Runtime Error
p03448
Input is given from Standard Input in the following format: A B C X
a, b, c, x = map(int, [input() for i in range(4)]) count = 0 for i in range(a + 1): if 500 * i == x: count += 1 break else if 500 * i > x: break else: for j in range(b + 1): if 500 * i + 100 * j == x: count += 1 break else if 500 * i + 100 * j > x: break else: for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: count += 1 break print(count)
Statement You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
[{"input": "2\n 2\n 2\n 100", "output": "2\n \n\nThere are two ways to satisfy the condition:\n\n * Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.\n * Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.\n\n* * *"}, {"input": "5\n 1\n 0\n 150", "output": "0\n \n\nNote that the total must be exactly X yen.\n\n* * *"}, {"input": "30\n 40\n 50\n 6000", "output": "213"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s399903924
Accepted
p02609
Input is given from Standard Input in the following format: N X
""" pppppppppppppppppppp ppppp ppppppppppppppppppp ppppppp ppppppppppppppppppppp pppppppp pppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppp pppppppp ppppppppppppppppppppp ppppppp ppppppppppppppppppp ppppp pppppppppppppppppppp """ import sys def data(): return sys.stdin.readline().strip() def out(var): sys.stdout.write(str(var)) def outa(*var, end="\n"): sys.stdout.write(" ".join(map(str, var)) + end) def l(): return list(sp()) def sp(): return map(int, data().split()) def calculate(string): result = 0 while string: c = bin(string)[2:].count("1") string = string % c result += 1 return result n = int(data()) s = list(data()) ones = [] powers = [] for i in range(n): if s[i] == "1": ones.append(i) length = len(ones) powers = [[0, 0] for i in range(n)] for i in range(n): if length - 1 > 0: powers[i][0] = pow(2, i, length - 1) powers[i][1] = pow(2, i, length + 1) powers = powers[::-1] s1, s2 = 0, 0 for i in ones: if length - 1 > 0: s1 = s1 + powers[i][0] s2 = s2 + powers[i][1] for i in range(n): if s[i] == "1": if length - 1 <= 0: out("0\n") continue temp = s1 temp = (temp - powers[i][0] + length - 1) % (length - 1) else: temp = s2 temp = (temp + powers[i][1]) % (length + 1) out(str(calculate(temp) + 1) + "\n")
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s229053225
Runtime Error
p02609
Input is given from Standard Input in the following format: N X
# -*- coding: utf-8 -*- def pop_count(nbin): return nbin.count("1") def bin2dec(nbin): nbin_str = "".join(nbin) return int(nbin_str, 2) def reverse(nbin, dig): nbin_list = list(nbin) if nbin_list[dig] == "0": nbin_list[dig] = "1" else: nbin_list[dig] = "0" return nbin_list def f(nbin): counter = 0 nbin_str = "".join(nbin) while nbin_str != "0b0": new_n = bin2dec(nbin_str) % pop_count(nbin_str) nbin_str = bin(new_n) counter += 1 return counter N = int(input()) X = "0b" + input() for i in range(N): print(f(reverse(X, i + 2)))
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s290882911
Runtime Error
p02609
Input is given from Standard Input in the following format: N X
import sys sys.setrecursionlimit(10**6) # 再帰関数の再帰の深さを設定 to_index = lambda x: int(x) - 1 # 入力した数字に1を引いたものを返す print_list_in_2D = lambda x: print( *x, sep="\n" ) # リストの要素を改行を挟んで表示する関数 # 入力を整数に変換して受け取る def input_int(): return int(input()) def map_int_input(): return map(int, input()) MII = map_int_input def MII_split(): return map(int, input().split()) def MII_to_index(): return map(to_index, input()) def MII_split_to_index(): return map(to_index, input().split()) # 入力全てを整数に変換したものの配列を受け取る def list_int_inputs(): return list(map(int, input())) LII = list_int_inputs def LII_split(): return list(map(int, input().split())) # 2次元リスト化 def LII_2D(rows_number): return [LII() for _ in range(rows_number)] def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)] N = input_int() X = input() X = int(X, 2) for i in range(1, N + 1): tmp = 1 << N - i X_i = X ^ tmp # print(f'{X_i=}') popcount = bin(X_i).count("1") it_num = X_i // popcount ans = 1 for j in range(it_num): X_i = X_i % popcount if X_i == 0: break popcount = bin(X_i).count("1") ans += 1 print(ans)
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s022329404
Accepted
p02609
Input is given from Standard Input in the following format: N X
N = int(input()) X = input() B = X.count("1") # print(B, 'B') base_mod_1 = [1 for i in range(N)] # 2^i mod B+1 if B > 1: base_mod_2 = [1 for i in range(N)] # 2^i mod B-1 for i in range(1, N): base_mod_1[i] = (base_mod_1[i - 1] * 2) % (B + 1) if B > 1: base_mod_2[i] = (base_mod_2[i - 1] * 2) % (B - 1) def num(A): b = 1 r = 0 for i in range(len(A)): r += b * int(A[-i - 1]) b *= 2 return r def f(n): global call call += 1 bit = 0 m = n while m > 0: if m % 2 == 1: bit += 1 m //= 2 next_n = n % bit if next_n > 0: f(next_n) x = num(X) x1 = x % (B + 1) if B > 1: x2 = x % (B - 1) # print('x', len(X)) for i in range(N): call = 0 if X[i] == "0": y = (x1 + base_mod_1[-i - 1]) % (B + 1) R = B + 1 call = 1 else: if B > 1: y = (x2 - base_mod_2[-i - 1]) % (B - 1) R = B - 1 call = 1 else: y = 0 # print(y, '+', call) if y > 0: f(y) print(call)
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s259130217
Runtime Error
p02609
Input is given from Standard Input in the following format: N X
#!/usr/bin/env python3 import sys sys.setrecursionlimit(300000) def solve(N: int, X: str): memo = {} def popcount(v): if v == 0: return 0 if v in memo: return memo[v] tmp, b = v, 0 while tmp > 0: b += tmp % 2 tmp //= 2 if v % b == 0: memo[v] = 1 return 1 memo[v] = 1 + popcount(v % b) return memo[v] X = X[::-1] bits = 0 for i in range(N): if X[i] == "1": bits += 1 sums = [0, 0] for i in range(N): if X[i] == "1": sums[0] += pow(2, i, bits - 1) sums[0] %= bits - 1 sums[1] += pow(2, i, bits + 1) sums[1] %= bits + 1 # print(bits, sums) ret = [] for i, x in enumerate(X): if x == "1": v = (sums[0] - (1 << i)) % (bits - 1) else: v = (sums[1] + (1 << i)) % (bits + 1) # print(i, x, v) ret.append(1 + popcount(v)) ret.reverse() for r in ret: print(r) return def solve_(N: int, X: str): # memo = [[-1] * 20 for _ in range(20)] memo = {} def popcount(v, b): if v in memo and b in memo[v]: return memo[v][b] if not v in memo: memo[v] = {} if v % b == 0: memo[v][b] = 1 return 1 next_v = v % b tmp = next_v c = 0 while tmp > 0: c += tmp % 2 tmp //= 2 ret = 1 + popcount(next_v, c) memo[v][b] = ret return ret X = X[::-1] count = 0 for i in range(N): if X[i] == "1": count += 1 s = 0 for i in range(N): if X[i] == "1": s += pow(2, i, count) s %= count memo[count] = {} memo[count] ret = [] for i, x in enumerate(X): if x == "1": v = N - (1 << i) b = count - 1 else: v = N + (1 << i) b = count + 1 print(i, i, x) print(v, b) ret.append(popcount(v, b)) ret.reverse() for r in ret: print(r) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = next(tokens) # type: str solve(N, X) if __name__ == "__main__": main()
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s382742233
Runtime Error
p02609
Input is given from Standard Input in the following format: N X
import heapq as hq T = int(input()) for _ in range(T): N = int(input()) camels = [list(map(int, input().split())) for _ in range(N)] base = 0 camels_L = [[] for _ in range(N + 1)] camels_R = [[] for _ in range(N + 1)] # 左から詰めるラクダと右から詰めるラクダを仕分ける for camel in camels: if camel[1] >= camel[2]: camels_L[camel[0]].append(camel[1] - camel[2]) base += camel[2] # LとRの低いほうを加算 else: # Rラクダは右から何列目かを考えるのでN - camel[0]と反転する camels_R[N - camel[0]].append(camel[2] - camel[1]) base += camel[1] # LとRの低いほうを加算 diff = 0 # Lラクダについて考える heap_camels = [] hq.heapify(heap_camels) for i in range(1, N + 1): # 左からi番目までが限度のラクダをまとめて追加 for camel in camels_L[i]: hq.heappush(heap_camels, camel) # 左からi番目までに入りきらない場合に低いものから除外 while len(heap_camels) > i: hq.heappop(heap_camels) # heapqに残ったものがすべての条件を満たしうれしさが最大 diff += sum(heap_camels) # Rラクダについても同様 heap_camels = [] hq.heapify(heap_camels) for i in range(1, N + 1): for camel in camels_R[i]: hq.heappush(heap_camels, camel) while len(heap_camels) > i: hq.heappop(heap_camels) diff += sum(heap_camels) print(diff + base)
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s650426950
Wrong Answer
p02609
Input is given from Standard Input in the following format: N X
import sys input = sys.stdin.readline #n = int(input()) #l = list(map(int, input().split())) ''' a=[] b=[] for i in range(): A, B = map(int, input().split()) a.append(A) b.append(B)''' n=int(input()) x=input().strip("\n") cnt=0 for i in range(n): if x[i:i+1]=="1": cnt+=1 print("a") """ #xx=list(x) pre=int(x,2) #print(pre) for i in range(n): if x[i:i+1]=="1": #t=-1 ad=-2**(n-1-i) else: #t=1 ad=2**(n-1-i) #cnt+=t now=pre+ad ans=0 while now!=0: now%=bin(now).count("1") ans+=1 print(ans) #cnt-=t"""
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]
Print N lines. The i-th line should contain the value f(X_i). * * *
s754755834
Runtime Error
p02609
Input is given from Standard Input in the following format: N X
arr=[0,1,1,2] n=4*(10**5)+2 for i in range(4,n): b=bin(i)[2:] k=b.count('1') arr.append(arr[i%k]+1) n=int(input()) z=input() kk=int(z,2) d=[1] for i in range(39): d.append(d[-1]*2) for i in range(n): if z[i]=='0': print(arr[kk+d[n-1-i]]) else: print(arr[kk-d[n-1-i]])
Statement Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7, it becomes 0 after two operations, as follows: * \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1. * \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0. You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
[{"input": "3\n 011", "output": "2\n 1\n 1\n \n\n * X_1 = 7, which will change as follows: 7 \\rightarrow 1 \\rightarrow 0. Thus, f(7) = 2.\n * X_2 = 1, which will change as follows: 1 \\rightarrow 0. Thus, f(1) = 1.\n * X_3 = 2, which will change as follows: 2 \\rightarrow 0. Thus, f(2) = 1.\n\n* * *"}, {"input": "23\n 00110111001011011001110", "output": "2\n 1\n 2\n 2\n 1\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 2\n 1\n 3"}]