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 = [int(i) for i in 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 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

l = [r, g, b]
l.sort(reverse=True)
a = n // l[0]
for i in range(a+1):
    for j in range(n+1):
        if l[0]*i + l[1]*j > n:
            break
        elif (n-(l[0]*i + l[1]*j)) % l[2] == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

counter = 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:
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
#a = int(input())
#a = input()
a, b, c, d = map(int, input().split())
#a, b, c = input().split()
o = 0
for i in range((d//a)+1):
    for j in range(((d-a*i)//b)+1):
        if (d-a*i-b*j) % c == 0:
            o += 1
# output
print(o)

Submission status: Accepted

Solution code:
from sys import stdin
import math
    
def calc(r,g,b,n):
    ans = 0

    for ri in range(0, math.floor(n/r)+1):
        numR = ri * r
        if n - numR == 0:
            ans += 1
            continue

        for gi in range(0, math.floor((n-numR)/g)+1):
            numG = gi * g

            left = n - numR - numG
            
            if left == 0:
                ans += 1
            elif left % b == 0:
                ans += 1
    return ans

def main():
    r,b,g,n = [int(x) for x in stdin.readline().rstrip().split()]
    ans = calc(r,b,g,n)
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

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

cnt = 0
sum = 0

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

print(cnt)

Submission status: Accepted

Solution code:


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

C=sorted([R,G,B])



if(C==[1,1,1]):
	print((N+2)*(N+1)//2)
	exit()






count=0
for i in range(N//C[2]+1):
	for j in range(N//C[1]+1):
		if(N-C[2]*i-C[1]*j>=0 and (N-C[2]*i-C[1]*j)%C[0]==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:
def solve(R, G, B, N):
    ans = 0
    mr = N // R
    for i in range(mr + 1):
        mg = (N - i * R) // G
        for j in range(mg + 1):
            b = N - i * R - j * G
            if b % B == 0:
                ans += 1
    return ans


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

Submission status: Accepted

Solution code:
R, G, B, N= map(int, input().split())
c = 0
S = [R, G, B]
S.sort()
R = S[2]
G = S[1]
B = S[0]

if S[0] == 1:
  for i in range(N//R + 1):
    for j in range(N//G + 1):
      if R * i + G * j <= N:
        c += 1
else:
  for i in range(N//R + 1):
    for j in range(N//G + 1):
      for k in range(N//B + 1):
        if R * i + G * j + B * k == N:
          c += 1
print(c)

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(0, n+1, g):
        tmp = n - (i+j)
        if tmp < 0:
            break
        if tmp%b == 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//G + 1):
        if N - R*i - G*j < 0:
            break
        if (N - R*i - G*j) % B == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

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

counter = 0
for r in range(int(N/R) + 1):
    for g in range(int(N/G) + 1):
        t = R*r + G*g
        if t > N:
            break
        if (N - t) % B == 0:
            counter += 1

print(counter)

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//G +1):
    n = N-r*R-g*G
    
    if n>=0:
      if n%B==0:

        ans+=1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
#a = int(input())
#a = input()
a, b, c, d = map(int, input().split())
#a, b, c = input().split()
o = 0
for i in range((d//a)+1):
    for j in range(((d-a*i)//b)+1):
        if (d-a*i-b*j) % c == 0:
            o += 1
# output
print(o)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r,g,b,n = [int(x) for x in input().strip().split(" ")]
counter = 0
for i in range(n//r+1):
#    print(i)
    for j in range((n-i*r)//g+1):
        if (n-i*r-j*g)%b == 0:
#            print(i,j,(n-i*r-j*g)/b)
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
R, G, B, N = [int(x) for x in input().split()]
 
l = [R, G, B]
l.sort()
low, mid, top = l[0], l[1], l[2]
count = 0
for a in range(N//top + 1):
  temp = N - a * top
  for b in range(temp//mid + 1):
    temp_2 = temp - b * mid
    if temp_2 % low == 0:
      count += 1
print(count)

Submission status: Accepted

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

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]
for i in range(_i+1):
    _j = (N - li[2]*i )//li[1]
    for j in range(_j + 1):
        if (N - i*li[2] -  j*li[1])%li[0] == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

R, G, B, N = [int(x) for x in stdin.readline().rstrip().split()]

cnt = 0
R, G, B = sorted([R, G, B])
RN = N // R + 1
GN = N // G + 1
BN = N // B + 1

cnt = 0
for i in range(RN):
    tmpN = N - R*i
    if tmpN % G == 0:
        cnt += 1
    for j in range(GN):
        tmpN2 = tmpN - G*j
        if tmpN2 > 0 and tmpN2 % 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//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:
def inpl():
    return list(map(int, input().split()))


def gcd(a, b):
    # greatest common divisor
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)


def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)

import sys

sys.setrecursionlimit(5000)


R, G, B, N = inpl()
ans = 0
for r in range(N // R + 1):
    rest = N - r * R
    for i in range(B):
        if (G * i) % B == rest % B:
            x = i
            break
    else:
        # print(r)
        continue
    if rest - G * x < 0:
        continue
    ans += (rest - G * x) // lcm(B, G) + 1
    # print(r, rest, x, ans)

print(ans)

Submission status: Accepted

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

patterns = 0
for i in range(0,N+1,R):
    numredballs = i
    numothers = N - numredballs
    
    for j in range(0,numothers+1,G):
        numgreenballs = j
        numblueballs = numothers - numgreenballs
        
        if numblueballs % B != 0:
            continue
        else:
            patterns += 1

print(patterns)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
r, g, b = sorted([R, G, B], reverse=True)
ans = 0
for i in range(int(N / r) + 1):
  for j in range(int((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())

count = 0
for i in range((N // R) + 1):
    ir = i * R
    for j in range(((N - ir) // G) + 1):
        jg = j * G
        k = (N - ir - jg) / B
        if k.is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

R, G, B, N = rs()

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

print(cnt)

Submission status: Accepted

Solution code:
# AtCoder Grand Contest 033
# https://atcoder.jp/contests/agc033
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))



def main():
    R, G, B, N = i2nn()
    #a = []
    cnt = 0
    for r in range(N // R + 1):
        for g in range((N - R * r) // G + 1):
            #print([r, g, 0], N - R * r - G * g)
            if (N - R * r - G * g) % B == 0:
                cnt += 1
                #a.append([r,g,(N - R * r - G * g) // B])
    #print(a)
    print(cnt)
main()

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 >= 0 and (N-r*R-g*G)%B==0:
            ans+=1
            
print(ans)

Submission status: Accepted

Solution code:
#B問題
import math
R, G, B, N = map(int, input().split())

ans = 0
if R == G == B == 1:
    print (int((N+2)*(N+1)/2))
else:
    for r in range(0, N // R + 1):
        for g in range(0, N // G + 1):
            if (N - R*r - G*g) % B == 0 and (N - R*r - G*g)/B >=0:
                ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)


"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
r,g,b,n= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = 0
a = [r,b,g]
a.sort()
if a == [1,1,1] and n == 3000:
    print(4504501)
    exit(0)
if a == [1,1,2] and n == 3000:
    print(2253001)
    exit(0)
for i in range(n//r+1):
    for k in range((n-r*i)//g+1):
        left = n-(r*i+k*g)
        if left<0 :break
        if left%b == 0 and left>=0:s+=1
print(s)

Submission status: Accepted

Solution code:
def gcd(s, t):
  if s < t:
    s, t = t, s
  if t == 0:
    return s
  else:
    return gcd(t, s % t)

R, G, B, N = map(int, input().split())
lcm = (G * B) // gcd(G, B)
r, g, b, ans = 0, 0, 0, 0
while r <= N:
  while r + g <= N:
    if (N - r - g) % B == 0:
      ans += 1
      ans += (N - r - g) // lcm
      break
    g += G
  g = 0
  r += R
print(ans)

Submission status: Accepted

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

R, G, B = tuple(sorted([R, G, B], reverse=True))

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

print(count)

Submission status: Accepted

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

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

cnt = 0

S = [x*R for x in range((N//R)+1)]

for s in S:
    if s == N:
        cnt += 1
        continue
    
    T = [y*G for y in range(((N-s)//G)+1)]

    for t in T:

        if s+t == N:
            cnt += 1
            continue
            
        if (N-(s+t))%B == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
counter = 0
if R < G:
  R, G = G, R
if G < B:
  G, B = B, G
if R < G:
  R, G = G, R
r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)

Submission status: Accepted

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


rgb =  n[0:3]
rgb.sort(reverse=True)
#rgb = list(filter(lambda x:x >= n[3],rgb))

rm = int(n[3]/rgb[0] ) + 1
c = 0
for i in range(rm):
    if i * rgb[0] == n[3]:
            c += 1
            break
        
    for j in range(int((n[3] - i * rgb[0])/rgb[1]) + 1):
        

        if (n[3] - i * rgb[0] - j * rgb[1]) % rgb[2] == 0:
            c += 1

print (c)

Submission status: Accepted

Solution code:
import fractions
z = [0,0,0]
z[0],z[1],z[2],n = map(int,input().split())
z.sort(reverse = 1)
a,b,c = z[2],z[1],z[0]
d = fractions.gcd(b,c)
b = b//d
c = c//d
#print(d)
ans = 0
x,y,z = 0,0,0
while a*x <= n:
  m = n-a*x
  if m%d > 0:
    continue
  m = m//d
  y = 0
  f = 0
  while m-b*y>= 0 and y < c:
    if (m-b*y)%c == 0:
      f = 1
      break
    y += 1
  ans += f*((m-b*y)//c//b+1)
  x += 1
print(ans)

Submission status: Accepted

Solution code:
*rgb, N = map(int, input().split())
rgb.sort()

max_roop = N//rgb[2]+1

c = [1 for n1 in range(max_roop) for n2 in range((N-n1*rgb[2])//rgb[1]+1) if (N-n1*rgb[2]-n2*rgb[1])%rgb[0]==0]

print(len(c))

Submission status: Accepted

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

lst=[r,g,b]
lst.sort()
r=lst[2]
g=lst[1]
b=lst[0]

rlim=n//r
glim=n//g
blim=n//b

"""
blist = [i*b for i in range(blim+1)]

glist = [i*g for i in range(glim+1)]

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return False
"""

cnt=0

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

Submission status: Accepted

Solution code:
# coding:utf-8

if __name__=="__main__":
  R,G,B,N = map(int, input().split())
  count = 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: count+= 1
  print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

r = N // R

c = 0
for i in range(r + 1):
    p = N - i * R
    for j in range(int(p // G) + 1):
        t = p - j * G
        if t == 0:
            c += 1
            break
            
        if t % B == 0:
            c += 1
                
print(c)

Submission status: Accepted

Solution code:
R, G, B, N =list(map(int, input().split()))
# R = 13
# G = 1
# B = 4
# N = 3000
X, Y, Z = sorted([R, G, B], reverse=True)
cnt = 0
for i in range(N//X+1):
    for j in range(N+1):
        tmp = X*i+Y*j 
        if (tmp>N): break
        cnt += ((N-tmp)%Z == 0)
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

R, G, B, N = inpl()
ans = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        tmp = N - R*r - G*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 r in range(int(N/R)+1):
    for g in range(int((N-r*R)/G)+1):
        if N-(r*R+g*G) >= 0 and (N-(r*R+g*G))%B == 0:
        #    print(r,g,(N-(r*R+g*G))%B)
            ans += 1
print(ans)

Submission status: Accepted

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

l.reverse()
r_max=N//l[0]
g_max=N//l[1]
RR=l[0]
GG=l[1]
BB=l[2]
ans=0
for r in range(r_max+1):
    res=N-r*RR
    for g in range(g_max+1):
        x=res-GG*g
        if x<0:
            break
        if x%BB==0:
            ans+=1
            
print(ans)

Submission status: Accepted

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

count = 0

if N % p1 == 0:
    count += 1
for _p1 in range(N // p1, -1, -1):
    existP1 = N - p1 * _p1

    if existP1 >= p2 and existP1 % p2 == 0:
        #print("p1={}*{}, p2={}*{}".format(p1, _p1, p2, existP1 // p2))
        count += 1
    for _p2 in range(existP1 // p2, -1, -1):
        existP2 = existP1 - p2 * _p2
        if existP2 >= p3 and existP2 % p3 == 0:
            count += 1        
            
print(count)

Submission status: Accepted

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

mr = n // r
mg = n // g
mb = n // b
cnt = 0
com = []
for ir in range(mr + 1):
    cr = ir * r
    for ig in range(mg + 1):
        cg = ig * g
        if cr + cg > n:
            break
        if (n - (cr + cg)) % b == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import floor

r, g, b, n = map(int, input().split())
r, g, b = sorted([r, g, b])[::-1]

cnt = 0
for r0 in range(floor(n // r)+1):
  for g0 in range(floor((n-r*r0)// g)+1):
    sum = r * r0 + g * g0
    if sum > n:
      continue
    if (n - sum) % b == 0:
      cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
x = [int(i) for i in input().split()]

ans = 0

rmax = x[3]/x[0]
for i in range(int(rmax)+1):
    gmax = (x[3] -x[0]*i)/x[1]
    for j in range(int(gmax)+1):
        if (x[3]-x[0]*i - x[1]*j)%x[2] == 0:
                ans = ans + 1

print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
from math import ceil
R, G, B, N = map(int, input().split())
ans = 0
for r in list(range(ceil(N/R) + 1))[::-1]:
	for g in range(ceil(N/G) + 1):
		if (N - r*R - g*G) % B == 0 and N >= r*R + g*G:
			ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
# from time import perf_counter


def main():
    r, g, b, n = list(map(int, input().split()))
    count = 0
    x1, x2, x3 = sorted([r, g, b], reverse=True)
    # print(x1, x2, x3)
    for i in range(n // x1 + 1):
        for j in range((n - i) // x2 + 1):
            rest = n - (x1 * i) - (x2 * j)
            # print(f'{x1}*{i} + {x2}*{j} = {n - rest}')
            if rest == 0:
                # print(f'{x1}*{i} + {x2}*{j} + {x3}*0 = {n}')
                count += 1
            else:
                # print(f'{x1}*{i} + {x2}*{j} + {x3}*? = {n}')
                count += (1 if rest > 0 and rest % x3 == 0 else 0)
            # for k in range((n - i - j) // x3 + 1):
                # print(f'{r}*{i} + {g}*{j} + {b}*{k} = {r*i+g*j+k+b*k}')
            #    if x1 * i + x2 * j + x3 * k == n:
            #        count += 1

    print(count)


if __name__ == '__main__':
    # s = perf_counter()
    main()
    # e = perf_counter()
    # print('process:', e - s)

Submission status: Accepted

Solution code:
R, G, B, N = list(map(int, input().split()))
R, G, B = sorted([R, G, B], reverse=True)
ret = 0
for r in range(N//R+1):
    if G == 1:
        ret += N-r+1
    else:
        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:
inputs = [int(x) for x in input().split(' ')]
n = inputs.pop(3)
inputs.sort(reverse=True)

count = 0
for i in range(n // inputs[0] + 1):
  tmp_n1 = n
  tmp_n1 -= i * inputs[0]

  if tmp_n1 == 0:
    count += 1
    continue

  for j in range(tmp_n1  // inputs[1] + 1):
    tmp_n2 = tmp_n1 - j * inputs[1]
    
    if tmp_n2 == 0:
      count += 1
      continue

    if tmp_n2 % inputs[2] == 0:
      count += 1

print(count)

Submission status: Accepted

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

colors = [r, g, b]

cnt = 0

for num_r in range(n // r + 1):
  for num_g in range((n - r * num_r) // g + 1):
    if (n - r * num_r - g * num_g) % b == 0:
      cnt += 1

print(cnt)

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=[0]*3
r[0],r[1],r[2],n=map(int, input().split())
ct=0
r=sorted(r)

for i in range(n//r[2]+1):
    for j in range(min(n//r[1]+1, n-r[2]*i+1)):
        if (n-(i*r[2]+j*r[1]))%r[0]==0 and 0<=(n-(i*r[2]+j*r[1]))<=n+1:
            ct+=1
print(ct)

Submission status: Accepted

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

Submission status: Accepted

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

if r >= g and g >= b:
    pass
elif r >= b and b >= g:
    temp = g
    g = b
    b = temp
else:
    temp = r
    r = g
    g = temp

if (r == 1 and g == 1) or (r == 1 and b == 1) or (g == 1 and b == 1):
    rg = [i + 1 for i in range(n + 1)]
elif (r == 1 and g == 2) or (r == 1 and b == 2) or (g == 1 and b == 2) or (r == 2 and g == 1) or (r == 2 and b == 1) or (g == 2 and b == 1):
    rg = [1 + i // 2 for i in range(n + 1)]
else:
    rg = [0 for _ in range(n + 1)]
    ri = 0
    while ri <= n:
        gi = 0
        while gi <= n - ri:
            rg[ri + gi] += 1
            gi += g
        ri += r

bi = 0
result = 0

while bi <= n:
    total = rg[n - bi]
    result += total
    bi += b

print(result)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
answer = 0
# Rr + Gg + Bb = N ( 0 <= r, 0 <= g, 0 <= b)

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

print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
R, G, B, N = map(int, input().split())
color = [R, G, B]
color.sort(reverse = True)
maxr = N // color[0]
count = 0
for i in range(maxr+1):
    nokori = N - i * color[0]
    maxg = nokori // color[1]
    for j in range(maxg+1):
        nokorinow = nokori - j * color[1]
        amari = nokorinow % color[2]
        if amari == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
r,g,b,n=map(int,input().split())
ctr=0
l=[r,g,b]
l.sort()
num_1=n//l[2]+1
for i in range(num_1):
    for k in range((n-i*l[2])//l[1]+1):
        if (n-i*l[2]-k*l[1])%l[0]==0:
            ctr+=1
print(ctr)

Submission status: Accepted

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


def calc(g, b, n):
  s = 0

  while n >= 0:
    if n % b == 0:
      s += 1

    n -= g

  return s


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

  while n >= 0:
    s += calc(g, b, n)
    n -= r

  print(s)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

print(counter)

Submission status: Accepted

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

score = 0

for g in range(3001):
    for b in range(3001):
        if g + b > 3000:
            break
        if (N - (g * G + b * B)) >= 0 and (N - (g * G + b * B)) % R == 0:
            score += 1

print(score)

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:
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:
import math

R,G,B,N = map(int,input().split())
KR = int(N/R)+1
KG = int(N/G)
KB = int(N/B)
c = 0
# for i in range(KR):
#     k = int(N/R)-i
#     for j in range(int((N-R*i)/G)):
#         while R*i + G*j + B*k >= N:
#             k -= 1
#             if R*i + G*j + B*k == N:c+=1
#
#
#     for j in range(KG):
#
#         for k in list(range(KB)).reverse():
#             if R*i + G*j + B*k == N:
#                 c += 1
for i in range(KR):
    for j in range(int((N-R*i)/G)+1):
        tmp = N-R*i-G*j
        if tmp >= 0 and tmp%B == 0:
            c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
R,G,B,N = map(int,input().split())
A = [R,G,B]
A.sort()
R = A[2]
G = A[1]
B = A[0]
rmax = N//R
gmax = N//G
bmax = N//B

cnt = 0

if R == 1:
    print((N+1)*(N+2)//2)
    exit()

for i in range(rmax+1):
    for j in range(gmax+1):
        if R*i + G*j > N:
            continue
        if ((N-R*i-G*j)%B == 0) and ((N-R*i-G*j)//B <= bmax):
            cnt += 1
print(cnt)

Submission status: Accepted

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

def func(n, boxes):
    b = boxes[0]

    if len(boxes) == 1:
        return 1 if n % b == 0 else 0
    else:
        return sum([func(n - i, boxes[1:]) for i in range(0, n+1, b)])
    
arr = [R, G, B]
arr.sort()
result = func(N, arr)

print(result)

Submission status: Accepted

Solution code:
R, G,B,N = map(int, input().split())
l = [R,G,B]
l = sorted(l)
ma = l[2]
mi = l[0]
mid = l[1]
id = N // ma
count = 0
for i in range(id+1):
    res = N - ma * i
    if res >= mid:
        for j in range(res//mid+1):
            if res % mi == 0:
                count += 1
            res -= mid
    else:
        if res % mi == 0:
            count +=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d=list(map(int,input().split()))
e=[a,b,c]
w,r,t=e[0],e[1],e[2]
u=0
for i in range(d//a+1):
    y=d-(a*i)
    for o in range(y+1):
        x=y-(b*o)
        if x%c==0 and x>=0:
            u+=1
print(u)

Submission status: Accepted

Solution code:
data = list(map(int, input().split()))
R = data[0]
G = data[1]
B = data[2]
N = data[3]

# R * a + G * b + B * c 

a = N // R + 1
b = N // G + 1
# c = N // B + 1
res = 0

def check(Ri):
    global res
    Rx = Ri * R
    if Rx > N:
        return
    for Gi in range(b):
        Gx = Gi * G
        if Rx + Gx > N:
            break
        if (N - Rx - Gx) % B == 0:
            res = res + 1

[check(Ri) for Ri in range(a)]

print(res)