Problem:


Score : 200 points

Problem Statement

Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:

Red boxes, each containing R red balls

Green boxes, each containing G green balls

Blue boxes, each containing B blue balls

Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes.
How many triples of non-negative integers (r,g,b) achieve this?

Constraints

All values in input are integers.

1 \leq R,G,B,N \leq 3000

Input

Input is given from Standard Input in the following format:

R G B N

Output

Print the answer.

Sample Input 1

1 2 3 4

Sample Output 1

4

Four triples achieve the objective, as follows:

(4,0,0)

(2,1,0)

(1,0,1)

(0,2,0)

Sample Input 2

13 1 4 3000

Sample Output 2

87058



Sample input:
1 2 3 4


Sample output:
4

Submission status: Accepted

Solution code:
r, g, b, n = map(int, raw_input().split())
count = 0
for i in xrange(n+1):
    if i*r > n:
        break	
    for j in xrange(n+1):
        if i*r + j*g > n:
            break
        if (n- i*r - j*g) % b == 0:
      		count += 1
print count

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
ans = 0
for i in range(N // R + 1):
    for j in range((N - R*i) // G + 1):
        if (N - i*R - j*G) % B == 0:
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
import sys

def main(inp):
    r,g,b,n = map(int,next(inp).split())
    box = sorted([r,g,b],reverse = True)
    
    ans = 0
    for i in range(int(n/box[0])+1):
        for j in range(int((n-i*box[0])/box[1])+1):
            if((n-i*box[0]-j*box[1])%box[2] == 0):
                ans += 1
    
    return ans
  
print(main(sys.stdin))

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
counter = 0
r = N // R + 1
for s in range(r):
  g = (N - s*R) // G + 1
  for t in range(g):
    u = N - R*s - G*t
    if u >= 0 and u % B == 0:
      counter += 1
print(counter)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
  for t in range(n-s+1):
    u = n - r*s - g*t
    if u >= 0 and u % b == 0:
      counter += 1
print(counter)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
cnt = 0
 
for i in range(n+1):
    for j in range(n-i+1):
        a = n - r*i - g*j
        if a >= 0 and a % b == 0:
            cnt += 1
 
print(cnt)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())

cnt=0
for i in range(0,n+1,r):
    for j in range(i,n+1,g):
        if (n-j)%b==0:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
R,G,B,N = [int(i) for i in input().split()]
num = 0
box = sorted([R,G,B], key=lambda x:-x)
nums = [N//b for b in box]
for i in range(nums[0]+1):
    if (nums[0]-i)*box[0] + nums[1]*box[1] + nums[2]*box[2] < N:
        break
    for j in range(nums[1]+1):
        resj = (nums[0]-i)*box[0] + (nums[1]-j)*box[1]
        if resj + nums[2]*box[2] < N:
            break
        if resj > N:
            continue
        if (N-resj)%box[2]!=0:
            continue
        num += 1
print(num)

Submission status: Accepted

Solution code:
R, G, B, N = list(map(int,input().split()))
cnt = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        if (N-r*R-g*G) % B == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
read = input
A = list(map(int, read().split()))
n = A[-1]
A = A[:3]
A.sort(reverse=True) # descending
ans = 0
if A[1] == A[2] and A[1] == 1: #deal with 1 1
    for i in range(n+1):
        tmp = i*A[0]
        if tmp > n:break
#         print(ans, i, A)
        ans += (n-tmp) - 0 + 1
else :
    for i in range(n+1):
        for j in range(n+1):
            tmp = i * A[0] + j * A[1]
            if tmp > n:break
            tmp = n - tmp
            if tmp % A[2] == 0:
    #             print(i, j, tmp//A[2])
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

count = 0

rmax = N // R
for r in range(rmax + 1):
    x = N - r * R
    gmax = x // G
    for g in range(gmax + 1):
        y = x - g * G
        if y >= 0 and y % B == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
ans=0
for i in range((n//r)+1):
    for j in range(((n-r*i)//g+1)):
        if (n-i*r-j*g)%b==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
# div2019B - RGB Boxes
r, g, b, n = list(map(int, input().rstrip().split()))
cnt = 0
for i in range(n // r + 1):
    for j in range((n - r * i) // g + 1):
        if (n - i * r - j * g) % b == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, raw_input().split(" "))

ans = 0
for tmp_r in range(0, 3001):
    if r * tmp_r > n:
        break
    for tmp_g in range(0, 3001):
        if r * tmp_r + g * tmp_g > n:
            break
        if (n - (r * tmp_r + g * tmp_g)) % b == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = list(map(int, input().split()))
ret = 0
for r in range(N//R+1):
    for g in range((N-r)//G+1):
        if N - (R*r+G*g) >= 0:
            if (N - (R*r+G*g)) % B == 0:
                ret += 1
print(ret)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        tmp = N - r * R - g * G
        if tmp % B == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

counter = 0
for r in range((N // R) + 1):
    for g in range(((N - (r * R)) // G) + 1):
        w_b_sum = N - ((R * r) + (G * g))

        if w_b_sum % B == 0 and w_b_sum >= 0:
            # print(r, g, (w_b_sum // B))
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
def sol():
    r,g,b,n=map(int,input().split())
    ans=chk=0
    for i in range(n+1):
        for j in range(n+1):
            if (i*r+j*g)>n: break
            if (n-(i*r+j*g))%b==0:
                ans+=1
    print(ans)
if __name__ == '__main__':
    sol()

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
 
count = 0
for i_r in range(0,int(n)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int(n)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):
 
            count +=1
 
print(count)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
 
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int(n/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):
 
            count +=1
 
print(count)

Submission status: Accepted

Solution code:
r,g,b,n = map(int,input().split())
a = [0]*(n+1)
a[0] = 1
for i in [r,g,b]:
    for j in range(n+1-i):
        a[j+i]+=a[j]
print(a[n])

Submission status: Accepted

Solution code:
r, g, b ,n = list(map(int, input().split()))
count = 0
for i in range(n//r + 1):
    for j in range((n-i*r)//g+1):
        if (n-i*r-j*g) % b == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
from sys import stdin
R, G, B, N = (int(i) for i in input().split())

dp = [0] * (N+1)
dp[0] = 1

for c in (R, G, B):
    for i in range(N + 1):
        if i + c <= N:
            dp[i+c] += dp[i]

print(dp[N])

Submission status: Accepted

Solution code:
def main():
    r, g, b, n = map(int, input().split())

    count = 0

    for i in range(3001):
        for j in range(3001):
            v = (i*r) + (j*g) 
            if n >= v and (n-v)%b == 0: 
                count += 1



    print(count)
                

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
R, G, B, N = (int(i) for i in input().split())

count = 0
for i in range(N+1):
    N1 = N - i*R
    for j in range(N1+1):
        b = (N1 - j*G)/B
        if b.is_integer() and b >= 0:
            count +=1

print(count)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
R,G,B,N = inpl()
# (R,G,B) = sorted([R,G,B])
ans = 0
for b in range(N//B+1):
    N1 = N - b*B
    for g in range(N1//G+1):
        N2 = N1 - g*G
        if N2 % R == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())
ans=0
for i in range(N//R+1):
    for e in range((N-R*i)//G+1):
        if (N-i*R-e*G)%B==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
ans = 0
nr = n // r
ng = n // g
for i in range(nr + 1):
    for j in range(ng + 1):
        tmp = n - i * r - j * g
        if tmp >= 0 and tmp % b == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
ans=0
for i in range(n//r+1):
    for j in range((n-r*i)//g+1):
        if (n-i*r-j*g)%b==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int,input().split())
count = 0
for r in range(N+1):
    for g in range(N+1-r*R):
        b = (N-r*R-g*G)
        if b%B == 0 and b >=0 :
            count+=1
print(count)

Submission status: Accepted

Solution code:
import numpy as np

IN = input().split()

dp = np.zeros((4,3001))
dp[0][0] = 1

for i in range(3):
    for j in range(3001):
        dp[i+1][j] += dp[i][j]
    for j in range(3001):
        if(j - int(IN[i]) >= 0):
            dp[i+1][j] += dp[i+1][j - int(IN[i])]

print(int(dp[3][int(IN[3])]))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())

R, G, B, N = mi()

count = 0
for i in range(N//R + 1):
    for j in range((N-i*R)//G + 1):
        if (N - i*R - j*G) % B == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
r,g,b,n = map(int, input().split())
ans = 0
for i in range(n // r + 1):
  res = n - r * i
  for j in range(res // g + 1): 
    res2 = res - g * j
    if res2 % b == 0:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, n = map(int, input().split())

ans = 0
r = 0

while r <= n:
    g = 0
    while r + g <= n:
        if (n - r - g) % B == 0:
            ans += 1
        g += G
    r += R

print(ans)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())

ans = 0

for i in range(3001):
    if i*r > n:
        break
    for j in range(3001):
        value = r*i + g*j
        if (n - value) < 0:
            break
        elif (n - value) % b == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R,G,B,N=list(map(int,input().split()))
cnt=0
for r in range((N//R)+1):
    for g in range(((N-R*r)//G)+1):
        if (N-R*r-G*g)%B==0:
            cnt=cnt+1
print (cnt)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())

num_max_r = n//r

ans = 0
for num_r in range(num_max_r + 1):
    
    n_r = n - num_r*r
    num_max_g = n_r//g
    
    for num_g in range(num_max_g + 1):
        n_r_g = n_r - num_g*g
        
        if n_r_g >= 0 and n_r_g % b == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
r,g,b,n = map(int,input().split())

res=0
tmp=n
tmp1=0
re=n//r+1
ge=n//g+1

for i in range(re):
	tmp = tmp - i*r
	tmp1 = tmp
	for j in range(ge):
		tmp1 = tmp - j*g
		if tmp1 < 0:
			break
		elif tmp1%b==0:
			res = res + 1
		tmp1 = tmp
	tmp=n

print(res)

Submission status: Accepted

Solution code:
r,g,b,n=map(int, input().split())

sum=0

for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        if (n-i*r-j*g)%b==0:
            sum=sum+1
        #    print(i*r,j*g,(n-(i*r)-(j*g))%b)

print(sum)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
ans=0
for i in range(n+1):
    for j in range(n+1):
        if r*i+g*j>n:
            break
        if (n-(r*i+g*j))%b==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
     
ans = 0
for r in range(int(N/R)+1):
    for g in range(int((N-r*R)/G)+1):
        if (N - (r*R + g*G))%B == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
r,g,b,n=map(int,input().split())
t=0
for i in range(0,(n-1)//r+2):
    d=n-r*i
    if d%gcd(g,b)==0:
        c=0
        for j in range(0,(d-1)//b+2):
            if (d-j*b)%g==0:
                c=1
                break
        if c==1:
            t+=(d-j*b)//(g*b//gcd(g,b))+1
print(t)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
cnt = 0

for r in range(N//R+1):
	for g in range((N-R*r)//G+1):
		if (N - R * r - G * g) % B == 0:
			cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
     
ans = 0
for r in range(int(N/R)+1):
    for g in range(int(N/G)+1):
        if r*R + g*G <= N:
            if (N - (r*R + g*G))%B == 0:
                ans += 1
     
print(ans)

Submission status: Accepted

Solution code:
# 2019/05/12
# diverta 2019 Programming Contest - B

# Input
r, g, b, n = map(int, input().split())

# Init
cnt = 0

# Calc
for i in range(n+1):
    rcnt = r * i
    if rcnt > n:
        break
    
    for j in range(n+1):
        rgcnt = rcnt + g * j
        if rgcnt > n:
            break
        bcnt = n - rgcnt
        if bcnt % b == 0:
            cnt += 1
# Output
print(cnt)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
R,G,B,N = inpl()
(R,G,B) = sorted([R,G,B])
ans = 0
for b in range(N//B+1):
    N1 = N - b*B
    for g in range(N1//G+1):
        N2 = N1 - g*G
        if N2 % R == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())

colors = sorted([r, g, b])

cnt = 0
for i in range(n // colors[2] + 1):
  for j in range((n - i*colors[2]) // colors[1] + 1):
    if (n - i*colors[2] - j*colors[1]) % colors[0] == 0:
      cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
ans=0
for i in range(n//r+1):
  for j in range((n-r*i)//g+1):
    if (n-i*r-g*j)%b==0:ans+=1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

count = 0


for r in range(N//R + 1):
	for g in range((N-r*R)//G + 1 ):
		if  (N - r*R - g*G) % B == 0:
				count += 1
				#print("r, g, b = " + str(r) + ", " + str(g) + ", " +  str((N - r*R - g*G)//B))

print(count)

Submission status: Accepted

Solution code:
R,G,B,N=map(int,input().split())

ans=[]

count=0
for r in range(int(N/R)+1):
    for g in range(int((N-r*R)/G)+1):
        
        if (N-r*R-g*G)%B==0:
            count+=1
            #ans.append([r,g,(N-r*R-g*G)/B])

#print(ans)
print(count)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
rmax = N // R
gmax = N // G
cnt = 0
for r in range(rmax + 1):
  for g in range(gmax + 1):
    rest = N - R * r - G * g
    if rest >= 0 and rest % B == 0:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
s_rgb = sorted([r, g, b], reverse=True)
count = 0
for i in range(int(n / s_rgb[0]) + 1)[::-1]:
    for j in range(int((n - s_rgb[0] * i) / s_rgb[1]) + 1)[::-1]:
        tmp = n - s_rgb[0] * i - s_rgb[1] * j
        if (tmp >= 0 and tmp % s_rgb[2] == 0):
            count += 1
print(count)

Submission status: Accepted

Solution code:
R,G,B,N = map(int, input().split())
rgb = [R,G,B]
rgb.sort(reverse = True)
#print(rgb)
ans = 0
for r in range(N//rgb[0]+1):
    n1 = N - rgb[0]*r
    for g in range(n1//rgb[1]+1):
        if (n1 - rgb[1]*g)%rgb[2] == 0:
            #print(r,g,n2//rgb[2])
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

import numpy as np

r = np.arange(0, N+1, R, dtype=np.int64)
g = np.arange(0, N+1, G, dtype=np.int64)
r, g = np.meshgrid(r, g)
b = N - r - g

print(np.sum(((b%B)==0) & (b>=0)))

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
# r, g, b, n = 13, 1, 4, 3000
# r, g, b, n = 1, 2, 3, 4
counter = 0
for i in range(0,n+1):
    j = 0
    if (n-i) % b == 0:
        while i >= r * j:
            if (i - r * j) % g == 0:
                counter += 1 
                # print(r*j, (i - r*j)/g,(n-i)/b)
            j += 1
print(counter)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
ans = 0
for r in range(3001):
    for g in range(3001):
        if (N - r * R - g * G) / B == (N - r * R - g * G) // B and (N - r * R - g * G) / B >= 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
R, G, B, N = map(int, input().split())
r = np.arange(0, int(N/R)+1)
g = np.arange(0, int(N/G)+1)
rg = r[:, np.newaxis]*R+g[np.newaxis, :]*G
mask = (rg<=N) & ((N-rg)%B==0)
print(np.sum(mask))

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())

cnt = 0
for r in range(N//R+1):
    for g in range((N-R*r)//G+1):
        if (N-R*r-G*g) % B == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())
cnt = 0
for i in range(n + 1):
    for j in range(n + 1):
        T = i * r + j * g
        if T > n:
            break

        if (n - T) % b == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def main():
    R, G, B, N = map(int, input().split())
    ans = 0
    cnt = 0
    for r in range(N + 1):
        for g in range(N + 1 - (R * r)):
            if (N - (R * r) - (G * g)) % B == 0 and N - (R * r) - (G * g) >= 0:
                cnt += 1
 
    print(cnt)
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
 
from collections import defaultdict
 
R, G, B, N = map(int, input().rstrip().split(' '))
A = [R, G, B]
 
dp = defaultdict(lambda: defaultdict(lambda: -1))
def rec(i, n):
    if dp[i][n] != -1:
        return dp[i][n]
    if n == 0:
        return 1
    if i == 2:
        return n % A[2] == 0
       
    temp = 0
    for j in range(n // A[i] + 1):
        temp += rec(i + 1, n - j * A[i])
        
    dp[i][n] = temp
    
    return temp
    
print(rec(0, N))

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        rem = N - (r * R + g * G)
        if rem < 0:
            break
        if rem == 0 or (rem > 0 and rem % B == 0):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        rem = N - (r * R + g * G)
        if rem == 0 or (rem > 0 and rem % B == 0):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())
ans = 0
for i in range(N//R+1):
    for j in range((N-i*R)//G+1):
        if (N-i*R-j*G) % B == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

ans = 0
for delim1 in range(0, N + 1):
    for delim2 in range(delim1, N + 1):
        left = delim1
        middle = delim2 - delim1
        right = N - delim2
        if left % R == 0 and middle % G == 0 and right % B == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def B(info):
    rgb = [0]*3
    *rgb, n = map(int,info.split())
    rgb.sort(reverse = True)
    count = 0
    for i in range(n//rgb[0]+1):
        new_n = n - i*rgb[0]
        if new_n < rgb[2]:
            if new_n == 0:
                count += 1
            continue
        for j in range(new_n//rgb[1]+1):
            if (new_n-rgb[1]*j)%rgb[2] == 0:
                count += 1

    return count

    
if __name__ == '__main__':
    print(B(input()))

Submission status: Accepted

Solution code:
def b_rgb_boxes(R, G, B, N):
    """Rr+Gg+Bb=N となる非負整数(r, g, b)の組はいくつか。"""
    # dp[i]: Rr+Gg+Bb=i となる非負整数(r, g, b)の組はいくつか
    dp = [0] * (N + 1)
    dp[0] = 1
    for c in (R, G, B):
        for i in range(N + 1):
            if i + c <= N:
                # Rr+Gg+Bb=i を達成する組のそれぞれに対して、
                # R,G,Bのどれかを足すと Rr+Gg+Bb=i+c を達成できる
                dp[i + c] += dp[i]
    return dp[N]

R, G, B, N = [int(i) for i in input().split()]
print(b_rgb_boxes(R, G, B, N))

Submission status: Accepted

Solution code:
R, B, G, N = (int(x) for x in input().split())
a = [R, B, G]
a = sorted(a)
b = a[2]
d = a[1]
f = a[0]
c = int(N / b)

count = 0

for i in range(c + 1):
    n = N - b * i
    e = int(n / d)
    for j in range(e + 1):
        m = n - d * j
        if m % a[0] == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import re
         
a,b,c,n = list(map(int,re.split(" ",input())))
N = n
s = []
s.append(a)
s.append(b)
s.append(c)
s.sort()
a,b,c = s
#print(a,b,c)
ans = 0
for i in range(int(N/c)+1):
  for j in range(int((N-i*c)/b)+1):
      if (N - i*c  - j*b)%a == 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_b
import itertools

intext = input()
[r, g, b, n] = map(int, intext.split())

rgb_list = [r, g, b]
rgb_list.sort(reverse=True)
[x, y, z] = rgb_list

cnt = 0
for x_val in range(0, n+1, x):
    # for y_val in range(0, n+1, y):
    for y_val in range(0, (y*((n-x_val)//z))+1, y):
        zan = n - x_val - y_val
        if zan >=0 and zan % z == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8 
r, g, b, n = map(int, input().split())
cnt = 0
for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        if (n-i*r-j*g)%b==0:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def b_rgb_boxes(R, G, B, N):
    """Rr+Gg+Bb=N となる整数(r, g, b)の組はいくつか。"""
    ans = 0
    for r in range(N + 1):
        for g in range(N + 1):
            t = N - R * r - G * g
            if t >= 0 and (t % B == 0):
                ans += 1
    return ans

R, G, B, N = [int(i) for i in input().split()]
print(b_rgb_boxes(R, G, B, N))

Submission status: Accepted

Solution code:
R,G,B,N = list(map(int,input().split()))
ans=0
for i in range(N//R+1):
    for j in range((N-i*R)//G+1):
        if((N-i*R-j*G)%B==0):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
r,g,b,n = (int(i) for i in input().split())
ans = 0
for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        if (n-i*r-j*g)%b==0: ans+=1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

ans = 0

r_max = N // R
for r in range(r_max + 1):
    g_max = (N - R * r) // G
    for g in range(g_max + 1):
        tmp = N - R * r - G * g
        if tmp % B == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = [int(s) for s in input().split()]
MAX = 3001
count = 0
proglist = [1 for r in range(MAX) for g in range(MAX) if (N-r*R-g*G) % B == 0 and (N-r*R-g*G) >= 0]
print(sum(proglist))

Submission status: Accepted

Solution code:
r, g, b, n = map(int, input().split())

count = 0
for i in range(n//r + 1):
    for j in range((n-r*i)//g + 1):
        if (n-r*i-g*j) % b == 0:
            count += 1


print(count)

Submission status: Accepted

Solution code:
R,G,B,N = map(int, input().split())
count = 0
for r in range(N // R + 1) :
    for g in range((N - r*R) // G + 1) :
        if (N - r*R - g*G) %B == 0 :
            count += 1
print(count)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

count = 0

for r in range(N//R+1):

  for g in range((N-r*R)//G+1):
    if (N - r*R - g*G) % B == 0:
      count += 1

print(count)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
count = 0
for i in range(N//R+1):
    for j in range((N-R*i)//G+1):
        if (N - R*i - G*j) % B == 0:
            count += 1
print(count)

Submission status: Accepted

Solution code:
# 入力
R, G, B, N = map(int, input().split())

# とりうるすべてのr, gの組に関して、条件を満たすbが存在するかを数え上げる
ans = sum(
    N - r * R - g * G >= 0 and (N - r * R - g * G) % B == 0
    for r in range(N // R + 1)
    for g in range((N - r * R) // G + 1)
)

# 出力
print(ans)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
cnt=0
for i in range(n+1):
        for j in range(n+1):
                z=n-(i*r+j*g)
                if 0<=z and z%b==0:
                        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def main(R, G, B, N):
    arr = [R, G, B]
    arr.sort(reverse=True)
    R, G, B = arr

    c = 0
    for r in range(N//R, -1, -1): 
        new1 = N - r*R
        for g in range(new1//G, -1, -1):
            if (new1 - g*G)%B == 0:
                c +=1
    print(c)

R, G, B, N = (int(i) for i in input().split())
main(R, G, B, N)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

ans = 0

for r in range(N//R+1):
    for g in range((N-R*r)//G+1):
        if( N - R*r - G*g) % B == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 12 12:43:56 2019

@author: Yamazaki Kenichi
"""

R,G,B,N = map(int,input().split())
RGB = [R, G, B]

dp = [[0,0,0] for i in range(N+1)]
dp[0] = [1,0,0]
for i in range(1,N+1):
    if R <= i:
        dp[i][0] += dp[i-R][0]
    if G <= i:
        dp[i][1] += (dp[i-G][0] + dp[i-G][1])
    if B <= i:
        dp[i][2] += (dp[i-B][0] + dp[i-B][1] + dp[i-B][2])
print(sum(dp[N]))

Submission status: Accepted

Solution code:
R,G,B,N = map(int, input().split())
c = 0
for i in range(0,int(N/R)+1):
    for j in range(0,int((N-R*i)/G)+1):
        if (N-R*i-G*j)%B == 0:
            c += 1
print(c)

Submission status: Accepted

Solution code:
r,g,b,n=list(map(int,input().split()))
cnt=0
for i in range(n+1):
        for j in range(n+1):
                z=n-(i*r+j*g)
                if 0<=z and z%b==0:
                        #print(i,j,z)
                        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
r, g, b, n = list(map(int, input().split()))

a1, a2, a3 = sorted([r, g, b])
ans = 0
a3n = n // a3
a2n = n // a2
for i in range(a3n + 1):
    for j in range(a2n + 1):
        r = n - (a3 * i + a2 * j)
        if r < 0:
            break
        if r % a1 == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import math


def kari():
    map(int, input().split())
    list(map(int, input().split()))
    math.ceil()

def main():
    red, green, blue, num = map(int, input().split())
    ans = 0
    for i in range(num + 1):
        for j in range(num + 1):
            nokori = num - red * i - blue * j
            if nokori < 0:
                break
            if nokori % green == 0:
                # print(i, j, nokori)
                ans += 1
        if num < red * i:
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

r, g, b, n = map(int, input().split())
ans = 0

for i in range(n+1):
    for j in range(n+1):
        x = n - g*i - b*j
        if x < 0:break
        if x % r == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())

ans = 0
rsum = 0
for r in range(0, N+1):
    if N < rsum:
        break
    rgsum = rsum
    for g in range(0, N+1):
        if N < rgsum:
            break
        left = N - rgsum
        if left % B == 0:
            ans += 1
        rgsum += G
    rsum += R

print(ans)

Submission status: Accepted

Solution code:
R,G,B,N=map(int,input().split())
r,g,b,count=0,0,0,0
for b in range(N+1):
	for g in range(N+1):
		r=-G*g-B*b+N
		if r<0:break
		if (r%R==0): count+=1
print(count)

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R + 1) :
    for g in range((N-r)//G + 1) :
        calc = r*R + g*G
        if N < calc :
            break
        if not (N-calc) % B :
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R + 1) :
    for g in range((N-r)//G + 1) :
        calc = r*R + g*G
        if N < calc :
            break
        if (N-calc) % B == 0 :
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
ans = 0
for i in range(N//R+1):
  for j in range((N-R*i)//G+1):
     if (N - R*i - G*j) % B == 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
R,G,B,N=map(int,input().split())
count=0
wa=0
for i in range(int(N/R)+1):
    for j in range(int((N-i*R)/G)+1):
        b=(N-i*R-j*G)/B
        if b>=0 and float.is_integer(b)==True:
            count=count+1
     
print(count)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def solve():
    R, G, B, N = list(map(int, input().split()))

    # r, g, bのそれぞれに関してforで回すとO(N**3)で間に合わないので、
    # rを固定する。するとO(N**2)で解ける
    ans = 0
    for g in range(N+1):
        if g*G > N: break
        for b in range(N+1):
            if g*G+b*B > N: break
            if (N - (g*G+b*B))%R == 0:
                ans += 1
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
R, G, B, N=map(int, input().split())
cnt=0
for r in range(int(N/R+1)):
    for g in range(int((N-(r*R))/G+1)):
        if (N-(r*R)-(g*G))%B==0:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#input
a = list(map(int,input().split())) #input from array of integer like "1 2 3"
n = a[3]
a = a[:3]
range_r = n//a[0]+1
range_g = n//a[1]+1
cnt = 0
for r in range(range_r):
  for g in range((n-r*a[0])//a[1]+1):
    rg = r*a[0]+g*a[1]
    if (n - rg)%a[2]==0:
      cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
r,g,b,n = map(int,input().split())
cnt = 0
for x in range(n+1):
    for y in range(n+1):
        z = n-r*x-g*y
        if z >= 0 and z%b == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
l = sorted([R, G, B])[::-1]

count = 0
for l0 in range(N//l[0]+1):
  n0 = N-l0*l[0]
  for l1 in range(n0//l[1]+1):
    l2 = n0 - l1*l[1]
    if l2%l[2] == 0 and l2 >= 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
R,G,B,N=map(int,input().split())
A=[0]*(N+1)
A[0]=1
for i in range(N+1-R):
    A[i+R]=A[i]
for k in range(N+1-G):
    A[k+G]+=A[k]
for h in range(N+1-B):
    A[h+B]+=A[h]
print(A[N])

Submission status: Accepted

Solution code:
# R*r + G*g + B*b == N の数
R, G, B, N = map(int, input().split())
R, G, B = list(sorted([R, G, B], reverse=True))
ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        if (N - (r * R + g * G)) % B != 0:
            continue
        b = (N - (r * R + g * G))/B
        if b < 0:
            break
        if r * R + g * G + b * B == N:
            ans += 1
        elif r * R + g * G + b * B > N:
            break

print(ans)

Submission status: Accepted

Solution code:
A,B,C,N=map(int, input().split())
count=0
for x in range(N+1):
  for y in range(N-x*A+1):
    b=(N-x*A-y*B)
    if b>=0 and b%C==0:
      count+=1
                
print(count)