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:
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
in_r, in_g, in_b, n = map(int, input().split())

ans = 0

in_list= [in_r,in_g,in_b]
sorted_list = sorted(in_list)

r = sorted_list[-1]
g = sorted_list[-2]
b = sorted_list[-3]

max_r = n // r

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

print(ans)

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:
def rgb_boxes(R: int, G: int, B: int, N: int)->int:
    res = 0
    for r in range(N+1):
        if r * R > N:
            break
        for g in range(N+1):
            if r * R + g * G > N:
                break
            if (N - (r*R + g*G)) % B == 0:
                res += 1

    return res


if __name__ == "__main__":
    R, G, B, N = map(int, input().split())

    ans = rgb_boxes(R, G, B, N)
    print(ans)

Submission status: Accepted

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

ans =0
for i in range(r_max+1):
    n_r = N-(R*i)
    if n_r==0:
        ans+=1
    else:
        g_max = n_r//G
        for j in range(g_max+1):
            n_g = n_r-G*j
            if n_g==0:
                ans+=1
            else:
                if n_g%B==0:
                    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys

R, G, B, N = input().split()
R = int(R)
G = int(G)
B = int(B)
N = int(N)

cnt = 0

for r in range(int(N/R)+1):
    N1 = N - R*r
    for g in range(int(N1/G)+1):
        N2 = N1 - G*g
        if N2 % 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(int(N/B)+1):
    for j in range(int((N-i*B)/G)+1):
        if((N-B*i-G*j)%R==0):
            cnt+=1
            
print(cnt)

Submission status: Accepted

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

count=0
for p1 in range(0,N+1,R):
    for p2 in range(0,N-p1+1,G):
        rR = p1
        gG = p2
        bB = N-p1-p2
        if bB%B==0:
            count+=1
print(count)

Submission status: Accepted

Solution code:
R, G, B, N = map(int,input().split())
count = 0
for sr in range(N+1):
    for sg in range(N+1-sr):
        sb = N-sr-sg
        if sr%R == 0 and sg%G == 0 and sb %B == 0:
            count += 1
print(count)

Submission status: Accepted

Solution code:
R,G,B,N=map(int,input().split())
R,G,B=sorted([R,G,B],reverse=True)
ans=0

nr=int(N/R)+1
for r in range(nr):
    s=N-r*R
    if s<0:
        continue
    ng=int(s/G)+1
    for g in range(ng):
        if (s-g*G)%B==0:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
def counter(r,g,b,n):
    count = 0
    max_y = n//g
    max_z = n//b

    for y in range(max_y + 1):
        for z in range(max_z + 1):
            x_before = n - g*y - b*z
            if( (x_before / r) < 0 ):
                break
            if( (x_before % r == 0) ):
                count += 1
    return count

r,g,b,n = map(int, input().split())
print(counter(r,g,b,n))

Submission status: Accepted

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

t = n // s[-1]
c = 0

for i in range(t+1):
    m = n - i * s[-1]
    t_1 = m // s[-2]
    for j in range(t_1+1):
        m_1 = m - j * s[-2]
        if m_1 % s[0] == 0:
            c += 1

print(c)

Submission status: Accepted

Solution code:
a, b, c, n = map(int, input().split())
ans = 0
for i in range(n//a + 1):
    rem = n - i*a
    for j in range(rem//b + 1):

        rem1 = rem - j*b
        if rem1 % c == 0:

            ans += 1


print(ans)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
boxSize=[r,g,b]
boxSize.sort(key=lambda x:-x)
# print(boxSize)
maxCnt=[n//boxSize[i]+1 for i in range(3)]
# print(maxCnt)
ans=0
if boxSize[1]==1:
    for cnt0 in range(maxCnt[0]):
        ans+=n-cnt0*boxSize[0]+1
else:
    for cnt0 in range(maxCnt[0]):
        for cnt1 in range(maxCnt[1]):
            reg=n-cnt0*boxSize[0]-cnt1*boxSize[1]
            if reg<0:
                break
            if reg%boxSize[2]==0:
                ans+=1
print(ans)

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())
ans = 0
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    S = N-r*R-g*G
    if S<0:
      break
    elif S%B==0:
      ans+=1
print(ans)

Submission status: Accepted

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


res = 0
for ri in range(N // R + 1):    
    for gi in range(N // G + 1):
        if (N - (ri * R + gi * G)) % B == 0 and N - (ri * R + gi * G) >= 0:
            res += 1    
print(res)

Submission status: Accepted

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

if R==1 and G==1 and B==1:
  print(int((N+2)*(N+1)*(1/2)))
else:
  RGB = [R, G, B]
  RGB.sort(reverse=True)

  R = RGB[0]
  G = RGB[1]
  B = RGB[2]

  cnt = 0
  NR = N//R
  NG = N//G
  for r in range(NR + 1):
    for g in range(NG + 1):
      NrRgG = N - (r*R + g*G)
      if NrRgG < 0:
        break
      elif NrRgG >= 0:
        if NrRgG % B == 0:
          cnt += 1
  print(cnt)

Submission status: Accepted

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

                cnt +=1
    print(cnt)
if __name__ =='__main__':
    main()

Submission status: Accepted

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

R, G, B, N = map(int, raw_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 str(_count)

Submission status: Accepted

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

S = min(R, G, B)
L = max(R, G, B)
M = R + G + B - S - L

cnt = 0
sum = 0
for i in range(N // L + 1)[::-1]:
    for j in range(N // M + 1):
        sum = N - i * L - j * M
        if sum < 0:
            break
        if sum % S == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
r,g,b,n = map(int,input().split())
counter = 0
sorts = sorted([r,g,b],reverse=True)
a = (n // sorts[0])+1

for i in range(a):
    test = n
    test = test-(sorts[0]*i)
    c = (test//sorts[1])+1
    for j in range(c):
        left = test - (sorts[1]*j)
        if left >= 0 and   left % sorts[2] == 0:
            counter += 1
            
print(counter)

Submission status: Accepted

Solution code:
res = 0
p = 0
R, G, B, N = map(int, input().split())
for i in range (N // R + 1):
    for j in range(N // G + 1):
        P =N - i*R - j*G
        if P < 0:
            break
        else:
            if(P % B == 0):
                res += 1


print(res)

Submission status: Accepted

Solution code:
'''
B - RGB Boxes
'''

r_weight, g_weight, b_weight, N = map(int, input().split())

ans = 0
for r in range(N+1):
    for g in range(N-r*r_weight+1):
        rem = N - r*r_weight - g*g_weight
        if rem % b_weight == 0 and rem >= 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
s = [r,g,b]
s.sort(reverse=True)
r,g,b=s[0],s[1],s[2]
"""
if r==1 and g == 1 and b==1:
    print(4504501)
    exit()
"""
cnt=0
for i in range(0,n//r+1):
    m = n - i*r
    for j in range(0,m//g+1):
        l = m - j*g
        if l%b==0:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
r, g, b, n = map(int, input().split())

nr_max = n // r
ng_max = n // g

count = 0
for i in range(nr_max + 1):
    tmp1 = r * i
    if tmp1 == n:
        count += 1
        break
    res = n - tmp1
    for j in range(res // g + 1):
        tmp2 = g * j + tmp1
        if tmp2 == n:
            count += 1
        if tmp2 >= n:
            break
        if (n - tmp2) % b == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
num = 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):
            num += 1
print(num)

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter
R,G,B,N = list(map(int, input().split()))
a = [R, G, B]
a.sort()
a = a[::-1]
R, G, B = a

s = 0
r_cand = np.arange(0, N + 1, R)[:, None]
g_cand = np.arange(0, N + 1, G)[None, :]
rest = N - r_cand - g_cand
rest = rest[rest >= 0]
c = Counter(rest)

s = 0
for k in c.keys():
    s += (k%B == 0) * c[k]

print(s)

Submission status: Accepted

Solution code:
N,M,S,L=map(int,input().split())
s = 0
for i in range(L//N+1):
    for j in range(L//M+1):
        k = (L-N*i - M*j)//S
        if k <0 :break
        if (L-N*i - M*j)//S == int((L-N*i - M*j)/S) and N*i + M*j + S*k == L:
            s+=1

print(s)

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))
b,g,r = sorted(A[0:3])
n = A[3]
count = 0
rr = 0
gg = 0
while n - r*rr >= 0:
  N = n - r*rr
  while True:
    if N - g*gg < 0:
      break
    elif (N - g*gg) % b == 0:
      count+=1
      gg+=1
    else:
      gg+=1
  rr+=1
  gg=0
print(count)

Submission status: Accepted

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

cnt = 0
for rr in range(n // r + 1):
  for gg in range((n - r * rr) // g + 1):
    rest = n - r * rr - g * gg
    cnt += (rest % b == 0)

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 17:52:43 2019

@author: nakamuratakayuki
"""

R,G,B,N = tuple(map(int,input().split()))
L = [R,G,B]
L.sort(reverse=True)
c = 0
rmax = N//L[0]

for i in range(rmax+1):
    Nc = N
    Nc -= i*L[0]
    if Nc%L[2] == 0:
            c += 1
    while True:
        Nc -= L[1]
        if Nc < 0:
            break
        if Nc%L[2] == 0:
            c += 1

print(c)

Submission status: Accepted

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

ans = 0
for r in range(0,N+1,R):
    for g in range(0,N+1,G):
        if r+g > N:
            break
        if (N-r-g)%B == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())
lis = [R,G,B]
lis = sorted(lis)
ans = 0
if min(lis) <= N:
    while N >= 0:
        i = 0
        while N - i*lis[1] >= 0:
            if (N-i*lis[1])%lis[0]==0:
                ans += 1
            i += 1
        N -= lis[2]
print(ans)

Submission status: Accepted

Solution code:
import os, sys, re, math

r,g,b,n = input().split(' ')
r,g,b,n = int(r), int(g), int(b), int(n)

ret = 0
ri = 0
while (ri * r <= n):
    rg = 0
    while (rg * g <= n - ri * r):
        if ((n - ri * r - rg * g) % b == 0):
            ret += 1
        rg += 1
    ri += 1

print(ret)

Submission status: Accepted

Solution code:
def main(R, G, B, N):
    count = 0
    for r in range(N+1):
        for g in range(N+1):
            remain = N - R * r - G * g
            if remain >= 0 and remain % B == 0:
                count += 1
    return count


if __name__ == "__main__":
    R, G, B, N = list(map(int, input().split()))
    print(main(R, G, B, N))

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 N >= G*i+B*j:
            if (N-(G*i+B*j))%R == 0:
               ans += 1
 
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(100000)

def f(a):
  global R,G,B,N,ans,Rm,Gm,Bm

  for b in range(N-R*a+1):
    cmod=(N-R*a-G*b)%B
    c=(N-R*a-G*b)//B
    if cmod==0 and  c>=0:
      ans+=1
    elif c<0:
      break

  if a>0:
    f(a-1)


R,G,B,N=list(map(int,input().split(" ")))

ans=0

f(N//R+1)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
R, G, B, N = map(int, input().split())

output = 0
# for g in range(N // G + 1):
#     for b in range(N // B + 1):
#         if (N - g*G - b*B) % R == 0:
#             if N >= g*G + b*B:
#                 output += 1
#             else:
#                 break

for r in range(N // R + 1):
    C = N - r*R
    for g in range(C // G + 1):
        if (C - g*G) % B == 0:
            if C >= g*G:
                output += 1
            else:
                break

print(output)

Submission status: Accepted

Solution code:
R,G,B,N = [int(x) for x in 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:
r,g,b,n = map(int, input().split())
dp = [[0] * 3001, [0] * 3001, [0] * 3001]
dp[0][0] = 1
dp[1][0] = 1
dp[2][0] = 1
for x in range(1, (n+1)):
    if x - r >= 0:
        dp[0][x] = dp[0][x-r]
for x in range(1, (n+1)):
    dp[1][x] = dp[0][x]
    if x-g >= 0:
        dp[1][x] += dp[1][x-g]
for x in range(1, (n+1)):
    dp[2][x] = dp[1][x]
    if x-b >= 0:
        dp[2][x] += dp[2][x-b]
print(dp[2][n])

Submission status: Accepted

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

dp = [0 for i in range(n+1)]
dp[0] = 1

for i in range(r, n+1, r):
    dp[i] = 1

for i in range(g, n+1):
    dp[i] += dp[i-g]

for i in range(b, n+1):
    dp[i] += dp[i-b]

print(dp[n])

Submission status: Accepted

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

#2種類の組み合わせ個数の組み合わせを求める関数
def kumiawase(x, y, n):
    p = max(x, y)
    q = min(x, y)

    kumi_kosu = 0

    for i in range(n // p + 1):
        if (n - p * i) % q == 0:
            kumi_kosu = kumi_kosu + 1
            #print('func, ', n - p * i, kumi_kosu)

    return kumi_kosu


p = [int(i) for i in input().split()]

#箱が最小となる個数を与える
r,g,b = sorted(p[0:3], reverse=True)
n = p[3]

#print(r,g,b,n)

kumi_kosu_2 = 0

#最大の場合の残り個数
#print(n // r)

for i in range(n // r + 1):
    kumi_kosu_2 = kumi_kosu_2 + kumiawase(g, b, n - r * i)
    #print('main, ', n - r * i, kumi_kosu_2)

print(kumi_kosu_2)

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):
        X = N - r * R - g * G
        if X % 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(1+n//r):
  red=i*r
  for j in range(1+(n-red)//g):
    green=j*g
    if((n-red-green)%b==0 and (n-red-green)>=0):
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

R,G,B,N =[int(x) for x in input().split()]
a = 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:
            a += 1
                       
           

print(a)

Submission status: Accepted

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

maxr=N//R
maxg=N//G

ans=0
for r in range(maxr,-1,-1):
  for g in range(maxg,-1,-1):
    if N-(r*R+g*G)>=0:
      if (N-(r*R+g*G))%B==0:
        ans+=1
print(ans)

Submission status: Accepted

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

def f(a, b):
    sho, amari = int(a/b), a%b
    return sho, amari


def ans(l, m, s):
    cnt = 0

    R_s, R_a = f(N, l)

    for i in range(R_s + 1):
        x = R_a + i * l # R を i 個使う
        G_s, G_a = f(x, m)
        for j in range(G_s + 1):
            y = G_a + j * m # G を j 個使う
            if y % s == 0:
                cnt += 1
    return cnt

li = [R, G, B]
li.sort(reverse=True)

cnt = ans(li[0], li[1], li[2])

print(cnt)

Submission status: Accepted

Solution code:
R,G,B,N = [int(x) for x in input().split()]
cnt = 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):
            cnt+=1

print(cnt)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

count = 0

for i in range(int(n/r)+1):
    for j in range(int((n-i*r)/g)+1):
        k =  n - i * r - j * g
        if k % 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-i*r)//g+1):
        if (n-r*i-g*j)%b==0:
            count+=1
print(count)

Submission status: Accepted

Solution code:
from sys import stdin
import math
input=input=stdin.readline().rstrip().split()
for i in range(len(input)):
  input[i]=int(input[i])

output=0
R=input[0]
G=input[1]
B=input[2]
N=input[3]
for r in range(math.floor(N/R)+1):
    for g in range(math.floor(N/G)+1):
        #for b in range(math.floor(N/B)+1):
        #print(r,g)
        #if r*R+g*G+b*B==N:
        b=N-(r*R+g*G)
        #b/B
        #if b>=0:
        if b<0:
            break
        if b % B == 0:
            #print(r,g)
            output+=1
print(output)

Submission status: Accepted

Solution code:
def gcd(n,m):
    while n > 0:
        a = n
        n = m % n
        m = a
    return m

R,G,B,N = map(int,input().split(" "))

C = G * B // gcd(G,B)

s = 0
b = 0
while b <= N:
    bb = b
    while bb <= N:
        if (N - bb) % B == 0:
            s += (N - bb) // C + 1
            bb = N + 1
        else:
            bb += G
    b += R

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d= input().split()
N = int(d)
R= int(a)
G = int(b)
B = int(c)

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

print(count)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
m=[r,g,b]
m.sort(reverse=1)
r,g,b=m[0],m[1],m[2]
ans=0
if m==[1,1,1]:
  print((n+2)*(n+1)//2)
else:
  for i in range(n+1):
    if r*i>n:
      break
    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:
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

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


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

print(count)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
# R, G, B, N = 1, 2, 3, 4
# R, G, B, N = 13, 1, 4, 3000


def count_r_ball_patterns(R, N_a):
    return 1 if N_a % R == 0 else 0


def count_rg_ball_patterns(R, G, B, N_b):
    max_g = N_b // G
    result = 0
    for g in range(max_g + 1):
        result = result + count_r_ball_patterns(R, N_b - G * g)
    return result


def count_rgb_ball_patterns(R, G, B, N):
    # count (r, g, b) satisties R * r + G * g + B * b = N
    R, G, B = sorted([R, G, B])
    max_b = N // B
    result = 0
    for b in range(max_b + 1):
        result = result + count_rg_ball_patterns(R, G, B, N - B * b)
    return result


if __name__ == "__main__":
    print(count_rgb_ball_patterns(R, G, B, N))

Submission status: Accepted

Solution code:
import math
r,g,b,n = [int(u) for u in input().split(" ")]
i = 0
for ir in range(math.floor(n/r)+1):
  if ir*r==n:
    i+=1
    break
  elif ir*r>n:
    break
  for ig in range(math.floor(n/g)+1):
    y = n - (ir*r+ig*g)
    if y<0:
      break
    if y%b==0:
      #print(ir,ig,y/b)
      i+=1
      continue
print(i)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
R,G,B,N =  map(int, input().split())
ans = 0
for n in range(N+1):
  s = n * R 
  if(s > N):
    break
  for n2 in range(N+1):
    s2 = s + n2 * G
    if(s2 > N):
      break
    if((N-s2) % B == 0):
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import operator as op
from io import StringIO
from collections import *
from functools import *
from fractions import gcd
import sys


def main(inputs):
    # n = int(next(inputs))
    # xs = list(map(int, next(inputs).split()))
    xs = list(map(int, next(inputs).split()))
    y = reduce(gcd, xs)
    r, g, b, n = map(op.floordiv, xs, [y]*4)
    ans = 0
    for i in range(1 + (n // r)):
        n_r = n - r*i
        for j in range(1 + (n_r // g)):
            if (n_r - g*j) % b == 0:
                #print("{}".format((i, j)))
                ans += 1
                pass
            pass
        pass
    return ans


def gen_inputs(str_=None):
    inputs = StringIO(str_) if str_ else sys.stdin
    while True:
        a = inputs.readline().rstrip()
        yield a
        pass
    pass


if __name__ == "__main__":
    print(main(gen_inputs()))
    pass

Submission status: Accepted

Solution code:
R,G,B,N=map(int,input().split())
ans=0
q=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:
rn,gn,bn,n=map(int,input().split())
nn=sorted([rn,gn,bn]) 
c=0
for r in range(1+n//nn[0]):
    rt=n-nn[0]*r
    for g in range(1+rt//nn[1]):
        gt=rt-nn[1]*g
        if gt%nn[2]==0:
            c+=1
print(c)

Submission status: Accepted

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

cnt=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:
            cnt+=1

print(cnt)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

Solution code:


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

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

print(count)

Submission status: Accepted

Solution code:
from statistics import median
R,G,B,N = map(int,input().split())
count = 0
n_max = max(R,G,B)
n_mid = median([R,G,B])
n_min = min(R,G,B)
for i in range(N//n_max + 1):
  x = N - i*n_max
  for j in range(x//n_mid + 1):
    y = x - j*n_mid
    if y % n_min == 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
import math
input = input().split()
r = int(input[0])
g = int(input[1])
b = int(input[2])
N = int(input[3])

count = 0
# print(N/r)
# print(math.ceil(N/r))
for x in range(math.ceil(N/r+0.0001)):
    for y in range(math.ceil((N-x*r)/g + 0.0001)):
        # print(str(x), str(y))
        if  (N - x*r - y*g) % b == 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*R)//G+1):
        if (N - r*R - g*G) % B == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

result = 0
max_r = n // r

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

Submission status: Accepted

Solution code:
r,g,b,n = map(int,input().split())
numR = n//r
numG = n//g
numB = n//b
c = 0
for i in range(0,n+1,r):
    for j in range(0,n+1,g):
        x = n-(i+j)
        if x%b ==0 and (i+j)<=n:
            c+=1

print(c)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
ans = 0
BN = []
for b in range(N+1):
    BN.append(N - (b * B))
BN = set(BN)
for r in range(N+1):
    for g in range(N+1):
        if r * R + g * G in BN:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math

line=input().split(" ")
n=int(line[3])
r=int(line[0])
g=int(line[1])
b=int(line[2])
nline=sorted([r,g,b])
x=int(nline[2])
y=int(nline[1])
z=int(nline[0])

answers=0
#print(x,y,z,n)


for i in range(math.ceil(n/x)+1):
    a=i
    if z!=1:
        for j in range(math.ceil((n-a*x)/y)+1):
            b=j
            c=(n-a*x-b*y)/z
            if c>=0 and (n-a*x-b*y)%z==0:
                answers+=1
                #print(a,b,c)
    else:
        if n-a*x>=0:
            if n-a*x==0:
                answers+=1
                #print('a', 1)
            elif (n-a*x)%y!=0:
                answers+=math.ceil((n-a*x)/y)
                #print('b', math.ceil((n-a*x)/y))
            else:
                answers+=(math.ceil((n-a*x)/y)+1)
                #print('c', math.ceil((n-a*x)/y)+1)
            

print(answers)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

nums = list(map(int, input().split()))
N = nums[3]
R, G, B = sorted(nums[:3])

d = reduce(gcd, [R, G, B])
# if N % d != 0:
#     print(0)
R, G, B, N = R//d, G//d, B//d, N//d

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

print(count)

Submission status: Accepted

Solution code:
r,g,b,n=list(map(int,input().split()))
count=0
for i in range(3001):
  for j in range(3001):
    a=n-(i*r+j*g)
    if(a<0):
      break
    if( a%b == 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*r)//G+1):
        tmp = R*r + G*g
        if (n - tmp) % B == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

def solve():
    R, G, B, N = map(int, input().split())
    dp = [[0 for __ in range(8)] for _ in range(6002)]
    for n in range(1,N+1):
        if n == R:
            dp[R][4] += 1
        if n == G:
            dp[G][2] += 1
        if n == B:
            dp[B][1] += 1

        dp[n][1] += dp[n-B][1]
        dp[n][2] += dp[n-G][2]
        dp[n][3] += (dp[n-G][1] + dp[n-G][3] + dp[n-B][2] + dp[n-B][3])//2
        dp[n][4] += dp[n-R][4]
        dp[n][5] += (dp[n-R][1] + dp[n-R][5] + dp[n-B][4] + dp[n-B][5])//2
        dp[n][6] += (dp[n-R][2] + dp[n-R][6] + dp[n-G][4] + dp[n-G][6])//2
        dp[n][7] += (dp[n-R][3] + dp[n-R][7] + dp[n-G][5] + dp[n-G][7] + dp[n-B][6] + dp[n-B][7])//3
    return str(sum(dp[N]))

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
a,b,c,n=map(int,input().split( ))

s=0
for i in range(n//a+1):
    for j in range((n-a*i)//b+1):
        ck=(n-a*i-b*j)
        if ck%c==0 and ck//c>=0:
            s+=1
        # print(i,j,ck,s)

print(s)

Submission status: Accepted

Solution code:
r,g,b,n = [int(i) for i in input().split()]

cnt = 0
for i in range(n//r+1):
  n_r = i*r
  if n_r > n:
    break
  for j in range(n//g+1):
    n_rg = j*g + n_r
    if n_rg > n:
      break
    if (n-n_rg)%b == 0:
      cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

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

dp =[[1, 1, 1]]
for x in range(n):
    dp.append([0, 0, 0])

for i in range(1, n + 1):
    for j in range(3):
        dp[i][j] = 0
        for q in range(j, 3):
            if i - l[q] >= 0:
                dp[i][j] = dp[i][j] + dp[i - l[q]][q]

print(dp[n][0])

Submission status: Accepted

Solution code:
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):
    
      #print("i,j,k",i,j,k)
    if (n-(i*r+j*g))%b==0:
        cnt+=1
        #print("ijk",i,j,k)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
answer = 0
s =s.split(" ")
R = int(s[0])
G = int(s[1])
B = int(s[2])
N = int(s[3])

def turukame(g,b,n):
    ans = 0
    for j in range(n//g+1):
        if (n-g*j) % b == 0:
            ans = ans + 1
    return ans


for i in range(N // R+1):
    answer = answer + turukame(G,B,N-R*i)

print(answer)